Skip to content

Commit

Permalink
fix(table): update table stories structure on storybook
Browse files Browse the repository at this point in the history
  • Loading branch information
anuradha9712 committed Nov 25, 2024
1 parent 0001106 commit b91a12d
Show file tree
Hide file tree
Showing 33 changed files with 2,169 additions and 1,411 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const schema: ColumnSchema[] = [
width: '40%',
resizable: true,
tooltip: true,
// pinned: 'left',
separator: true,
translate: (a) => ({
title: `${a.firstName} ${a.lastName}`,
Expand All @@ -21,9 +20,6 @@ const schema: ColumnSchema[] = [
{ label: 'H-R', value: 'h-r' },
{ label: 'S-Z', value: 's-z' },
],
// comparator: (a, b) => (
// a.lastName.localeCompare(b.lastName) && a.firstName.localeCompare(b.firstName)
// ),
onFilterChange: (a, filters) => {
for (const filter of filters) {
switch (filter) {
Expand All @@ -40,28 +36,40 @@ const schema: ColumnSchema[] = [
}
return false;
},
// cellType: 'AVATAR'
cellType: 'AVATAR_WITH_TEXT',
},
{
name: 'customCell',
displayName: 'Custom Cell',
width: 200,
resizable: true,
cellRenderer: (props) => {
const { loading } = props;

if (loading) return <PlaceholderParagraph length="medium" />;

const [weight, setWeight] = React.useState('');

const onChangeWeight = (value: string) => {
setWeight(value);
};

return <EditableInput placeholder="Add Weight" value={weight} onChange={onChangeWeight} size="tiny" />;
},
},
{
name: 'email',
displayName: 'Email',
width: 250,
resizable: true,
sorting: false,
// separator: true,
// pinned: 'left',
// align: 'center',
// comparator: (a, b) => a.email.title.localeCompare(b.email.title),
cellType: 'WITH_META_LIST',
// image: iconImg,
},
{
name: 'gender',
displayName: 'Gender',
width: 180,
resizable: true,
// separator: true,
comparator: (a, b) => a.gender.localeCompare(b.gender),
cellType: 'STATUS_HINT',
translate: (a) => ({
Expand Down Expand Up @@ -89,30 +97,6 @@ const schema: ColumnSchema[] = [
translate: () => ({
icon: 'events',
}),
// separator: true,
// status: "success"
},
{
name: 'customCell',
displayName: 'Custom Cell',
width: 200,
resizable: true,
// pinned: 'right',
// separator: true,
cellRenderer: (props) => {
const { loading } = props;

if (loading) return <PlaceholderParagraph length="medium" />;

const [weight, setWeight] = React.useState('');

const onChangeWeight = (value: string) => {
setWeight(value);
};

return <EditableInput placeholder="Add Weight" value={weight} onChange={onChangeWeight} size="tiny" />;
},
// status: "success"
},
];

Expand Down
2 changes: 1 addition & 1 deletion core/components/organisms/table/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ export const Header = (props: HeaderProps) => {
className="ml-4"
onClick={onClearSelection}
>
Clear Selection
Clear selection
</Button>
{selectionActionRenderer && <Divider vertical={true} className="mx-4 Table-Header--Divider" />}
</div>
Expand Down
155 changes: 155 additions & 0 deletions core/components/organisms/table/__stories__/ErrorInTable.story.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
import * as React from 'react';
import { Card, Table, EmptyState, Button } from '@/index';
import schema from '@/components/organisms/grid/__stories__/_common_/schema';
import { AsyncTable, SyncTable } from '@/components/organisms/table/__stories__/_common_/types';
import noContent from '@innovaccer/mds-images/ui-states/404-nothing-here-3.svg';

// CSF format story
export const errorInTable = () => {
const errorTemplate = () => {
return (
<EmptyState>
<EmptyState.Image src={noContent}></EmptyState.Image>
<EmptyState.Title>Failed to load data</EmptyState.Title>
<EmptyState.Description>
We are unable to fetch the data. Try again. If the issue persists, contact Innovaccer support.
</EmptyState.Description>
<EmptyState.Actions>
<Button icon="refresh">Try again</Button>
</EmptyState.Actions>
</EmptyState>
);
};

return (
<div className="vh-75">
<Card className="h-100 overflow-hidden">
<Table schema={schema} data={[]} error={true} errorTemplate={errorTemplate} />
</Card>
</div>
);
};

const ImagePath = JSON.stringify(noContent);

const customCode = `() => {
// import noContent from '@innovaccer/mds-images/ui-states/404-nothing-here-3.svg';
const schema = [
{
name: 'name',
displayName: 'Name',
width: '40%',
resizable: true,
tooltip: true,
separator: true,
translate: (a) => ({
title: \`\${a.firstName} \${a.lastName}\`,
firstName: a.firstName,
lastName: a.lastName,
}),
filters: [
{ label: 'A-G', value: 'a-g' },
{ label: 'H-R', value: 'h-r' },
{ label: 'S-Z', value: 's-z' },
],
onFilterChange: (a, filters) => {
for (const filter of filters) {
switch (filter) {
case 'a-g':
if (a.firstName[0].toLowerCase() >= 'a' && a.firstName[0].toLowerCase() <= 'g') return true;
break;
case 'h-r':
if (a.firstName[0].toLowerCase() >= 'h' && a.firstName[0].toLowerCase() <= 'r') return true;
break;
case 's-z':
if (a.firstName[0].toLowerCase() >= 's' && a.firstName[0].toLowerCase() <= 'z') return true;
break;
}
}
return false;
},
cellType: 'AVATAR_WITH_TEXT',
},
{
name: 'email',
displayName: 'Email',
width: 250,
resizable: true,
sorting: false,
cellType: 'WITH_META_LIST',
},
{
name: 'gender',
displayName: 'Gender',
width: 180,
resizable: true,
comparator: (a, b) => a.gender.localeCompare(b.gender),
cellType: 'STATUS_HINT',
translate: (a) => ({
title: a.gender,
statusAppearance: a.gender === 'Female' ? 'alert' : 'success',
}),
filters: [
{ label: 'Male', value: 'male' },
{ label: 'Female', value: 'female' },
],
onFilterChange: (a, filters) => {
for (const filter of filters) {
if (a.gender.toLowerCase() === filter) return true;
}
return false;
},
},
{
name: 'icon',
displayName: 'Icon',
width: 100,
resizable: true,
align: 'center',
cellType: 'ICON',
translate: () => ({
icon: 'events',
}),
}
];
const errorTemplate = () => {
return (
<EmptyState>
<EmptyState.Image src={${ImagePath}}></EmptyState.Image>
<EmptyState.Title>Failed to load data</EmptyState.Title>
<EmptyState.Description>
We are unable to fetch the data. Try again. If the issue persists, contact Innovaccer support.
</EmptyState.Description>
<EmptyState.Actions>
<Button icon="refresh">Try again</Button>
</EmptyState.Actions>
</EmptyState>
);
};
return (
<div className="vh-75">
<Card className="h-100 overflow-hidden">
<Table data={[]} schema={schema} error={true} errorTemplate={errorTemplate} />
</Card>
</div>
);
}`;

export default {
title: 'Components/Table/Error In Table',
component: Table,
parameters: {
docs: {
docPage: {
customCode,
props: {
components: { AsyncTable, SyncTable },
exclude: ['showHead'],
},
},
},
},
};
Loading

0 comments on commit b91a12d

Please sign in to comment.