Skip to content

Commit

Permalink
Environments data model
Browse files Browse the repository at this point in the history
  • Loading branch information
gschier committed Oct 23, 2023
1 parent afe6a3b commit 8328d20
Show file tree
Hide file tree
Showing 26 changed files with 132 additions and 1,179 deletions.
1,000 changes: 43 additions & 957 deletions src-tauri/Cargo.lock

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ http = "0.2.8"
reqwest = { version = "0.11.14", features = ["json"] }
tokio = { version = "1.25.0", features = ["sync"] }
futures = "0.3.26"
deno_core = "0.222.0"
deno_ast = { version = "0.29.5", features = ["transpiling"] }
sqlx = { version = "0.6.2", features = ["sqlite", "runtime-tokio-rustls", "json", "chrono", "time", "offline"] }
uuid = "1.3.0"
rand = "0.8.5"
Expand Down
Binary file modified src-tauri/icons/128x128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src-tauri/icons/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src-tauri/icons/32x32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src-tauri/icons/Square107x107Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src-tauri/icons/Square142x142Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src-tauri/icons/Square150x150Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src-tauri/icons/Square284x284Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src-tauri/icons/Square30x30Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src-tauri/icons/Square310x310Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src-tauri/icons/Square44x44Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src-tauri/icons/Square71x71Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src-tauri/icons/Square89x89Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src-tauri/icons/StoreLogo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src-tauri/icons/icon.icns
Binary file not shown.
Binary file modified src-tauri/icons/icon.ico
Binary file not shown.
Binary file modified src-tauri/icons/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion src-tauri/plugins/plugin.ts

This file was deleted.

51 changes: 28 additions & 23 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use reqwest::redirect::Policy;
use serde::Serialize;
use sqlx::migrate::Migrator;
use sqlx::sqlite::SqlitePoolOptions;
use sqlx::types::Json;
use sqlx::types::{Json, JsonValue};
use sqlx::{Pool, Sqlite};
use tauri::regex::Regex;
#[cfg(target_os = "macos")]
Expand All @@ -34,7 +34,6 @@ use window_ext::WindowExt;
use crate::models::generate_id;

mod models;
mod runtime;
mod window_ext;

#[derive(serde::Serialize)]
Expand Down Expand Up @@ -192,24 +191,6 @@ async fn actually_send_ephemeral_request(

let raw_response = client.execute(sendable_req).await;

let plugin_rel_path = "plugins/plugin.ts";
let plugin_path = match app_handle.path_resolver().resolve_resource(plugin_rel_path) {
Some(p) => p,
None => {
return response_err(
response,
format!("Plugin not found at {}", plugin_rel_path),
&app_handle,
pool,
)
.await;
}
};

if let Err(e) = runtime::run_plugin_sync(plugin_path.to_str().unwrap()) {
return response_err(response, e.to_string(), &app_handle, pool).await;
}

match raw_response {
Ok(v) => {
let mut response = response.clone();
Expand Down Expand Up @@ -478,6 +459,29 @@ async fn requests(
.map_err(|e| e.to_string())
}

#[tauri::command]
async fn environments(
workspace_id: &str,
db_instance: State<'_, Mutex<Pool<Sqlite>>>,
) -> Result<Vec<models::Environment>, String> {
let pool = &*db_instance.lock().await;
let environments = models::find_environments(workspace_id, pool)
.await
.expect("Failed to find environments");

println!("");
if environments.is_empty() {
println!("CREATING DEFAULT ENVIRONMENT");
let data: HashMap<String, JsonValue> = HashMap::new();
let environment = models::create_environment(workspace_id, "Default", data, pool)
.await
.expect("Failed to create default environment");
Ok(vec![environment])
} else {
Ok(environments)
}
}

#[tauri::command]
async fn get_request(
id: &str,
Expand Down Expand Up @@ -603,10 +607,12 @@ fn main() {
})
})
.invoke_handler(tauri::generate_handler![
new_window,
workspaces,
get_request,
environments,
requests,
responses,
new_window,
get_request,
send_request,
send_ephemeral_request,
duplicate_request,
Expand All @@ -617,7 +623,6 @@ fn main() {
update_workspace,
update_request,
delete_request,
responses,
get_key_value,
set_key_value,
delete_response,
Expand Down
16 changes: 0 additions & 16 deletions src-tauri/src/runtime.js

This file was deleted.

149 changes: 0 additions & 149 deletions src-tauri/src/runtime.rs

This file was deleted.

12 changes: 6 additions & 6 deletions src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"package": {
"productName": "Yaak",
"version": "2023.0.19"
"version": "2023.0.20"
},
"tauri": {
"windows": [],
Expand All @@ -18,8 +18,10 @@
"all": true
},
"protocol": {
"assetScope": ["$APPDATA/responses/*"],
"asset": true
"assetScope": [
"$APPDATA/responses/*"
],
"asset": true
},
"fs": {
"readFile": true,
Expand Down Expand Up @@ -51,7 +53,6 @@
"identifier": "co.schier.yaak",
"longDescription": "The best cross-platform visual API client",
"resources": [
"plugins/*",
"migrations/*"
],
"shortDescription": "The best API client",
Expand All @@ -76,8 +77,7 @@
"timestampUrl": ""
}
},
"security": {
},
"security": {},
"systemTray": {
"iconAsTemplate": true,
"iconPath": "icons/icon.png"
Expand Down
12 changes: 6 additions & 6 deletions src-web/components/WorkspaceActionsDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ export const WorkspaceActionsDropdown = memo(function WorkspaceDropdown({ classN
workspaces.length <= 1
? []
: [
...workspaceItems,
{
type: 'separator',
label: activeWorkspace?.name,
},
];
...workspaceItems,
{
type: 'separator',
label: activeWorkspace?.name,
},
];

return [
...activeWorkspaceItems,
Expand Down
22 changes: 22 additions & 0 deletions src-web/hooks/useEnvironments.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { useQuery } from '@tanstack/react-query';
import { invoke } from '@tauri-apps/api';
import type { Environment } from '../lib/models';
import { useActiveWorkspaceId } from './useActiveWorkspaceId';

export function environmentsQueryKey({ workspaceId }: { workspaceId: string }) {
return ['environments', { workspaceId }];
}

export function useEnvironments() {
const workspaceId = useActiveWorkspaceId();
return (
useQuery({
enabled: workspaceId != null,
queryKey: environmentsQueryKey({ workspaceId: workspaceId ?? 'n/a' }),
queryFn: async () => {
if (workspaceId == null) return [];
return (await invoke('environments', { workspaceId })) as Environment[];
},
}).data ?? []
);
}
Loading

0 comments on commit 8328d20

Please sign in to comment.