Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Datagrid): Filter flyout #2406

Merged
merged 65 commits into from
Nov 29, 2022
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
8d85c9b
fix: filter flyout doesn't close
AlexanderMelox Sep 29, 2022
3662c42
feat(Datagrid): Added number and dropdown input filter
AlexanderMelox Oct 11, 2022
211f4f6
feat(Datagrid): added filterTypes and date between filter
AlexanderMelox Oct 14, 2022
cba9ff2
feat: added cell key to headers and hasClickedOnDatePicker
AlexanderMelox Oct 20, 2022
42939ca
chore: pull from main
AlexanderMelox Oct 20, 2022
9f94513
fix: removed unused imports
AlexanderMelox Oct 20, 2022
4cf03b0
chore: update yarn lock and cache
AlexanderMelox Oct 25, 2022
45cde8a
chore(Datagrid): moved filterTypes to useFiltering.js
AlexanderMelox Oct 25, 2022
9f19cb8
feat(Datagrid): changed status icon to return obj
AlexanderMelox Oct 25, 2022
fc6a38b
feat(datagrid): refactor date filter
AlexanderMelox Oct 25, 2022
d404ccb
fix(datagrid): removed console.log
AlexanderMelox Oct 25, 2022
cd8edc2
feat(datagrid): refactored number filter
AlexanderMelox Oct 25, 2022
580ac1d
feat(datagrid): refactored dropdown filter
AlexanderMelox Oct 25, 2022
9d2de3b
feat(datagrid): removed type and changed date filter
AlexanderMelox Oct 25, 2022
71c86db
fix(datagrid): fixed filterTypes key to reflect changes
AlexanderMelox Oct 25, 2022
6b73252
fix(datagrid): changed status_icon to password strength
AlexanderMelox Oct 26, 2022
832b7ff
feat(datagrid): adds checkbox filter
AlexanderMelox Oct 26, 2022
6e5b834
feat(datagrid): adding batch actions
AlexanderMelox Oct 31, 2022
482aea3
feat(datagrid): adds batch filter method
AlexanderMelox Nov 2, 2022
be850f3
fix(datagrid): removed unnecessary date function
AlexanderMelox Nov 2, 2022
f52ae7f
chore: update branch
AlexanderMelox Nov 2, 2022
0ae49b1
fix(datagrid): added nullish coalescing to filterProps check
AlexanderMelox Nov 2, 2022
7618a3c
fix(datagrid): this component is no longer needed
AlexanderMelox Nov 2, 2022
a3586dc
feat(datagrid): adds props for action set labels and callbacks
AlexanderMelox Nov 3, 2022
4d3b667
feat(datagrid): added flyoutIconDescription prop
AlexanderMelox Nov 3, 2022
3d2d419
feat(datagrid): added missing copyright headers
AlexanderMelox Nov 3, 2022
07d957b
feat(datagrid): added carbon prefixes
AlexanderMelox Nov 3, 2022
5b80f58
feat(datagrid): overrides action set to display 48px button size
AlexanderMelox Nov 3, 2022
71373b9
feat(datagrid): adds checkbox filter
AlexanderMelox Nov 7, 2022
8b834a4
fix(datagrid): changes chance for each individual property
AlexanderMelox Nov 7, 2022
68fa1b4
feat(datagrid): added extra callback functions to props
AlexanderMelox Nov 8, 2022
98a79b8
fix(datagrid): added open class back
AlexanderMelox Nov 8, 2022
d904e58
feat(datagrid): refactored flyout components
AlexanderMelox Nov 9, 2022
a143ecc
feat(datagrid): refactored filters to be render in flyout
AlexanderMelox Nov 10, 2022
9991bf7
feat(datagrid): fixed resetting filters
AlexanderMelox Nov 10, 2022
2108e20
Merge branch 'main' into 2251--filter-flyout-import
AlexanderMelox Nov 10, 2022
ff96f3b
fix(datagrid): action set styles
AlexanderMelox Nov 10, 2022
fea38a9
fix(datagrid): redundant change
AlexanderMelox Nov 10, 2022
622356f
fix(datagrid): redundant change
AlexanderMelox Nov 10, 2022
32d4bf8
fix(datagrid): fixed css properties order
AlexanderMelox Nov 10, 2022
2466e0a
fix(datagrid): fixed constant typo
AlexanderMelox Nov 11, 2022
be1fe48
fix(datagrid): fix linting
AlexanderMelox Nov 11, 2022
4508e20
chore(datagrid): fix linting issues
AlexanderMelox Nov 11, 2022
7d3eba2
feat(datagrid): adds variation prop
AlexanderMelox Nov 11, 2022
29c7c90
Merge branch 'main' into 2251--filter-flyout-import
AlexanderMelox Nov 11, 2022
be47489
Merge branch 'main' into 2251--filter-flyout-import
AlexanderMelox Nov 14, 2022
8d7cea6
Merge branch 'main' into 2251--filter-flyout-import
AlexanderMelox Nov 15, 2022
9e0df26
feat: adds FilterSummary
AlexanderMelox Nov 16, 2022
0e015ff
fix: removes stylint-disable
AlexanderMelox Nov 16, 2022
1476272
Merge branch 'filter-summary' into 2251--filter-flyout-import
AlexanderMelox Nov 16, 2022
ff342f2
fix(FilterSummary): changed filters prop
AlexanderMelox Nov 17, 2022
9c7ed37
feat(FilterFlyout): adding filter tags
AlexanderMelox Nov 17, 2022
54782f5
Merge branch 'filter-summary' into 2251--filter-flyout-import
AlexanderMelox Nov 17, 2022
0d4f3fd
chore(FilterSummary): clean up adding reset filters
AlexanderMelox Nov 17, 2022
5ce1147
feat(Datagrid): adds FilterSummary
AlexanderMelox Nov 18, 2022
a277e08
fix: added null check to filterProps
AlexanderMelox Nov 18, 2022
243c40b
Merge branch 'main' of github.com:carbon-design-system/ibm-cloud-cogn…
AlexanderMelox Nov 18, 2022
c314b03
feat(Datagrid): adds optional onChange from user
AlexanderMelox Nov 21, 2022
de84cb5
feat(Datagrid): added constant, storybook actions and emptystate props
AlexanderMelox Nov 21, 2022
67b4f12
chore: merge main
AlexanderMelox Nov 22, 2022
be16be6
Merge branch 'main' into 2251--filter-flyout-import
matthewgallo Nov 28, 2022
d4b648d
Merge branch 'main' into 2251--filter-flyout-import
AlexanderMelox Nov 28, 2022
7187e90
Merge branch 'main' of github.com:carbon-design-system/ibm-cloud-cogn…
AlexanderMelox Nov 29, 2022
065835f
fix: yarn.lock
AlexanderMelox Nov 29, 2022
9a28d00
chore: format files
AlexanderMelox Nov 29, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
338 changes: 323 additions & 15 deletions packages/cloud-cognitive/src/components/Datagrid/Datagrid.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,30 @@
* LICENSE file in the root directory of this source tree.
*/

import React, { useState, useEffect } from 'react';
import React, { useState, useEffect, useCallback } from 'react';
import { range, makeData, newPersonWithTwoLines } from './utils/makeData';
import { StatusIcon } from '../StatusIcon';

import { getStoryTitle } from '../../global/js/utils/story-helper';

import { action } from '@storybook/addon-actions';
import { Activity16, Add16 } from '@carbon/icons-react';
import { DataTable } from 'carbon-components-react';

import {
Activity16,
Restart16,
Download16,
Filter16,
Add16,
} from '@carbon/icons-react';
import {
DataTable,
Button,
DatePicker,
DatePickerInput,
TextInput,
Dropdown,
Checkbox,
} from 'carbon-components-react';
import {
Datagrid,
useDatagrid,
Expand All @@ -25,6 +41,7 @@ import {
useSelectAllWithToggle,
useStickyColumn,
useActionsColumn,
useFiltering,
} from '.';

import { SelectAllWitHToggle, LeftPanelStory } from './Datagrid.stories';
Expand All @@ -36,6 +53,8 @@ import styles from './_storybook-styles.scss';
import { DatagridActions } from './utils/DatagridActions';
import { DatagridPagination } from './utils/DatagridPagination';
import { Wrapper } from './utils/Wrapper';
import { ButtonMenu, ButtonMenuItem } from '../ButtonMenu';
import { FilterFlyout } from './Datagrid/addons/Filtering';

export default {
title: getStoryTitle(Datagrid.displayName),
Expand Down Expand Up @@ -74,6 +93,15 @@ const defaultHeader = [
accessor: 'visits',
width: 60,
},
{
Header: 'Status',
accessor: 'status',
},
{
Header: 'Joined',
accessor: 'joined',
Cell: ({ cell: { value } }) => <span>{value.toLocaleDateString()}</span>,
},
{
Header: 'Someone 1',
accessor: 'someone1',
Expand Down Expand Up @@ -102,18 +130,6 @@ const defaultHeader = [
Header: 'Someone 7',
accessor: 'someone7',
},
{
Header: 'Someone 8',
accessor: 'someone8',
},
{
Header: 'Someone 9',
accessor: 'someone9',
},
{
Header: 'Someone 10',
accessor: 'someone10',
},
];

const { TableBatchAction, TableBatchActions } = DataTable;
Expand Down Expand Up @@ -308,6 +324,298 @@ export const SelectableRow = () => {
return <Datagrid datagridState={{ ...datagridState }} />;
};

export const Filtering = () => {
const headers = [
{
Header: 'Row Index',
accessor: (row, i) => i,
sticky: 'left',
id: 'rowIndex', // id is required when accessor is a function.
},
{
Header: 'First Name',
accessor: 'firstName',
},
{
Header: 'Last Name',
accessor: 'lastName',
},
{
Header: 'Age',
accessor: 'age',
width: 50,
},
{
Header: 'Visits',
accessor: 'visits',
filter: 'number',
width: 60,
},
{
Header: 'Status',
accessor: 'status',
},
// Shows the date filter example
{
Header: 'Joined',
accessor: 'joined',
filter: 'date',
Cell: ({ cell: { value } }) => <span>{value.toLocaleDateString()}</span>,
},
// Shows the radio button filter example
{
Header: 'Password strength',
accessor: 'passwordStrength',
filter: 'checkbox',
Cell: ({ cell: { value } }) => {
const iconProps = {
size: 'sm',
theme: 'light',
kind: value,
iconDescription: value,
};

return (
<span
style={{
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
}}
>
<StatusIcon {...iconProps} />
{iconProps.iconDescription}
</span>
);
},
},
];

const columns = React.useMemo(() => headers, []);
const [data] = useState(makeData(100));

const FilterDatagridActions = (datagridState) => {
const {
selectedFlatRows,
setGlobalFilter,
CustomizeColumnsButton,
RowSizeDropdown,
rowSizeDropdownProps,
useDenseHeader,
getFilterFlyoutProps,
applyFilters,
} = datagridState;

/** State for filters */
const [passwordOptions, setPasswordOptions] = useState([
{ label: 'Normal', value: 'normal', selected: false },
{ label: 'Minor warning', value: 'minor-warning', selected: false },
{ label: 'Critical', value: 'critical', selected: false },
]);

const downloadCsv = () => {
alert('Downloading...');
};
const { TableToolbarContent, TableToolbarSearch } = DataTable;

const refreshColumns = () => {
alert('refreshing...');
};
const leftPanelClick = () => {
alert('open/close left panel...');
};
const searchForAColumn = 'Search';
const isNothingSelected = selectedFlatRows.length === 0;
const style = {
'button:nth-child(1) > span:nth-child(1)': {
bottom: '-37px',
},
};

const handlePasswordStrengthChange = (isSelected, id) => {
const passwordOptionsCopy = [...passwordOptions];
const option = passwordOptionsCopy.find((option) => option.label === id);
option.selected = isSelected;
setPasswordOptions(passwordOptionsCopy);
};

const renderFilterFlyout = useCallback(() => {
return (
<FilterFlyout {...getFilterFlyoutProps()}>
<DatePicker
datePickerType="range"
onChange={(value) => {
applyFilters({ column: 'joined', value });
}}
>
<DatePickerInput
id="date-picker-input-id-start"
placeholder="mm/dd/yyyy"
labelText="Joined start date"
/>
<DatePickerInput
id="date-picker-input-id-finish"
placeholder="mm/dd/yyyy"
labelText="Joined end date"
/>
</DatePicker>
<TextInput
invalidText="A valid value is required"
labelText="Visits"
placeholder="Type a number amount of visits"
onChange={(event) => {
applyFilters({
column: 'visits',
value: event.target.value,
});
}}
/>
<Dropdown
id="marital-status-dropdown"
ariaLabel="Marital status dropdown"
items={['relationship', 'complicated', 'single']}
label="Marital status"
titleText="Marital status"
onChange={({ selectedItem }) => {
applyFilters({
column: 'status',
value: selectedItem,
});
}}
/>
<fieldset className="bx--fieldset">
AlexanderMelox marked this conversation as resolved.
Show resolved Hide resolved
<legend className="bx--label">Password strength</legend>
{passwordOptions.map((option) => (
<Checkbox
key={option.label}
selected={option.selected}
labelText={option.label}
onChange={(isSelected) => {
handlePasswordStrengthChange(isSelected, option.label);
applyFilters({
column: 'passwordStrength',
value: passwordOptions,
});
}}
id={option.label}
/>
))}
</fieldset>
</FilterFlyout>
);
}, []);

return (
isNothingSelected &&
(useDenseHeader && useDenseHeader ? (
<TableToolbarContent size="sm">
<div style={style}>
<Button
kind="ghost"
hasIconOnly
tooltipPosition="bottom"
renderIcon={Download16}
iconDescription={'Download CSV'}
onClick={downloadCsv}
/>
</div>
<div style={style}>
<Button
kind="ghost"
hasIconOnly
tooltipPosition="bottom"
renderIcon={Filter16}
iconDescription={'Left panel'}
onClick={leftPanelClick}
/>
</div>
{renderFilterFlyout()}
<RowSizeDropdown {...rowSizeDropdownProps} />
<div style={style} className={`${blockClass}__toolbar-divider`}>
<Button kind="ghost" renderIcon={Add16} iconDescription={'Action'}>
Ghost button
</Button>
</div>

{CustomizeColumnsButton && (
<div style={style}>
<CustomizeColumnsButton />
</div>
)}
</TableToolbarContent>
) : (
<TableToolbarContent>
<TableToolbarSearch
size="xl"
id="columnSearch"
persistent
placeHolderText={searchForAColumn}
onChange={(e) => setGlobalFilter(e.target.value)}
/>
{renderFilterFlyout()}
<RowSizeDropdown {...rowSizeDropdownProps} />
<div style={style}>
<Button
kind="ghost"
hasIconOnly
tooltipPosition="bottom"
renderIcon={Restart16}
iconDescription={'Refresh'}
onClick={refreshColumns}
/>
</div>
<div style={style}>
<Button
kind="ghost"
hasIconOnly
tooltipPosition="bottom"
renderIcon={Download16}
iconDescription={'Download CSV'}
onClick={downloadCsv}
/>
</div>
{CustomizeColumnsButton && (
<div style={style}>
<CustomizeColumnsButton />
</div>
)}
<ButtonMenu label="Primary button" renderIcon={Add16}>
<ButtonMenuItem
itemText="Option 1"
onClick={action(`Click on ButtonMenu Option 1`)}
/>
<ButtonMenuItem
itemText="Option 2"
onClick={action(`Click on ButtonMenu Option 2`)}
/>
<ButtonMenuItem
itemText="Option 3"
onClick={action(`Click on ButtonMenu Option 3`)}
/>
</ButtonMenu>
</TableToolbarContent>
))
);
};

const datagridState = useDatagrid(
{
columns,
data,
filterProps: {
updateMethod: 'batch',
},
DatagridActions: FilterDatagridActions,
batchActions: true,
toolbarBatchActions: getBatchActions(),
},
useSelectRows,
useFiltering
);

return <Datagrid datagridState={{ ...datagridState }} />;
};

export const RadioSelect = () => {
const columns = React.useMemo(() => defaultHeader, []);
const [data] = useState(makeData(10));
Expand Down
Loading