Skip to content

Commit d72b875

Browse files
authored
Merge pull request #1474 from merico-dev/1473-apply-field-array-tabs-on-viz-table
1473 apply field array tabs on viz table
2 parents 33a287f + 4d09d72 commit d72b875

File tree

9 files changed

+37
-78
lines changed

9 files changed

+37
-78
lines changed

api/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@devtable/api",
3-
"version": "13.25.0",
3+
"version": "13.26.0",
44
"description": "",
55
"main": "index.js",
66
"scripts": {

dashboard/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@devtable/dashboard",
3-
"version": "13.25.0",
3+
"version": "13.26.0",
44
"license": "Apache-2.0",
55
"publishConfig": {
66
"access": "public",

dashboard/src/components/plugins/editor-components/field-array-tabs/tab-list.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const DraggableTab = ({ value, index, children }: DraggableTabProps) => {
2424
<Tabs.Tab
2525
ref={ref}
2626
value={value}
27-
icon={<IconGripHorizontal size={14} color={hovering ? 'rgb(34, 139, 230)' : 'transparent'} />}
27+
icon={<IconGripHorizontal size={14} color={hovering || index === 0 ? 'rgb(34, 139, 230)' : 'transparent'} />}
2828
onMouseEnter={setTrue}
2929
onMouseLeave={setFalse}
3030
>

dashboard/src/components/plugins/viz-components/table/editors/columns/column.tsx

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,12 @@
1-
import { Button, Divider, Group, NumberInput, Select, Stack, Text, TextInput } from '@mantine/core';
2-
import { Control, Controller, UseFieldArrayRemove, UseFormWatch } from 'react-hook-form';
3-
import { Trash } from 'tabler-icons-react';
1+
import { Divider, Group, NumberInput, Stack, Text, TextInput } from '@mantine/core';
2+
import { Control, Controller, UseFormWatch } from 'react-hook-form';
3+
import { useTranslation } from 'react-i18next';
44
import { DataFieldSelector } from '~/components/panel/settings/common/data-field-selector';
5+
import { HorizontalAlignSelector } from '~/components/plugins/editor-components';
56
import { BackgroundColorSelect } from '../../components/background-color-select';
6-
import { DEFAULT_CELL_FUNC_CONTENT, IColumnConf, ITableConf, ValueType } from '../../type';
7+
import { DEFAULT_CELL_FUNC_CONTENT, ITableConf, ValueType } from '../../type';
78
import { ValueTypeSelector } from '../../value-type-selector';
89
import { FuncContentEditor } from './func_content-editor';
9-
import { useTranslation } from 'react-i18next';
10-
import { HorizontalAlignSelector } from '~/components/plugins/editor-components';
11-
12-
const alignmentOptions = [
13-
{
14-
label: 'Left',
15-
value: 'left',
16-
},
17-
{
18-
label: 'Center',
19-
value: 'center',
20-
},
21-
{
22-
label: 'Right',
23-
value: 'right',
24-
},
25-
];
2610

2711
const PostFixPX = () => (
2812
<Text color="dimmed" size={12}>
@@ -34,10 +18,8 @@ interface IColumnField {
3418
control: Control<ITableConf, $TSFixMe>;
3519
watch: UseFormWatch<ITableConf>;
3620
index: number;
37-
remove: UseFieldArrayRemove;
38-
column: IColumnConf;
3921
}
40-
export const ColumnField = ({ control, index, watch, remove, column }: IColumnField) => {
22+
export const ColumnField = ({ control, index, watch }: IColumnField) => {
4123
const { t } = useTranslation();
4224
const value_type = watch(`columns.${index}.value_type`);
4325
const queryID = watch('query_id');
@@ -103,11 +85,6 @@ export const ColumnField = ({ control, index, watch, remove, column }: IColumnFi
10385
control={control}
10486
render={({ field }) => <BackgroundColorSelect {...field} />}
10587
/>
106-
107-
<Divider mb={4} mt={12} variant="dashed" />
108-
<Button leftIcon={<Trash size={16} />} color="red" variant="light" onClick={() => remove(index)}>
109-
{t('viz.table.column.delete')}
110-
</Button>
11188
</Stack>
11289
);
11390
};

dashboard/src/components/plugins/viz-components/table/editors/columns/index.tsx

Lines changed: 23 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,33 @@
1-
import { Divider, Stack, Switch, Tabs, Text, Textarea } from '@mantine/core';
1+
import { Switch, Textarea } from '@mantine/core';
22
import { randomId } from '@mantine/hooks';
3-
import { Control, Controller, UseFormWatch, useFieldArray } from 'react-hook-form';
4-
import { Plus } from 'tabler-icons-react';
3+
import { Control, Controller, UseFormWatch } from 'react-hook-form';
4+
import { useTranslation } from 'react-i18next';
5+
import { FieldArrayTabs } from '~/components/plugins/editor-components';
56
import { IColumnConf, ITableConf, ValueType } from '../../type';
67
import { ColumnField } from './column';
7-
import { useTranslation } from 'react-i18next';
88

99
interface IColumnsField {
1010
control: Control<ITableConf, $TSFixMe>;
1111
watch: UseFormWatch<ITableConf>;
1212
}
1313
export const ColumnsField = ({ control, watch }: IColumnsField) => {
1414
const { t } = useTranslation();
15-
const { fields, append, remove, update } = useFieldArray({
16-
control,
17-
name: 'columns',
18-
});
1915

20-
const addColumn = () => {
16+
const getItem = () => {
2117
const id = randomId();
22-
append({
18+
return {
2319
id,
2420
label: id,
2521
align: 'center',
2622
value_field: '',
2723
value_type: ValueType.string,
2824
width: '',
29-
} as IColumnConf);
25+
} as IColumnConf;
26+
};
27+
28+
const renderTabName = (field: IColumnConf, index: number) => {
29+
const n = field.label.trim();
30+
return n ? n : index + 1;
3031
};
3132

3233
watch(['columns', 'ignored_column_keys']);
@@ -63,38 +64,17 @@ export const ColumnsField = ({ control, watch }: IColumnsField) => {
6364
/>
6465
)}
6566
{!use_raw_columns && (
66-
<Stack>
67-
<Tabs
68-
defaultValue={'0'}
69-
styles={{
70-
tab: {
71-
paddingTop: '0px',
72-
paddingBottom: '0px',
73-
},
74-
panel: {
75-
padding: '0px',
76-
paddingTop: '6px',
77-
},
78-
}}
79-
>
80-
<Tabs.List>
81-
{fields.map((_item, index) => (
82-
<Tabs.Tab key={_item.id} value={index.toString()}>
83-
{index + 1}
84-
{/* {field.name.trim() ? field.name : index + 1} */}
85-
</Tabs.Tab>
86-
))}
87-
<Tabs.Tab onClick={addColumn} value="add">
88-
<Plus size={18} color="#228be6" />
89-
</Tabs.Tab>
90-
</Tabs.List>
91-
{fields.map((column, index) => (
92-
<Tabs.Panel key={column.id} value={index.toString()}>
93-
<ColumnField control={control} watch={watch} index={index} column={column} remove={remove} />
94-
</Tabs.Panel>
95-
))}
96-
</Tabs>
97-
</Stack>
67+
<FieldArrayTabs<ITableConf, IColumnConf>
68+
control={control}
69+
watch={watch}
70+
name="columns"
71+
getItem={getItem}
72+
addButtonText={t('viz.table.column.add')}
73+
deleteButtonText={t('viz.table.column.delete')}
74+
renderTabName={renderTabName}
75+
>
76+
{({ field, index }) => <ColumnField control={control} watch={watch} index={index} />}
77+
</FieldArrayTabs>
9878
)}
9979
</>
10080
);

dashboard/src/components/plugins/viz-components/table/translation.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const en = {
55
viz_name: 'Table',
66
column: {
77
labels: 'Columns',
8+
add: 'Add a column',
89
delete: 'Delete this column',
910
query_id: 'Query',
1011
query_id_hint: 'Load table data from this query',
@@ -50,6 +51,7 @@ const zh = {
5051
viz_name: '表格',
5152
column: {
5253
labels: '列设置',
54+
add: '加一列',
5355
delete: '删除这个列',
5456
query_id: '表格数据来源',
5557
query_id_hint: '通过所选的查询获取表格数据',

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@devtable/root",
3-
"version": "13.25.0",
3+
"version": "13.26.0",
44
"private": true,
55
"workspaces": [
66
"api",

settings-form/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@devtable/settings-form",
3-
"version": "13.25.0",
3+
"version": "13.26.0",
44
"license": "Apache-2.0",
55
"publishConfig": {
66
"access": "public",

website/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "@devtable/website",
33
"private": true,
44
"license": "Apache-2.0",
5-
"version": "13.25.0",
5+
"version": "13.26.0",
66
"scripts": {
77
"dev": "vite",
88
"preview": "vite preview"

0 commit comments

Comments
 (0)