Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Tauri code after search endpoint changes #90

Merged
merged 5 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,18 @@ yarn # Install dependencies
yarn run dev
```

Alternatively, you can use the Tauri-based desktop app by running:

```bash
cd desktop
# Install dependencies
yarn
# run the Tauri dev server
yarn run tauri dev
```

(See the [desktop README](desktop/README.md) for more details.)

## Terminology

When configuring or working on Terraphim, you will encounter the following
Expand Down
3 changes: 3 additions & 0 deletions crates/terraphim_config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ pub enum TerraphimConfigError {

#[error("Url error")]
Url(#[from] url::ParseError),

#[error("IO error")]
Io(#[from] std::io::Error),
}

/// A role is a collection of settings for a specific user
Expand Down
1 change: 1 addition & 0 deletions desktop/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ node_modules
dist
dist-ssr
*.local
vite.config.*.mjs

# Editor directories and files
.vscode/*
Expand Down
28 changes: 24 additions & 4 deletions desktop/src-tauri/src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,31 @@ pub struct ConfigResponse {
pub config: Config,
}

/// Response type for showing the search results
///
/// This is used when searching for documents
/// and returning the results
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct SearchResponse {
/// Status of the search
pub status: Status,
/// The search results
pub results: Vec<Document>,
}

/// Search All TerraphimGraphs defined in a config by query param
#[command]
pub async fn search(
config_state: State<'_, ConfigState>,
search_query: SearchQuery,
) -> Result<Vec<Document>> {
) -> Result<SearchResponse> {
log::info!("Search called with {:?}", search_query);
let terraphim_service = TerraphimService::new(config_state.inner().clone());
Ok(terraphim_service.search(&search_query).await?)
let results = terraphim_service.search(&search_query).await?;
Ok(SearchResponse {
status: Status::Success,
results,
})
}

#[command]
Expand All @@ -89,8 +105,12 @@ pub async fn get_config(config_state: tauri::State<'_, ConfigState>) -> Result<C
pub async fn update_config(
config_state: tauri::State<'_, ConfigState>,
config_new: Config,
) -> Result<terraphim_config::Config> {
) -> Result<ConfigResponse> {
log::info!("Update config called with {:?}", config_new);
let terraphim_service = TerraphimService::new(config_state.inner().clone());
Ok(terraphim_service.update_config(config_new).await?)
let config = terraphim_service.update_config(config_new).await?;
Ok(ConfigResponse {
status: Status::Success,
config,
})
}
16 changes: 13 additions & 3 deletions desktop/src-tauri/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,23 @@ use terraphim_config::{
};
use terraphim_types::{KnowledgeGraphInputType, RelevanceFunction};

/// The path to the default haystack directory
// TODO: Replace this with a file-based config loader based on `twelf` in the
// future
const DEFAULT_HAYSTACK_PATH: &str = "../../docs/";

/// Load the default config
///
// TODO: Replace this with a file-based config loader based on `twelf` in the
// future
pub(crate) fn load_config() -> Result<Config, TerraphimConfigError> {
let automata_path = AutomataPath::from_local("data/term_to_id.json");

// Create the path to the default haystack directory
// by concating the current directory with the default haystack path
let docs_path = std::env::current_dir()?.join(DEFAULT_HAYSTACK_PATH);
println!("Docs path: {:?}", docs_path);

ConfigBuilder::new()
.global_shortcut("Ctrl+X")
.add_role(
Expand All @@ -33,7 +43,7 @@ pub(crate) fn load_config() -> Result<Config, TerraphimConfigError> {
publish: true,
},
haystacks: vec![Haystack {
path: PathBuf::from("localsearch"),
path: docs_path.clone(),
service: ServiceType::Ripgrep,
}],
extra: AHashMap::new(),
Expand All @@ -55,7 +65,7 @@ pub(crate) fn load_config() -> Result<Config, TerraphimConfigError> {
publish: true,
},
haystacks: vec![Haystack {
path: PathBuf::from("localsearch"),
path: docs_path.clone(),
service: ServiceType::Ripgrep,
}],
extra: AHashMap::new(),
Expand All @@ -77,7 +87,7 @@ pub(crate) fn load_config() -> Result<Config, TerraphimConfigError> {
publish: true,
},
haystacks: vec![Haystack {
path: PathBuf::from("/tmp/system_operator/pages/"),
path: docs_path,
service: ServiceType::Ripgrep,
}],
extra: AHashMap::new(),
Expand Down
5 changes: 3 additions & 2 deletions desktop/src/lib/Search/Search.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { input, is_tauri, role, serverUrl } from "../stores";
import ResultItem from "./ResultItem.svelte";
import type { Document, SearchResponse } from "./SearchResult";
import logo from "/public/assets/terraphim_gray.png";
import logo from "/assets/terraphim_gray.png";

let results: Document[] = [];
let error: string | null = null;
Expand Down Expand Up @@ -73,7 +73,7 @@
}
}
</script>

<form on:submit|preventDefault={$input}>
<Field>
<Input
type="search"
Expand All @@ -84,6 +84,7 @@
autofocus
/>
</Field>
</form>
{#if error}
<p class="error">{error}</p>
{:else if results.length}
Expand Down
156 changes: 0 additions & 156 deletions terraphim_server/dist/assets/index-6464eebb.js

This file was deleted.

2 changes: 1 addition & 1 deletion terraphim_server/dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<link rel="icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Svelte + TS + Vite App</title>
<script type="module" crossorigin src="/assets/index-6464eebb.js"></script>
<script type="module" crossorigin src="/assets/index-8e6532b7.js"></script>
<link rel="stylesheet" href="/assets/index-36fd5f08.css">
</head>
<body>
Expand Down
Loading