Skip to content

Commit

Permalink
[TableListView] Hide tag filter when savedObjectTagging is not provid…
Browse files Browse the repository at this point in the history
  • Loading branch information
sebelga authored May 6, 2024
1 parent 7a69fdd commit a4140cf
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const getMockServices = (overrides?: Partial<Services>) => {
getTagIdsFromReferences: () => [],
bulkGetUserProfiles: jest.fn(() => Promise.resolve([])),
getUserProfile: jest.fn(),
isTaggingEnabled: () => true,
...overrides,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export function Table<T extends UserContentCommonSchema>({
clearTagSelection,
createdByEnabled,
}: Props<T>) {
const { getTagList } = useServices();
const { getTagList, isTaggingEnabled } = useServices();

const renderToolsLeft = useCallback(() => {
if (!deleteItems || selectedIds.length === 0) {
Expand Down Expand Up @@ -181,7 +181,9 @@ export function Table<T extends UserContentCommonSchema>({
};
}, [hasUpdatedAtMetadata, onSortChange, tableSort]);

const tagFilterPanel = useMemo<SearchFilterConfig>(() => {
const tagFilterPanel = useMemo<SearchFilterConfig | null>(() => {
if (!isTaggingEnabled()) return null;

return {
type: 'custom_component',
component: () => {
Expand All @@ -202,6 +204,7 @@ export function Table<T extends UserContentCommonSchema>({
}, [
isPopoverOpen,
isInUse,
isTaggingEnabled,
closePopover,
options,
totalActiveFilters,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export const getStoryServices = (params: Params, action: ActionFn = () => {}) =>
getTagIdsFromReferences: () => [],
bulkGetUserProfiles: () => Promise.resolve([]),
getUserProfile: jest.fn(),
isTaggingEnabled: () => true,
...params,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ export interface Services {
/** Handler to retrieve the list of available tags */
getTagList: () => Tag[];
TagList: FC<TagListProps>;
/** Predicate to indicate if tagging features is enabled */
isTaggingEnabled: () => boolean;
/** Predicate function to indicate if some of the saved object references are tags */
itemHasTags: (references: SavedObjectsReference[]) => boolean;
/** Handler to return the url to navigate to the kibana tags management */
Expand Down Expand Up @@ -260,6 +262,7 @@ export const TableListViewKibanaProvider: FC<
DateFormatterComp={(props) => <FormattedRelative {...props} />}
currentAppId$={application.currentAppId$}
navigateToUrl={application.navigateToUrl}
isTaggingEnabled={() => Boolean(savedObjectsTagging)}
getTagList={getTagList}
TagList={TagList}
itemHasTags={itemHasTags}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ import moment, { Moment } from 'moment';
import { act } from 'react-dom/test-utils';
import type { ReactWrapper } from 'enzyme';
import type { LocationDescriptor, History } from 'history';
import type { UserContentCommonSchema } from '@kbn/content-management-table-list-view-common';

import { WithServices } from './__jest__';
import { getTagList } from './mocks';
import { TableListViewTable, type TableListViewTableProps } from './table_list_view_table';
import { getActions } from './table_list_view.test.helpers';
import type { UserContentCommonSchema } from '@kbn/content-management-table-list-view-common';
import type { Services } from './services';

const mockUseEffect = useEffect;

Expand Down Expand Up @@ -75,13 +76,17 @@ describe('TableListView', () => {
jest.useRealTimers();
});

const setup = registerTestBed<string, TableListViewTableProps>(
WithServices<TableListViewTableProps>(TableListViewTable),
{
defaultProps: { ...requiredProps },
memoryRouter: { wrapComponent: true },
}
);
const setup = (
propsOverride?: Partial<TableListViewTableProps>,
serviceOverride?: Partial<Services>
) =>
registerTestBed<string, TableListViewTableProps>(
WithServices<TableListViewTableProps>(TableListViewTable, serviceOverride),
{
defaultProps: { ...requiredProps },
memoryRouter: { wrapComponent: true },
}
)(propsOverride);

describe('empty prompt', () => {
test('render default empty prompt', async () => {
Expand Down Expand Up @@ -756,9 +761,11 @@ describe('TableListView', () => {
});
});

const { component, table, find } = testBed!;
const { component, table, find, exists } = testBed!;
component.update();

expect(exists('tagFilterPopoverButton')).toBe(true);

const getSearchBoxValue = () => find('tableListSearchBox').props().defaultValue;

const getLastCallArgsFromFindItems = () =>
Expand Down Expand Up @@ -851,6 +858,25 @@ describe('TableListView', () => {
expect(getSearchBoxValue()).toBe(expected);
expect(searchTerm).toBe(expected);
});

test('should not have the tag filter if tagging is disabled', async () => {
let testBed: TestBed;
const findItems = jest.fn().mockResolvedValue({ total: hits.length, hits });

await act(async () => {
testBed = await setup(
{
findItems,
},
{ isTaggingEnabled: () => false }
);
});

const { component, exists } = testBed!;
component.update();

expect(exists('tagFilterPopoverButton')).toBe(false);
});
});

describe('initialFilter', () => {
Expand Down

0 comments on commit a4140cf

Please sign in to comment.