From deaeb5433c7a53f739efe7674e2ff5fb660cd78a Mon Sep 17 00:00:00 2001 From: Alexey Date: Tue, 10 Aug 2021 15:52:22 +0300 Subject: [PATCH] [refactor] GH-5 Cells renderers in a single file --- src/cells/AntdBooleanCell.tsx | 28 ------ src/cells/AntdButtonCell.tsx | 22 ----- src/cells/AntdCellHorizontalLayout.tsx | 4 +- src/cells/AntdCellRateWidget.tsx | 28 ------ src/cells/AntdEnumCell.tsx | 25 ----- src/cells/AntdImageCell.tsx | 20 ---- src/cells/AntdNumberCell.tsx | 26 ----- src/cells/AntdSimpleCells.tsx | 125 +++++++++++++++++++++++++ src/cells/AntdTextCell.tsx | 28 ------ src/cells/AntdTimeCell.tsx | 28 ------ src/cells/index.ts | 38 ++++---- 11 files changed, 149 insertions(+), 223 deletions(-) delete mode 100644 src/cells/AntdBooleanCell.tsx delete mode 100644 src/cells/AntdButtonCell.tsx delete mode 100644 src/cells/AntdCellRateWidget.tsx delete mode 100644 src/cells/AntdEnumCell.tsx delete mode 100644 src/cells/AntdImageCell.tsx delete mode 100644 src/cells/AntdNumberCell.tsx create mode 100644 src/cells/AntdSimpleCells.tsx delete mode 100644 src/cells/AntdTextCell.tsx delete mode 100644 src/cells/AntdTimeCell.tsx diff --git a/src/cells/AntdBooleanCell.tsx b/src/cells/AntdBooleanCell.tsx deleted file mode 100644 index 95f8493..0000000 --- a/src/cells/AntdBooleanCell.tsx +++ /dev/null @@ -1,28 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2020 Agentlab and others. - * - * This program and the accompanying materials are made available under the - * terms of the GNU General Public License v. 3.0 which is available at - * https://www.gnu.org/licenses/gpl-3.0.html. - * - * SPDX-License-Identifier: GPL-3.0-only - ********************************************************************************/ -import React from 'react'; - -import { rankWith, RankedTester, isBooleanControl } from '../testers'; -import { withStoreToCellProps } from '../util/ContextToProps'; - -import { AntdCheckbox } from '../antd-controls/AntdCheckbox'; -import { CellRenderer } from './CellRenderer'; - -export const AntdBooleanCell = (props: any) => { - return ; -}; - -/** - * Default tester for text-based/string controls. - * @type {RankedTester} - */ -export const antdBooleanCellTester: RankedTester = rankWith(2, isBooleanControl); - -export const AntdBooleanCellWithStore = withStoreToCellProps(AntdBooleanCell); diff --git a/src/cells/AntdButtonCell.tsx b/src/cells/AntdButtonCell.tsx deleted file mode 100644 index e29e607..0000000 --- a/src/cells/AntdButtonCell.tsx +++ /dev/null @@ -1,22 +0,0 @@ -import React from 'react'; - -import { uiTypeIs, rankWith, RankedTester } from '../testers'; -import { withStoreToCellProps } from '../util/ContextToProps'; -import { Button } from 'antd'; - -export const AntdButtonCell = (props: any) => { - const options = props.uiOptions; - return ( - - ); -}; - -/** - * Default tester for text-based/string controls. - * @type {RankedTester} - */ -export const antdButtonCellTester: RankedTester = rankWith(2, uiTypeIs('Button')); - -export const AntdButtonCellWithStore = withStoreToCellProps(AntdButtonCell); diff --git a/src/cells/AntdCellHorizontalLayout.tsx b/src/cells/AntdCellHorizontalLayout.tsx index e3a6f50..00df6c4 100644 --- a/src/cells/AntdCellHorizontalLayout.tsx +++ b/src/cells/AntdCellHorizontalLayout.tsx @@ -18,7 +18,7 @@ import { get } from 'lodash-es'; import { Idx } from '../util/layout'; -export const AntdHorizontalLayoutRenderer: React.FC = ({ viewElement, view, data, schema }) => { +export const AntdCellHorizontalLayoutRenderer: React.FC = ({ viewElement, view, data, schema }) => { //const layout = viewElement as Layout; const Render: React.FC = ({ idx, schema, viewElement, view, data, enabled, form }) => { const options = viewElement.options || {}; @@ -54,4 +54,4 @@ export const AntdHorizontalLayoutRenderer: React.FC = ({ view ); }; -export const antdHorizontalLayoutTester: RankedTester = rankWith(2, uiTypeIs('CellHorizontalLayout')); +export const antdCellHorizontalLayoutTester: RankedTester = rankWith(2, uiTypeIs('CellHorizontalLayout')); diff --git a/src/cells/AntdCellRateWidget.tsx b/src/cells/AntdCellRateWidget.tsx deleted file mode 100644 index 897b4ef..0000000 --- a/src/cells/AntdCellRateWidget.tsx +++ /dev/null @@ -1,28 +0,0 @@ -import React from 'react'; - -import { withStoreToCellProps } from '../util/ContextToProps'; -import { Rate } from 'antd'; - -import { uiTypeIs, rankWith, RankedTester } from '../testers'; - -export const AntdCellRateWidget = (props: any /*: EnumCellProps & WithClassname*/) => { - return ( - - - {`(${props.data})`} - - ); -}; - -/** - * Default tester for enum controls. - * @type {RankedTester} - */ -export const antdCellRateWidgetTester: RankedTester = rankWith(5, uiTypeIs('Rate')); - -export const AntdCellRateWidgetWithStore = withStoreToCellProps(AntdCellRateWidget); diff --git a/src/cells/AntdEnumCell.tsx b/src/cells/AntdEnumCell.tsx deleted file mode 100644 index 975b72a..0000000 --- a/src/cells/AntdEnumCell.tsx +++ /dev/null @@ -1,25 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2020 Agentlab and others. - * - * This program and the accompanying materials are made available under the - * terms of the GNU General Public License v. 3.0 which is available at - * https://www.gnu.org/licenses/gpl-3.0.html. - * - * SPDX-License-Identifier: GPL-3.0-only - ********************************************************************************/ -import React from 'react'; - -import { rankWith, RankedTester, isEnumControl } from '../testers'; -import { withStoreToCellProps } from '../util/ContextToProps'; - -import { AntdSelect } from '../antd-controls/AntdSelect'; - -export const AntdEnumCell = (props: any /*: EnumCellProps & WithClassname*/) => ; - -/** - * Default tester for enum controls. - * @type {RankedTester} - */ -export const antdEnumCellTester: RankedTester = rankWith(2, isEnumControl); - -export const AntdEnumCellWithStore = withStoreToCellProps(AntdEnumCell); diff --git a/src/cells/AntdImageCell.tsx b/src/cells/AntdImageCell.tsx deleted file mode 100644 index 4037633..0000000 --- a/src/cells/AntdImageCell.tsx +++ /dev/null @@ -1,20 +0,0 @@ -import React from 'react'; - -import { uiTypeIs, rankWith, RankedTester } from '../testers'; -import { withStoreToCellProps } from '../util/ContextToProps'; -import { Image } from 'antd'; -import { useEffect } from '@storybook/addons'; -import './cell.css'; - -export const AntdImageCell = (props: any) => { - const { data } = props; - return ; -}; - -/** - * Default tester for text-based/string controls. - * @type {RankedTester} - */ -export const antdImageCellTester: RankedTester = rankWith(2, uiTypeIs('ImageCell')); - -export const AntdImageCellWithStore = withStoreToCellProps(AntdImageCell); diff --git a/src/cells/AntdNumberCell.tsx b/src/cells/AntdNumberCell.tsx deleted file mode 100644 index e743770..0000000 --- a/src/cells/AntdNumberCell.tsx +++ /dev/null @@ -1,26 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2020 Agentlab and others. - * - * This program and the accompanying materials are made available under the - * terms of the GNU General Public License v. 3.0 which is available at - * https://www.gnu.org/licenses/gpl-3.0.html. - * - * SPDX-License-Identifier: GPL-3.0-only - ********************************************************************************/ -import React from 'react'; - -import { rankWith, RankedTester, isIntegerControl, isNumberControl } from '../testers'; -import { withStoreToCellProps } from '../util/ContextToProps'; - -import { AntdInputNumber } from '../antd-controls/AntdInputNumber'; -import { CellRenderer } from './CellRenderer'; - -export const AntdNumberCell = (props: any) => { - return ; -}; - -export const antdIntegerCellTester: RankedTester = rankWith(2, isIntegerControl); -export const AntdIntegerCellWithStore = withStoreToCellProps(AntdNumberCell); - -export const antdNumberCellTester: RankedTester = rankWith(2, isNumberControl); -export const AntdNumberCellWithStore = withStoreToCellProps(AntdNumberCell); diff --git a/src/cells/AntdSimpleCells.tsx b/src/cells/AntdSimpleCells.tsx new file mode 100644 index 0000000..a575f42 --- /dev/null +++ b/src/cells/AntdSimpleCells.tsx @@ -0,0 +1,125 @@ +/******************************************************************************** + * Copyright (c) 2020 Agentlab and others. + * + * This program and the accompanying materials are made available under the + * terms of the GNU General Public License v. 3.0 which is available at + * https://www.gnu.org/licenses/gpl-3.0.html. + * + * SPDX-License-Identifier: GPL-3.0-only + ********************************************************************************/ +import { get } from 'lodash-es'; + +import React from 'react'; +import { Button, Card, Image, Row, Col, Rate } from 'antd'; + +import { + rankWith, + RankedTester, + isBooleanControl, + isDateTimeControl, + isEnumControl, + isIntegerControl, + isNumberControl, + isStringControl, + uiTypeIs, +} from '../testers'; +import { withStoreToCellProps } from '../util/ContextToProps'; + +import { AntdCheckbox } from '../antd-controls/AntdCheckbox'; +import { AntdInputDate } from '../antd-controls/AntdInputDate'; +import { AntdInputNumber } from '../antd-controls/AntdInputNumber'; +import { AntdInputText } from '../antd-controls/AntdInputText'; +import { AntdSelect } from '../antd-controls/AntdSelect'; +import { CellRenderer } from './CellRenderer'; + +import './cell.css'; + +/** + * AntdBooleanCell + */ +export const AntdBooleanCell = (props: any) => { + return ; +}; +export const antdBooleanCellTester: RankedTester = rankWith(2, isBooleanControl); +export const AntdBooleanCellWithStore = withStoreToCellProps(AntdBooleanCell); + +/** + * AntdButtonCell + */ +export const AntdButtonCell = (props: any) => { + const options = props.uiOptions; + return ( + + ); +}; +export const antdButtonCellTester: RankedTester = rankWith(2, uiTypeIs('Button')); +export const AntdButtonCellWithStore = withStoreToCellProps(AntdButtonCell); + +/** + * AntdEnumCell + */ +export const AntdEnumCell = (props: any /*: EnumCellProps & WithClassname*/) => ; +export const antdEnumCellTester: RankedTester = rankWith(2, isEnumControl); +export const AntdEnumCellWithStore = withStoreToCellProps(AntdEnumCell); + +/** + * AntdNumberCell & AntdIntegerCell + */ +export const AntdNumberCell = (props: any) => { + return ; +}; + +export const antdIntegerCellTester: RankedTester = rankWith(2, isIntegerControl); +export const AntdIntegerCellWithStore = withStoreToCellProps(AntdNumberCell); + +export const antdNumberCellTester: RankedTester = rankWith(2, isNumberControl); +export const AntdNumberCellWithStore = withStoreToCellProps(AntdNumberCell); + +/** + * AntdImageCell + */ +export const AntdImageCell = (props: any) => { + const { data } = props; + return ; +}; +export const antdImageCellTester: RankedTester = rankWith(2, uiTypeIs('ImageCell')); +export const AntdImageCellWithStore = withStoreToCellProps(AntdImageCell); + +/** + * AntdRateCell + */ +export const AntdRateCell = (props: any /*: EnumCellProps & WithClassname*/) => { + return ( + + + {`(${props.data})`} + + ); +}; +export const antdRateCellTester: RankedTester = rankWith(5, uiTypeIs('Rate')); +export const AntdRateCellWithStore = withStoreToCellProps(AntdRateCell); + +/** + * AntdTextCell + */ +export const AntdTextCell = (props: any) => { + return ; +}; +export const antdTextCellTester: RankedTester = rankWith(1, isStringControl); +export const AntdTextCellWithStore = withStoreToCellProps(AntdTextCell); + +/** + * AntdTimeCell + */ +export const AntdTimeCell = (props: any) => { + return ; +}; +export const antdTimeCellTester: RankedTester = rankWith(2, isDateTimeControl); +export const AntdTimeCellWithStore = withStoreToCellProps(AntdTimeCell); diff --git a/src/cells/AntdTextCell.tsx b/src/cells/AntdTextCell.tsx deleted file mode 100644 index 2cda88c..0000000 --- a/src/cells/AntdTextCell.tsx +++ /dev/null @@ -1,28 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2020 Agentlab and others. - * - * This program and the accompanying materials are made available under the - * terms of the GNU General Public License v. 3.0 which is available at - * https://www.gnu.org/licenses/gpl-3.0.html. - * - * SPDX-License-Identifier: GPL-3.0-only - ********************************************************************************/ -import React from 'react'; - -import { rankWith, RankedTester, isStringControl } from '../testers'; -import { withStoreToCellProps } from '../util/ContextToProps'; - -import { AntdInputText } from '../antd-controls/AntdInputText'; -import { CellRenderer } from './CellRenderer'; - -export const AntdTextCell = (props: any) => { - return ; -}; - -/** - * Default tester for text-based/string controls. - * @type {RankedTester} - */ -export const antdTextCellTester: RankedTester = rankWith(1, isStringControl); - -export const AntdTextCellWithStore = withStoreToCellProps(AntdTextCell); diff --git a/src/cells/AntdTimeCell.tsx b/src/cells/AntdTimeCell.tsx deleted file mode 100644 index 111dda1..0000000 --- a/src/cells/AntdTimeCell.tsx +++ /dev/null @@ -1,28 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2020 Agentlab and others. - * - * This program and the accompanying materials are made available under the - * terms of the GNU General Public License v. 3.0 which is available at - * https://www.gnu.org/licenses/gpl-3.0.html. - * - * SPDX-License-Identifier: GPL-3.0-only - ********************************************************************************/ -import React from 'react'; - -import { rankWith, RankedTester, isDateTimeControl } from '../testers'; -import { withStoreToCellProps } from '../util/ContextToProps'; - -import { AntdInputDate } from '../antd-controls/AntdInputDate'; -import { CellRenderer } from './CellRenderer'; - -export const AntdTimeCell = (props: any) => { - return ; -}; - -/** - * Default tester for text-based/string controls. - * @type {RankedTester} - */ -export const antdTimeCellTester: RankedTester = rankWith(2, isDateTimeControl); - -export const AntdTimeCellWithStore = withStoreToCellProps(AntdTimeCell); diff --git a/src/cells/index.ts b/src/cells/index.ts index a85ba56..99c8aff 100644 --- a/src/cells/index.ts +++ b/src/cells/index.ts @@ -8,23 +8,30 @@ * SPDX-License-Identifier: GPL-3.0-only ********************************************************************************/ import { CellRendererRegistryEntry } from '../renderers'; -import { antdBooleanCellTester, AntdBooleanCellWithStore } from './AntdBooleanCell'; -import { antdEnumCellTester, AntdEnumCellWithStore } from './AntdEnumCell'; import { + antdBooleanCellTester, + AntdBooleanCellWithStore, + antdButtonCellTester, + AntdButtonCellWithStore, + antdEnumCellTester, + AntdEnumCellWithStore, antdIntegerCellTester, AntdIntegerCellWithStore, + antdImageCellTester, + AntdImageCellWithStore, antdNumberCellTester, AntdNumberCellWithStore, -} from './AntdNumberCell'; -import { antdTextCellTester, AntdTextCellWithStore } from './AntdTextCell'; -import { antdTimeCellTester, AntdTimeCellWithStore } from './AntdTimeCell'; + antdRateCellTester, + AntdRateCellWithStore, + antdTextCellTester, + AntdTextCellWithStore, + antdTimeCellTester, + AntdTimeCellWithStore, +} from './AntdSimpleCells'; import { tinyMCECellTester, TinyMCECellWithStore } from './TinyMCECell'; -import { antdImageCellTester, AntdImageCellWithStore } from './AntdImageCell'; import { antdCellCardLayoutTester, AntdCellCardLayout } from './AntdCellCardLayout'; -import { antdHorizontalLayoutTester, AntdHorizontalLayoutRenderer } from './AntdCellHorizontalLayout'; -import { antdCellRateWidgetTester, AntdCellRateWidgetWithStore } from './AntdCellRateWidget'; +import { antdCellHorizontalLayoutTester, AntdCellHorizontalLayoutRenderer } from './AntdCellHorizontalLayout'; import { antdCellG2Tester, AntdCellG2 } from './AntdCellG2'; -import { antdButtonCellTester, AntdButtonCellWithStore } from './AntdButtonCell'; export const antdCells: CellRendererRegistryEntry[] = [ { tester: antdBooleanCellTester, cell: AntdBooleanCellWithStore }, @@ -36,15 +43,14 @@ export const antdCells: CellRendererRegistryEntry[] = [ { tester: tinyMCECellTester, cell: TinyMCECellWithStore }, { tester: antdImageCellTester, cell: AntdImageCellWithStore }, { tester: antdCellCardLayoutTester, cell: AntdCellCardLayout }, - { tester: antdHorizontalLayoutTester, cell: AntdHorizontalLayoutRenderer }, - { tester: antdCellRateWidgetTester, cell: AntdCellRateWidgetWithStore }, + { tester: antdCellHorizontalLayoutTester, cell: AntdCellHorizontalLayoutRenderer }, + { tester: antdRateCellTester, cell: AntdRateCellWithStore }, { tester: antdCellG2Tester, cell: AntdCellG2 }, { tester: antdButtonCellTester, cell: AntdButtonCellWithStore }, ]; -export * from './AntdBooleanCell'; -export * from './AntdEnumCell'; -export * from './AntdNumberCell'; -export * from './AntdTextCell'; -export * from './AntdTimeCell'; +export * from './AntdSimpleCells'; export * from './TinyMCECell'; +export * from './AntdCellCardLayout'; +export * from './AntdCellHorizontalLayout'; +export * from './AntdCellG2';