-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from openscript/develop
Enhance unique constraint implementation
- Loading branch information
Showing
15 changed files
with
936 additions
and
767 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
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,73 @@ | ||
import { Meta, Description, Source } from '@storybook/addon-docs/blocks'; | ||
import Readme from '../README.md'; | ||
|
||
<Meta title="Usage|Integrations/Ant Design" /> | ||
|
||
# Ant Design integration | ||
This page shows how an input and a preview component with Ant Design (`>= 4`) can be built and connected to this component. | ||
|
||
First the imports need to be declared. | ||
|
||
<Source language='tsx' code={` | ||
import * as React from 'react'; | ||
import { DSVImport as Import, ColumnsType, useDSVImport } from 'react-dsv-import'; | ||
import { Form, Input, Table } from 'antd'; | ||
`} /> | ||
|
||
## Input component | ||
<Source language='tsx' code={` | ||
const TextareaInput: React.FC = () => { | ||
const [, dispatch] = useDSVImport(); | ||
const handleChange = (event: React.ChangeEvent<HTMLTextAreaElement>) => { | ||
dispatch({ type: 'setRaw', raw: event.target.value }); | ||
}; | ||
return <Input.TextArea rows={15} onChange={handleChange} />; | ||
}; | ||
`} /> | ||
|
||
## Preview component | ||
<Source language='tsx' code={` | ||
const TablePreview: React.FC = () => { | ||
const [context] = useDSVImport(); | ||
const getRowKey = (record: { [key: string]: string }) => { | ||
return context.parsed.indexOf(record); | ||
}; | ||
return ( | ||
<Table pagination={false} dataSource={context.parsed} rowKey={getRowKey}> | ||
{context.columns.map((r) => { | ||
return <Table.Column key={r.key} dataIndex={r.key} title={r.label ? r.label : r.key} />; | ||
})} | ||
</Table> | ||
); | ||
}; | ||
`} /> | ||
|
||
## Create context | ||
|
||
<Source language='tsx' code={` | ||
export interface Props<T> { | ||
onChange?: (value: T[]) => void; | ||
columns: ColumnsType<T>; | ||
} | ||
export const DSVImport = <T extends { [key: string]: string }>(props: Props<T>) => { | ||
const intl = useIntl(); | ||
return ( | ||
<Form layout='vertical'> | ||
<Import<T> columns={props.columns} onChange={props.onChange}> | ||
<Form.Item label='Input'> | ||
<TextareaInput /> | ||
</Form.Item> | ||
<Form.Item label='Preview'> | ||
<TablePreview /> | ||
</Form.Item> | ||
</Import> | ||
</Form> | ||
); | ||
}; | ||
`} /> |
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 @@ | ||
console.log('asdsa'); |
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,19 @@ | ||
import { Meta, Description, Source } from '@storybook/addon-docs/blocks'; | ||
|
||
<Meta title="Usage|Integrations/Material UI" /> | ||
|
||
# Material UI integration | ||
This page shows how an input and a preview component with Material UI can be built and connected to this component. It's possible to put everything into one file. | ||
|
||
First the imports need to be declared. | ||
|
||
<Source language='tsx' code={` | ||
import * as React from 'react'; | ||
import { DSVImport as Import, ColumnsType, useDSVImport } from 'react-dsv-import'; | ||
`} /> | ||
|
||
## Input component | ||
|
||
## Preview component | ||
|
||
## Create context |
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,7 +1,6 @@ | ||
import { Meta, Description } from '@storybook/addon-docs/blocks'; | ||
import Readme from '../README.md'; | ||
|
||
|
||
<Meta title="Start" /> | ||
<Meta title="Start|Readme" /> | ||
|
||
<Description markdown={Readme} /> |
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
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
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
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 |
---|---|---|
|
@@ -60,17 +60,19 @@ describe('TablePreview', () => { | |
{ forename: '', surname: '', email: '[email protected]' } | ||
], | ||
validation: [ | ||
{ column: 'email', message: 'Contains duplicates' }, | ||
{ column: 'email', row: 0, message: 'Contains duplicates' }, | ||
{ column: 'email', row: 1, message: 'Contains duplicates' }, | ||
{ column: 'email', row: 1, message: 'No example address, please' }, | ||
{ column: 'forename', row: 1, message: 'Forename is required' } | ||
] | ||
}); | ||
const tableBody = container.querySelector('tbody'); | ||
const tableHead = container.querySelector('thead tr'); | ||
|
||
expect(tableHead?.children[2]).toHaveClass('error'); | ||
expect(tableHead?.children[2]).toHaveAttribute('title', 'Contains duplicates'); | ||
|
||
expect(tableBody?.children[1].children[0]).toHaveClass('error'); | ||
expect(tableBody?.children[1].children[0]).toHaveAttribute('title', 'Forename is required'); | ||
expect(tableBody?.children[1].children[2]).toHaveAttribute( | ||
'title', | ||
'Contains duplicates;No example address, please' | ||
); | ||
}); | ||
}); |
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
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
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 |
---|---|---|
|
@@ -13,7 +13,8 @@ describe('validatorMiddleware', () => { | |
const middleware = createValidatorMiddleware<TestType>(); | ||
const parsed: TestType[] = [ | ||
{ forename: 'Hans', surname: 'Muster', email: '[email protected]' }, | ||
{ forename: 'Heidi', surname: 'Muster', email: '[email protected]' } | ||
{ forename: 'Heidi', surname: 'Muster', email: '[email protected]' }, | ||
{ forename: 'Joe', surname: 'Doe', email: '[email protected]' } | ||
]; | ||
|
||
it('should return an empty array if there are no errors', () => { | ||
|
@@ -34,7 +35,10 @@ describe('validatorMiddleware', () => { | |
|
||
expect(dispatchMock).toBeCalledWith({ | ||
type: 'setValidation', | ||
errors: [{ column: 'email', message: 'Contains duplicates' }] | ||
errors: [ | ||
{ column: 'email', row: 0, message: 'Contains duplicates' }, | ||
{ column: 'email', row: 1, message: 'Contains duplicates' } | ||
] | ||
}); | ||
}); | ||
|
||
|
@@ -50,7 +54,7 @@ describe('validatorMiddleware', () => { | |
|
||
expect(dispatchMock).toBeCalledWith({ | ||
type: 'setValidation', | ||
errors: [{ column: 'forename', row: 1, message: "No 'Hans' allowed" }] | ||
errors: [{ column: 'forename', row: 0, message: "No 'Hans' allowed" }] | ||
}); | ||
}); | ||
}); |
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
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 +1 @@ | ||
export type ValidationError<T> = { column: keyof T; row?: number; message: string }; | ||
export type ValidationError<T> = { column: keyof T; row: number; message: string }; |
Oops, something went wrong.