Skip to content

Commit

Permalink
fix: fixed Table propTypes is removed in prod mode (#2031)
Browse files Browse the repository at this point in the history
Co-authored-by: shijia.me <shijia.me@bytedance.com>
  • Loading branch information
shijiatongxue and shijiame authored Jan 19, 2024
1 parent 424e683 commit 12ad898
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 70 deletions.
5 changes: 4 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ module.exports = {
'jsx-a11y/mouse-events-have-key-events': ['warn'],
'object-curly-spacing': ['error', 'always'],
'space-before-blocks': ['error', 'always'],
'max-len': 'off'
'max-len': 'off',
'react/forbid-foreign-prop-types': ['error', { "allowInPropTypes": true }]

},
globals: {
"sinon": "readonly",
Expand Down Expand Up @@ -130,6 +132,7 @@ module.exports = {
}
}
],
'react/forbid-foreign-prop-types': ['error', { "allowInPropTypes": true }]
}
},
],
Expand Down
89 changes: 47 additions & 42 deletions packages/semi-ui/table/Body/BaseRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,51 +62,56 @@ export interface BaseRowProps {
virtualized?: Virtualized;
visible: boolean; // required
/** whether display none */
displayNone?: boolean;
displayNone?: boolean
}

/**
* avoid affected by https://www.npmjs.com/package/babel-plugin-transform-react-remove-prop-types
*/
export const baseRowPropTypes = {
anyColumnFixed: PropTypes.bool,
cellWidths: PropTypes.array.isRequired,
className: PropTypes.string,
columns: PropTypes.array.isRequired,
components: PropTypes.object.isRequired,
disabled: PropTypes.bool,
expandIcon: PropTypes.oneOfType([PropTypes.bool, PropTypes.func, PropTypes.node]),
expandableRow: PropTypes.bool,
expanded: PropTypes.bool,
displayNone: PropTypes.bool,
expandedRow: PropTypes.bool,
fixed: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
height: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
hideExpandedColumn: PropTypes.bool,
hovered: PropTypes.bool.isRequired,
indent: PropTypes.number,
indentSize: PropTypes.number,
index: PropTypes.number,
isSection: PropTypes.bool,
level: PropTypes.number,
onDidUpdate: PropTypes.func,
onHover: PropTypes.func,
onRow: PropTypes.func,
onRowClick: PropTypes.func,
onRowContextMenu: PropTypes.func,
onRowDoubleClick: PropTypes.func,
onRowMouseEnter: PropTypes.func,
onRowMouseLeave: PropTypes.func,
prefixCls: PropTypes.string,
record: PropTypes.object,
renderExpandIcon: PropTypes.func,
replaceClassName: PropTypes.string,
rowExpandable: PropTypes.func,
rowKey: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired, // real key of the row
selected: PropTypes.bool,
store: PropTypes.object,
style: PropTypes.object,
virtualized: PropTypes.oneOfType([PropTypes.object, PropTypes.bool]),
visible: PropTypes.bool.isRequired,
};

export default class TableRow extends BaseComponent<BaseRowProps, Record<string, any>> {
static propTypes = {
anyColumnFixed: PropTypes.bool,
cellWidths: PropTypes.array.isRequired,
className: PropTypes.string,
columns: PropTypes.array.isRequired,
components: PropTypes.object.isRequired,
disabled: PropTypes.bool,
expandIcon: PropTypes.oneOfType([PropTypes.bool, PropTypes.func, PropTypes.node]),
expandableRow: PropTypes.bool,
expanded: PropTypes.bool,
displayNone: PropTypes.bool,
expandedRow: PropTypes.bool,
fixed: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
height: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
hideExpandedColumn: PropTypes.bool,
hovered: PropTypes.bool.isRequired,
indent: PropTypes.number,
indentSize: PropTypes.number,
index: PropTypes.number,
isSection: PropTypes.bool,
level: PropTypes.number,
onDidUpdate: PropTypes.func,
onHover: PropTypes.func,
onRow: PropTypes.func,
onRowClick: PropTypes.func,
onRowContextMenu: PropTypes.func,
onRowDoubleClick: PropTypes.func,
onRowMouseEnter: PropTypes.func,
onRowMouseLeave: PropTypes.func,
prefixCls: PropTypes.string,
record: PropTypes.object,
renderExpandIcon: PropTypes.func,
replaceClassName: PropTypes.string,
rowExpandable: PropTypes.func,
rowKey: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired, // real key of the row
selected: PropTypes.bool,
store: PropTypes.object,
style: PropTypes.object,
virtualized: PropTypes.oneOfType([PropTypes.object, PropTypes.bool]),
visible: PropTypes.bool.isRequired,
};
static propTypes = baseRowPropTypes;

static defaultProps = {
columns: [] as [],
Expand Down
48 changes: 27 additions & 21 deletions packages/semi-ui/table/Body/SectionRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,32 +40,38 @@ export interface SectionRowProps {
rowKey?: RowKey<any>
}

/**
* avoid affected by https://www.npmjs.com/package/babel-plugin-transform-react-remove-prop-types
*/
export const sectionRowPropTypes = {
record: PropTypes.object,
index: PropTypes.number,
columns: PropTypes.array,
group: PropTypes.object.isRequired,
groupKey: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,
data: PropTypes.array,
renderGroupSection: PropTypes.func, // render group title
onGroupedRow: PropTypes.func,
clickGroupedRowToExpand: PropTypes.bool,
components: PropTypes.object,
expanded: PropTypes.bool,
prefixCls: PropTypes.string,
onExpand: PropTypes.func,
virtualized: PropTypes.oneOfType([PropTypes.bool, PropTypes.object]),
style: PropTypes.object,
renderExpandIcon: PropTypes.func, // passing to baseRow
className: PropTypes.string,
store: PropTypes.object,
rowKey: PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.func]),
};

/**
* Grouping component title row
*/
class SectionRow extends PureComponent<SectionRowProps> {
static contextType = TableContext;
static propTypes = {
record: PropTypes.object,
index: PropTypes.number,
columns: PropTypes.array,
group: PropTypes.object.isRequired,
groupKey: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,
data: PropTypes.array,
renderGroupSection: PropTypes.func, // render group title
onGroupedRow: PropTypes.func,
clickGroupedRowToExpand: PropTypes.bool,
components: PropTypes.object,
expanded: PropTypes.bool,
prefixCls: PropTypes.string,
onExpand: PropTypes.func,
virtualized: PropTypes.oneOfType([PropTypes.bool, PropTypes.object]),
style: PropTypes.object,
renderExpandIcon: PropTypes.func, // passing to baseRow
className: PropTypes.string,
store: PropTypes.object,
rowKey: PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.func]),
};
static propTypes = sectionRowPropTypes;

static defaultProps = {
prefixCls: cssClasses.PREFIX,
components: {
Expand Down
12 changes: 6 additions & 6 deletions packages/semi-ui/table/Body/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import Store from '@douyinfe/semi-foundation/utils/Store';
import BaseComponent, { BaseProps } from '../../_base/baseComponent';
import { logger } from '../utils';
import ColGroup from '../ColGroup';
import BaseRow from './BaseRow';
import BaseRow, { baseRowPropTypes } from './BaseRow';
import ExpandedRow from './ExpandedRow';
import SectionRow from './SectionRow';
import SectionRow, { sectionRowPropTypes } from './SectionRow';
import TableHeader from '../TableHeader';
import ConfigContext from '../../configProvider/context';
import TableContext, { TableContextProps } from '../table-context';
Expand Down Expand Up @@ -74,7 +74,7 @@ export interface BodyProps extends BaseProps {
renderExpandIcon: (record: Record<string, any>, isNested: boolean) => ReactNode | null;
headerRef?: React.MutableRefObject<HTMLDivElement> | ((instance: any) => void);
onScroll?: VirtualizedOnScroll;
keepDOM?: boolean;
keepDOM?: boolean
}

export interface BodyState {
Expand Down Expand Up @@ -457,7 +457,7 @@ class Body extends BaseComponent<BodyProps, BodyState> {
*/
renderSectionRow = (props: RenderSectionRowProps = { groupKey: undefined }) => {
const { dataSource, rowKey, group, groupKey, index } = props;
const sectionRowPickKeys = Object.keys(SectionRow.propTypes);
const sectionRowPickKeys = Object.keys(sectionRowPropTypes);
const sectionRowProps: any = pick(props, sectionRowPickKeys);

const { handleRowExpanded } = this.context;
Expand Down Expand Up @@ -543,7 +543,7 @@ class Body extends BaseComponent<BodyProps, BodyState> {
expandRowByClick,
} = props;

const baseRowPickKeys = Object.keys(BaseRow.propTypes);
const baseRowPickKeys = Object.keys(baseRowPropTypes);
const baseRowProps: Record<string, any> = pick(props, baseRowPickKeys);

let key = getRecordKey(record, rowKey);
Expand Down Expand Up @@ -847,7 +847,7 @@ export interface RenderExpandedRowProps {
virtualized?: Virtualized;
level?: number;
keepDOM?: boolean;
displayNone?: boolean;
displayNone?: boolean
}

export interface RenderSectionRowProps {
Expand Down

0 comments on commit 12ad898

Please sign in to comment.