Skip to content

Commit

Permalink
feat(datagrid): exports FilterContext (#3067)
Browse files Browse the repository at this point in the history
* feat(datagrid): exports FilterContext

* fix: changes the export to custom hook

* fix: removed duplicate import that broke build
  • Loading branch information
AlexanderMelox authored Jun 20, 2023
1 parent 8fb7c59 commit 31d0989
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
export { default as useSubscribeToEventEmitter } from './useSubscribeToEventEmitter';
export { default as useFilters } from './useFilters';
export { default as useShouldDisableButtons } from './useShouldDisableButtons';
export { default as useFilterContext } from './useFilterContext';
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { FilterContext } from '../FilterProvider';
import { useContext } from 'react';

const useFilterContext = () => {
// get the context
const context = useContext(FilterContext);

// if `undefined`, throw an error
if (context === undefined) {
throw new Error('useFilterContext was used outside of its Provider');
}

return context;
};

export default useFilterContext;
1 change: 1 addition & 0 deletions packages/ibm-products/src/components/Datagrid/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ export { default as useInlineEdit } from './useInlineEdit';
export { default as useEditableCell } from './useEditableCell';
export { default as useFiltering } from './useFiltering';
export { getAutoSizedColumnWidth } from './utils/getAutoSizedColumnWidth';
export { useFilterContext } from './Datagrid/addons/Filtering/hooks';
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,36 @@
* LICENSE file in the root directory of this source tree.
*/

import React, { useLayoutEffect, useState, useContext } from 'react';
import {
TableToolbarContent,
TableToolbarSearch,
Add,
ChevronDown,
Download,
Filter,
Restart,
} from '@carbon/react/icons';
import {
Button,
IconButton,
OverflowMenu,
OverflowMenuItem,
ComposedModal,
Dropdown,
IconButton,
ModalBody,
ModalHeader,
ModalFooter,
Dropdown,
ModalHeader,
OverflowMenu,
OverflowMenuItem,
TableToolbarContent,
TableToolbarSearch,
} from '@carbon/react';
import {
Download,
Add,
Restart,
ChevronDown,
Filter,
} from '@carbon/react/icons';
import { ButtonMenu, ButtonMenuItem } from '../../ButtonMenu';
import React, { useLayoutEffect, useState } from 'react';

import { action } from '@storybook/addon-actions';
import { pkg } from '../../../settings';
import { ButtonMenu, ButtonMenuItem } from '../../ButtonMenu';
import { FilterContext } from '../Datagrid/addons/Filtering';
import { useFilterContext } from '../Datagrid/addons/Filtering/hooks';

const blockClass = `${pkg.prefix}--datagrid`;
export const DatagridActions = (datagridState) => {
const { setPanelOpen } = useContext(FilterContext);
const { setPanelOpen } = useFilterContext();
const {
selectedFlatRows,
setGlobalFilter,
Expand Down
1 change: 1 addition & 0 deletions packages/ibm-products/src/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export {
useInlineEdit,
useFiltering,
getAutoSizedColumnWidth,
useFilterContext,
} from './Datagrid';
export { EditTearsheet } from './EditTearsheet';
export { EditTearsheetNarrow } from './EditTearsheetNarrow';
Expand Down

0 comments on commit 31d0989

Please sign in to comment.