Skip to content

Commit

Permalink
make filter options dissapear for non-filterable languages
Browse files Browse the repository at this point in the history
Signed-off-by: abbyhu2000 <[email protected]>
  • Loading branch information
abbyhu2000 committed Aug 21, 2024
1 parent 9385d53 commit d72472c
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
3 changes: 1 addition & 2 deletions src/plugins/data/public/query/query_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,8 @@ import {
IndexPatternsService,
} from '../../common';
import { getUiSettings } from '../services';
import { IndexPattern, ISearchStart } from '..';
import { IndexPattern } from '..';
import { ConfigSchema } from '../../config';
import { SearchService } from '../search/search_service';

/**
* Query Service
Expand Down
28 changes: 26 additions & 2 deletions src/plugins/data/public/ui/search_bar/search_bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -251,12 +251,36 @@ class SearchBarUI extends Component<SearchBarProps, State> {
*/
private shouldRenderTimeFilterInSavedQueryForm() {
const { dateRangeFrom, dateRangeTo, showDatePicker } = this.props;
const enhancement = this.queryStringService
.getLanguageManager()
.getQueryEnhancements(this.state.query?.language!);

// if it is an enhanced language, check the filterable field
if (enhancement) {
return enhancement.fields?.filterable;
}

// otherwise, check if showDatePicker is enabled
return (
showDatePicker ||
(!showDatePicker && dateRangeFrom !== undefined && dateRangeTo !== undefined)
);
}

private shouldRenderFilterInSavedQueryForm() {
const enhancement = this.queryStringService
.getLanguageManager()
.getQueryEnhancements(this.state.query?.language!);

// if it is an enhanced language, check the filterable field
if (enhancement) {
return enhancement.fields?.filterable;
}

// otherwise, check if filters are enabled
return this.props.showFilterBar;
}

public setFilterBarHeight = () => {
requestAnimationFrame(() => {
const height =
Expand Down Expand Up @@ -560,7 +584,7 @@ class SearchBarUI extends Component<SearchBarProps, State> {
savedQueryService={this.savedQueryService}
onSave={this.onSave}
onClose={() => this.setState({ showSaveQueryModal: false })}
showFilterOption={this.props.showFilterBar}
showFilterOption={this.shouldRenderFilterInSavedQueryForm()}
showTimeFilterOption={this.shouldRenderTimeFilterInSavedQueryForm()}
/>
) : null}
Expand All @@ -569,7 +593,7 @@ class SearchBarUI extends Component<SearchBarProps, State> {
savedQueryService={this.savedQueryService}
onSave={(savedQueryMeta) => this.onSave(savedQueryMeta, true)}
onClose={() => this.setState({ showSaveNewQueryModal: false })}
showFilterOption={this.props.showFilterBar}
showFilterOption={this.shouldRenderFilterInSavedQueryForm()}
showTimeFilterOption={this.shouldRenderTimeFilterInSavedQueryForm()}
/>
) : null}
Expand Down
1 change: 1 addition & 0 deletions src/plugins/data/public/ui/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export interface QueryEnhancement {
};
fields?: {
visualizable?: boolean;
filterable?: boolean;
};
// List of supported app names that this enhancement should be enabled for,
// if not provided it will be enabled for all apps
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/query_enhancements/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export class QueryEnhancementsPlugin
},
fields: {
visualizable: false,
filterable: false,
},
supportedAppNames: ['discover'],
},
Expand All @@ -97,6 +98,7 @@ export class QueryEnhancementsPlugin
},
fields: {
visualizable: false,
filterable: false,
},
supportedAppNames: ['discover'],
},
Expand Down

0 comments on commit d72472c

Please sign in to comment.