refactor(table): move callbacks from table element

call table callbacks in hocs
This commit is contained in:
Chika 2021-04-27 10:53:28 +03:00
parent 82c428101d
commit aa59a7813a
2 changed files with 8 additions and 7 deletions

View File

@ -65,7 +65,6 @@ const Table = ({
rows,
params: { features },
withTableValue,
callbacks,
}) => {
return (
<TableWrapper>
@ -95,7 +94,6 @@ const Table = ({
tableName,
rowIndex: ri,
propName: rowPropName,
columnCallback: callbacks && callbacks[rowPropName],
...columns[columnIndex].props,
});
return (

View File

@ -6,21 +6,24 @@ import { useStores } from 'client/hooks/useStores';
import { observer } from 'mobx-react-lite';
export default Table => props => {
const { name: tableName } = props;
const { name: tableName, callbacks } = props;
const ObservedTable = observer(Table);
const { calculationStore } = useStores();
const tableData = calculationStore.tables[tableName];
return () => (
<ObservedTable {...props} {...tableData} withTableValue={withTableValue} />
<ObservedTable
{...props}
{...tableData}
withTableValue={withTableValue(callbacks)}
/>
);
};
const withTableValue = Component => ({
const withTableValue = callbacks => Component => ({
tableName,
rowIndex,
propName,
validation,
columnCallback,
...props
}) =>
observer(() => {
@ -28,7 +31,7 @@ const withTableValue = Component => ({
tableName,
rowIndex,
propName,
columnCallback,
columnCallback: callbacks && callbacks[propName],
});
const { status } = useTableStatus({ tableName, rowIndex, propName });
const { validateStatus, message } = useTableValidation({