mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-24 17:48:30 +02:00
Fix UpdateSource for sync upserts
This commit is contained in:
@@ -921,10 +921,17 @@ async fn cmd_import_data<R: Runtime>(
|
|||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let upserted =
|
let upserted = batch_upsert(
|
||||||
batch_upsert(&window, workspaces, environments, folders, http_requests, grpc_requests)
|
&window,
|
||||||
.await
|
workspaces,
|
||||||
.map_err(|e| e.to_string())?;
|
environments,
|
||||||
|
folders,
|
||||||
|
http_requests,
|
||||||
|
grpc_requests,
|
||||||
|
&UpdateSource::Import,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.map_err(|e| e.to_string())?;
|
||||||
|
|
||||||
analytics::track_event(
|
analytics::track_event(
|
||||||
&window,
|
&window,
|
||||||
|
|||||||
@@ -2013,6 +2013,7 @@ pub enum UpdateSource {
|
|||||||
Window,
|
Window,
|
||||||
Plugin,
|
Plugin,
|
||||||
Background,
|
Background,
|
||||||
|
Import,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn emit_upserted_model<R: Runtime>(
|
fn emit_upserted_model<R: Runtime>(
|
||||||
@@ -2100,11 +2101,12 @@ pub async fn batch_upsert<R: Runtime>(
|
|||||||
folders: Vec<Folder>,
|
folders: Vec<Folder>,
|
||||||
http_requests: Vec<HttpRequest>,
|
http_requests: Vec<HttpRequest>,
|
||||||
grpc_requests: Vec<GrpcRequest>,
|
grpc_requests: Vec<GrpcRequest>,
|
||||||
|
update_source: &UpdateSource,
|
||||||
) -> Result<BatchUpsertResult> {
|
) -> Result<BatchUpsertResult> {
|
||||||
let mut imported_resources = BatchUpsertResult::default();
|
let mut imported_resources = BatchUpsertResult::default();
|
||||||
|
|
||||||
for v in workspaces {
|
for v in workspaces {
|
||||||
let x = upsert_workspace(&window, v, &UpdateSource::Window).await?;
|
let x = upsert_workspace(&window, v, update_source).await?;
|
||||||
imported_resources.workspaces.push(x.clone());
|
imported_resources.workspaces.push(x.clone());
|
||||||
}
|
}
|
||||||
info!("Imported {} workspaces", imported_resources.workspaces.len());
|
info!("Imported {} workspaces", imported_resources.workspaces.len());
|
||||||
@@ -2120,7 +2122,7 @@ pub async fn batch_upsert<R: Runtime>(
|
|||||||
if let Some(_) = imported_resources.environments.iter().find(|f| f.id == v.id) {
|
if let Some(_) = imported_resources.environments.iter().find(|f| f.id == v.id) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let x = upsert_environment(&window, v, &UpdateSource::Window).await?;
|
let x = upsert_environment(&window, v, update_source).await?;
|
||||||
imported_resources.environments.push(x.clone());
|
imported_resources.environments.push(x.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2137,20 +2139,20 @@ pub async fn batch_upsert<R: Runtime>(
|
|||||||
if let Some(_) = imported_resources.folders.iter().find(|f| f.id == v.id) {
|
if let Some(_) = imported_resources.folders.iter().find(|f| f.id == v.id) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let x = upsert_folder(&window, v, &UpdateSource::Window).await?;
|
let x = upsert_folder(&window, v, update_source).await?;
|
||||||
imported_resources.folders.push(x.clone());
|
imported_resources.folders.push(x.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
info!("Imported {} folders", imported_resources.folders.len());
|
info!("Imported {} folders", imported_resources.folders.len());
|
||||||
|
|
||||||
for v in http_requests {
|
for v in http_requests {
|
||||||
let x = upsert_http_request(&window, v, &UpdateSource::Window).await?;
|
let x = upsert_http_request(&window, v, update_source).await?;
|
||||||
imported_resources.http_requests.push(x.clone());
|
imported_resources.http_requests.push(x.clone());
|
||||||
}
|
}
|
||||||
info!("Imported {} http_requests", imported_resources.http_requests.len());
|
info!("Imported {} http_requests", imported_resources.http_requests.len());
|
||||||
|
|
||||||
for v in grpc_requests {
|
for v in grpc_requests {
|
||||||
let x = upsert_grpc_request(&window, v, &UpdateSource::Window).await?;
|
let x = upsert_grpc_request(&window, v, update_source).await?;
|
||||||
imported_resources.grpc_requests.push(x.clone());
|
imported_resources.grpc_requests.push(x.clone());
|
||||||
}
|
}
|
||||||
info!("Imported {} grpc_requests", imported_resources.grpc_requests.len());
|
info!("Imported {} grpc_requests", imported_resources.grpc_requests.len());
|
||||||
|
|||||||
@@ -416,6 +416,7 @@ pub(crate) async fn apply_sync_ops<R: Runtime>(
|
|||||||
folders_to_upsert,
|
folders_to_upsert,
|
||||||
http_requests_to_upsert,
|
http_requests_to_upsert,
|
||||||
grpc_requests_to_upsert,
|
grpc_requests_to_upsert,
|
||||||
|
&UpdateSource::Sync,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
|||||||
@@ -65,7 +65,6 @@ export const syncWorkspace = createFastMutation<
|
|||||||
mutationKey: [],
|
mutationKey: [],
|
||||||
mutationFn: async ({ workspaceId, syncDir }) => {
|
mutationFn: async ({ workspaceId, syncDir }) => {
|
||||||
const ops = (await calculateSync(workspaceId, syncDir)) ?? [];
|
const ops = (await calculateSync(workspaceId, syncDir)) ?? [];
|
||||||
console.log('SYNCING WORKSPACE', ops);
|
|
||||||
if (ops.length === 0) {
|
if (ops.length === 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import { atom, useAtom } from 'jotai';
|
import { atom, useAtom } from 'jotai';
|
||||||
import { useRef, useState } from 'react';
|
import { useRef } from 'react';
|
||||||
|
import type { Components } from 'react-markdown';
|
||||||
import Markdown from 'react-markdown';
|
import Markdown from 'react-markdown';
|
||||||
import remarkGfm from 'remark-gfm';
|
import remarkGfm from 'remark-gfm';
|
||||||
|
import { useStateWithDeps } from '../hooks/useStateWithDeps';
|
||||||
import { Button } from './core/Button';
|
import { Button } from './core/Button';
|
||||||
import type { EditorProps } from './core/Editor/Editor';
|
import type { EditorProps } from './core/Editor/Editor';
|
||||||
import { Editor } from './core/Editor/Editor';
|
import { Editor } from './core/Editor/Editor';
|
||||||
@@ -30,12 +32,14 @@ export function MarkdownEditor({
|
|||||||
name,
|
name,
|
||||||
defaultMode = 'preview',
|
defaultMode = 'preview',
|
||||||
doneButtonLabel = 'Save',
|
doneButtonLabel = 'Save',
|
||||||
|
forceUpdateKey,
|
||||||
...editorProps
|
...editorProps
|
||||||
}: Props) {
|
}: Props) {
|
||||||
const containerRef = useRef<HTMLDivElement>(null);
|
|
||||||
const [rawViewMode, setViewMode] = useAtom(viewModeAtom);
|
const [rawViewMode, setViewMode] = useAtom(viewModeAtom);
|
||||||
|
const [value, setValue] = useStateWithDeps<string>(defaultValue, [forceUpdateKey]);
|
||||||
|
|
||||||
|
const containerRef = useRef<HTMLDivElement>(null);
|
||||||
const viewMode = rawViewMode[name] ?? defaultMode;
|
const viewMode = rawViewMode[name] ?? defaultMode;
|
||||||
const [value, setValue] = useState<string>(defaultValue);
|
|
||||||
|
|
||||||
const editor = (
|
const editor = (
|
||||||
<Editor
|
<Editor
|
||||||
@@ -46,6 +50,7 @@ export function MarkdownEditor({
|
|||||||
defaultValue={defaultValue}
|
defaultValue={defaultValue}
|
||||||
onChange={setValue}
|
onChange={setValue}
|
||||||
autoFocus
|
autoFocus
|
||||||
|
forceUpdateKey={forceUpdateKey}
|
||||||
{...editorProps}
|
{...editorProps}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
@@ -55,21 +60,7 @@ export function MarkdownEditor({
|
|||||||
<p className="text-text-subtle">No description</p>
|
<p className="text-text-subtle">No description</p>
|
||||||
) : (
|
) : (
|
||||||
<Prose className="max-w-xl overflow-y-auto max-h-full">
|
<Prose className="max-w-xl overflow-y-auto max-h-full">
|
||||||
<Markdown
|
<Markdown remarkPlugins={[remarkGfm]} components={markdownComponents}>
|
||||||
remarkPlugins={[remarkGfm]}
|
|
||||||
components={{
|
|
||||||
a: ({ href, children, ...rest }) => {
|
|
||||||
if (href && !href.match(/https?:\/\//)) {
|
|
||||||
href = `http://${href}`;
|
|
||||||
}
|
|
||||||
return (
|
|
||||||
<a target="_blank" rel="noreferrer noopener" href={href} {...rest}>
|
|
||||||
{children}
|
|
||||||
</a>
|
|
||||||
);
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{value}
|
{value}
|
||||||
</Markdown>
|
</Markdown>
|
||||||
</Prose>
|
</Prose>
|
||||||
@@ -131,3 +122,17 @@ export function MarkdownEditor({
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const markdownComponents: Partial<Components> = {
|
||||||
|
// Ensure links open in external browser by adding target="_blank"
|
||||||
|
a: ({ href, children, ...rest }) => {
|
||||||
|
if (href && !href.match(/https?:\/\//)) {
|
||||||
|
href = `http://${href}`;
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<a target="_blank" rel="noreferrer noopener" href={href} {...rest}>
|
||||||
|
{children}
|
||||||
|
</a>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|||||||
@@ -485,9 +485,9 @@ export const RequestPane = memo(function RequestPane({
|
|||||||
<Input
|
<Input
|
||||||
label="Request Name"
|
label="Request Name"
|
||||||
hideLabel
|
hideLabel
|
||||||
forceUpdateKey={forceUpdateKey}
|
forceUpdateKey={updateKey}
|
||||||
defaultValue={activeRequest.name}
|
defaultValue={activeRequest.name}
|
||||||
className="font-sans !text-xl"
|
className="font-sans !text-2xl"
|
||||||
inputWrapperClassName="!px-0"
|
inputWrapperClassName="!px-0"
|
||||||
containerClassName="border-0"
|
containerClassName="border-0"
|
||||||
placeholder={fallbackRequestName(activeRequest)}
|
placeholder={fallbackRequestName(activeRequest)}
|
||||||
@@ -499,7 +499,7 @@ export const RequestPane = memo(function RequestPane({
|
|||||||
placeholder="Request description"
|
placeholder="Request description"
|
||||||
defaultValue={activeRequest.description}
|
defaultValue={activeRequest.description}
|
||||||
stateKey={`description.${activeRequest.id}`}
|
stateKey={`description.${activeRequest.id}`}
|
||||||
forceUpdateKey={forceUpdateKey}
|
forceUpdateKey={updateKey}
|
||||||
onChange={(description) =>
|
onChange={(description) =>
|
||||||
updateRequest({ id: activeRequestId, update: { description } })
|
updateRequest({ id: activeRequestId, update: { description } })
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,14 @@ export function WorkspaceSettingsDialog({ workspaceId, hide }: Props) {
|
|||||||
const { mutate: updateWorkspace } = useUpdateWorkspace(workspaceId ?? null);
|
const { mutate: updateWorkspace } = useUpdateWorkspace(workspaceId ?? null);
|
||||||
const { mutateAsync: deleteActiveWorkspace } = useDeleteActiveWorkspace();
|
const { mutateAsync: deleteActiveWorkspace } = useDeleteActiveWorkspace();
|
||||||
|
|
||||||
if (workspace == null) return null;
|
if (workspace == null) {
|
||||||
|
return (
|
||||||
|
<Banner color="danger">
|
||||||
|
<InlineCode>Workspace</InlineCode> not found
|
||||||
|
</Banner>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (workspaceMeta == null)
|
if (workspaceMeta == null)
|
||||||
return (
|
return (
|
||||||
<Banner color="danger">
|
<Banner color="danger">
|
||||||
|
|||||||
@@ -42,8 +42,6 @@ export function Tabs({
|
|||||||
}: Props) {
|
}: Props) {
|
||||||
const ref = useRef<HTMLDivElement | null>(null);
|
const ref = useRef<HTMLDivElement | null>(null);
|
||||||
|
|
||||||
value = value ?? tabs[0]?.value;
|
|
||||||
|
|
||||||
// Update tabs when value changes
|
// Update tabs when value changes
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const tabs = ref.current?.querySelectorAll<HTMLDivElement>(`[data-tab]`);
|
const tabs = ref.current?.querySelectorAll<HTMLDivElement>(`[data-tab]`);
|
||||||
|
|||||||
Reference in New Issue
Block a user