Skip to content

Commit

Permalink
add storybook
Browse files Browse the repository at this point in the history
  • Loading branch information
jdeniau committed Mar 5, 2024
1 parent a76f5cd commit 9250db4
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 4 deletions.
87 changes: 87 additions & 0 deletions src/renderer/component/Connection/ConnectionPage.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import { action } from '@storybook/addon-actions';
import type { Meta, StoryObj } from '@storybook/react';
import { DEFAULT_THEME } from '../../../configuration/themes';
import { testables } from '../../../contexts/ConfigurationContext';
import { ConnectionContext } from '../../../contexts/ConnectionContext';
import ConnectionPage from './ConnectionPage';

const { ConfigurationContext } = testables;

const meta: Meta<typeof ConnectionPage> = {
component: ConnectionPage,
decorators: [
(Story) => (
<ConnectionContext.Provider
value={{
currentConnectionName: null,
connectionNameList: [],
connectTo: async (connection) => {
action('connectTo')(connection);
},
}}
>
<Story />
</ConnectionContext.Provider>
),
(Story) => (
<ConfigurationContext.Provider
value={{
configuration: {
version: 1,
theme: DEFAULT_THEME.name,
connections: {
test: {
name: 'test',
host: 'localhost',
port: 3307,
user: 'root',
password: '',
},
'production connection': {
name: 'prod',
host: 'localhost',
port: 3306,
user: 'root',
password: '',
},
},
},

addConnectionToConfig: (connection) => {
action('addConnectionToConfig')(connection);
},
updateConnectionState: (connectionName, key, value) => {
action('updateConnectionState')(connectionName, key, value);
},
editConnection: (name, connection) => {
action('editConnection')(name, connection);
},
}}
>
<Story />
</ConfigurationContext.Provider>
),
],
};

export default meta;
type Story = StoryObj<typeof ConnectionPage>;

/*
*👇 Render functions are a framework specific feature to allow you control on how the component renders.
* See https://storybook.js.org/docs/api/csf
* to learn how to use render functions.
*/
export const Primary: Story = {};

// export const Edit: Story = {
// args: {
// connection: {
// name: 'test',
// host: 'localhost',
// port: 3307,
// user: 'test-user',
// password: '',
// },
// },
// };
4 changes: 0 additions & 4 deletions src/renderer/component/Connection/ConnectionPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ function ConnectionPage() {
const registeredConnectionList = useConfiguration().configuration.connections;
const { connectTo } = useConnectionContext();

if (registeredConnectionList === null) {
return <div>Reading configuration...</div>;
}

const connectionList = Object.values(registeredConnectionList);

if (Object.keys(registeredConnectionList).length === 0) {
Expand Down

0 comments on commit 9250db4

Please sign in to comment.