123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- import type {Field, JsonFormObject} from 'sentry/components/forms/types';
- import type {FormSearchField} from 'sentry/stores/formSearchStore';
- import FormSearchStore from 'sentry/stores/formSearchStore';
- type Params = {
- fields: Record<string, Field>;
- formGroups: JsonFormObject[];
- route: string;
- };
- const createSearchMap = ({
- route,
- formGroups,
- fields,
- ...other
- }: Params): FormSearchField[] => {
-
-
-
- const listOfFields = formGroups
- ? formGroups.flatMap(formGroup => formGroup.fields)
- : Object.keys(fields).map(fieldName => fields[fieldName]);
- return listOfFields.map<FormSearchField>(field => ({
- ...other,
- route,
- title: typeof field !== 'function' ? (field.label as string) : undefined,
- description: typeof field !== 'function' ? (field.help as string) : undefined,
- field,
- }));
- };
- export function loadSearchMap() {
-
-
- const context = require.context('../data/forms', true, /\.tsx?$/);
-
- const allFormFields: FormSearchField[] = context.keys().flatMap(key => {
- const mod = context(key);
-
-
- if (!mod?.route) {
- return [];
- }
- const searchMap = createSearchMap({
-
- formGroups: mod.default || mod.formGroups,
- fields: mod.fields,
- route: mod.route,
- });
- if (searchMap !== null) {
- return searchMap;
- }
- return [];
- });
- FormSearchStore.loadSearchMap(allFormFields);
- }
|