mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
[TableListView] Hide tag filter when savedObjectTagging is not provided (#182577)
This commit is contained in:
parent
7a69fdd469
commit
a4140cfd5d
5 changed files with 45 additions and 11 deletions
|
@ -27,6 +27,7 @@ export const getMockServices = (overrides?: Partial<Services>) => {
|
|||
getTagIdsFromReferences: () => [],
|
||||
bulkGetUserProfiles: jest.fn(() => Promise.resolve([])),
|
||||
getUserProfile: jest.fn(),
|
||||
isTaggingEnabled: () => true,
|
||||
...overrides,
|
||||
};
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
@ -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: () => {
|
||||
|
@ -202,6 +204,7 @@ export function Table<T extends UserContentCommonSchema>({
|
|||
}, [
|
||||
isPopoverOpen,
|
||||
isInUse,
|
||||
isTaggingEnabled,
|
||||
closePopover,
|
||||
options,
|
||||
totalActiveFilters,
|
||||
|
|
|
@ -73,6 +73,7 @@ export const getStoryServices = (params: Params, action: ActionFn = () => {}) =>
|
|||
getTagIdsFromReferences: () => [],
|
||||
bulkGetUserProfiles: () => Promise.resolve([]),
|
||||
getUserProfile: jest.fn(),
|
||||
isTaggingEnabled: () => true,
|
||||
...params,
|
||||
};
|
||||
|
||||
|
|
|
@ -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 */
|
||||
|
@ -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}
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
@ -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 () => {
|
||||
|
@ -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 = () =>
|
||||
|
@ -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', () => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue