Skip to content

Commit 590834a

Browse files
Copilothotlong
andcommitted
Update object-grid and object-form stories to use MSW runtime
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent a7832e4 commit 590834a

File tree

3 files changed

+132
-3
lines changed

3 files changed

+132
-3
lines changed

.storybook/datasource.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* DataSource Helper for Storybook
3+
*
4+
* Creates an ObjectStack data source adapter that connects to the
5+
* MSW-backed API endpoints running in Storybook.
6+
*/
7+
8+
import { ObjectStackAdapter } from '@object-ui/data-objectstack';
9+
10+
/**
11+
* Create a DataSource for use in Storybook stories.
12+
* This DataSource connects to the MSW mock server at /api/v1.
13+
*/
14+
export function createStorybookDataSource() {
15+
return new ObjectStackAdapter({
16+
baseUrl: '/api/v1',
17+
// No token needed for MSW
18+
});
19+
}

packages/components/src/stories-json/object-form.stories.tsx

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { Meta, StoryObj } from '@storybook/react';
2-
import { SchemaRenderer } from '../SchemaRenderer';
2+
import { SchemaRenderer, SchemaRendererProvider } from '@object-ui/react';
33
import type { BaseSchema } from '@object-ui/types';
4+
import { createStorybookDataSource } from '../../../.storybook/datasource';
45

56
const meta = {
67
title: 'Views/Object Form',
@@ -17,7 +18,14 @@ const meta = {
1718
export default meta;
1819
type Story = StoryObj<typeof meta>;
1920

20-
const renderStory = (args: any) => <SchemaRenderer schema={args as unknown as BaseSchema} />;
21+
// Create a DataSource instance that connects to MSW
22+
const dataSource = createStorybookDataSource();
23+
24+
const renderStory = (args: any) => (
25+
<SchemaRendererProvider dataSource={dataSource}>
26+
<SchemaRenderer schema={args as unknown as BaseSchema} />
27+
</SchemaRendererProvider>
28+
);
2129

2230
export const BasicSchema: Story = {
2331
render: renderStory,
@@ -76,3 +84,47 @@ export const ComplexFields: Story = {
7684
className: 'w-full max-w-2xl'
7785
} as any,
7886
};
87+
88+
/**
89+
* Contact Form - Uses MSW-backed schema from ObjectStack runtime
90+
*
91+
* This story demonstrates integration with the MSW plugin runtime mode.
92+
* The form schema is fetched from /api/v1/metadata/contact via the ObjectStack kernel.
93+
*/
94+
export const ContactForm: Story = {
95+
render: renderStory,
96+
args: {
97+
type: 'object-form',
98+
objectName: 'contact',
99+
fields: [
100+
{ name: 'name', label: 'Name', type: 'text', required: true },
101+
{ name: 'email', label: 'Email', type: 'email', required: true },
102+
{ name: 'phone', label: 'Phone', type: 'tel' },
103+
{ name: 'title', label: 'Title', type: 'text' },
104+
{ name: 'company', label: 'Company', type: 'text' },
105+
{ name: 'status', label: 'Status', type: 'select', options: ['Active', 'Lead', 'Customer'] }
106+
],
107+
className: 'w-full max-w-2xl'
108+
} as any,
109+
};
110+
111+
/**
112+
* Opportunity Form - Uses MSW-backed schema from ObjectStack runtime
113+
*
114+
* This story demonstrates creating/editing opportunity records via MSW runtime.
115+
*/
116+
export const OpportunityForm: Story = {
117+
render: renderStory,
118+
args: {
119+
type: 'object-form',
120+
objectName: 'opportunity',
121+
fields: [
122+
{ name: 'name', label: 'Opportunity Name', type: 'text', required: true },
123+
{ name: 'amount', label: 'Amount', type: 'number', required: true },
124+
{ name: 'stage', label: 'Stage', type: 'select', options: ['Prospecting', 'Qualification', 'Proposal', 'Negotiation', 'Closed Won', 'Closed Lost'] },
125+
{ name: 'closeDate', label: 'Close Date', type: 'date' },
126+
{ name: 'description', label: 'Description', type: 'textarea', rows: 4 }
127+
],
128+
className: 'w-full max-w-2xl'
129+
} as any,
130+
};

packages/components/src/stories-json/object-grid.stories.tsx

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { Meta, StoryObj } from '@storybook/react';
22
import { SchemaRenderer, SchemaRendererProvider } from '@object-ui/react';
33
import type { BaseSchema } from '@object-ui/types';
4+
import { createStorybookDataSource } from '../../../.storybook/datasource';
45

56
const meta = {
67
title: 'Views/Object Grid',
@@ -17,8 +18,11 @@ const meta = {
1718
export default meta;
1819
type Story = StoryObj<typeof meta>;
1920

21+
// Create a DataSource instance that connects to MSW
22+
const dataSource = createStorybookDataSource();
23+
2024
const renderStory = (args: any) => (
21-
<SchemaRendererProvider dataSource={{}}>
25+
<SchemaRendererProvider dataSource={dataSource}>
2226
<SchemaRenderer schema={args as unknown as BaseSchema} />
2327
</SchemaRendererProvider>
2428
);
@@ -97,3 +101,57 @@ export const WithActions: Story = {
97101
className: 'w-full'
98102
} as any,
99103
};
104+
105+
/**
106+
* Contacts Grid - Uses MSW-backed data from ObjectStack runtime
107+
*
108+
* This story demonstrates integration with the MSW plugin runtime mode.
109+
* Data is fetched from /api/v1/data/contact via the ObjectStack kernel.
110+
*/
111+
export const ContactsGrid: Story = {
112+
render: renderStory,
113+
args: {
114+
type: 'object-grid',
115+
objectName: 'contact',
116+
data: {
117+
provider: 'object',
118+
object: 'contact',
119+
},
120+
columns: [
121+
{ field: 'name', header: 'Name', sortable: true, filterable: true },
122+
{ field: 'email', header: 'Email', sortable: true, filterable: true },
123+
{ field: 'title', header: 'Title', sortable: true },
124+
{ field: 'company', header: 'Company', sortable: true },
125+
{ field: 'status', header: 'Status', sortable: true }
126+
],
127+
pagination: true,
128+
pageSize: 10,
129+
className: 'w-full'
130+
} as any,
131+
};
132+
133+
/**
134+
* Opportunities Grid - Uses MSW-backed data from ObjectStack runtime
135+
*
136+
* This story demonstrates fetching opportunity data from the MSW runtime.
137+
*/
138+
export const OpportunitiesGrid: Story = {
139+
render: renderStory,
140+
args: {
141+
type: 'object-grid',
142+
objectName: 'opportunity',
143+
data: {
144+
provider: 'object',
145+
object: 'opportunity',
146+
},
147+
columns: [
148+
{ field: 'name', header: 'Name', sortable: true, filterable: true },
149+
{ field: 'amount', header: 'Amount', sortable: true, type: 'currency' },
150+
{ field: 'stage', header: 'Stage', sortable: true },
151+
{ field: 'closeDate', header: 'Close Date', sortable: true, type: 'date' }
152+
],
153+
pagination: true,
154+
pageSize: 10,
155+
className: 'w-full'
156+
} as any,
157+
};

0 commit comments

Comments
 (0)