|
| 1 | +import type { Meta, StoryObj } from '@storybook/react-vite' |
| 2 | +import type { GitDiff } from '../../../index' |
| 3 | +import { useState } from 'react' |
| 4 | +import { DiffPanelView, DiffPatchView } from './diff-panel-view' |
| 5 | + |
| 6 | +const PATCH = `diff --git a/src/rpc/functions/log.ts b/src/rpc/functions/log.ts |
| 7 | +index 1234567..89abcde 100644 |
| 8 | +--- a/src/rpc/functions/log.ts |
| 9 | ++++ b/src/rpc/functions/log.ts |
| 10 | +@@ -72,7 +72,7 @@ export const log = defineRpcFunction({ |
| 11 | + name: 'git:log', |
| 12 | + type: 'query', |
| 13 | +- snapshot: true, |
| 14 | ++ dump: async (_ctx, handler) => { /* bake head of history */ }, |
| 15 | + jsonSerializable: true, |
| 16 | + setup: (ctx) => {` |
| 17 | + |
| 18 | +const data: GitDiff = { |
| 19 | + isRepo: true, |
| 20 | + staged: false, |
| 21 | + path: null, |
| 22 | + files: [ |
| 23 | + { path: 'src/rpc/functions/log.ts', additions: 14, deletions: 3, binary: false }, |
| 24 | + { path: 'src/client/components/views/log-panel-view.tsx', additions: 162, deletions: 40, binary: false }, |
| 25 | + { path: 'src/client/lib/refs.ts', additions: 71, deletions: 0, binary: false }, |
| 26 | + { path: 'public/preview.png', additions: 0, deletions: 0, binary: true }, |
| 27 | + ], |
| 28 | + totalAdditions: 247, |
| 29 | + totalDeletions: 43, |
| 30 | + patch: null, |
| 31 | + truncated: false, |
| 32 | +} |
| 33 | + |
| 34 | +// Wire the scope toggle + file selection so the panel is interactive, and feed |
| 35 | +// the selected file's patch through the `DiffPatchView` slot. |
| 36 | +function Harness(props: Partial<React.ComponentProps<typeof DiffPanelView>>) { |
| 37 | + const [staged, setStaged] = useState(false) |
| 38 | + const [selected, setSelected] = useState<string | null>('src/rpc/functions/log.ts') |
| 39 | + return ( |
| 40 | + <DiffPanelView |
| 41 | + data={data} |
| 42 | + loading={false} |
| 43 | + staged={staged} |
| 44 | + selected={selected} |
| 45 | + onSelectScope={setStaged} |
| 46 | + onSelectFile={setSelected} |
| 47 | + onRefresh={() => undefined} |
| 48 | + patchSlot={<DiffPatchView patch={PATCH} loading={false} truncated={false} />} |
| 49 | + {...props} |
| 50 | + /> |
| 51 | + ) |
| 52 | +} |
| 53 | + |
| 54 | +const meta = { |
| 55 | + title: 'Panels/Diff', |
| 56 | + component: Harness, |
| 57 | +} satisfies Meta<typeof Harness> |
| 58 | + |
| 59 | +export default meta |
| 60 | +type Story = StoryObj<typeof meta> |
| 61 | + |
| 62 | +export const Default: Story = {} |
| 63 | +export const NoSelection: Story = { args: { selected: null } } |
| 64 | +export const Loading: Story = { args: { data: null, loading: true } } |
| 65 | +export const NoChanges: Story = { args: { data: { ...data, files: [], totalAdditions: 0, totalDeletions: 0 } } } |
| 66 | +export const NotARepo: Story = { args: { data: { ...data, isRepo: false } } } |
0 commit comments