mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
[Embeddable] Hide edit filters if embeddable is type search (#202320)
## Summary This PR hides `Edit filters` button when the type of embeddable is `search`. Closes: #196730
This commit is contained in:
parent
bc4ead165a
commit
666e771c21
4 changed files with 19 additions and 1 deletions
|
@ -32,6 +32,7 @@ export interface PublishesFilters {
|
|||
export type PublishesUnifiedSearch = PublishesTimeRange &
|
||||
PublishesFilters & {
|
||||
isCompatibleWithUnifiedSearch?: () => boolean;
|
||||
canEditUnifiedSearch?: () => boolean;
|
||||
query$: PublishingSubject<Query | AggregateQuery | undefined>;
|
||||
};
|
||||
|
||||
|
|
|
@ -18,6 +18,8 @@ import { FiltersNotificationActionApi } from './filters_notification_action';
|
|||
import { FiltersNotificationPopover } from './filters_notification_popover';
|
||||
import { ViewMode } from '@kbn/presentation-publishing';
|
||||
|
||||
const canEditUnifiedSearch = jest.fn().mockReturnValue(true);
|
||||
|
||||
const getMockPhraseFilter = (key: string, value: string): Filter => {
|
||||
return {
|
||||
meta: {
|
||||
|
@ -67,6 +69,7 @@ describe('filters notification popover', () => {
|
|||
parentApi: {
|
||||
viewMode: viewModeSubject,
|
||||
},
|
||||
canEditUnifiedSearch,
|
||||
};
|
||||
});
|
||||
|
||||
|
@ -99,6 +102,14 @@ describe('filters notification popover', () => {
|
|||
).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('does not render an edit button when canEditUnifiedSearch returns false', async () => {
|
||||
await renderAndOpenPopover();
|
||||
canEditUnifiedSearch.mockReturnValueOnce(false);
|
||||
expect(
|
||||
await screen.queryByTestId('filtersNotificationModal__editButton')
|
||||
).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders an edit button when the edit panel action is compatible', async () => {
|
||||
updateViewMode('edit');
|
||||
updateFilters([getMockPhraseFilter('ay', 'oh')]);
|
||||
|
|
|
@ -42,6 +42,7 @@ export function FiltersNotificationPopover({ api }: { api: FiltersNotificationAc
|
|||
|
||||
const filters = useMemo(() => api.filters$?.value, [api]);
|
||||
const displayName = dashboardFilterNotificationActionStrings.getDisplayName();
|
||||
const canEditUnifiedSearch = api.canEditUnifiedSearch?.() ?? true;
|
||||
|
||||
const { queryString, queryLanguage } = useMemo(() => {
|
||||
const query = api.query$?.value;
|
||||
|
@ -67,6 +68,8 @@ export function FiltersNotificationPopover({ api }: { api: FiltersNotificationAc
|
|||
getViewModeSubject(api ?? undefined)
|
||||
);
|
||||
|
||||
const showEditButton = !disableEditbutton && parentViewMode === 'edit' && canEditUnifiedSearch;
|
||||
|
||||
return (
|
||||
<EuiPopover
|
||||
button={
|
||||
|
@ -126,7 +129,7 @@ export function FiltersNotificationPopover({ api }: { api: FiltersNotificationAc
|
|||
</EuiFormRow>
|
||||
)}
|
||||
</EuiForm>
|
||||
{!disableEditbutton && parentViewMode === 'edit' && (
|
||||
{showEditButton && (
|
||||
<EuiPopoverFooter>
|
||||
<EuiFlexGroup
|
||||
gutterSize="s"
|
||||
|
|
|
@ -110,6 +110,8 @@ export const initializeSearchEmbeddableApi = async (
|
|||
searchSource.getField('query')
|
||||
);
|
||||
|
||||
const canEditUnifiedSearch = () => false;
|
||||
|
||||
/** This is the state that has to be fetched */
|
||||
const rows$ = new BehaviorSubject<DataTableRecord[]>([]);
|
||||
const columnsMeta$ = new BehaviorSubject<DataTableColumnsMeta | undefined>(undefined);
|
||||
|
@ -189,6 +191,7 @@ export const initializeSearchEmbeddableApi = async (
|
|||
setFilters,
|
||||
query$,
|
||||
setQuery,
|
||||
canEditUnifiedSearch,
|
||||
},
|
||||
stateManager,
|
||||
comparators: {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue