Skip to content

Commit

Permalink
feat: refactor switcher component (#380)
Browse files Browse the repository at this point in the history
* chore: remove old dimension switcher

* refactor: rename icon prefix

* docs: complete switcher api

* refactor: refactor switcher result data structure

* docs: update api docs

* fix: export component

* refactor: refactor switcher

* chore: increase bundle size
  • Loading branch information
wjgogogo authored Sep 28, 2021
1 parent 334aac4 commit f5c2993
Show file tree
Hide file tree
Showing 36 changed files with 491 additions and 1,122 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { act } from 'react-dom/test-utils';
import { getContainer } from '../util/helpers';
import { SheetEntry } from '../util/sheet-entry';
import { getContainer } from 'tests/util/helpers';
import { Switcher } from '@/components/switcher';
import { SwitcherItem } from '@/components/switcher/interface';
import { SwitcherFields, SwitcherItem } from '@/components/switcher/interface';
import 'antd/dist/antd.min.css';

const mockRows: SwitcherItem[] = [
{ id: 'area', displayName: '区域' },
Expand Down Expand Up @@ -43,29 +43,30 @@ const mockValues: SwitcherItem[] = [
];

function MainLayout() {
const values = ['cost', 'price', 'cost/price'];

const fields: SwitcherFields = {
rows: {
items: mockRows,
},
columns: {
items: mockCols,
},
values: {
selectable: true,
expandable: true,
items: mockValues,
},
};
return (
<div>
<div style={{ margin: '10px' }}>
<Switcher
rows={mockRows}
cols={mockCols}
values={mockValues}
{...fields}
onSubmit={(result) => {
// eslint-disable-next-line no-console
console.log('result: ', result);
}}
/>
</div>
<SheetEntry
dataCfg={{
fields: {
values: values,
},
}}
options={{}}
/>
</div>
);
}
Expand Down
28 changes: 16 additions & 12 deletions packages/s2-core/__tests__/spreadsheet/table-sheet-spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
TableSheet,
} from '@/index';
import { Switcher } from '@/components/switcher';
import { SwitcherItem } from '@/components/switcher/interface';
import { SwitcherFields } from '@/components/switcher/interface';

let s2: TableSheet;

Expand Down Expand Up @@ -159,14 +159,18 @@ function MainLayout({ callback }) {
};
}, []);

const switcherValues: SwitcherItem[] = columns.map((field) => {
return {
id: field,
displayName: find(meta, { field })?.name,
checked: true,
};
});

const switcherFields: SwitcherFields = {
columns: {
selectable: true,
items: columns.map((field) => {
return {
id: field,
displayName: find(meta, { field })?.name,
checked: true,
};
}),
},
};
useEffect(() => {
callback({
setShowPagination,
Expand All @@ -177,11 +181,11 @@ function MainLayout({ callback }) {
<Space direction="vertical">
<Space>
<Switcher
values={switcherValues}
{...switcherFields}
onSubmit={(result) => {
console.log('result: ', result);
const { hiddenValues } = result;
setHiddenColumnFields(hiddenValues);
const { hideItems } = result.columns;
setHiddenColumnFields(hideItems.map((i) => i.id));
}}
/>
<Switch
Expand Down

This file was deleted.

This file was deleted.

Loading

0 comments on commit f5c2993

Please sign in to comment.