Skip to content

Commit 3f2c71e

Browse files
authored
Merge pull request #265 from objectstack-ai/copilot/switch-components-to-msw-mode
2 parents 984541a + c7d26a9 commit 3f2c71e

File tree

5 files changed

+37
-5
lines changed

5 files changed

+37
-5
lines changed

.storybook/mocks.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@ export const handlers = [
1717
// - /api/v1/data/:object (GET, POST)
1818
// - /api/v1/data/:object/:id (GET, PUT, DELETE)
1919
// - /api/v1/metadata/*
20+
// - /api/v1/index.json (for ObjectStackClient.connect())
2021
// - /api/bootstrap
2122
];

.storybook/msw-browser.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,17 @@ export async function startMockServer() {
4545
baseUrl: '/api/v1',
4646
logRequests: true,
4747
customHandlers: [
48+
// Handle /api/v1/index.json for ObjectStackClient.connect()
49+
http.get('/api/v1/index.json', async () => {
50+
return HttpResponse.json({
51+
version: '1.0',
52+
objects: ['contact', 'opportunity', 'account'],
53+
endpoints: {
54+
data: '/api/v1/data',
55+
metadata: '/api/v1/metadata'
56+
}
57+
});
58+
}),
4859
// Explicitly handle all metadata requests to prevent pass-through
4960
http.get('/api/v1/metadata/*', async () => {
5061
return HttpResponse.json({});

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

Lines changed: 10 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-config/datasource';
45

56
const meta = {
67
title: 'Views/Gantt',
@@ -20,7 +21,14 @@ const meta = {
2021
export default meta;
2122
type Story = StoryObj<typeof meta>;
2223

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

2533
export const ProjectSchedule: Story = {
2634
render: renderStory,

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

Lines changed: 10 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-config/datasource';
45

56
const meta = {
67
title: 'Views/Map',
@@ -20,7 +21,14 @@ const meta = {
2021
export default meta;
2122
type Story = StoryObj<typeof meta>;
2223

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

2533
export const StoreLocations: Story = {
2634
render: renderStory,

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

Lines changed: 5 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-config/datasource';
45

56
const meta = {
67
title: 'Views/Object View',
@@ -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
);

0 commit comments

Comments
 (0)