59 lines
2.7 KiB
JavaScript
59 lines
2.7 KiB
JavaScript
import React, { createContext, useEffect, useState } from 'react';
|
|
import { translateAttributes } from '../../utils/usefulFn';
|
|
import List from '../list';
|
|
import ToolBar from '../list/toolBar';
|
|
import ButtonGroup from '../list/buttonGroup';
|
|
import Style from './index.module.less';
|
|
import { useWidth } from '../../platforms/web/responsive/useWidth';
|
|
import { useFeatures } from '../../platforms/web';
|
|
import { assert } from 'oak-domain/lib/utils/assert';
|
|
export const TableContext = createContext({
|
|
tableAttributes: undefined,
|
|
entity: undefined,
|
|
schema: undefined,
|
|
setTableAttributes: undefined,
|
|
setSchema: undefined,
|
|
onReset: undefined,
|
|
});
|
|
const ProList = (props) => {
|
|
const { buttonGroup, entity, extraActions, onAction, disabledOp, attributes, data, loading, tablePagination, rowSelection, onReload, disableSerialNumber, title, hideDefaultButtons = false, extraContent, size = 'large', scroll, empty, opWidth, oakPath, } = props;
|
|
assert(!tablePagination);
|
|
const [tableAttributes, setTableAttributes] = useState([]);
|
|
const features = useFeatures();
|
|
const [schema, setSchema] = useState(undefined);
|
|
const width = useWidth();
|
|
const isMobile = width === 'xs';
|
|
const initTableAttributes = () => {
|
|
if (schema) {
|
|
const judgeAttributes = translateAttributes(schema, entity, attributes);
|
|
const newTableAttributes = judgeAttributes.map((ele) => ({
|
|
attribute: ele,
|
|
show: true,
|
|
}));
|
|
setTableAttributes(newTableAttributes);
|
|
}
|
|
};
|
|
useEffect(() => {
|
|
initTableAttributes();
|
|
}, [attributes, schema]);
|
|
return (<TableContext.Provider value={{
|
|
tableAttributes,
|
|
entity: entity,
|
|
schema,
|
|
setTableAttributes,
|
|
setSchema,
|
|
onReset: () => {
|
|
initTableAttributes();
|
|
},
|
|
}}>
|
|
<div className={Style.container}>
|
|
{!isMobile && !hideDefaultButtons && (<ToolBar title={title} extraContent={extraContent} buttonGroup={buttonGroup} reload={() => {
|
|
onReload ? onReload() : features.runningTree.refresh(oakPath);
|
|
}}/>)}
|
|
{isMobile && <ButtonGroup items={buttonGroup}/>}
|
|
<List entity={entity} extraActions={extraActions} onAction={onAction} disabledOp={disabledOp} attributes={attributes} scroll={scroll} empty={empty} data={data} loading={loading} size={size} tablePagination={tablePagination} rowSelection={rowSelection} disableSerialNumber={disableSerialNumber} opWidth={opWidth} oakPath={oakPath}/>
|
|
</div>
|
|
</TableContext.Provider>);
|
|
};
|
|
export default ProList;
|