Skip to content
This repository has been archived by the owner on Apr 19, 2024. It is now read-only.

Commit

Permalink
Revert "feat(Table): add async actions rendering"
Browse files Browse the repository at this point in the history
This reverts commit 98172cb.
  • Loading branch information
reslene committed Mar 6, 2024
1 parent 98172cb commit 2d1bd42
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 98 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@numaryhq/storybook",
"version": "1.3.0",
"version": "1.2.0",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"files": [
Expand Down
16 changes: 2 additions & 14 deletions src/Table/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export type RowProps = {
keys: Array<string | ((item: any) => void) | null | ReactElement>;
item: any;
id?: string;
renderActions?: () => Promise<any> | any;
renderActions?: () => any;
sx?: SxProps<Theme>;
};

Expand All @@ -78,20 +78,8 @@ export const Row: FunctionComponent<RowProps> = ({
renderActions,
sx,
}) => {
const [actions, setActions] = useState();
const pSx = sx || {};

useEffect(() => {
(async () => {
if (renderActions) {
const renderActionsPromise = await renderActions();
if (renderActionsPromise) {
setActions(renderActionsPromise);
}
}
})();
}, []);

const styles = {
whiteSpace: 'nowrap',
width: '350px',
Expand Down Expand Up @@ -136,7 +124,7 @@ export const Row: FunctionComponent<RowProps> = ({
}
}
})}
{actions && renderActions && <TableCell>{actions}</TableCell>}
{renderActions && <TableCell>{renderActions()}</TableCell>}
</>
</TableRow>
);
Expand Down
84 changes: 1 addition & 83 deletions src/Table/stories.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import React, { useState } from 'react';

import { Box } from '@mui/material';
import { get, reverse, sortBy, uniqueId } from 'lodash';
import { get, reverse, sortBy } from 'lodash';

import { DefaultAutocompleteCheckbox } from './Filters/AutocompleteSelect/stories';

import { Row, Table } from './index';

import { LoadingButton } from '../Buttons/LoadingButton';
import { Chip } from '../Chip';
import { SourceDestination } from '../Sections/SourceDestination';
import { storyDocsParameters } from '../utils';
Expand Down Expand Up @@ -84,87 +83,6 @@ export const DefaultTable = () => (
DefaultTable.storyName = 'Default';
DefaultTable.parameters = storyDocsParameters;

const getDumbPromise = async () => new Promise((resolve) => resolve('Async'));

export const AsyncActionTable = () => {
const renderActionsItem = async (user: User) => {
const label = await getDumbPromise();
const onClick = () => {
alert('work');
};

return (
<Box component="span" sx={{ float: 'right' }}>
<LoadingButton content={`${label} & ${user.name}`} onClick={onClick} />
</Box>
);
};

return (
<Table
labels={labels}
id="default"
items={items}
columns={[
{ key: 'name', label: 'Lastname', width: 20 },
{ key: 'actions', label: '', width: 80 },
]}
onNext={() => null}
onPrevious={() => null}
renderItem={(user: User, index) => (
<Row
key={index}
keys={['name']}
renderActions={async () => await renderActionsItem(user)}
item={user}
/>
)}
/>
);
};

AsyncActionTable.storyName = 'Async Action';
AsyncActionTable.parameters = storyDocsParameters;

export const ActionTable = () => {
const renderActionsItem = (user: User) => {
const onClick = () => {
alert('work');
};

return (
<Box component="span" sx={{ float: 'right' }}>
<LoadingButton content={user.name} onClick={onClick} />
</Box>
);
};

return (
<Table
labels={labels}
id="default"
items={items}
columns={[
{ key: 'name', label: 'Lastname', width: 20 },
{ key: 'actions', label: '', width: 80 },
]}
onNext={() => null}
onPrevious={() => null}
renderItem={(user: User, index) => (
<Row
key={index}
keys={['name']}
renderActions={() => renderActionsItem(user)}
item={user}
/>
)}
/>
);
};

ActionTable.storyName = 'Action';
ActionTable.parameters = storyDocsParameters;

export const SortTable = () => {
const [data, setData] = useState(items);
const [idSort, setIdSort] = useState('asc');
Expand Down

0 comments on commit 2d1bd42

Please sign in to comment.