-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(frontend): add storybook for development and design (#246)
- Loading branch information
Showing
9 changed files
with
4,415 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
{ | ||
"extends": "next/core-web-vitals" | ||
"extends": [ | ||
"next/core-web-vitals", | ||
"plugin:storybook/recommended" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,3 +42,5 @@ public/widget.js | |
public/robots.txt | ||
public/sitemap.xml | ||
public/sitemap-*.xml | ||
|
||
*storybook.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import type { StorybookConfig } from '@storybook/nextjs'; | ||
|
||
const config: StorybookConfig = { | ||
stories: [ | ||
'../src/!(pages)/**/*.mdx', | ||
'../src/!(pages)/**/*.stories.@(js|jsx|mjs|ts|tsx)', | ||
], | ||
addons: [ | ||
'@storybook/addon-onboarding', | ||
'@storybook/addon-links', | ||
'@storybook/addon-essentials', | ||
'@chromatic-com/storybook', | ||
'@storybook/addon-interactions', | ||
], | ||
framework: { | ||
name: '@storybook/nextjs', | ||
options: {}, | ||
}, | ||
staticDirs: ['../public'], | ||
}; | ||
export default config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import type { Preview } from "@storybook/react"; | ||
import '../src/app/globals.css'; | ||
|
||
const preview: Preview = { | ||
parameters: { | ||
controls: { | ||
matchers: { | ||
color: /(background|color)$/i, | ||
date: /Date$/i, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
export default preview; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
frontend/app/src/experimental/chat-verify-service/api.mock.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { fn } from '@storybook/test'; | ||
import * as api from './api'; | ||
|
||
export * from './api'; | ||
export const verify = fn(api.verify).mockName('verify'); | ||
export const getVerify = fn(api.getVerify).mockName('getVerify'); |
84 changes: 84 additions & 0 deletions
84
frontend/app/src/experimental/chat-verify-service/message-verify.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { AuthProvider } from '@/components/auth/AuthProvider'; | ||
import { ChatMessageController } from '@/components/chat/chat-message-controller'; | ||
import { getVerify, verify, VerifyState } from '@/experimental/chat-verify-service/api.mock'; | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
import { mutate } from 'swr'; | ||
import { MessageVerify } from './message-verify'; | ||
|
||
// More on how to set up stories at: https://storybook.js.org/docs/writing-stories#default-export | ||
const meta = { | ||
title: 'Experimental/MessageVerify', | ||
component: undefined, | ||
parameters: { | ||
// Optional parameter to center the component in the Canvas. More info: https://storybook.js.org/docs/configure/story-layout | ||
layout: 'centered', | ||
}, | ||
// This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs | ||
tags: [], | ||
// More on argTypes: https://storybook.js.org/docs/api/argtypes | ||
argTypes: { | ||
// user: { description: 'User message controller' }, | ||
// assistant: { description: 'Assistant message controller' }, | ||
}, | ||
// Use `fn` to spy on the onClick arg, which will appear in the actions panel once invoked: https://storybook.js.org/docs/essentials/actions#action-args | ||
args: {}, | ||
beforeEach: async () => { | ||
await mutate(() => true, undefined, { revalidate: true }); | ||
verify.mockReturnValue(Promise.resolve({ job_id: '000' })); | ||
localStorage.setItem('tidbai.experimental.verify-chat-message', 'on'); | ||
return () => { | ||
verify.mockReset(); | ||
localStorage.removeItem('tidbai.experimental.verify-chat-message'); | ||
}; | ||
}, | ||
render (_, { id }) { | ||
return ( | ||
<AuthProvider key={id} isLoading={false} isValidating={false} me={{ email: '[email protected]', is_active: true, is_superuser: true, is_verified: true, id: '000' }} reload={() => {}}> | ||
<MessageVerify | ||
user={new ChatMessageController({ finished_at: new Date(), id: 0, role: 'user', content: 'Question' } as any, undefined)} | ||
assistant={new ChatMessageController({ finished_at: new Date(), id: 1, role: 'assistant', content: 'Answer' } as any, undefined)} | ||
/> | ||
</AuthProvider> | ||
); | ||
}, | ||
} satisfies Meta<any>; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof meta>; | ||
|
||
// More on writing stories with args: https://storybook.js.org/docs/writing-stories/args | ||
export const Verified: Story = { | ||
beforeEach: () => { | ||
getVerify.mockReturnValue(Promise.resolve({ | ||
status: VerifyState.SUCCESS, | ||
message: 'This is a success message returned from server', | ||
runs: [ | ||
{ sql: 'SOME A FROM B FROM C FROM D FROM E FROM F FROM G', results: [], success: true, explanation: 'some description for this SQL' }, | ||
], | ||
})); | ||
}, | ||
}; | ||
|
||
export const Validating: Story = { | ||
beforeEach: () => { | ||
getVerify.mockReturnValue(Promise.resolve({ | ||
status: VerifyState.VALIDATING, | ||
message: 'This is a validating message returned from server', | ||
runs: [], | ||
})); | ||
}, | ||
}; | ||
|
||
export const Failed: Story = { | ||
beforeEach: () => { | ||
getVerify.mockReturnValue(Promise.resolve({ | ||
status: VerifyState.FAILED, | ||
message: 'This is a failed message returned from server', | ||
runs: [ | ||
{ sql: 'SOME A FROM B FROM C FROM D FROM E FROM F FROM G', results: [], success: true, explanation: 'Some description for this SQL' }, | ||
{ sql: 'SOME A FROM B FROM C FROM D FROM E FROM F FROM G', results: [], success: false, explanation: 'Another description for this SQL', sql_error_code: 8848, sql_error_message: 'TiDB Error Message', warnings: [] }, | ||
], | ||
})); | ||
}, | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.