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