Skip to content

Commit

Permalink
Remove unnecessary story
Browse files Browse the repository at this point in the history
  • Loading branch information
djhi committed Dec 17, 2024
1 parent 437bfa2 commit be8eab8
Showing 1 changed file with 2 additions and 88 deletions.
90 changes: 2 additions & 88 deletions packages/ra-core/src/controller/edit/useEditController.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@ import * as React from 'react';
import { Route, Routes, useLocation } from 'react-router';
import {
CoreAdminContext,
EditBase,
EditController,
Form,
InputProps,
testDataProvider,
TestMemoryRouter,
useInput,
} from '../..';

export default {
Expand Down Expand Up @@ -79,93 +75,11 @@ export const EncodedIdWithPercentage = ({
);
};

export const OverrideRecordWithLocation = ({
url = '/posts/1',
dataProvider = testDataProvider({
// @ts-expect-error
getOne: () =>
Promise.resolve({
data: { id: 1, title: 'hello', value: 'a value' },
}),
}),
}) => {
return (
<TestMemoryRouter key={url} initialEntries={[url]}>
<CoreAdminContext dataProvider={dataProvider}>
<Routes>
<Route
path="/posts/:id"
element={
<EditBase resource="posts">
<div
style={{
padding: '1rem',
}}
>
<LocationInspector deep />
<Form>
<div
style={{
display: 'flex',
flexDirection: 'column',
gap: '1rem',
}}
>
<TextInput source="title" />
<TextInput source="value" />
</div>
</Form>
</div>
</EditBase>
}
/>
</Routes>
</CoreAdminContext>
</TestMemoryRouter>
);
};

OverrideRecordWithLocation.argTypes = {
url: {
options: [
'unmodified',
'modified with location state',
'modified with location search',
],
mapping: {
unmodified: '/posts/1',
'modified with location state': {
pathname: '/posts/1',
state: { record: { value: 'from-state' } },
},
'modified with location search': `/posts/1?source=${encodeURIComponent(JSON.stringify({ value: 'from-search' }))}`,
},
control: { type: 'select' },
},
};

const LocationInspector = ({ deep }: { deep?: boolean }) => {
const LocationInspector = () => {
const location = useLocation();
return (
<p>
Location:{' '}
<code>{deep ? JSON.stringify(location) : location.pathname}</code>
Location: <code>{location.pathname}</code>
</p>
);
};

const TextInput = (props: InputProps) => {
const input = useInput(props);

return (
<div
style={{
display: 'flex',
flexDirection: 'column',
}}
>
<label htmlFor={input.id}>{props.source}</label>
<input id={input.id} {...input.field} />
</div>
);
};

0 comments on commit be8eab8

Please sign in to comment.