Skip to content

Commit

Permalink
[Embeddable] Hide edit filters if embeddable is type search (elastic#…
Browse files Browse the repository at this point in the history
…202320)

## Summary
This PR hides `Edit filters` button when the type of embeddable is
`search`.

Closes: elastic#196730
  • Loading branch information
kowalczyk-krzysztof authored Dec 3, 2024
1 parent bc4ead1 commit 666e771
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export interface PublishesFilters {
export type PublishesUnifiedSearch = PublishesTimeRange &
PublishesFilters & {
isCompatibleWithUnifiedSearch?: () => boolean;
canEditUnifiedSearch?: () => boolean;
query$: PublishingSubject<Query | AggregateQuery | undefined>;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -67,6 +69,7 @@ describe('filters notification popover', () => {
parentApi: {
viewMode: viewModeSubject,
},
canEditUnifiedSearch,
};
});

Expand Down Expand Up @@ -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')]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -67,6 +68,8 @@ export function FiltersNotificationPopover({ api }: { api: FiltersNotificationAc
getViewModeSubject(api ?? undefined)
);

const showEditButton = !disableEditbutton && parentViewMode === 'edit' && canEditUnifiedSearch;

return (
<EuiPopover
button={
Expand Down Expand Up @@ -126,7 +129,7 @@ export function FiltersNotificationPopover({ api }: { api: FiltersNotificationAc
</EuiFormRow>
)}
</EuiForm>
{!disableEditbutton && parentViewMode === 'edit' && (
{showEditButton && (
<EuiPopoverFooter>
<EuiFlexGroup
gutterSize="s"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -189,6 +191,7 @@ export const initializeSearchEmbeddableApi = async (
setFilters,
query$,
setQuery,
canEditUnifiedSearch,
},
stateManager,
comparators: {
Expand Down

0 comments on commit 666e771

Please sign in to comment.