Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Advanced Settings] Fix search does not work for terms with ":" #193506

Merged
merged 9 commits into from
Sep 25, 2024
17 changes: 15 additions & 2 deletions packages/kbn-management/settings/application/hooks/use_fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { Query } from '@elastic/eui';
import { Ast, Query } from '@elastic/eui';
import { getFieldDefinitions } from '@kbn/management-settings-field-definition';
import { FieldDefinition } from '@kbn/management-settings-types';
import { UiSettingsScope } from '@kbn/core-ui-settings-common';
import { Clause } from '@elastic/eui/src/components/search_bar/query/ast';
import { useServices } from '../services';
import { useSettings } from './use_settings';

Expand All @@ -29,7 +30,19 @@ export const useFields = (scope: UiSettingsScope, query?: Query): FieldDefinitio
isOverridden: (key) => isOverriddenSetting(key, scope),
});
if (query) {
return Query.execute(query, fields);
const clauses: Clause[] = query.ast.clauses.map((clause) =>
// If the clause value contains `:` and is not a category filter, add it as a term clause
// This allows searching for settings that include `:` in their names
clause.type === 'field' && clause.field !== 'categories'
? {
type: 'term',
match: 'must',
value: `${clause.field}:${clause.value}`,
}
: clause
);

return Query.execute(new Query(Ast.create(clauses), undefined, query.text), fields);
}
return fields;
};