Fixed some routing and introspection requests

This commit is contained in:
Gregory Schier
2023-10-25 21:53:18 -07:00
parent 2f998ddfb6
commit 2f64f45aba
8 changed files with 2076 additions and 7274 deletions

9280
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -17,13 +17,17 @@
"prepare": "husky install" "prepare": "husky install"
}, },
"dependencies": { "dependencies": {
"@codemirror/autocomplete": "6.2.0",
"@codemirror/commands": "^6.2.1", "@codemirror/commands": "^6.2.1",
"@codemirror/lang-html": "^6.4.2", "@codemirror/lang-html": "^6.4.2",
"@codemirror/lang-javascript": "^6.1.4", "@codemirror/lang-javascript": "^6.1.4",
"@codemirror/lang-json": "^6.0.1", "@codemirror/lang-json": "^6.0.1",
"@codemirror/lang-xml": "^6.0.2", "@codemirror/lang-xml": "^6.0.2",
"@codemirror/language": "^6.6.0", "@codemirror/language": "6.2.1",
"@codemirror/lint": "6.2.1",
"@codemirror/search": "^6.2.3", "@codemirror/search": "^6.2.3",
"@codemirror/state": "6.2.0",
"@codemirror/view": "6.2.1",
"@lezer/generator": "^1.2.2", "@lezer/generator": "^1.2.2",
"@lezer/highlight": "^1.1.3", "@lezer/highlight": "^1.1.3",
"@lezer/lr": "^1.3.3", "@lezer/lr": "^1.3.3",
@@ -35,10 +39,9 @@
"@tanstack/react-query-devtools": "^4.28.0", "@tanstack/react-query-devtools": "^4.28.0",
"@tanstack/react-query-persist-client": "^4.28.0", "@tanstack/react-query-persist-client": "^4.28.0",
"@tauri-apps/api": "^1.5.1", "@tauri-apps/api": "^1.5.1",
"@vitejs/plugin-react": "^3.1.0",
"buffer": "^6.0.3", "buffer": "^6.0.3",
"classnames": "^2.3.2", "classnames": "^2.3.2",
"cm6-graphql": "^0.0.4-canary-b30a2325.0", "cm6-graphql": "^0.0.10",
"codemirror": "^6.0.1", "codemirror": "^6.0.1",
"focus-trap-react": "^10.1.1", "focus-trap-react": "^10.1.1",
"format-graphql": "^1.4.0", "format-graphql": "^1.4.0",
@@ -56,7 +59,7 @@
}, },
"devDependencies": { "devDependencies": {
"@tailwindcss/nesting": "^0.0.0-insiders.565cd3e", "@tailwindcss/nesting": "^0.0.0-insiders.565cd3e",
"@tauri-apps/cli": "^1.5.4", "@tauri-apps/cli": "^1.5.6",
"@types/node": "^18.7.10", "@types/node": "^18.7.10",
"@types/papaparse": "^5.3.7", "@types/papaparse": "^5.3.7",
"@types/parse-color": "^1.0.1", "@types/parse-color": "^1.0.1",
@@ -66,6 +69,7 @@
"@types/uuid": "^9.0.1", "@types/uuid": "^9.0.1",
"@typescript-eslint/eslint-plugin": "^5.57.0", "@typescript-eslint/eslint-plugin": "^5.57.0",
"@typescript-eslint/parser": "^5.57.0", "@typescript-eslint/parser": "^5.57.0",
"@vitejs/plugin-react": "^3.1.0",
"autoprefixer": "^10.4.13", "autoprefixer": "^10.4.13",
"eslint": "^8.34.0", "eslint": "^8.34.0",
"eslint-config-prettier": "^8.6.0", "eslint-config-prettier": "^8.6.0",

View File

@@ -83,9 +83,13 @@ async fn actually_send_ephemeral_request(
let environments = find_environments(&request.workspace_id, pool) let environments = find_environments(&request.workspace_id, pool)
.await .await
.expect("Failed to find environments"); .expect("Failed to find environments");
let environment: models::Environment = environments.first().unwrap().clone();
let mut url_string = render::render(&request.url, environment.clone()); // TODO: Use active environment
let environment = environments.first();
let mut url_string = match environment {
Some(e) => render::render(&request.url, e.clone()),
None => request.url.to_string(),
};
if !url_string.starts_with("http://") && !url_string.starts_with("https://") { if !url_string.starts_with("http://") && !url_string.starts_with("https://") {
url_string = format!("http://{}", url_string); url_string = format!("http://{}", url_string);

View File

@@ -4,8 +4,8 @@ use crate::models::Environment;
pub fn render(template: &str, environment: Environment) -> String { pub fn render(template: &str, environment: Environment) -> String {
let variables = environment.data; let variables = environment.data;
let re = Regex::new(r"\$\{\[\s*([^]\s]+)\s*]}").expect("Failed to create regex"); Regex::new(r"\$\{\[\s*([^]\s]+)\s*]}")
let rendered = re .expect("Failed to create regex")
.replace(template, |caps: &tauri::regex::Captures| { .replace(template, |caps: &tauri::regex::Captures| {
let key = caps.get(1).unwrap().as_str(); let key = caps.get(1).unwrap().as_str();
match variables.get(key) { match variables.get(key) {
@@ -19,7 +19,5 @@ pub fn render(template: &str, environment: Environment) -> String {
None => "".to_string(), None => "".to_string(),
} }
}) })
.to_string(); .to_string()
rendered
} }

View File

@@ -53,7 +53,7 @@ function WorkspaceOrRedirect() {
const request = requests.find((r) => r.id === recentRequests[0]); const request = requests.find((r) => r.id === recentRequests[0]);
const routes = useAppRoutes(); const routes = useAppRoutes();
if (request === undefined || environmentId === null) { if (request === undefined) {
return <Workspace />; return <Workspace />;
} }
@@ -61,7 +61,7 @@ function WorkspaceOrRedirect() {
<Navigate <Navigate
to={routes.paths.request({ to={routes.paths.request({
workspaceId: request.workspaceId, workspaceId: request.workspaceId,
environmentId, environmentId: environmentId ?? undefined,
requestId: request.id, requestId: request.id,
})} })}
/> />

View File

@@ -57,7 +57,6 @@ export const DialogProvider = ({ children }: { children: React.ReactNode }) => {
function DialogInstance({ id, render, ...props }: DialogEntry) { function DialogInstance({ id, render, ...props }: DialogEntry) {
const { actions } = useContext(DialogContext); const { actions } = useContext(DialogContext);
const children = render({ hide: () => actions.hide(id) }); const children = render({ hide: () => actions.hide(id) });
console.log("ACITEV WORKSPAXCE ID 2", useActiveWorkspaceId());
return ( return (
<Dialog open onClose={() => actions.hide(id)} {...props}> <Dialog open onClose={() => actions.hide(id)} {...props}>
{children} {children}

View File

@@ -21,7 +21,9 @@ type Props = {
className?: string; className?: string;
}; };
export const WorkspaceActionsDropdown = memo(function WorkspaceActionsDropdown({ className }: Props) { export const WorkspaceActionsDropdown = memo(function WorkspaceActionsDropdown({
className,
}: Props) {
const workspaces = useWorkspaces(); const workspaces = useWorkspaces();
const activeWorkspace = useActiveWorkspace(); const activeWorkspace = useActiveWorkspace();
const activeWorkspaceId = activeWorkspace?.id ?? null; const activeWorkspaceId = activeWorkspace?.id ?? null;
@@ -55,7 +57,10 @@ export const WorkspaceActionsDropdown = memo(function WorkspaceActionsDropdown({
color="gray" color="gray"
onClick={() => { onClick={() => {
hide(); hide();
routes.navigate('workspace', { workspaceId: w.id, environmentId }); routes.navigate('workspace', {
workspaceId: w.id,
environmentId: environmentId ?? undefined,
});
}} }}
> >
This Window This Window
@@ -68,7 +73,10 @@ export const WorkspaceActionsDropdown = memo(function WorkspaceActionsDropdown({
onClick={async () => { onClick={async () => {
hide(); hide();
await invoke('new_window', { await invoke('new_window', {
url: routes.paths.workspace({ workspaceId: w.id, environmentId }), url: routes.paths.workspace({
workspaceId: w.id,
environmentId: environmentId ?? undefined,
}),
}); });
}} }}
> >
@@ -85,12 +93,12 @@ export const WorkspaceActionsDropdown = memo(function WorkspaceActionsDropdown({
workspaces.length <= 1 workspaces.length <= 1
? [] ? []
: [ : [
...workspaceItems, ...workspaceItems,
{ {
type: 'separator', type: 'separator',
label: activeWorkspace?.name, label: activeWorkspace?.name,
}, },
]; ];
return [ return [
...activeWorkspaceItems, ...activeWorkspaceItems,
@@ -138,14 +146,15 @@ export const WorkspaceActionsDropdown = memo(function WorkspaceActionsDropdown({
}, },
]; ];
}, [ }, [
workspaces,
activeWorkspace?.name, activeWorkspace?.name,
createWorkspace,
deleteWorkspace.mutate, deleteWorkspace.mutate,
dialog, dialog,
routes, environmentId,
prompt, prompt,
routes,
updateWorkspace, updateWorkspace,
createWorkspace, workspaces,
]); ]);
return ( return (

View File

@@ -6,7 +6,7 @@ import type { Environment } from '../lib/models';
export type RouteParamsWorkspace = { export type RouteParamsWorkspace = {
workspaceId: string; workspaceId: string;
environmentId: string | null; environmentId?: string;
}; };
export type RouteParamsRequest = RouteParamsWorkspace & { export type RouteParamsRequest = RouteParamsWorkspace & {
@@ -55,7 +55,7 @@ export function useAppRoutes() {
this.navigate('request', { this.navigate('request', {
workspaceId, workspaceId,
environmentId: environmentId ?? null, environmentId: environmentId ?? null,
requestId: requestId, requestId,
}); });
} }
}, },