Skip to content

Commit

Permalink
feat(Datagrid): add feature flag to select hooks until fully released (
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewgallo authored May 4, 2023
1 parent 5959308 commit 387b593
Show file tree
Hide file tree
Showing 17 changed files with 179 additions and 37 deletions.
2 changes: 1 addition & 1 deletion packages/cloud-cognitive/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ const App = () => {
};
```

### Enabling Canary components
### Enabling Canary components and flagged features

Components that have not yet completed the release review process are considered
to be canary and require the consumer to enable via a feature flag in a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ export default {
page: mdx,
},
},
argTypes: {
featureFlags: {
table: {
disable: true,
},
},
},
};

const getColumns = (rows) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ export default {
styles,
docs: { page: mdx },
},
argTypes: {
featureFlags: {
table: {
disable: true,
},
},
},
};

const blockClass = `${pkg.prefix}--datagrid`;
Expand Down Expand Up @@ -199,6 +206,12 @@ const ColumnCustomizationUsage = ({ ...args }) => {
useColumnOrder
);

// Warnings are ordinarily silenced in storybook, add this to test
pkg._silenceWarnings(false);
// Enable feature flag for `useCustomizeColumns` hook
pkg.feature['Datagrid.useCustomizeColumns'] = true;
pkg._silenceWarnings(true);

return (
<>
<Datagrid datagridState={datagridState} />
Expand Down Expand Up @@ -235,6 +248,7 @@ export const ColumnCustomizationUsageStory = prepareStory(
},
args: {
...columnCustomizationControlProps,
featureFlags: ['Datagrid.useCustomizeColumns'],
},
}
);
Expand Down Expand Up @@ -263,6 +277,12 @@ const ColumnCustomizationWithFixedColumn = ({ ...args }) => {
);
const [data] = useState(makeData(10));

// Warnings are ordinarily silenced in storybook, add this to test
pkg._silenceWarnings(false);
// Enable feature flag for `useCustomizeColumns` hook
pkg.feature['Datagrid.useCustomizeColumns'] = true;
pkg._silenceWarnings(true);

const datagridState = useDatagrid(
{
className: `c4p--datagrid__hidden--columns`,
Expand Down Expand Up @@ -337,6 +357,7 @@ export const ColumnCustomizationWithFixedColumnStory = prepareStory(
},
args: {
...columnCustomizationControlProps,
featureFlags: ['Datagrid.useCustomizeColumns'],
},
}
);
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable react-hooks/exhaustive-deps */
/**
* Copyright IBM Corp. 2022, 2022
* Copyright IBM Corp. 2022, 2023
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
Expand All @@ -20,6 +20,7 @@ import { DatagridActions } from '../../utils/DatagridActions';
import { DatagridPagination } from '../../utils/DatagridPagination';
import { makeData } from '../../utils/makeData';
import { ARG_TYPES } from '../../utils/getArgTypes';
import { pkg } from '../../../../settings';

export default {
title: `${getStoryTitle(Datagrid.displayName)}/Extensions/ExpandableRow`,
Expand All @@ -28,6 +29,13 @@ export default {
styles,
docs: { page: mdx },
},
argTypes: {
featureFlags: {
table: {
disable: true,
},
},
},
};

const defaultHeader = [
Expand Down Expand Up @@ -198,6 +206,12 @@ const ExpandedRows = ({ ...args }) => {
const [data] = useState(makeData(10));
const rows = React.useMemo(() => data, [data]);

// Warnings are ordinarily silenced in storybook, add this to test.
pkg._silenceWarnings(false);
// Enable feature flag for `useExpandedRow` hook
pkg.feature['Datagrid.useExpandedRow'] = true;
pkg._silenceWarnings(true);

const datagridState = useDatagrid(
{
columns,
Expand Down Expand Up @@ -236,5 +250,6 @@ export const ExpandableRowStory = prepareStory(BasicTemplateWrapper, {
},
args: {
...expandableRowControlProps,
featureFlags: ['Datagrid.useExpandedRow'],
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { makeData } from '../../utils/makeData';
import { ARG_TYPES } from '../../utils/getArgTypes';
import { DatagridActions } from '../../utils/DatagridActions';
import { StatusIcon } from '../../../StatusIcon';
import { pkg } from '../../../../settings';

export default {
title: `${getStoryTitle(Datagrid.displayName)}/Extensions/Filtering/Flyout`,
Expand All @@ -28,6 +29,13 @@ export default {
styles,
docs: { page: mdx },
},
argTypes: {
featureFlags: {
table: {
disable: true,
},
},
},
};

const getBatchActions = () => {
Expand Down Expand Up @@ -153,6 +161,12 @@ const FilteringUsage = ({ defaultGridProps }) => {
const columns = React.useMemo(() => headers, []);
const [data] = useState(makeData(20));

// Warnings are ordinarily silenced in storybook, add this to test
pkg._silenceWarnings(false);
// Enable feature flag for `useFiltering` hook
pkg.feature['Datagrid.useFiltering'] = true;
pkg._silenceWarnings(true);

const datagridState = useDatagrid(
{
columns,
Expand Down Expand Up @@ -310,6 +324,7 @@ export const FlyoutBatch = prepareStory(FilteringTemplateWrapper, {
onFlyoutClose: action('onFlyoutClose'),
filters,
},
featureFlags: ['Datagrid.useFiltering'],
},
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable react-hooks/exhaustive-deps */
/**
* Copyright IBM Corp. 2022, 2022
* Copyright IBM Corp. 2022, 2023
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
Expand Down Expand Up @@ -31,6 +31,13 @@ export default {
styles,
docs: { page: mdx },
},
argTypes: {
featureFlags: {
table: {
disable: true,
},
},
},
};

const sharedDatagridProps = {
Expand Down Expand Up @@ -84,6 +91,11 @@ const InlineEditUsage = ({ ...args }) => {
const [data, setData] = useState(makeData(10));
const columns = React.useMemo(() => getInlineEditColumns(), []);

// Warnings are ordinarily silenced in storybook, add this to test.
pkg._silenceWarnings(false);
pkg.feature['Datagrid.useInlineEdit'] = true;
pkg._silenceWarnings(true);

const datagridState = useDatagrid(
{
columns,
Expand Down Expand Up @@ -151,5 +163,6 @@ export const InlineEditUsageStory = prepareStory(InlineEditTemplateWrapper, {
},
args: {
...inlineEditUsageControlProps,
featureFlags: ['Datagrid.useInlineEdit'],
},
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable react-hooks/exhaustive-deps */
/**
* Copyright IBM Corp. 2022, 2022
* Copyright IBM Corp. 2022, 2023
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
Expand All @@ -19,6 +19,7 @@ import mdx from '../../Datagrid.mdx';
import { DatagridActions } from '../../utils/DatagridActions';
import { makeData } from '../../utils/makeData';
import { ARG_TYPES } from '../../utils/getArgTypes';
import { pkg } from '../../../../settings';

export default {
title: `${getStoryTitle(Datagrid.displayName)}/Extensions/NestedRows`,
Expand All @@ -27,6 +28,13 @@ export default {
styles,
docs: { page: mdx },
},
argTypes: {
featureFlags: {
table: {
disable: true,
},
},
},
};

const defaultHeader = [
Expand Down Expand Up @@ -146,6 +154,13 @@ const sharedDatagridProps = {
const NestedRows = ({ ...args }) => {
const columns = React.useMemo(() => defaultHeader, []);
const [data] = useState(makeData(10, 5, 2, 2));

// Warnings are ordinarily silenced in storybook, add this to test
pkg._silenceWarnings(false);
// Enable feature flag for `useNestedRows` hook
pkg.feature['Datagrid.useNestedRows'] = true;
pkg._silenceWarnings(true);

const datagridState = useDatagrid(
{
columns,
Expand Down Expand Up @@ -184,5 +199,6 @@ export const NestedRowsUsageStory = prepareStory(BasicTemplateWrapper, {
},
args: {
...nestedRowsControlProps,
featureFlags: ['Datagrid.useNestedRows'],
},
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable react-hooks/exhaustive-deps */
/**
* Copyright IBM Corp. 2022, 2022
* Copyright IBM Corp. 2022, 2023
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
Expand All @@ -27,6 +27,7 @@ import { DatagridActions } from '../../utils/DatagridActions';
import { DatagridPagination } from '../../utils/DatagridPagination';
import { makeData } from '../../utils/makeData';
import { ARG_TYPES } from '../../utils/getArgTypes';
import { pkg } from '../../../../settings';

export default {
title: `${getStoryTitle(Datagrid.displayName)}/Extensions/RowActionButtons`,
Expand All @@ -35,6 +36,13 @@ export default {
styles,
docs: { page: mdx },
},
argTypes: {
featureFlags: {
table: {
disable: true,
},
},
},
};

const defaultHeader = [
Expand Down Expand Up @@ -166,6 +174,12 @@ const RowActionButtons = ({ ...args }) => {
const [data] = useState(makeData(10));
const rows = React.useMemo(() => data, [data]);

// Warnings are ordinarily silenced in storybook, add this to test.
pkg._silenceWarnings(false);
// Enable feature flag for `useActionsColumn` hook
pkg.feature['Datagrid.useActionsColumn'] = true;
pkg._silenceWarnings(true);

const datagridState = useDatagrid(
{
columns,
Expand Down Expand Up @@ -208,6 +222,7 @@ export const RowActionButtonsUsageStory = prepareStory(
},
args: {
...rowActionButtonsProps,
featureFlags: ['Datagrid.useActionsColumn'],
},
}
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
* Licensed Materials - Property of IBM
* 5724-Q36
* (c) Copyright IBM Corp. 2021
* US Government Users Restricted Rights - Use, duplication or disclosure
* restricted by GSA ADP Schedule Contract with IBM Corp.
/**
* Copyright IBM Corp. 2021, 2023
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
import React from 'react';

import React, { useEffect } from 'react';
import cx from 'classnames';
import {
IconSkeleton,
Expand All @@ -16,6 +16,10 @@ import { pkg } from '../../settings';
const blockClass = `${pkg.prefix}--datagrid`;

const useActionsColumn = (hooks) => {
useEffect(() => {
pkg.checkReportFeatureEnabled('Datagrid.useActionsColumn');
}, []);

const useAttachActionsOnInstance = (instance) => {
const { rowActions, isFetching, selectedFlatRows } = instance;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
/**
* Copyright IBM Corp. 2022, 2022
* Copyright IBM Corp. 2022, 2023
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/

import * as React from 'react';
import { pkg } from '../../settings';
import {
CustomizeColumnsTearsheetWrapper,
ToggleButtonWrapper,
} from './Datagrid/addons/CustomizeColumns';

const useCustomizeColumns = (hooks) => {
React.useEffect(() => {
pkg.checkReportFeatureEnabled('Datagrid.useCustomizeColumns');
}, []);

const [isTearsheetOpen, setIsTearsheetOpen] = React.useState(false);
hooks.useInstance.push((instance) => {
const { customizeColumnsProps } = instance;
Expand Down
19 changes: 12 additions & 7 deletions packages/cloud-cognitive/src/components/Datagrid/useExpandedRow.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
/*
* Licensed Materials - Property of IBM
* 5724-Q36
* (c) Copyright IBM Corp. 2020
* US Government Users Restricted Rights - Use, duplication or disclosure
* restricted by GSA ADP Schedule Contract with IBM Corp.
/**
* Copyright IBM Corp. 2020, 2023
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
import { useState } from 'react';

import { useEffect, useState } from 'react';
import { pkg } from '../../settings';
import DatagridExpandedRow from './Datagrid/DatagridExpandedRow';
import useRowExpander from './useRowExpander';

const useExpandedRow = (hooks) => {
useEffect(() => {
pkg.checkReportFeatureEnabled('Datagrid.useExpandedRow');
}, []);

useRowExpander(hooks);
const useInstance = (instance) => {
const { rows, expandedContentHeight, ExpandedRowContentComponent } =
Expand Down
Loading

0 comments on commit 387b593

Please sign in to comment.