Git support (#143)

This commit is contained in:
Gregory Schier
2025-02-07 07:59:48 -08:00
committed by GitHub
parent cffc7714c1
commit 1a7c27663a
111 changed files with 4264 additions and 372 deletions

View File

@@ -48,10 +48,10 @@ export const createFolder = createFastMutation<
export const syncWorkspace = createFastMutation<
void,
void,
{ workspaceId: string; syncDir: string }
{ workspaceId: string; syncDir: string; force?: boolean }
>({
mutationKey: [],
mutationFn: async ({ workspaceId, syncDir }) => {
mutationFn: async ({ workspaceId, syncDir, force }) => {
const ops = (await calculateSync(workspaceId, syncDir)) ?? [];
if (ops.length === 0) {
console.log('Nothing to sync', workspaceId, syncDir);
@@ -72,66 +72,68 @@ export const syncWorkspace = createFastMutation<
console.log('Filesystem changes detected', { dbOps, ops });
const confirmed = await showConfirm({
id: 'commit-sync',
title: 'Filesystem Changes Detected',
confirmText: 'Apply Changes',
description: (
<VStack space={3}>
{isDeletingWorkspace && (
<Banner color="danger">
🚨 <strong>Changes contain a workspace deletion!</strong>
</Banner>
)}
<p>
{pluralizeCount('file', dbOps.length)} in the directory have changed. Do you want to
apply the updates to your workspace?
</p>
<div className="overflow-y-auto max-h-[10rem]">
<table className="w-full text-sm mb-auto min-w-full max-w-full divide-y divide-surface-highlight">
<thead>
<tr>
<th className="py-1 text-left">Name</th>
<th className="py-1 text-right pl-4">Operation</th>
</tr>
</thead>
<tbody className="divide-y divide-surface-highlight">
{dbOps.map((op, i) => {
let name = '';
let label = '';
let color = '';
if (op.type === 'dbCreate') {
label = 'create';
name = fallbackRequestName(op.fs.model);
color = 'text-success';
} else if (op.type === 'dbUpdate') {
label = 'update';
name = fallbackRequestName(op.fs.model);
color = 'text-info';
} else if (op.type === 'dbDelete') {
label = 'delete';
name = fallbackRequestName(op.model);
color = 'text-danger';
} else {
return null;
}
return (
<tr key={i} className="text-text">
<td className="py-1">{name}</td>
<td className="py-1 pl-4 text-right">
<InlineCode className={color}>{label}</InlineCode>
</td>
const confirmed = force
? true
: await showConfirm({
id: 'commit-sync',
title: 'Filesystem Changes Detected',
confirmText: 'Apply Changes',
description: (
<VStack space={3}>
{isDeletingWorkspace && (
<Banner color="danger">
🚨 <strong>Changes contain a workspace deletion!</strong>
</Banner>
)}
<p>
{pluralizeCount('file', dbOps.length)} in the directory have changed. Do you want to
apply the updates to your workspace?
</p>
<div className="overflow-y-auto max-h-[10rem]">
<table className="w-full text-sm mb-auto min-w-full max-w-full divide-y divide-surface-highlight">
<thead>
<tr>
<th className="py-1 text-left">Name</th>
<th className="py-1 text-right pl-4">Operation</th>
</tr>
);
})}
</tbody>
</table>
</div>
</VStack>
),
});
</thead>
<tbody className="divide-y divide-surface-highlight">
{dbOps.map((op, i) => {
let name = '';
let label = '';
let color = '';
if (op.type === 'dbCreate') {
label = 'create';
name = fallbackRequestName(op.fs.model);
color = 'text-success';
} else if (op.type === 'dbUpdate') {
label = 'update';
name = fallbackRequestName(op.fs.model);
color = 'text-info';
} else if (op.type === 'dbDelete') {
label = 'delete';
name = fallbackRequestName(op.model);
color = 'text-danger';
} else {
return null;
}
return (
<tr key={i} className="text-text">
<td className="py-1">{name}</td>
<td className="py-1 pl-4 text-right">
<InlineCode className={color}>{label}</InlineCode>
</td>
</tr>
);
})}
</tbody>
</table>
</div>
</VStack>
),
});
if (confirmed) {
await applySync(workspaceId, syncDir, ops);
}

View File

@@ -1,18 +1,17 @@
import type {WebsocketRequest} from "@yaakapp-internal/models";
import type { WebsocketRequest } from '@yaakapp-internal/models';
import { deleteWebsocketRequest as cmdDeleteWebsocketRequest } from '@yaakapp-internal/ws';
import { InlineCode } from '../components/core/InlineCode';
import { createFastMutation } from '../hooks/useFastMutation';
import { trackEvent } from '../lib/analytics';
import { showConfirm } from '../lib/confirm';
import { showConfirmDelete } from '../lib/confirm';
import { fallbackRequestName } from '../lib/fallbackRequestName';
export const deleteWebsocketRequest = createFastMutation({
mutationKey: ['delete_websocket_request'],
mutationFn: async (request: WebsocketRequest) => {
const confirmed = await showConfirm({
const confirmed = await showConfirmDelete({
id: 'delete-websocket-request',
title: 'Delete WebSocket Request',
variant: 'delete',
description: (
<>
Permanently delete <InlineCode>{fallbackRequestName(request)}</InlineCode>?

View File

@@ -0,0 +1,27 @@
import { SettingsTab } from '../components/Settings/SettingsTab';
import { getActiveWorkspaceId } from '../hooks/useActiveWorkspace';
import { createFastMutation } from '../hooks/useFastMutation';
import { trackEvent } from '../lib/analytics';
import { router } from '../lib/router';
import { invokeCmd } from '../lib/tauri';
export const openSettings = createFastMutation<void, string, SettingsTab | null>({
mutationKey: ['open_settings'],
mutationFn: async function (tab) {
const workspaceId = getActiveWorkspaceId();
if (workspaceId == null) return;
trackEvent('dialog', 'show', { id: 'settings', tab: `${tab}` });
const location = router.buildLocation({
to: '/workspaces/$workspaceId/settings',
params: { workspaceId },
search: { tab: tab ?? SettingsTab.General },
});
await invokeCmd('cmd_new_child_window', {
url: location.href,
label: 'settings',
title: 'Yaak Settings',
innerSize: [750, 600],
});
},
});

View File

@@ -0,0 +1,25 @@
import { WorkspaceSettingsDialog } from '../components/WorkspaceSettingsDialog';
import { getActiveWorkspaceId } from '../hooks/useActiveWorkspace';
import { createFastMutation } from '../hooks/useFastMutation';
import { showDialog } from '../lib/dialog';
export const openWorkspaceSettings = createFastMutation<void, string, { openSyncMenu?: boolean }>({
mutationKey: ['open_workspace_settings'],
async mutationFn({ openSyncMenu }) {
const workspaceId = getActiveWorkspaceId();
showDialog({
id: 'workspace-settings',
title: 'Workspace Settings',
size: 'md',
render({ hide }) {
return (
<WorkspaceSettingsDialog
workspaceId={workspaceId}
hide={hide}
openSyncMenu={openSyncMenu}
/>
);
},
});
},
});