Skip to content

Commit

Permalink
feat(Datagrid): Filter flyout (carbon-design-system#2406)
Browse files Browse the repository at this point in the history
* fix: filter flyout doesn't close

* feat(Datagrid): Added number and dropdown input filter

* feat(Datagrid): added filterTypes and date between filter

* feat: added cell key to headers and hasClickedOnDatePicker

* fix: removed unused imports

* chore: update yarn lock and cache

* chore(Datagrid): moved filterTypes to useFiltering.js

* feat(Datagrid): changed status icon to return obj

* feat(datagrid): refactor date filter

* fix(datagrid): removed console.log

* feat(datagrid): refactored number filter

* feat(datagrid): refactored dropdown filter

* feat(datagrid): removed type and changed date filter

* fix(datagrid): fixed filterTypes key to reflect changes

* fix(datagrid): changed status_icon to password strength

* feat(datagrid): adds checkbox filter

* feat(datagrid): adding batch actions

* feat(datagrid): adds batch filter method

* fix(datagrid): removed unnecessary date function

* fix(datagrid): added nullish coalescing to filterProps check

* fix(datagrid): this component is no longer needed

* feat(datagrid): adds props for action set labels and callbacks

* feat(datagrid): added flyoutIconDescription prop

* feat(datagrid): added missing copyright headers

* feat(datagrid): added carbon prefixes

* feat(datagrid): overrides action set to display 48px button size

* feat(datagrid): adds checkbox filter

* fix(datagrid): changes chance for each individual property

* feat(datagrid): added extra callback functions to props

* fix(datagrid): added open class back

* feat(datagrid): refactored flyout components

* feat(datagrid): refactored filters to be render in flyout

* feat(datagrid): fixed resetting filters

* fix(datagrid): action set styles

* fix(datagrid): redundant change

* fix(datagrid): redundant change

* fix(datagrid): fixed css properties order

* fix(datagrid): fixed constant typo

* fix(datagrid): fix linting

* chore(datagrid): fix linting issues

* feat(datagrid): adds variation prop

* feat: adds FilterSummary

* fix: removes stylint-disable

* fix(FilterSummary): changed filters prop

* feat(FilterFlyout): adding filter tags

* chore(FilterSummary): clean up adding reset filters

* feat(Datagrid): adds FilterSummary

* fix: added null check to filterProps

* feat(Datagrid): adds optional onChange from user

* feat(Datagrid): added constant, storybook actions and emptystate props

* fix: yarn.lock

* chore: format files

Co-authored-by: Matt Gallo <[email protected]>
  • Loading branch information
2 people authored and Ratheeshrajan committed Jan 31, 2023
1 parent c207d63 commit 2079c78
Show file tree
Hide file tree
Showing 35 changed files with 1,705 additions and 684 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,15 @@
}

// remove the hover behaviour from the side nav
.#{$prefix}--side-nav.#{$prefix}--side-nav--rail:not(.#{$prefix}--side-nav--fixed):not(.#{$prefix}--side-product-nav):hover {
.#{$prefix}--side-nav.#{$prefix}--side-nav--rail:not(
.#{$prefix}--side-nav--fixed
):not(.#{$prefix}--side-product-nav):hover {
width: carbon--mini-units(6);
}

.#{$prefix}--side-nav.#{$prefix}--side-nav--rail:not(.#{$prefix}--side-nav--fixed):not(.#{$prefix}--side-product-nav):hover.#{$prefix}--side-nav--expanded {
.#{$prefix}--side-nav.#{$prefix}--side-nav--rail:not(
.#{$prefix}--side-nav--fixed
):not(.#{$prefix}--side-product-nav):hover.#{$prefix}--side-nav--expanded {
width: carbon--mini-units(32);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@
.#{$block-class}.#{$carbon-prefix}--btn-set.#{$block-class}--max
.#{$block-class}__action-button:not(.#{$block-class}__action-button--ghost),
.#{$block-class}.#{$carbon-prefix}--btn-set.#{$block-class}--row-quadruple
.#{$block-class}__action-button:not(.#{$block-class}__action-button--ghost) {
.#{$block-class}__action-button:not(
.#{$block-class}__action-button--ghost
) {
max-width: rem(232px);
flex: 0 1 25%;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,9 @@
.#{$block-class} .#{$carbon-prefix}--structured-list-row,
.#{$block-class}
.#{$block-class}__selections.#{$carbon-prefix}--structured-list--selection
.#{$carbon-prefix}--structured-list-row:hover:not(.#{$carbon-prefix}--structured-list-row--header-row):not(.#{$carbon-prefix}--structured-list-row--selected) {
.#{$carbon-prefix}--structured-list-row:hover:not(
.#{$carbon-prefix}--structured-list-row--header-row
):not(.#{$carbon-prefix}--structured-list-row--selected) {
border-bottom: 0;
}

Expand Down
249 changes: 230 additions & 19 deletions packages/cloud-cognitive/src/components/Datagrid/Datagrid.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,39 @@
* LICENSE file in the root directory of this source tree.
*/

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

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 {
Datagrid,
useActionsColumn,
useDatagrid,
useDisableSelectRows,
useFiltering,
useInfiniteScroll,
useRowIsMouseOver,
useSelectAllWithToggle,
useSelectRows,
useSortableColumns,
useDisableSelectRows,
useSelectAllWithToggle,
useStickyColumn,
useActionsColumn,
} from '.';

import { SelectAllWitHToggle, LeftPanelStory } from './Datagrid.stories';
import mdx from './Datagrid.mdx';
import { LeftPanelStory, SelectAllWitHToggle } from './Datagrid.stories';

import { pkg } from '../../settings';

import styles from './_storybook-styles.scss';
import { DatagridActions } from './utils/DatagridActions';
import { DatagridPagination } from './utils/DatagridPagination';
import { Wrapper } from './utils/Wrapper';
import styles from './_storybook-styles.scss';

export default {
title: getStoryTitle(Datagrid.displayName),
Expand Down Expand Up @@ -74,6 +77,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 +114,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 @@ -312,6 +312,217 @@ 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 checkbox 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>
);
},
},
// Shows the checkbox filter example
{
Header: 'Role',
accessor: 'role',
},
];

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

const filters = [
{
type: 'date',
column: 'joined',
props: {
DatePicker: {
datePickerType: 'range',
},
DatePickerInput: {
start: {
id: 'date-picker-input-id-start',
placeholder: 'mm/dd/yyyy',
labelText: 'Joined start date',
},
end: {
id: 'date-picker-input-id-end',
placeholder: 'mm/dd/yyyy',
labelText: 'Joined end date',
},
},
},
},
{
type: 'number',
column: 'visits',
props: {
NumberInput: {
min: 0,
id: 'visits-number-input',
invalidText: 'A valid value is required',
label: 'Visits',
placeholder: 'Type a number amount of visits',
},
},
},
{
type: 'checkbox',
column: 'passwordStrength',
props: {
FormGroup: {
legendText: 'Password strength',
},
Checkbox: [
{
id: 'normal',
labelText: 'Normal',
value: 'normal',
},
{
id: 'minor-warning',
labelText: 'Minor warning',
value: 'minor-warning',
},
{
id: 'critical',
labelText: 'Critical',
value: 'critical',
},
],
},
},
{
type: 'radio',
column: 'role',
props: {
FormGroup: {
legendText: 'Role',
},
RadioButtonGroup: {
orientation: 'vertical',
legend: 'Role legend',
name: 'role-radio-button-group',
},
RadioButton: [
{
id: 'developer',
labelText: 'Developer',
value: 'developer',
},
{
id: 'designer',
labelText: 'Designer',
value: 'designer',
},
{
id: 'researcher',
labelText: 'Researcher',
value: 'researcher',
},
],
},
},
{
type: 'dropdown',
column: 'status',
props: {
Dropdown: {
id: 'marital-status-dropdown',
ariaLabel: 'Marital status dropdown',
items: ['relationship', 'complicated', 'single'],
label: 'Marital status',
titleText: 'Marital status',
},
},
},
];

const datagridState = useDatagrid(
{
columns,
data,
emptyStateTitle: 'No filters match',
emptyStateDescription:
'Data was not found with the current filters applied. Change filters or clear filters to see other results.',
filterProps: {
variation: 'flyout',
updateMethod: 'batch',
primaryActionLabel: 'Apply',
secondaryActionLabel: 'Cancel',
flyoutIconDescription: 'Open filters',
shouldClickOutsideToClose: false,
onFlyoutOpen: action('onFlyoutOpen'),
onFlyoutClose: action('onFlyoutClose'),
filters,
},
DatagridActions,
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

0 comments on commit 2079c78

Please sign in to comment.