@backstage/plugin-scaffolder 1.31.0-next.2 → 1.31.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/CHANGELOG.md +57 -0
  2. package/dist/alpha.d.ts +2 -0
  3. package/dist/components/fields/EntityNamePicker/schema.esm.js +4 -3
  4. package/dist/components/fields/EntityNamePicker/schema.esm.js.map +1 -1
  5. package/dist/components/fields/EntityPicker/EntityPicker.esm.js +1 -1
  6. package/dist/components/fields/EntityPicker/EntityPicker.esm.js.map +1 -1
  7. package/dist/components/fields/EntityPicker/schema.esm.js +10 -9
  8. package/dist/components/fields/EntityPicker/schema.esm.js.map +1 -1
  9. package/dist/components/fields/EntityTagsPicker/EntityTagsPicker.esm.js +44 -24
  10. package/dist/components/fields/EntityTagsPicker/EntityTagsPicker.esm.js.map +1 -1
  11. package/dist/components/fields/EntityTagsPicker/schema.esm.js +8 -7
  12. package/dist/components/fields/EntityTagsPicker/schema.esm.js.map +1 -1
  13. package/dist/components/fields/MultiEntityPicker/MultiEntityPicker.esm.js +15 -7
  14. package/dist/components/fields/MultiEntityPicker/MultiEntityPicker.esm.js.map +1 -1
  15. package/dist/components/fields/MultiEntityPicker/schema.esm.js +5 -5
  16. package/dist/components/fields/MultiEntityPicker/schema.esm.js.map +1 -1
  17. package/dist/components/fields/MyGroupsPicker/MyGroupsPicker.esm.js +10 -6
  18. package/dist/components/fields/MyGroupsPicker/MyGroupsPicker.esm.js.map +1 -1
  19. package/dist/components/fields/MyGroupsPicker/schema.esm.js +4 -9
  20. package/dist/components/fields/MyGroupsPicker/schema.esm.js.map +1 -1
  21. package/dist/components/fields/OwnedEntityPicker/OwnedEntityPicker.esm.js +25 -14
  22. package/dist/components/fields/OwnedEntityPicker/OwnedEntityPicker.esm.js.map +1 -1
  23. package/dist/components/fields/OwnedEntityPicker/schema.esm.js +2 -19
  24. package/dist/components/fields/OwnedEntityPicker/schema.esm.js.map +1 -1
  25. package/dist/components/fields/OwnerPicker/schema.esm.js +9 -8
  26. package/dist/components/fields/OwnerPicker/schema.esm.js.map +1 -1
  27. package/dist/components/fields/RepoBranchPicker/RepoBranchPicker.esm.js +3 -1
  28. package/dist/components/fields/RepoBranchPicker/RepoBranchPicker.esm.js.map +1 -1
  29. package/dist/components/fields/RepoBranchPicker/schema.esm.js +5 -6
  30. package/dist/components/fields/RepoBranchPicker/schema.esm.js.map +1 -1
  31. package/dist/components/fields/RepoUrlPicker/RepoUrlPicker.esm.js +3 -1
  32. package/dist/components/fields/RepoUrlPicker/RepoUrlPicker.esm.js.map +1 -1
  33. package/dist/components/fields/RepoUrlPicker/schema.esm.js.map +1 -1
  34. package/dist/components/fields/SecretInput/SecretInput.esm.js +3 -2
  35. package/dist/components/fields/SecretInput/SecretInput.esm.js.map +1 -1
  36. package/dist/index.d.ts +28 -34
  37. package/dist/translation.esm.js +4 -0
  38. package/dist/translation.esm.js.map +1 -1
  39. package/package.json +22 -22
package/CHANGELOG.md CHANGED
@@ -1,5 +1,62 @@
1
1
  # @backstage/plugin-scaffolder
2
2
 
3
+ ## 1.31.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 4235e87: add templating extensions page
8
+
9
+ ### Patch Changes
10
+
11
+ - 92c3658: Full support in EntityPicker (and derivatives) for default EntityPresentationApi
12
+ - fb58f20: Internal update to use the new `pluginId` option of `createFrontendPlugin`.
13
+ - d7da01d: Fix EntityPicker field to render description as markdown, matching other form components in the system.
14
+ - 36ae651: Fixing a bug where the name for `templatingExtensions` was incorrectly set to `templateExtensions`
15
+ - 72d019d: Removed various typos
16
+ - a274e0a: Migrate custom fields to new schema factory function;
17
+ standardize field descriptions to prefer ui:description and present consistently,
18
+ utilizing ScaffolderField component where possible.
19
+ - Updated dependencies
20
+ - @backstage/frontend-plugin-api@0.10.2
21
+ - @backstage/integration@1.17.0
22
+ - @backstage/core-components@0.17.2
23
+ - @backstage/catalog-model@1.7.4
24
+ - @backstage/core-compat-api@0.4.2
25
+ - @backstage/plugin-catalog-react@1.18.0
26
+ - @backstage/plugin-scaffolder-react@1.16.0
27
+ - @backstage/core-plugin-api@1.10.7
28
+ - @backstage/catalog-client@1.10.0
29
+ - @backstage/integration-react@1.2.7
30
+ - @backstage/plugin-permission-react@0.4.34
31
+ - @backstage/errors@1.2.7
32
+ - @backstage/types@1.2.1
33
+ - @backstage/plugin-catalog-common@1.1.4
34
+ - @backstage/plugin-scaffolder-common@1.5.11
35
+
36
+ ## 1.31.0-next.3
37
+
38
+ ### Patch Changes
39
+
40
+ - a274e0a: Migrate custom fields to new schema factory function;
41
+ standardize field descriptions to prefer ui:description and present consistently,
42
+ utilizing ScaffolderField component where possible.
43
+ - Updated dependencies
44
+ - @backstage/integration@1.17.0-next.3
45
+ - @backstage/core-compat-api@0.4.2-next.3
46
+ - @backstage/core-components@0.17.2-next.1
47
+ - @backstage/core-plugin-api@1.10.7-next.0
48
+ - @backstage/plugin-catalog-react@1.18.0-next.3
49
+ - @backstage/plugin-scaffolder-react@1.16.0-next.3
50
+ - @backstage/catalog-client@1.10.0-next.0
51
+ - @backstage/catalog-model@1.7.3
52
+ - @backstage/errors@1.2.7
53
+ - @backstage/frontend-plugin-api@0.10.2-next.1
54
+ - @backstage/integration-react@1.2.7-next.3
55
+ - @backstage/types@1.2.1
56
+ - @backstage/plugin-catalog-common@1.1.4-next.0
57
+ - @backstage/plugin-permission-react@0.4.34-next.1
58
+ - @backstage/plugin-scaffolder-common@1.5.11-next.0
59
+
3
60
  ## 1.31.0-next.2
4
61
 
5
62
  ### Patch Changes
package/dist/alpha.d.ts CHANGED
@@ -80,6 +80,8 @@ declare const scaffolderTranslationRef: _backstage_core_plugin_api_alpha.Transla
80
80
  readonly "fields.entityPicker.description": "An entity from the catalog";
81
81
  readonly "fields.entityTagsPicker.title": "Tags";
82
82
  readonly "fields.entityTagsPicker.description": "Add any relevant tags, hit 'Enter' to add new tags. Valid format: [a-z0-9+#] separated by [-], at most 63 characters";
83
+ readonly "fields.multiEntityPicker.title": "Entity";
84
+ readonly "fields.multiEntityPicker.description": "An entity from the catalog";
83
85
  readonly "fields.myGroupsPicker.title": "Entity";
84
86
  readonly "fields.myGroupsPicker.description": "An entity from the catalog";
85
87
  readonly "fields.ownedEntityPicker.title": "Entity";
@@ -1,7 +1,8 @@
1
- import { z } from 'zod';
2
- import { makeFieldSchemaFromZod } from '../utils.esm.js';
1
+ import { makeFieldSchema } from '@backstage/plugin-scaffolder-react';
3
2
 
4
- const EntityNamePickerFieldSchema = makeFieldSchemaFromZod(z.string());
3
+ const EntityNamePickerFieldSchema = makeFieldSchema({
4
+ output: (z) => z.string()
5
+ });
5
6
  const EntityNamePickerSchema = EntityNamePickerFieldSchema.schema;
6
7
 
7
8
  export { EntityNamePickerSchema };
@@ -1 +1 @@
1
- {"version":3,"file":"schema.esm.js","sources":["../../../../src/components/fields/EntityNamePicker/schema.ts"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { z } from 'zod';\nimport { makeFieldSchemaFromZod } from '../utils';\n\nconst EntityNamePickerFieldSchema = makeFieldSchemaFromZod(z.string());\n\nexport const EntityNamePickerSchema = EntityNamePickerFieldSchema.schema;\n\nexport type EntityNamePickerProps = typeof EntityNamePickerFieldSchema.type;\n"],"names":[],"mappings":";;;AAkBA,MAAM,2BAA8B,GAAA,sBAAA,CAAuB,CAAE,CAAA,MAAA,EAAQ,CAAA;AAE9D,MAAM,yBAAyB,2BAA4B,CAAA;;;;"}
1
+ {"version":3,"file":"schema.esm.js","sources":["../../../../src/components/fields/EntityNamePicker/schema.ts"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { makeFieldSchema } from '@backstage/plugin-scaffolder-react';\n\nconst EntityNamePickerFieldSchema = makeFieldSchema({\n output: z => z.string(),\n});\n\nexport const EntityNamePickerSchema = EntityNamePickerFieldSchema.schema;\n\nexport type EntityNamePickerProps = typeof EntityNamePickerFieldSchema.TProps;\n"],"names":[],"mappings":";;AAiBA,MAAM,8BAA8B,eAAgB,CAAA;AAAA,EAClD,MAAA,EAAQ,CAAK,CAAA,KAAA,CAAA,CAAE,MAAO;AACxB,CAAC,CAAA;AAEM,MAAM,yBAAyB,2BAA4B,CAAA;;;;"}
@@ -106,7 +106,7 @@ const EntityPicker = (props) => {
106
106
  ScaffolderField,
107
107
  {
108
108
  rawErrors,
109
- rawDescription: description,
109
+ rawDescription: uiSchema["ui:description"] ?? description,
110
110
  required,
111
111
  disabled: isDisabled,
112
112
  errors,
@@ -1 +1 @@
1
- {"version":3,"file":"EntityPicker.esm.js","sources":["../../../../src/components/fields/EntityPicker/EntityPicker.tsx"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport {\n type EntityFilterQuery,\n CATALOG_FILTER_EXISTS,\n} from '@backstage/catalog-client';\nimport {\n Entity,\n parseEntityRef,\n stringifyEntityRef,\n} from '@backstage/catalog-model';\nimport { useApi } from '@backstage/core-plugin-api';\nimport {\n EntityDisplayName,\n EntityRefPresentationSnapshot,\n catalogApiRef,\n entityPresentationApiRef,\n} from '@backstage/plugin-catalog-react';\nimport TextField from '@material-ui/core/TextField';\nimport Autocomplete, {\n AutocompleteChangeReason,\n createFilterOptions,\n} from '@material-ui/lab/Autocomplete';\nimport { useCallback, useEffect } from 'react';\nimport useAsync from 'react-use/esm/useAsync';\nimport {\n EntityPickerFilterQueryValue,\n EntityPickerProps,\n EntityPickerUiOptions,\n EntityPickerFilterQuery,\n} from './schema';\nimport { VirtualizedListbox } from '../VirtualizedListbox';\nimport { useTranslationRef } from '@backstage/core-plugin-api/alpha';\nimport { scaffolderTranslationRef } from '../../../translation';\nimport { ScaffolderField } from '@backstage/plugin-scaffolder-react/alpha';\n\nexport { EntityPickerSchema } from './schema';\n\n/**\n * The underlying component that is rendered in the form for the `EntityPicker`\n * field extension.\n *\n * @public\n */\nexport const EntityPicker = (props: EntityPickerProps) => {\n const { t } = useTranslationRef(scaffolderTranslationRef);\n const {\n onChange,\n schema: {\n title = t('fields.entityPicker.title'),\n description = t('fields.entityPicker.description'),\n },\n required,\n uiSchema,\n rawErrors,\n formData,\n idSchema,\n errors,\n } = props;\n const catalogFilter = buildCatalogFilter(uiSchema);\n const defaultKind = uiSchema['ui:options']?.defaultKind;\n const defaultNamespace =\n uiSchema['ui:options']?.defaultNamespace || undefined;\n const isDisabled = uiSchema?.['ui:disabled'] ?? false;\n\n const catalogApi = useApi(catalogApiRef);\n const entityPresentationApi = useApi(entityPresentationApiRef);\n\n const { value: entities, loading } = useAsync(async () => {\n const fields = [\n 'kind',\n 'metadata.name',\n 'metadata.namespace',\n 'metadata.title',\n 'metadata.description',\n 'spec.profile.displayName',\n 'spec.type',\n ];\n const { items } = await catalogApi.getEntities(\n catalogFilter\n ? { filter: catalogFilter, fields }\n : { filter: undefined, fields },\n );\n\n const entityRefToPresentation = new Map<\n string,\n EntityRefPresentationSnapshot\n >(\n await Promise.all(\n items.map(async item => {\n const presentation = await entityPresentationApi.forEntity(item)\n .promise;\n return [stringifyEntityRef(item), presentation] as [\n string,\n EntityRefPresentationSnapshot,\n ];\n }),\n ),\n );\n\n return { catalogEntities: items, entityRefToPresentation };\n });\n\n const allowArbitraryValues =\n uiSchema['ui:options']?.allowArbitraryValues ?? true;\n\n const getLabel = useCallback(\n (freeSoloValue: string) => {\n try {\n // Will throw if defaultKind or defaultNamespace are not set\n const parsedRef = parseEntityRef(freeSoloValue, {\n defaultKind,\n defaultNamespace,\n });\n\n return stringifyEntityRef(parsedRef);\n } catch (err) {\n return freeSoloValue;\n }\n },\n [defaultKind, defaultNamespace],\n );\n\n const onSelect = useCallback(\n (_: any, ref: string | Entity | null, reason: AutocompleteChangeReason) => {\n // ref can either be a string from free solo entry or\n if (typeof ref !== 'string') {\n // if ref does not exist: pass 'undefined' to trigger validation for required value\n onChange(ref ? stringifyEntityRef(ref as Entity) : undefined);\n } else {\n if (reason === 'blur' || reason === 'create-option') {\n // Add in default namespace, etc.\n let entityRef = ref;\n try {\n // Attempt to parse the entity ref into it's full form.\n entityRef = stringifyEntityRef(\n parseEntityRef(ref as string, {\n defaultKind,\n defaultNamespace,\n }),\n );\n } catch (err) {\n // If the passed in value isn't an entity ref, do nothing.\n }\n // We need to check against formData here as that's the previous value for this field.\n if (formData !== ref || allowArbitraryValues) {\n onChange(entityRef);\n }\n }\n }\n },\n [onChange, formData, defaultKind, defaultNamespace, allowArbitraryValues],\n );\n\n // Since free solo can be enabled, attempt to parse as a full entity ref first, then fall\n // back to the given value.\n const selectedEntity =\n entities?.catalogEntities.find(e => stringifyEntityRef(e) === formData) ??\n (allowArbitraryValues && formData ? getLabel(formData) : '');\n\n useEffect(() => {\n if (\n required &&\n !allowArbitraryValues &&\n entities?.catalogEntities.length === 1 &&\n selectedEntity === ''\n ) {\n onChange(stringifyEntityRef(entities.catalogEntities[0]));\n }\n }, [entities, onChange, selectedEntity, required, allowArbitraryValues]);\n\n return (\n <ScaffolderField\n rawErrors={rawErrors}\n rawDescription={description}\n required={required}\n disabled={isDisabled}\n errors={errors}\n >\n <Autocomplete\n disabled={\n isDisabled ||\n (required &&\n !allowArbitraryValues &&\n entities?.catalogEntities.length === 1)\n }\n id={idSchema?.$id}\n value={selectedEntity}\n loading={loading}\n onChange={onSelect}\n options={entities?.catalogEntities || []}\n getOptionLabel={option =>\n // option can be a string due to freeSolo.\n typeof option === 'string'\n ? option\n : entities?.entityRefToPresentation.get(stringifyEntityRef(option))\n ?.entityRef!\n }\n autoSelect\n freeSolo={allowArbitraryValues}\n renderInput={params => (\n <TextField\n {...params}\n label={title}\n margin=\"dense\"\n variant=\"outlined\"\n required={required}\n disabled={isDisabled}\n InputProps={params.InputProps}\n />\n )}\n renderOption={option => <EntityDisplayName entityRef={option} />}\n filterOptions={createFilterOptions<Entity>({\n stringify: option =>\n entities?.entityRefToPresentation.get(stringifyEntityRef(option))\n ?.primaryTitle!,\n })}\n ListboxComponent={VirtualizedListbox}\n />\n </ScaffolderField>\n );\n};\n\n/**\n * Converts a especial `{exists: true}` value to the `CATALOG_FILTER_EXISTS` symbol.\n *\n * @param value - The value to convert.\n * @returns The converted value.\n */\nfunction convertOpsValues(\n value: Exclude<EntityPickerFilterQueryValue, Array<any>>,\n): string | symbol {\n if (typeof value === 'object' && value.exists) {\n return CATALOG_FILTER_EXISTS;\n }\n return value?.toString();\n}\n\n/**\n * Converts schema filters to entity filter query, replacing `{exists:true}` values\n * with the constant `CATALOG_FILTER_EXISTS`.\n *\n * @param schemaFilters - An object containing schema filters with keys as filter names\n * and values as filter values.\n * @returns An object with the same keys as the input object, but with `{exists:true}` values\n * transformed to `CATALOG_FILTER_EXISTS` symbol.\n */\nfunction convertSchemaFiltersToQuery(\n schemaFilters: EntityPickerFilterQuery,\n): Exclude<EntityFilterQuery, Array<any>> {\n const query: EntityFilterQuery = {};\n\n for (const [key, value] of Object.entries(schemaFilters)) {\n if (Array.isArray(value)) {\n query[key] = value;\n } else {\n query[key] = convertOpsValues(value);\n }\n }\n\n return query;\n}\n\n/**\n * Builds an `EntityFilterQuery` based on the `uiSchema` passed in.\n * If `catalogFilter` is specified in the `uiSchema`, it is converted to a `EntityFilterQuery`.\n * If `allowedKinds` is specified in the `uiSchema` will support the legacy `allowedKinds` option.\n *\n * @param uiSchema The `uiSchema` of an `EntityPicker` component.\n * @returns An `EntityFilterQuery` based on the `uiSchema`, or `undefined` if `catalogFilter` is not specified in the `uiSchema`.\n */\nfunction buildCatalogFilter(\n uiSchema: EntityPickerProps['uiSchema'],\n): EntityFilterQuery | undefined {\n const allowedKinds = uiSchema['ui:options']?.allowedKinds;\n\n const catalogFilter: EntityPickerUiOptions['catalogFilter'] | undefined =\n uiSchema['ui:options']?.catalogFilter ||\n (allowedKinds && { kind: allowedKinds });\n\n if (!catalogFilter) {\n return undefined;\n }\n\n if (Array.isArray(catalogFilter)) {\n return catalogFilter.map(convertSchemaFiltersToQuery);\n }\n\n return convertSchemaFiltersToQuery(catalogFilter);\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;AAyDa,MAAA,YAAA,GAAe,CAAC,KAA6B,KAAA;AACxD,EAAA,MAAM,EAAE,CAAA,EAAM,GAAA,iBAAA,CAAkB,wBAAwB,CAAA;AACxD,EAAM,MAAA;AAAA,IACJ,QAAA;AAAA,IACA,MAAQ,EAAA;AAAA,MACN,KAAA,GAAQ,EAAE,2BAA2B,CAAA;AAAA,MACrC,WAAA,GAAc,EAAE,iCAAiC;AAAA,KACnD;AAAA,IACA,QAAA;AAAA,IACA,QAAA;AAAA,IACA,SAAA;AAAA,IACA,QAAA;AAAA,IACA,QAAA;AAAA,IACA;AAAA,GACE,GAAA,KAAA;AACJ,EAAM,MAAA,aAAA,GAAgB,mBAAmB,QAAQ,CAAA;AACjD,EAAM,MAAA,WAAA,GAAc,QAAS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,CAAA,aAAa,CAAG,EAAA;AAChC,IAAO,OAAA,aAAA,CAAc,IAAI,2BAA2B,CAAA;AAAA;AAGtD,EAAA,OAAO,4BAA4B,aAAa,CAAA;AAClD;;;;"}
1
+ {"version":3,"file":"EntityPicker.esm.js","sources":["../../../../src/components/fields/EntityPicker/EntityPicker.tsx"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport {\n type EntityFilterQuery,\n CATALOG_FILTER_EXISTS,\n} from '@backstage/catalog-client';\nimport {\n Entity,\n parseEntityRef,\n stringifyEntityRef,\n} from '@backstage/catalog-model';\nimport { useApi } from '@backstage/core-plugin-api';\nimport {\n EntityDisplayName,\n EntityRefPresentationSnapshot,\n catalogApiRef,\n entityPresentationApiRef,\n} from '@backstage/plugin-catalog-react';\nimport TextField from '@material-ui/core/TextField';\nimport Autocomplete, {\n AutocompleteChangeReason,\n createFilterOptions,\n} from '@material-ui/lab/Autocomplete';\nimport { useCallback, useEffect } from 'react';\nimport useAsync from 'react-use/esm/useAsync';\nimport {\n EntityPickerFilterQueryValue,\n EntityPickerProps,\n EntityPickerUiOptions,\n EntityPickerFilterQuery,\n} from './schema';\nimport { VirtualizedListbox } from '../VirtualizedListbox';\nimport { useTranslationRef } from '@backstage/core-plugin-api/alpha';\nimport { scaffolderTranslationRef } from '../../../translation';\nimport { ScaffolderField } from '@backstage/plugin-scaffolder-react/alpha';\n\nexport { EntityPickerSchema } from './schema';\n\n/**\n * The underlying component that is rendered in the form for the `EntityPicker`\n * field extension.\n *\n * @public\n */\nexport const EntityPicker = (props: EntityPickerProps) => {\n const { t } = useTranslationRef(scaffolderTranslationRef);\n const {\n onChange,\n schema: {\n title = t('fields.entityPicker.title'),\n description = t('fields.entityPicker.description'),\n },\n required,\n uiSchema,\n rawErrors,\n formData,\n idSchema,\n errors,\n } = props;\n const catalogFilter = buildCatalogFilter(uiSchema);\n const defaultKind = uiSchema['ui:options']?.defaultKind;\n const defaultNamespace =\n uiSchema['ui:options']?.defaultNamespace || undefined;\n const isDisabled = uiSchema?.['ui:disabled'] ?? false;\n\n const catalogApi = useApi(catalogApiRef);\n const entityPresentationApi = useApi(entityPresentationApiRef);\n\n const { value: entities, loading } = useAsync(async () => {\n const fields = [\n 'kind',\n 'metadata.name',\n 'metadata.namespace',\n 'metadata.title',\n 'metadata.description',\n 'spec.profile.displayName',\n 'spec.type',\n ];\n const { items } = await catalogApi.getEntities(\n catalogFilter\n ? { filter: catalogFilter, fields }\n : { filter: undefined, fields },\n );\n\n const entityRefToPresentation = new Map<\n string,\n EntityRefPresentationSnapshot\n >(\n await Promise.all(\n items.map(async item => {\n const presentation = await entityPresentationApi.forEntity(item)\n .promise;\n return [stringifyEntityRef(item), presentation] as [\n string,\n EntityRefPresentationSnapshot,\n ];\n }),\n ),\n );\n\n return { catalogEntities: items, entityRefToPresentation };\n });\n\n const allowArbitraryValues =\n uiSchema['ui:options']?.allowArbitraryValues ?? true;\n\n const getLabel = useCallback(\n (freeSoloValue: string) => {\n try {\n // Will throw if defaultKind or defaultNamespace are not set\n const parsedRef = parseEntityRef(freeSoloValue, {\n defaultKind,\n defaultNamespace,\n });\n\n return stringifyEntityRef(parsedRef);\n } catch (err) {\n return freeSoloValue;\n }\n },\n [defaultKind, defaultNamespace],\n );\n\n const onSelect = useCallback(\n (_: any, ref: string | Entity | null, reason: AutocompleteChangeReason) => {\n // ref can either be a string from free solo entry or\n if (typeof ref !== 'string') {\n // if ref does not exist: pass 'undefined' to trigger validation for required value\n onChange(ref ? stringifyEntityRef(ref as Entity) : undefined);\n } else {\n if (reason === 'blur' || reason === 'create-option') {\n // Add in default namespace, etc.\n let entityRef = ref;\n try {\n // Attempt to parse the entity ref into it's full form.\n entityRef = stringifyEntityRef(\n parseEntityRef(ref as string, {\n defaultKind,\n defaultNamespace,\n }),\n );\n } catch (err) {\n // If the passed in value isn't an entity ref, do nothing.\n }\n // We need to check against formData here as that's the previous value for this field.\n if (formData !== ref || allowArbitraryValues) {\n onChange(entityRef);\n }\n }\n }\n },\n [onChange, formData, defaultKind, defaultNamespace, allowArbitraryValues],\n );\n\n // Since free solo can be enabled, attempt to parse as a full entity ref first, then fall\n // back to the given value.\n const selectedEntity =\n entities?.catalogEntities.find(e => stringifyEntityRef(e) === formData) ??\n (allowArbitraryValues && formData ? getLabel(formData) : '');\n\n useEffect(() => {\n if (\n required &&\n !allowArbitraryValues &&\n entities?.catalogEntities.length === 1 &&\n selectedEntity === ''\n ) {\n onChange(stringifyEntityRef(entities.catalogEntities[0]));\n }\n }, [entities, onChange, selectedEntity, required, allowArbitraryValues]);\n\n return (\n <ScaffolderField\n rawErrors={rawErrors}\n rawDescription={uiSchema['ui:description'] ?? description}\n required={required}\n disabled={isDisabled}\n errors={errors}\n >\n <Autocomplete\n disabled={\n isDisabled ||\n (required &&\n !allowArbitraryValues &&\n entities?.catalogEntities.length === 1)\n }\n id={idSchema?.$id}\n value={selectedEntity}\n loading={loading}\n onChange={onSelect}\n options={entities?.catalogEntities || []}\n getOptionLabel={option =>\n // option can be a string due to freeSolo.\n typeof option === 'string'\n ? option\n : entities?.entityRefToPresentation.get(stringifyEntityRef(option))\n ?.entityRef!\n }\n autoSelect\n freeSolo={allowArbitraryValues}\n renderInput={params => (\n <TextField\n {...params}\n label={title}\n margin=\"dense\"\n variant=\"outlined\"\n required={required}\n disabled={isDisabled}\n InputProps={params.InputProps}\n />\n )}\n renderOption={option => <EntityDisplayName entityRef={option} />}\n filterOptions={createFilterOptions<Entity>({\n stringify: option =>\n entities?.entityRefToPresentation.get(stringifyEntityRef(option))\n ?.primaryTitle!,\n })}\n ListboxComponent={VirtualizedListbox}\n />\n </ScaffolderField>\n );\n};\n\n/**\n * Converts a especial `{exists: true}` value to the `CATALOG_FILTER_EXISTS` symbol.\n *\n * @param value - The value to convert.\n * @returns The converted value.\n */\nfunction convertOpsValues(\n value: Exclude<EntityPickerFilterQueryValue, Array<any>>,\n): string | symbol {\n if (typeof value === 'object' && value.exists) {\n return CATALOG_FILTER_EXISTS;\n }\n return value?.toString();\n}\n\n/**\n * Converts schema filters to entity filter query, replacing `{exists:true}` values\n * with the constant `CATALOG_FILTER_EXISTS`.\n *\n * @param schemaFilters - An object containing schema filters with keys as filter names\n * and values as filter values.\n * @returns An object with the same keys as the input object, but with `{exists:true}` values\n * transformed to `CATALOG_FILTER_EXISTS` symbol.\n */\nfunction convertSchemaFiltersToQuery(\n schemaFilters: EntityPickerFilterQuery,\n): Exclude<EntityFilterQuery, Array<any>> {\n const query: EntityFilterQuery = {};\n\n for (const [key, value] of Object.entries(schemaFilters)) {\n if (Array.isArray(value)) {\n query[key] = value;\n } else {\n query[key] = convertOpsValues(value);\n }\n }\n\n return query;\n}\n\n/**\n * Builds an `EntityFilterQuery` based on the `uiSchema` passed in.\n * If `catalogFilter` is specified in the `uiSchema`, it is converted to a `EntityFilterQuery`.\n * If `allowedKinds` is specified in the `uiSchema` will support the legacy `allowedKinds` option.\n *\n * @param uiSchema The `uiSchema` of an `EntityPicker` component.\n * @returns An `EntityFilterQuery` based on the `uiSchema`, or `undefined` if `catalogFilter` is not specified in the `uiSchema`.\n */\nfunction buildCatalogFilter(\n uiSchema: EntityPickerProps['uiSchema'],\n): EntityFilterQuery | undefined {\n const allowedKinds = uiSchema['ui:options']?.allowedKinds;\n\n const catalogFilter: EntityPickerUiOptions['catalogFilter'] | undefined =\n uiSchema['ui:options']?.catalogFilter ||\n (allowedKinds && { kind: allowedKinds });\n\n if (!catalogFilter) {\n return undefined;\n }\n\n if (Array.isArray(catalogFilter)) {\n return catalogFilter.map(convertSchemaFiltersToQuery);\n }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O,CAAA,OAAA,CAAQ,aAAa,CAAG,EAAA;AACxD,IAAI,IAAA,KAAA,CAAM,OAAQ,CAAA,KAAK,CAAG,EAAA;AACxB,MAAA,KAAA,CAAM,GAAG,CAAI,GAAA,KAAA;AAAA,KACR,MAAA;AACL,MAAM,KAAA,CAAA,GAAG,CAAI,GAAA,gBAAA,CAAiB,KAAK,CAAA;AAAA;AACrC;AAGF,EAAO,OAAA,KAAA;AACT;AAUA,SAAS,mBACP,QAC+B,EAAA;AAC/B,EAAM,MAAA,YAAA,GAAe,QAAS,CAAA,YAAY,CAAG,EAAA,YAAA;AAE7C,EAAM,MAAA,aAAA,GACJ,SAAS,YAAY,CAAA,EAAG,iBACvB,YAAgB,IAAA,EAAE,MAAM,YAAa,EAAA;AAExC,EAAA,IAAI,CAAC,aAAe,EAAA;AAClB,IAAO,OAAA,KAAA,CAAA;AAAA;AAGT,EAAI,IAAA,KAAA,CAAM,OAAQ,CAAA,aAAa,CAAG,EAAA;AAChC,IAAO,OAAA,aAAA,CAAc,IAAI,2BAA2B,CAAA;AAAA;AAGtD,EAAA,OAAO,4BAA4B,aAAa,CAAA;AAClD;;;;"}
@@ -1,12 +1,11 @@
1
- import { z } from 'zod';
2
- import { makeFieldSchemaFromZod } from '../utils.esm.js';
1
+ import { makeFieldSchema } from '@backstage/plugin-scaffolder-react';
3
2
 
4
- const entityQueryFilterExpressionSchema = z.record(
3
+ const createEntityQueryFilterExpressionSchema = (z) => z.record(
5
4
  z.string().or(z.object({ exists: z.boolean().optional() })).or(z.array(z.string()))
6
5
  );
7
- const EntityPickerFieldSchema = makeFieldSchemaFromZod(
8
- z.string(),
9
- z.object({
6
+ const EntityPickerFieldSchema = makeFieldSchema({
7
+ output: (z) => z.string(),
8
+ uiOptions: (z) => z.object({
10
9
  /**
11
10
  * @deprecated Use `catalogFilter` instead.
12
11
  */
@@ -20,10 +19,12 @@ const EntityPickerFieldSchema = makeFieldSchemaFromZod(
20
19
  defaultNamespace: z.union([z.string(), z.literal(false)]).optional().describe(
21
20
  "The default namespace. Options with this namespace will not be prefixed."
22
21
  ),
23
- catalogFilter: z.array(entityQueryFilterExpressionSchema).or(entityQueryFilterExpressionSchema).optional().describe("List of key-value filter expression for entities")
22
+ catalogFilter: ((t) => t.or(t.array()))(
23
+ createEntityQueryFilterExpressionSchema(z)
24
+ ).optional().describe("List of key-value filter expression for entities")
24
25
  })
25
- );
26
+ });
26
27
  const EntityPickerSchema = EntityPickerFieldSchema.schema;
27
28
 
28
- export { EntityPickerFieldSchema, EntityPickerSchema, entityQueryFilterExpressionSchema };
29
+ export { EntityPickerFieldSchema, EntityPickerSchema, createEntityQueryFilterExpressionSchema };
29
30
  //# sourceMappingURL=schema.esm.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"schema.esm.js","sources":["../../../../src/components/fields/EntityPicker/schema.ts"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { z } from 'zod';\nimport { makeFieldSchemaFromZod } from '../utils';\n\n/**\n * @public\n */\nexport const entityQueryFilterExpressionSchema = z.record(\n z\n .string()\n .or(z.object({ exists: z.boolean().optional() }))\n .or(z.array(z.string())),\n);\n\n/**\n * @public\n */\nexport const EntityPickerFieldSchema = makeFieldSchemaFromZod(\n z.string(),\n z.object({\n /**\n * @deprecated Use `catalogFilter` instead.\n */\n allowedKinds: z\n .array(z.string())\n .optional()\n .describe(\n 'DEPRECATED: Use `catalogFilter` instead. List of kinds of entities to derive options from',\n ),\n defaultKind: z\n .string()\n .optional()\n .describe(\n 'The default entity kind. Options of this kind will not be prefixed.',\n ),\n allowArbitraryValues: z\n .boolean()\n .optional()\n .describe('Whether to allow arbitrary user input. Defaults to true'),\n defaultNamespace: z\n .union([z.string(), z.literal(false)])\n .optional()\n .describe(\n 'The default namespace. Options with this namespace will not be prefixed.',\n ),\n catalogFilter: z\n .array(entityQueryFilterExpressionSchema)\n .or(entityQueryFilterExpressionSchema)\n .optional()\n .describe('List of key-value filter expression for entities'),\n }),\n);\n\n/**\n * The input props that can be specified under `ui:options` for the\n * `EntityPicker` field extension.\n *\n * @public\n */\nexport type EntityPickerUiOptions =\n typeof EntityPickerFieldSchema.uiOptionsType;\n\nexport type EntityPickerProps = typeof EntityPickerFieldSchema.type;\n\nexport const EntityPickerSchema = EntityPickerFieldSchema.schema;\n\nexport type EntityPickerFilterQuery = z.TypeOf<\n typeof entityQueryFilterExpressionSchema\n>;\n\nexport type EntityPickerFilterQueryValue =\n EntityPickerFilterQuery[keyof EntityPickerFilterQuery];\n"],"names":[],"mappings":";;;AAqBO,MAAM,oCAAoC,CAAE,CAAA,MAAA;AAAA,EACjD,CAAA,CACG,QACA,CAAA,EAAA,CAAG,EAAE,MAAO,CAAA,EAAE,MAAQ,EAAA,CAAA,CAAE,OAAQ,EAAA,CAAE,UAAW,EAAC,CAAC,CAC/C,CAAA,EAAA,CAAG,EAAE,KAAM,CAAA,CAAA,CAAE,MAAO,EAAC,CAAC;AAC3B;AAKO,MAAM,uBAA0B,GAAA,sBAAA;AAAA,EACrC,EAAE,MAAO,EAAA;AAAA,EACT,EAAE,MAAO,CAAA;AAAA;AAAA;AAAA;AAAA,IAIP,YAAA,EAAc,EACX,KAAM,CAAA,CAAA,CAAE,QAAQ,CAAA,CAChB,UACA,CAAA,QAAA;AAAA,MACC;AAAA,KACF;AAAA,IACF,WAAa,EAAA,CAAA,CACV,MAAO,EAAA,CACP,UACA,CAAA,QAAA;AAAA,MACC;AAAA,KACF;AAAA,IACF,sBAAsB,CACnB,CAAA,OAAA,GACA,QAAS,EAAA,CACT,SAAS,yDAAyD,CAAA;AAAA,IACrE,gBAAkB,EAAA,CAAA,CACf,KAAM,CAAA,CAAC,EAAE,MAAO,EAAA,EAAG,CAAE,CAAA,OAAA,CAAQ,KAAK,CAAC,CAAC,CAAA,CACpC,UACA,CAAA,QAAA;AAAA,MACC;AAAA,KACF;AAAA,IACF,aAAA,EAAe,CACZ,CAAA,KAAA,CAAM,iCAAiC,CAAA,CACvC,EAAG,CAAA,iCAAiC,CACpC,CAAA,QAAA,EACA,CAAA,QAAA,CAAS,kDAAkD;AAAA,GAC/D;AACH;AAaO,MAAM,qBAAqB,uBAAwB,CAAA;;;;"}
1
+ {"version":3,"file":"schema.esm.js","sources":["../../../../src/components/fields/EntityPicker/schema.ts"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { z as zod } from 'zod';\nimport { makeFieldSchema } from '@backstage/plugin-scaffolder-react';\n\nexport const createEntityQueryFilterExpressionSchema = (z: typeof zod) =>\n z.record(\n z\n .string()\n .or(z.object({ exists: z.boolean().optional() }))\n .or(z.array(z.string())),\n );\n\n/**\n * @public\n */\nexport const EntityPickerFieldSchema = makeFieldSchema({\n output: z => z.string(),\n uiOptions: z =>\n z.object({\n /**\n * @deprecated Use `catalogFilter` instead.\n */\n allowedKinds: z\n .array(z.string())\n .optional()\n .describe(\n 'DEPRECATED: Use `catalogFilter` instead. List of kinds of entities to derive options from',\n ),\n defaultKind: z\n .string()\n .optional()\n .describe(\n 'The default entity kind. Options of this kind will not be prefixed.',\n ),\n allowArbitraryValues: z\n .boolean()\n .optional()\n .describe('Whether to allow arbitrary user input. Defaults to true'),\n defaultNamespace: z\n .union([z.string(), z.literal(false)])\n .optional()\n .describe(\n 'The default namespace. Options with this namespace will not be prefixed.',\n ),\n catalogFilter: (t => t.or(t.array()))(\n createEntityQueryFilterExpressionSchema(z),\n )\n .optional()\n .describe('List of key-value filter expression for entities'),\n }),\n});\n\n/**\n * The input props that can be specified under `ui:options` for the\n * `EntityPicker` field extension.\n *\n * @public\n */\nexport type EntityPickerUiOptions = NonNullable<\n (typeof EntityPickerFieldSchema.TProps.uiSchema)['ui:options']\n>;\n\nexport type EntityPickerProps = typeof EntityPickerFieldSchema.TProps;\n\nexport const EntityPickerSchema = EntityPickerFieldSchema.schema;\n\nexport type EntityPickerFilterQuery = zod.TypeOf<\n ReturnType<typeof createEntityQueryFilterExpressionSchema>\n>;\n\nexport type EntityPickerFilterQueryValue =\n EntityPickerFilterQuery[keyof EntityPickerFilterQuery];\n"],"names":[],"mappings":";;AAkBa,MAAA,uCAAA,GAA0C,CAAC,CAAA,KACtD,CAAE,CAAA,MAAA;AAAA,EACA,CAAA,CACG,QACA,CAAA,EAAA,CAAG,EAAE,MAAO,CAAA,EAAE,MAAQ,EAAA,CAAA,CAAE,OAAQ,EAAA,CAAE,UAAW,EAAC,CAAC,CAC/C,CAAA,EAAA,CAAG,EAAE,KAAM,CAAA,CAAA,CAAE,MAAO,EAAC,CAAC;AAC3B;AAKK,MAAM,0BAA0B,eAAgB,CAAA;AAAA,EACrD,MAAA,EAAQ,CAAK,CAAA,KAAA,CAAA,CAAE,MAAO,EAAA;AAAA,EACtB,SAAA,EAAW,CACT,CAAA,KAAA,CAAA,CAAE,MAAO,CAAA;AAAA;AAAA;AAAA;AAAA,IAIP,YAAA,EAAc,EACX,KAAM,CAAA,CAAA,CAAE,QAAQ,CAAA,CAChB,UACA,CAAA,QAAA;AAAA,MACC;AAAA,KACF;AAAA,IACF,WAAa,EAAA,CAAA,CACV,MAAO,EAAA,CACP,UACA,CAAA,QAAA;AAAA,MACC;AAAA,KACF;AAAA,IACF,sBAAsB,CACnB,CAAA,OAAA,GACA,QAAS,EAAA,CACT,SAAS,yDAAyD,CAAA;AAAA,IACrE,gBAAkB,EAAA,CAAA,CACf,KAAM,CAAA,CAAC,EAAE,MAAO,EAAA,EAAG,CAAE,CAAA,OAAA,CAAQ,KAAK,CAAC,CAAC,CAAA,CACpC,UACA,CAAA,QAAA;AAAA,MACC;AAAA,KACF;AAAA,IACF,gBAAgB,CAAK,CAAA,KAAA,CAAA,CAAE,EAAG,CAAA,CAAA,CAAE,OAAO,CAAA;AAAA,MACjC,wCAAwC,CAAC;AAAA,KAExC,CAAA,QAAA,EACA,CAAA,QAAA,CAAS,kDAAkD;AAAA,GAC/D;AACL,CAAC;AAcM,MAAM,qBAAqB,uBAAwB,CAAA;;;;"}
@@ -5,15 +5,27 @@ import useEffectOnce from 'react-use/esm/useEffectOnce';
5
5
  import { makeValidator } from '@backstage/catalog-model';
6
6
  import { useApi } from '@backstage/core-plugin-api';
7
7
  import { catalogApiRef } from '@backstage/plugin-catalog-react';
8
- import FormControl from '@material-ui/core/FormControl';
9
8
  import TextField from '@material-ui/core/TextField';
10
9
  import Autocomplete from '@material-ui/lab/Autocomplete';
11
10
  import { useTranslationRef } from '@backstage/core-plugin-api/alpha';
12
11
  import { scaffolderTranslationRef } from '../../../translation.esm.js';
12
+ import { ScaffolderField } from '@backstage/plugin-scaffolder-react/alpha';
13
13
  export { EntityTagsPickerSchema } from './schema.esm.js';
14
14
 
15
15
  const EntityTagsPicker = (props) => {
16
- const { formData, onChange, uiSchema } = props;
16
+ const { t } = useTranslationRef(scaffolderTranslationRef);
17
+ const {
18
+ formData,
19
+ onChange,
20
+ schema: {
21
+ title = t("fields.entityTagsPicker.title"),
22
+ description = t("fields.entityTagsPicker.description")
23
+ },
24
+ uiSchema,
25
+ rawErrors,
26
+ required,
27
+ errors
28
+ } = props;
17
29
  const catalogApi = useApi(catalogApiRef);
18
30
  const [tagOptions, setTagOptions] = useState([]);
19
31
  const [inputValue, setInputValue] = useState("");
@@ -23,7 +35,6 @@ const EntityTagsPicker = (props) => {
23
35
  const showCounts = uiSchema["ui:options"]?.showCounts;
24
36
  const helperText = uiSchema["ui:options"]?.helperText;
25
37
  const isDisabled = uiSchema?.["ui:disabled"] ?? false;
26
- const { t } = useTranslationRef(scaffolderTranslationRef);
27
38
  const { loading, value: existingTags } = useAsync(async () => {
28
39
  const facet = "metadata.tags";
29
40
  const tagsRequest = { facets: [facet] };
@@ -57,34 +68,43 @@ const EntityTagsPicker = (props) => {
57
68
  }
58
69
  };
59
70
  useEffectOnce(() => onChange(formData || []));
60
- return /* @__PURE__ */ jsx(FormControl, { margin: "normal", children: /* @__PURE__ */ jsx(
61
- Autocomplete,
71
+ return /* @__PURE__ */ jsx(
72
+ ScaffolderField,
62
73
  {
63
- multiple: true,
64
- freeSolo: true,
65
- filterSelectedOptions: true,
66
- onChange: setTags,
74
+ rawErrors,
75
+ rawDescription: helperText ?? uiSchema["ui:description"] ?? description,
76
+ required,
67
77
  disabled: isDisabled,
68
- value: formData || [],
69
- inputValue,
70
- loading,
71
- options: tagOptions,
72
- ChipProps: { size: "small" },
73
- renderOption: (option) => showCounts ? `${option} (${existingTags?.[option]})` : option,
74
- renderInput: (params) => /* @__PURE__ */ jsx(
75
- TextField,
78
+ errors,
79
+ children: /* @__PURE__ */ jsx(
80
+ Autocomplete,
76
81
  {
77
- ...params,
78
- label: t("fields.entityTagsPicker.title"),
82
+ multiple: true,
83
+ freeSolo: true,
84
+ filterSelectedOptions: true,
85
+ onChange: setTags,
79
86
  disabled: isDisabled,
80
- onChange: (e) => setInputValue(e.target.value),
81
- error: inputError,
82
- helperText: helperText ?? t("fields.entityTagsPicker.description"),
83
- FormHelperTextProps: { margin: "dense", style: { marginLeft: 0 } }
87
+ value: formData || [],
88
+ inputValue,
89
+ loading,
90
+ options: tagOptions,
91
+ ChipProps: { size: "small" },
92
+ renderOption: (option) => showCounts ? `${option} (${existingTags?.[option]})` : option,
93
+ renderInput: (params) => /* @__PURE__ */ jsx(
94
+ TextField,
95
+ {
96
+ ...params,
97
+ label: title,
98
+ disabled: isDisabled,
99
+ onChange: (e) => setInputValue(e.target.value),
100
+ error: inputError,
101
+ FormHelperTextProps: { margin: "dense", style: { marginLeft: 0 } }
102
+ }
103
+ )
84
104
  }
85
105
  )
86
106
  }
87
- ) });
107
+ );
88
108
  };
89
109
 
90
110
  export { EntityTagsPicker };
@@ -1 +1 @@
1
- {"version":3,"file":"EntityTagsPicker.esm.js","sources":["../../../../src/components/fields/EntityTagsPicker/EntityTagsPicker.tsx"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { ChangeEvent, useState } from 'react';\nimport useAsync from 'react-use/esm/useAsync';\nimport useEffectOnce from 'react-use/esm/useEffectOnce';\nimport { GetEntityFacetsRequest } from '@backstage/catalog-client';\nimport { makeValidator } from '@backstage/catalog-model';\nimport { useApi } from '@backstage/core-plugin-api';\nimport { catalogApiRef } from '@backstage/plugin-catalog-react';\nimport FormControl from '@material-ui/core/FormControl';\nimport TextField from '@material-ui/core/TextField';\nimport Autocomplete from '@material-ui/lab/Autocomplete';\nimport { EntityTagsPickerProps } from './schema';\nimport { useTranslationRef } from '@backstage/core-plugin-api/alpha';\nimport { scaffolderTranslationRef } from '../../../translation';\n\nexport { EntityTagsPickerSchema } from './schema';\n\n/**\n * The underlying component that is rendered in the form for the `EntityTagsPicker`\n * field extension.\n *\n * @public\n */\nexport const EntityTagsPicker = (props: EntityTagsPickerProps) => {\n const { formData, onChange, uiSchema } = props;\n const catalogApi = useApi(catalogApiRef);\n const [tagOptions, setTagOptions] = useState<string[]>([]);\n const [inputValue, setInputValue] = useState('');\n const [inputError, setInputError] = useState(false);\n const tagValidator = makeValidator().isValidTag;\n const kinds = uiSchema['ui:options']?.kinds;\n const showCounts = uiSchema['ui:options']?.showCounts;\n const helperText = uiSchema['ui:options']?.helperText;\n const isDisabled = uiSchema?.['ui:disabled'] ?? false;\n\n const { t } = useTranslationRef(scaffolderTranslationRef);\n\n const { loading, value: existingTags } = useAsync(async () => {\n const facet = 'metadata.tags';\n const tagsRequest: GetEntityFacetsRequest = { facets: [facet] };\n if (kinds) {\n tagsRequest.filter = { kind: kinds };\n }\n\n const { facets } = await catalogApi.getEntityFacets(tagsRequest);\n\n const tagFacets = Object.fromEntries(\n facets[facet].map(({ value, count }) => [value, count]),\n );\n\n setTagOptions(\n Object.keys(tagFacets).sort((a, b) =>\n showCounts ? tagFacets[b] - tagFacets[a] : a.localeCompare(b),\n ),\n );\n\n return tagFacets;\n });\n\n const setTags = (_: ChangeEvent<{}>, values: string[] | null) => {\n // Reset error state in case all tags were removed\n let hasError = false;\n let addDuplicate = false;\n const currentTags = formData || [];\n\n // If adding a new tag\n if (values?.length && currentTags.length < values.length) {\n const newTag = (values[values.length - 1] = values[values.length - 1]\n .toLocaleLowerCase('en-US')\n .trim());\n hasError = !tagValidator(newTag);\n addDuplicate = currentTags.indexOf(newTag) !== -1;\n }\n\n setInputError(hasError);\n setInputValue(!hasError ? '' : inputValue);\n if (!hasError && !addDuplicate) {\n onChange(values || []);\n }\n };\n\n // Initialize field to always return an array\n useEffectOnce(() => onChange(formData || []));\n\n return (\n <FormControl margin=\"normal\">\n <Autocomplete\n multiple\n freeSolo\n filterSelectedOptions\n onChange={setTags}\n disabled={isDisabled}\n value={formData || []}\n inputValue={inputValue}\n loading={loading}\n options={tagOptions}\n ChipProps={{ size: 'small' }}\n renderOption={option =>\n showCounts ? `${option} (${existingTags?.[option]})` : option\n }\n renderInput={params => (\n <TextField\n {...params}\n label={t('fields.entityTagsPicker.title')}\n disabled={isDisabled}\n onChange={e => setInputValue(e.target.value)}\n error={inputError}\n helperText={helperText ?? t('fields.entityTagsPicker.description')}\n FormHelperTextProps={{ margin: 'dense', style: { marginLeft: 0 } }}\n />\n )}\n />\n </FormControl>\n );\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;AAqCa,MAAA,gBAAA,GAAmB,CAAC,KAAiC,KAAA;AAChE,EAAA,MAAM,EAAE,QAAA,EAAU,QAAU,EAAA,QAAA,EAAa,GAAA,KAAA;AACzC,EAAM,MAAA,UAAA,GAAa,OAAO,aAAa,CAAA;AACvC,EAAA,MAAM,CAAC,UAAY,EAAA,aAAa,CAAI,GAAA,QAAA,CAAmB,EAAE,CAAA;AACzD,EAAA,MAAM,CAAC,UAAA,EAAY,aAAa,CAAA,GAAI,SAAS,EAAE,CAAA;AAC/C,EAAA,MAAM,CAAC,UAAA,EAAY,aAAa,CAAA,GAAI,SAAS,KAAK,CAAA;AAClD,EAAM,MAAA,YAAA,GAAe,eAAgB,CAAA,UAAA;AACrC,EAAM,MAAA,KAAA,GAAQ,QAAS,CAAA,YAAY,CAAG,EAAA,KAAA;AACtC,EAAM,MAAA,UAAA,GAAa,QAAS,CAAA,YAAY,CAAG,EAAA,UAAA;AAC3C,EAAM,MAAA,UAAA,GAAa,QAAS,CAAA,YAAY,CAAG,EAAA,UAAA;AAC3C,EAAM,MAAA,UAAA,GAAa,QAAW,GAAA,aAAa,CAAK,IAAA,KAAA;AAEhD,EAAA,MAAM,EAAE,CAAA,EAAM,GAAA,iBAAA,CAAkB,wBAAwB,CAAA;AAExD,EAAA,MAAM,EAAE,OAAS,EAAA,KAAA,EAAO,YAAa,EAAA,GAAI,SAAS,YAAY;AAC5D,IAAA,MAAM,KAAQ,GAAA,eAAA;AACd,IAAA,MAAM,WAAsC,GAAA,EAAE,MAAQ,EAAA,CAAC,KAAK,CAAE,EAAA;AAC9D,IAAA,IAAI,KAAO,EAAA;AACT,MAAY,WAAA,CAAA,MAAA,GAAS,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AAAA,GAGN,EAAA,CAAA;AAEJ;;;;"}
1
+ {"version":3,"file":"EntityTagsPicker.esm.js","sources":["../../../../src/components/fields/EntityTagsPicker/EntityTagsPicker.tsx"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { ChangeEvent, useState } from 'react';\nimport useAsync from 'react-use/esm/useAsync';\nimport useEffectOnce from 'react-use/esm/useEffectOnce';\nimport { GetEntityFacetsRequest } from '@backstage/catalog-client';\nimport { makeValidator } from '@backstage/catalog-model';\nimport { useApi } from '@backstage/core-plugin-api';\nimport { catalogApiRef } from '@backstage/plugin-catalog-react';\nimport TextField from '@material-ui/core/TextField';\nimport Autocomplete from '@material-ui/lab/Autocomplete';\nimport { EntityTagsPickerProps } from './schema';\nimport { useTranslationRef } from '@backstage/core-plugin-api/alpha';\nimport { scaffolderTranslationRef } from '../../../translation';\nimport { ScaffolderField } from '@backstage/plugin-scaffolder-react/alpha';\n\nexport { EntityTagsPickerSchema } from './schema';\n\n/**\n * The underlying component that is rendered in the form for the `EntityTagsPicker`\n * field extension.\n *\n * @public\n */\nexport const EntityTagsPicker = (props: EntityTagsPickerProps) => {\n const { t } = useTranslationRef(scaffolderTranslationRef);\n const {\n formData,\n onChange,\n schema: {\n title = t('fields.entityTagsPicker.title'),\n description = t('fields.entityTagsPicker.description'),\n },\n uiSchema,\n rawErrors,\n required,\n errors,\n } = props;\n const catalogApi = useApi(catalogApiRef);\n const [tagOptions, setTagOptions] = useState<string[]>([]);\n const [inputValue, setInputValue] = useState('');\n const [inputError, setInputError] = useState(false);\n const tagValidator = makeValidator().isValidTag;\n const kinds = uiSchema['ui:options']?.kinds;\n const showCounts = uiSchema['ui:options']?.showCounts;\n const helperText = uiSchema['ui:options']?.helperText;\n const isDisabled = uiSchema?.['ui:disabled'] ?? false;\n\n const { loading, value: existingTags } = useAsync(async () => {\n const facet = 'metadata.tags';\n const tagsRequest: GetEntityFacetsRequest = { facets: [facet] };\n if (kinds) {\n tagsRequest.filter = { kind: kinds };\n }\n\n const { facets } = await catalogApi.getEntityFacets(tagsRequest);\n\n const tagFacets = Object.fromEntries(\n facets[facet].map(({ value, count }) => [value, count]),\n );\n\n setTagOptions(\n Object.keys(tagFacets).sort((a, b) =>\n showCounts ? tagFacets[b] - tagFacets[a] : a.localeCompare(b),\n ),\n );\n\n return tagFacets;\n });\n\n const setTags = (_: ChangeEvent<{}>, values: string[] | null) => {\n // Reset error state in case all tags were removed\n let hasError = false;\n let addDuplicate = false;\n const currentTags = formData || [];\n\n // If adding a new tag\n if (values?.length && currentTags.length < values.length) {\n const newTag = (values[values.length - 1] = values[values.length - 1]\n .toLocaleLowerCase('en-US')\n .trim());\n hasError = !tagValidator(newTag);\n addDuplicate = currentTags.indexOf(newTag) !== -1;\n }\n\n setInputError(hasError);\n setInputValue(!hasError ? '' : inputValue);\n if (!hasError && !addDuplicate) {\n onChange(values || []);\n }\n };\n\n // Initialize field to always return an array\n useEffectOnce(() => onChange(formData || []));\n\n return (\n <ScaffolderField\n rawErrors={rawErrors}\n rawDescription={helperText ?? uiSchema['ui:description'] ?? description}\n required={required}\n disabled={isDisabled}\n errors={errors}\n >\n <Autocomplete\n multiple\n freeSolo\n filterSelectedOptions\n onChange={setTags}\n disabled={isDisabled}\n value={formData || []}\n inputValue={inputValue}\n loading={loading}\n options={tagOptions}\n ChipProps={{ size: 'small' }}\n renderOption={option =>\n showCounts ? `${option} (${existingTags?.[option]})` : option\n }\n renderInput={params => (\n <TextField\n {...params}\n label={title}\n disabled={isDisabled}\n onChange={e => setInputValue(e.target.value)}\n error={inputError}\n F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AA,CAAA,CAAE,OAAO,KAAK,CAAA;AAAA,cAC3C,KAAO,EAAA,UAAA;AAAA,cACP,mBAAA,EAAqB,EAAE,MAAQ,EAAA,OAAA,EAAS,OAAO,EAAE,UAAA,EAAY,GAAI;AAAA;AAAA;AACnE;AAAA;AAEJ;AAAA,GACF;AAEJ;;;;"}
@@ -1,14 +1,15 @@
1
- import { z } from 'zod';
2
- import { makeFieldSchemaFromZod } from '../utils.esm.js';
1
+ import { makeFieldSchema } from '@backstage/plugin-scaffolder-react';
3
2
 
4
- const EntityTagsPickerFieldSchema = makeFieldSchemaFromZod(
5
- z.array(z.string()),
6
- z.object({
3
+ const EntityTagsPickerFieldSchema = makeFieldSchema({
4
+ output: (z) => z.array(z.string()),
5
+ uiOptions: (z) => z.object({
7
6
  kinds: z.array(z.string()).optional().describe("List of kinds of entities to derive tags from"),
8
7
  showCounts: z.boolean().optional().describe("Whether to show usage counts per tag"),
9
- helperText: z.string().optional().describe("Helper text to display")
8
+ helperText: z.string().optional().describe(
9
+ "Helper text to display; DEPRECATED, simply use ui:description"
10
+ )
10
11
  })
11
- );
12
+ });
12
13
  const EntityTagsPickerSchema = EntityTagsPickerFieldSchema.schema;
13
14
 
14
15
  export { EntityTagsPickerFieldSchema, EntityTagsPickerSchema };
@@ -1 +1 @@
1
- {"version":3,"file":"schema.esm.js","sources":["../../../../src/components/fields/EntityTagsPicker/schema.ts"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { z } from 'zod';\nimport { makeFieldSchemaFromZod } from '../utils';\n\n/**\n * @public\n */\nexport const EntityTagsPickerFieldSchema = makeFieldSchemaFromZod(\n z.array(z.string()),\n z.object({\n kinds: z\n .array(z.string())\n .optional()\n .describe('List of kinds of entities to derive tags from'),\n showCounts: z\n .boolean()\n .optional()\n .describe('Whether to show usage counts per tag'),\n helperText: z.string().optional().describe('Helper text to display'),\n }),\n);\n\nexport const EntityTagsPickerSchema = EntityTagsPickerFieldSchema.schema;\n\nexport type EntityTagsPickerProps = typeof EntityTagsPickerFieldSchema.type;\n\n/**\n * The input props that can be specified under `ui:options` for the\n * `EntityTagsPicker` field extension.\n *\n * @public\n */\nexport type EntityTagsPickerUiOptions =\n typeof EntityTagsPickerFieldSchema.uiOptionsType;\n"],"names":[],"mappings":";;;AAqBO,MAAM,2BAA8B,GAAA,sBAAA;AAAA,EACzC,CAAE,CAAA,KAAA,CAAM,CAAE,CAAA,MAAA,EAAQ,CAAA;AAAA,EAClB,EAAE,MAAO,CAAA;AAAA,IACP,KAAA,EAAO,CACJ,CAAA,KAAA,CAAM,CAAE,CAAA,MAAA,EAAQ,CAChB,CAAA,QAAA,EACA,CAAA,QAAA,CAAS,+CAA+C,CAAA;AAAA,IAC3D,YAAY,CACT,CAAA,OAAA,GACA,QAAS,EAAA,CACT,SAAS,sCAAsC,CAAA;AAAA,IAClD,YAAY,CAAE,CAAA,MAAA,GAAS,QAAS,EAAA,CAAE,SAAS,wBAAwB;AAAA,GACpE;AACH;AAEO,MAAM,yBAAyB,2BAA4B,CAAA;;;;"}
1
+ {"version":3,"file":"schema.esm.js","sources":["../../../../src/components/fields/EntityTagsPicker/schema.ts"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { makeFieldSchema } from '@backstage/plugin-scaffolder-react';\n\n/**\n * @public\n */\nexport const EntityTagsPickerFieldSchema = makeFieldSchema({\n output: z => z.array(z.string()),\n uiOptions: z =>\n z.object({\n kinds: z\n .array(z.string())\n .optional()\n .describe('List of kinds of entities to derive tags from'),\n showCounts: z\n .boolean()\n .optional()\n .describe('Whether to show usage counts per tag'),\n helperText: z\n .string()\n .optional()\n .describe(\n 'Helper text to display; DEPRECATED, simply use ui:description',\n ),\n }),\n});\n\nexport const EntityTagsPickerSchema = EntityTagsPickerFieldSchema.schema;\n\nexport type EntityTagsPickerProps = typeof EntityTagsPickerFieldSchema.TProps;\n\n/**\n * The input props that can be specified under `ui:options` for the\n * `EntityTagsPicker` field extension.\n *\n * @public\n */\nexport type EntityTagsPickerUiOptions = NonNullable<\n (typeof EntityTagsPickerFieldSchema.TProps.uiSchema)['ui:options']\n>;\n"],"names":[],"mappings":";;AAoBO,MAAM,8BAA8B,eAAgB,CAAA;AAAA,EACzD,QAAQ,CAAK,CAAA,KAAA,CAAA,CAAE,KAAM,CAAA,CAAA,CAAE,QAAQ,CAAA;AAAA,EAC/B,SAAA,EAAW,CACT,CAAA,KAAA,CAAA,CAAE,MAAO,CAAA;AAAA,IACP,KAAA,EAAO,CACJ,CAAA,KAAA,CAAM,CAAE,CAAA,MAAA,EAAQ,CAChB,CAAA,QAAA,EACA,CAAA,QAAA,CAAS,+CAA+C,CAAA;AAAA,IAC3D,YAAY,CACT,CAAA,OAAA,GACA,QAAS,EAAA,CACT,SAAS,sCAAsC,CAAA;AAAA,IAClD,UAAY,EAAA,CAAA,CACT,MAAO,EAAA,CACP,UACA,CAAA,QAAA;AAAA,MACC;AAAA;AACF,GACH;AACL,CAAC;AAEM,MAAM,yBAAyB,2BAA4B,CAAA;;;;"}
@@ -4,22 +4,29 @@ import { stringifyEntityRef, parseEntityRef } from '@backstage/catalog-model';
4
4
  import { useApi } from '@backstage/core-plugin-api';
5
5
  import { catalogApiRef, entityPresentationApiRef, EntityDisplayName } from '@backstage/plugin-catalog-react';
6
6
  import TextField from '@material-ui/core/TextField';
7
- import FormControl from '@material-ui/core/FormControl';
8
7
  import Autocomplete from '@material-ui/lab/Autocomplete';
9
8
  import { useState, useCallback, useEffect } from 'react';
10
9
  import useAsync from 'react-use/esm/useAsync';
11
10
  import { VirtualizedListbox } from '../VirtualizedListbox.esm.js';
11
+ import { ScaffolderField } from '@backstage/plugin-scaffolder-react/alpha';
12
+ import { useTranslationRef } from '@backstage/frontend-plugin-api';
13
+ import { scaffolderTranslationRef } from '../../../translation.esm.js';
12
14
  export { MultiEntityPickerSchema } from './schema.esm.js';
13
15
 
14
16
  const MultiEntityPicker = (props) => {
17
+ const { t } = useTranslationRef(scaffolderTranslationRef);
15
18
  const {
16
19
  onChange,
17
- schema: { title = "Entity", description = "An entity from the catalog" },
20
+ schema: {
21
+ title = t("fields.multiEntityPicker.title"),
22
+ description = t("fields.multiEntityPicker.description")
23
+ },
18
24
  required,
19
25
  uiSchema,
20
26
  rawErrors,
21
27
  formData,
22
- idSchema
28
+ idSchema,
29
+ errors
23
30
  } = props;
24
31
  const catalogFilter = buildCatalogFilter(uiSchema);
25
32
  const defaultKind = uiSchema["ui:options"]?.defaultKind;
@@ -78,11 +85,13 @@ const MultiEntityPicker = (props) => {
78
85
  }
79
86
  }, [entities, onChange, required, allowArbitraryValues]);
80
87
  return /* @__PURE__ */ jsx(
81
- FormControl,
88
+ ScaffolderField,
82
89
  {
83
- margin: "normal",
90
+ rawErrors,
91
+ rawDescription: uiSchema["ui:description"] ?? description,
84
92
  required,
85
- error: rawErrors?.length > 0 && !formData,
93
+ disabled: isDisabled,
94
+ errors,
86
95
  children: /* @__PURE__ */ jsx(
87
96
  Autocomplete,
88
97
  {
@@ -109,7 +118,6 @@ const MultiEntityPicker = (props) => {
109
118
  label: title,
110
119
  disabled: isDisabled,
111
120
  margin: "dense",
112
- helperText: description,
113
121
  FormHelperTextProps: {
114
122
  margin: "dense",
115
123
  style: { marginLeft: 0 }
@@ -1 +1 @@
1
- {"version":3,"file":"MultiEntityPicker.esm.js","sources":["../../../../src/components/fields/MultiEntityPicker/MultiEntityPicker.tsx"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport {\n type EntityFilterQuery,\n CATALOG_FILTER_EXISTS,\n} from '@backstage/catalog-client';\nimport {\n Entity,\n parseEntityRef,\n stringifyEntityRef,\n} from '@backstage/catalog-model';\nimport { useApi } from '@backstage/core-plugin-api';\nimport {\n catalogApiRef,\n entityPresentationApiRef,\n EntityDisplayName,\n EntityRefPresentationSnapshot,\n} from '@backstage/plugin-catalog-react';\nimport TextField from '@material-ui/core/TextField';\nimport FormControl from '@material-ui/core/FormControl';\nimport Autocomplete, {\n AutocompleteChangeReason,\n} from '@material-ui/lab/Autocomplete';\nimport { useCallback, useEffect, useState } from 'react';\nimport useAsync from 'react-use/esm/useAsync';\nimport { FieldValidation } from '@rjsf/utils';\nimport {\n MultiEntityPickerFilterQueryValue,\n MultiEntityPickerProps,\n MultiEntityPickerUiOptions,\n MultiEntityPickerFilterQuery,\n} from './schema';\nimport { VirtualizedListbox } from '../VirtualizedListbox';\n\nexport { MultiEntityPickerSchema } from './schema';\n\n/**\n * The underlying component that is rendered in the form for the `MultiEntityPicker`\n * field extension.\n */\nexport const MultiEntityPicker = (props: MultiEntityPickerProps) => {\n const {\n onChange,\n schema: { title = 'Entity', description = 'An entity from the catalog' },\n required,\n uiSchema,\n rawErrors,\n formData,\n idSchema,\n } = props;\n\n const catalogFilter = buildCatalogFilter(uiSchema);\n const defaultKind = uiSchema['ui:options']?.defaultKind;\n const defaultNamespace =\n uiSchema['ui:options']?.defaultNamespace || undefined;\n const isDisabled = uiSchema?.['ui:disabled'] ?? false;\n const [noOfItemsSelected, setNoOfItemsSelected] = useState(0);\n\n const catalogApi = useApi(catalogApiRef);\n const entityPresentationApi = useApi(entityPresentationApiRef);\n const { value: entities, loading } = useAsync(async () => {\n const { items } = await catalogApi.getEntities(\n catalogFilter ? { filter: catalogFilter } : undefined,\n );\n const entityRefToPresentation = new Map<\n string,\n EntityRefPresentationSnapshot\n >(\n await Promise.all(\n items.map(async item => {\n const presentation = await entityPresentationApi.forEntity(item)\n .promise;\n return [stringifyEntityRef(item), presentation] as [\n string,\n EntityRefPresentationSnapshot,\n ];\n }),\n ),\n );\n return { entities: items, entityRefToPresentation };\n });\n const allowArbitraryValues =\n uiSchema['ui:options']?.allowArbitraryValues ?? true;\n\n // if not specified, maxItems defaults to undefined\n const maxItems = props.schema.maxItems;\n\n const onSelect = useCallback(\n (_: any, refs: (string | Entity)[], reason: AutocompleteChangeReason) => {\n const values = refs\n .map(ref => {\n if (typeof ref !== 'string') {\n // if ref does not exist: pass 'undefined' to trigger validation for required value\n return ref ? stringifyEntityRef(ref as Entity) : undefined;\n }\n if (reason === 'blur' || reason === 'create-option') {\n // Add in default namespace, etc.\n let entityRef = ref;\n try {\n // Attempt to parse the entity ref into it's full form.\n entityRef = stringifyEntityRef(\n parseEntityRef(ref as string, {\n defaultKind,\n defaultNamespace,\n }),\n );\n } catch (err) {\n // If the passed in value isn't an entity ref, do nothing.\n }\n\n // We need to check against formData here as that's the previous value for this field.\n if (formData?.includes(ref) || allowArbitraryValues) {\n return entityRef;\n }\n }\n\n return undefined;\n })\n .filter(ref => ref !== undefined) as string[];\n\n setNoOfItemsSelected(values.length);\n onChange(values);\n },\n [onChange, formData, defaultKind, defaultNamespace, allowArbitraryValues],\n );\n\n useEffect(() => {\n if (required && !allowArbitraryValues && entities?.entities?.length === 1) {\n onChange([stringifyEntityRef(entities?.entities[0])]);\n }\n }, [entities, onChange, required, allowArbitraryValues]);\n\n return (\n <FormControl\n margin=\"normal\"\n required={required}\n error={rawErrors?.length > 0 && !formData}\n >\n <Autocomplete\n multiple\n filterSelectedOptions\n disabled={\n isDisabled ||\n (required &&\n !allowArbitraryValues &&\n entities?.entities?.length === 1)\n }\n id={idSchema?.$id}\n defaultValue={formData}\n loading={loading}\n onChange={onSelect}\n options={entities?.entities || []}\n renderOption={option => <EntityDisplayName entityRef={option} />}\n getOptionLabel={option =>\n // option can be a string due to freeSolo.\n typeof option === 'string'\n ? option\n : entities?.entityRefToPresentation.get(stringifyEntityRef(option))\n ?.entityRef!\n }\n getOptionDisabled={_options =>\n maxItems ? noOfItemsSelected >= maxItems : false\n }\n autoSelect\n freeSolo={allowArbitraryValues}\n renderInput={params => (\n <TextField\n {...params}\n label={title}\n disabled={isDisabled}\n margin=\"dense\"\n helperText={description}\n FormHelperTextProps={{\n margin: 'dense',\n style: { marginLeft: 0 },\n }}\n variant=\"outlined\"\n required={required}\n InputProps={{\n ...params.InputProps,\n required: formData?.length === 0 && required,\n }}\n />\n )}\n ListboxComponent={VirtualizedListbox}\n />\n </FormControl>\n );\n};\n\nexport const validateMultiEntityPickerValidation = (\n values: string[],\n validation: FieldValidation,\n) => {\n values.forEach(value => {\n try {\n parseEntityRef(value);\n } catch {\n validation.addError(`${value} is not a valid entity ref`);\n }\n });\n};\n\n/**\n * Converts a special `{exists: true}` value to the `CATALOG_FILTER_EXISTS` symbol.\n *\n * @param value - The value to convert.\n * @returns The converted value.\n */\nfunction convertOpsValues(\n value: Exclude<MultiEntityPickerFilterQueryValue, Array<any>>,\n): string | symbol {\n if (typeof value === 'object' && value.exists) {\n return CATALOG_FILTER_EXISTS;\n }\n return value?.toString();\n}\n\n/**\n * Converts schema filters to entity filter query, replacing `{exists:true}` values\n * with the constant `CATALOG_FILTER_EXISTS`.\n *\n * @param schemaFilters - An object containing schema filters with keys as filter names\n * and values as filter values.\n * @returns An object with the same keys as the input object, but with `{exists:true}` values\n * transformed to `CATALOG_FILTER_EXISTS` symbol.\n */\nfunction convertSchemaFiltersToQuery(\n schemaFilters: MultiEntityPickerFilterQuery,\n): Exclude<EntityFilterQuery, Array<any>> {\n const query: EntityFilterQuery = {};\n\n for (const [key, value] of Object.entries(schemaFilters)) {\n if (Array.isArray(value)) {\n query[key] = value;\n } else {\n query[key] = convertOpsValues(value);\n }\n }\n\n return query;\n}\n\n/**\n * Builds an `EntityFilterQuery` based on the `uiSchema` passed in.\n * If `catalogFilter` is specified in the `uiSchema`, it is converted to a `EntityFilterQuery`.\n *\n * @param uiSchema The `uiSchema` of an `EntityPicker` component.\n * @returns An `EntityFilterQuery` based on the `uiSchema`, or `undefined` if `catalogFilter` is not specified in the `uiSchema`.\n */\nfunction buildCatalogFilter(\n uiSchema: MultiEntityPickerProps['uiSchema'],\n): EntityFilterQuery | undefined {\n const catalogFilter: MultiEntityPickerUiOptions['catalogFilter'] | undefined =\n uiSchema['ui:options']?.catalogFilter;\n\n if (!catalogFilter) {\n return undefined;\n }\n\n if (Array.isArray(catalogFilter)) {\n return catalogFilter.map(convertSchemaFiltersToQuery);\n }\n\n return convertSchemaFiltersToQuery(catalogFilter);\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;AAqDa,MAAA,iBAAA,GAAoB,CAAC,KAAkC,KAAA;AAClE,EAAM,MAAA;AAAA,IACJ,QAAA;AAAA,IACA,MAAQ,EAAA,EAAE,KAAQ,GAAA,QAAA,EAAU,cAAc,4BAA6B,EAAA;AAAA,IACvE,QAAA;AAAA,IACA,QAAA;AAAA,IACA,SAAA;AAAA,IACA,QAAA;AAAA,IACA;AAAA,GACE,GAAA,KAAA;AAEJ,EAAM,MAAA,aAAA,GAAgB,mBAAmB,QAAQ,CAAA;AACjD,EAAM,MAAA,WAAA,GAAc,QAAS,CAAA,YAAY,CAAG,EAAA,WAAA;AAC5C,EAAA,MAAM,gBACJ,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AM,OAAQ,CAAA,aAAa,CAAG,EAAA;AAChC,IAAO,OAAA,aAAA,CAAc,IAAI,2BAA2B,CAAA;AAAA;AAGtD,EAAA,OAAO,4BAA4B,aAAa,CAAA;AAClD;;;;"}
1
+ {"version":3,"file":"MultiEntityPicker.esm.js","sources":["../../../../src/components/fields/MultiEntityPicker/MultiEntityPicker.tsx"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport {\n type EntityFilterQuery,\n CATALOG_FILTER_EXISTS,\n} from '@backstage/catalog-client';\nimport {\n Entity,\n parseEntityRef,\n stringifyEntityRef,\n} from '@backstage/catalog-model';\nimport { useApi } from '@backstage/core-plugin-api';\nimport {\n catalogApiRef,\n entityPresentationApiRef,\n EntityDisplayName,\n EntityRefPresentationSnapshot,\n} from '@backstage/plugin-catalog-react';\nimport TextField from '@material-ui/core/TextField';\nimport Autocomplete, {\n AutocompleteChangeReason,\n} from '@material-ui/lab/Autocomplete';\nimport { useCallback, useEffect, useState } from 'react';\nimport useAsync from 'react-use/esm/useAsync';\nimport { FieldValidation } from '@rjsf/utils';\nimport {\n MultiEntityPickerFilterQueryValue,\n MultiEntityPickerProps,\n MultiEntityPickerUiOptions,\n MultiEntityPickerFilterQuery,\n} from './schema';\nimport { VirtualizedListbox } from '../VirtualizedListbox';\nimport { ScaffolderField } from '@backstage/plugin-scaffolder-react/alpha';\nimport { useTranslationRef } from '@backstage/frontend-plugin-api';\nimport { scaffolderTranslationRef } from '../../../translation';\n\nexport { MultiEntityPickerSchema } from './schema';\n\n/**\n * The underlying component that is rendered in the form for the `MultiEntityPicker`\n * field extension.\n */\nexport const MultiEntityPicker = (props: MultiEntityPickerProps) => {\n const { t } = useTranslationRef(scaffolderTranslationRef);\n const {\n onChange,\n schema: {\n title = t('fields.multiEntityPicker.title'),\n description = t('fields.multiEntityPicker.description'),\n },\n required,\n uiSchema,\n rawErrors,\n formData,\n idSchema,\n errors,\n } = props;\n\n const catalogFilter = buildCatalogFilter(uiSchema);\n const defaultKind = uiSchema['ui:options']?.defaultKind;\n const defaultNamespace =\n uiSchema['ui:options']?.defaultNamespace || undefined;\n const isDisabled = uiSchema?.['ui:disabled'] ?? false;\n const [noOfItemsSelected, setNoOfItemsSelected] = useState(0);\n\n const catalogApi = useApi(catalogApiRef);\n const entityPresentationApi = useApi(entityPresentationApiRef);\n const { value: entities, loading } = useAsync(async () => {\n const { items } = await catalogApi.getEntities(\n catalogFilter ? { filter: catalogFilter } : undefined,\n );\n const entityRefToPresentation = new Map<\n string,\n EntityRefPresentationSnapshot\n >(\n await Promise.all(\n items.map(async item => {\n const presentation = await entityPresentationApi.forEntity(item)\n .promise;\n return [stringifyEntityRef(item), presentation] as [\n string,\n EntityRefPresentationSnapshot,\n ];\n }),\n ),\n );\n return { entities: items, entityRefToPresentation };\n });\n const allowArbitraryValues =\n uiSchema['ui:options']?.allowArbitraryValues ?? true;\n\n // if not specified, maxItems defaults to undefined\n const maxItems = props.schema.maxItems;\n\n const onSelect = useCallback(\n (_: any, refs: (string | Entity)[], reason: AutocompleteChangeReason) => {\n const values = refs\n .map(ref => {\n if (typeof ref !== 'string') {\n // if ref does not exist: pass 'undefined' to trigger validation for required value\n return ref ? stringifyEntityRef(ref as Entity) : undefined;\n }\n if (reason === 'blur' || reason === 'create-option') {\n // Add in default namespace, etc.\n let entityRef = ref;\n try {\n // Attempt to parse the entity ref into it's full form.\n entityRef = stringifyEntityRef(\n parseEntityRef(ref as string, {\n defaultKind,\n defaultNamespace,\n }),\n );\n } catch (err) {\n // If the passed in value isn't an entity ref, do nothing.\n }\n\n // We need to check against formData here as that's the previous value for this field.\n if (formData?.includes(ref) || allowArbitraryValues) {\n return entityRef;\n }\n }\n\n return undefined;\n })\n .filter(ref => ref !== undefined) as string[];\n\n setNoOfItemsSelected(values.length);\n onChange(values);\n },\n [onChange, formData, defaultKind, defaultNamespace, allowArbitraryValues],\n );\n\n useEffect(() => {\n if (required && !allowArbitraryValues && entities?.entities?.length === 1) {\n onChange([stringifyEntityRef(entities?.entities[0])]);\n }\n }, [entities, onChange, required, allowArbitraryValues]);\n\n return (\n <ScaffolderField\n rawErrors={rawErrors}\n rawDescription={uiSchema['ui:description'] ?? description}\n required={required}\n disabled={isDisabled}\n errors={errors}\n >\n <Autocomplete\n multiple\n filterSelectedOptions\n disabled={\n isDisabled ||\n (required &&\n !allowArbitraryValues &&\n entities?.entities?.length === 1)\n }\n id={idSchema?.$id}\n defaultValue={formData}\n loading={loading}\n onChange={onSelect}\n options={entities?.entities || []}\n renderOption={option => <EntityDisplayName entityRef={option} />}\n getOptionLabel={option =>\n // option can be a string due to freeSolo.\n typeof option === 'string'\n ? option\n : entities?.entityRefToPresentation.get(stringifyEntityRef(option))\n ?.entityRef!\n }\n getOptionDisabled={_options =>\n maxItems ? noOfItemsSelected >= maxItems : false\n }\n autoSelect\n freeSolo={allowArbitraryValues}\n renderInput={params => (\n <TextField\n {...params}\n label={title}\n disabled={isDisabled}\n margin=\"dense\"\n FormHelperTextProps={{\n margin: 'dense',\n style: { marginLeft: 0 },\n }}\n variant=\"outlined\"\n required={required}\n InputProps={{\n ...params.InputProps,\n required: formData?.length === 0 && required,\n }}\n />\n )}\n ListboxComponent={VirtualizedListbox}\n />\n </ScaffolderField>\n );\n};\n\nexport const validateMultiEntityPickerValidation = (\n values: string[],\n validation: FieldValidation,\n) => {\n values.forEach(value => {\n try {\n parseEntityRef(value);\n } catch {\n validation.addError(`${value} is not a valid entity ref`);\n }\n });\n};\n\n/**\n * Converts a special `{exists: true}` value to the `CATALOG_FILTER_EXISTS` symbol.\n *\n * @param value - The value to convert.\n * @returns The converted value.\n */\nfunction convertOpsValues(\n value: Exclude<MultiEntityPickerFilterQueryValue, Array<any>>,\n): string | symbol {\n if (typeof value === 'object' && value.exists) {\n return CATALOG_FILTER_EXISTS;\n }\n return value?.toString();\n}\n\n/**\n * Converts schema filters to entity filter query, replacing `{exists:true}` values\n * with the constant `CATALOG_FILTER_EXISTS`.\n *\n * @param schemaFilters - An object containing schema filters with keys as filter names\n * and values as filter values.\n * @returns An object with the same keys as the input object, but with `{exists:true}` values\n * transformed to `CATALOG_FILTER_EXISTS` symbol.\n */\nfunction convertSchemaFiltersToQuery(\n schemaFilters: MultiEntityPickerFilterQuery,\n): Exclude<EntityFilterQuery, Array<any>> {\n const query: EntityFilterQuery = {};\n\n for (const [key, value] of Object.entries(schemaFilters)) {\n if (Array.isArray(value)) {\n query[key] = value;\n } else {\n query[key] = convertOpsValues(value);\n }\n }\n\n return query;\n}\n\n/**\n * Builds an `EntityFilterQuery` based on the `uiSchema` passed in.\n * If `catalogFilter` is specified in the `uiSchema`, it is converted to a `EntityFilterQuery`.\n *\n * @param uiSchema The `uiSchema` of an `EntityPicker` component.\n * @returns An `EntityFilterQuery` based on the `uiSchema`, or `undefined` if `catalogFilter` is not specified in the `uiSchema`.\n */\nfunction buildCatalogFilter(\n uiSchema: MultiEntityPickerProps['uiSchema'],\n): EntityFilterQuery | undefined {\n const catalogFilter: MultiEntityPickerUiOptions['catalogFilter'] | undefined =\n uiSchema['ui:options']?.catalogFilter;\n\n if (!catalogFilter) {\n return undefined;\n }\n\n if (Array.isArray(catalogFilter)) {\n return catalogFilter.map(convertSchemaFiltersToQuery);\n }\n\n return convertSchemaFiltersToQuery(catalogFilter);\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;AAuDa,MAAA,iBAAA,GAAoB,CAAC,KAAkC,KAAA;AAClE,EAAA,MAAM,EAAE,CAAA,EAAM,GAAA,iBAAA,CAAkB,wBAAwB,CAAA;AACxD,EAAM,MAAA;AAAA,IACJ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KAAK,CAAG,EAAA;AACxB,MAAA,KAAA,CAAM,GAAG,CAAI,GAAA,KAAA;AAAA,KACR,MAAA;AACL,MAAM,KAAA,CAAA,GAAG,CAAI,GAAA,gBAAA,CAAiB,KAAK,CAAA;AAAA;AACrC;AAGF,EAAO,OAAA,KAAA;AACT;AASA,SAAS,mBACP,QAC+B,EAAA;AAC/B,EAAM,MAAA,aAAA,GACJ,QAAS,CAAA,YAAY,CAAG,EAAA,aAAA;AAE1B,EAAA,IAAI,CAAC,aAAe,EAAA;AAClB,IAAO,OAAA,KAAA,CAAA;AAAA;AAGT,EAAI,IAAA,KAAA,CAAM,OAAQ,CAAA,aAAa,CAAG,EAAA;AAChC,IAAO,OAAA,aAAA,CAAc,IAAI,2BAA2B,CAAA;AAAA;AAGtD,EAAA,OAAO,4BAA4B,aAAa,CAAA;AAClD;;;;"}
@@ -1,12 +1,12 @@
1
1
  import { z } from 'zod';
2
- import { makeFieldSchemaFromZod } from '../utils.esm.js';
2
+ import { makeFieldSchema } from '@backstage/plugin-scaffolder-react';
3
3
 
4
4
  const entityQueryFilterExpressionSchema = z.record(
5
5
  z.string().or(z.object({ exists: z.boolean().optional() })).or(z.array(z.string()))
6
6
  );
7
- const MultiEntityPickerFieldSchema = makeFieldSchemaFromZod(
8
- z.array(z.string()),
9
- z.object({
7
+ const MultiEntityPickerFieldSchema = makeFieldSchema({
8
+ output: (z) => z.array(z.string()),
9
+ uiOptions: (z) => z.object({
10
10
  defaultKind: z.string().optional().describe(
11
11
  "The default entity kind. Options of this kind will not be prefixed."
12
12
  ),
@@ -16,7 +16,7 @@ const MultiEntityPickerFieldSchema = makeFieldSchemaFromZod(
16
16
  ),
17
17
  catalogFilter: z.array(entityQueryFilterExpressionSchema).or(entityQueryFilterExpressionSchema).optional().describe("List of key-value filter expression for entities")
18
18
  })
19
- );
19
+ });
20
20
  const MultiEntityPickerSchema = MultiEntityPickerFieldSchema.schema;
21
21
 
22
22
  export { MultiEntityPickerFieldSchema, MultiEntityPickerSchema, entityQueryFilterExpressionSchema };
@@ -1 +1 @@
1
- {"version":3,"file":"schema.esm.js","sources":["../../../../src/components/fields/MultiEntityPicker/schema.ts"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { z } from 'zod';\nimport { makeFieldSchemaFromZod } from '../utils';\n\nexport const entityQueryFilterExpressionSchema = z.record(\n z\n .string()\n .or(z.object({ exists: z.boolean().optional() }))\n .or(z.array(z.string())),\n);\n\nexport const MultiEntityPickerFieldSchema = makeFieldSchemaFromZod(\n z.array(z.string()),\n z.object({\n defaultKind: z\n .string()\n .optional()\n .describe(\n 'The default entity kind. Options of this kind will not be prefixed.',\n ),\n allowArbitraryValues: z\n .boolean()\n .optional()\n .describe('Whether to allow arbitrary user input. Defaults to true'),\n defaultNamespace: z\n .union([z.string(), z.literal(false)])\n .optional()\n .describe(\n 'The default namespace. Options with this namespace will not be prefixed.',\n ),\n catalogFilter: z\n .array(entityQueryFilterExpressionSchema)\n .or(entityQueryFilterExpressionSchema)\n .optional()\n .describe('List of key-value filter expression for entities'),\n }),\n);\n\n/**\n * The input props that can be specified under `ui:options` for the\n * `EntityPicker` field extension.\n */\nexport type MultiEntityPickerUiOptions =\n typeof MultiEntityPickerFieldSchema.uiOptionsType;\n\nexport type MultiEntityPickerProps = typeof MultiEntityPickerFieldSchema.type;\n\nexport const MultiEntityPickerSchema = MultiEntityPickerFieldSchema.schema;\n\nexport type MultiEntityPickerFilterQuery = z.TypeOf<\n typeof entityQueryFilterExpressionSchema\n>;\n\nexport type MultiEntityPickerFilterQueryValue =\n MultiEntityPickerFilterQuery[keyof MultiEntityPickerFilterQuery];\n"],"names":[],"mappings":";;;AAkBO,MAAM,oCAAoC,CAAE,CAAA,MAAA;AAAA,EACjD,CAAA,CACG,QACA,CAAA,EAAA,CAAG,EAAE,MAAO,CAAA,EAAE,MAAQ,EAAA,CAAA,CAAE,OAAQ,EAAA,CAAE,UAAW,EAAC,CAAC,CAC/C,CAAA,EAAA,CAAG,EAAE,KAAM,CAAA,CAAA,CAAE,MAAO,EAAC,CAAC;AAC3B;AAEO,MAAM,4BAA+B,GAAA,sBAAA;AAAA,EAC1C,CAAE,CAAA,KAAA,CAAM,CAAE,CAAA,MAAA,EAAQ,CAAA;AAAA,EAClB,EAAE,MAAO,CAAA;AAAA,IACP,WAAa,EAAA,CAAA,CACV,MAAO,EAAA,CACP,UACA,CAAA,QAAA;AAAA,MACC;AAAA,KACF;AAAA,IACF,sBAAsB,CACnB,CAAA,OAAA,GACA,QAAS,EAAA,CACT,SAAS,yDAAyD,CAAA;AAAA,IACrE,gBAAkB,EAAA,CAAA,CACf,KAAM,CAAA,CAAC,EAAE,MAAO,EAAA,EAAG,CAAE,CAAA,OAAA,CAAQ,KAAK,CAAC,CAAC,CAAA,CACpC,UACA,CAAA,QAAA;AAAA,MACC;AAAA,KACF;AAAA,IACF,aAAA,EAAe,CACZ,CAAA,KAAA,CAAM,iCAAiC,CAAA,CACvC,EAAG,CAAA,iCAAiC,CACpC,CAAA,QAAA,EACA,CAAA,QAAA,CAAS,kDAAkD;AAAA,GAC/D;AACH;AAWO,MAAM,0BAA0B,4BAA6B,CAAA;;;;"}
1
+ {"version":3,"file":"schema.esm.js","sources":["../../../../src/components/fields/MultiEntityPicker/schema.ts"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { z as zod } from 'zod';\nimport { makeFieldSchema } from '@backstage/plugin-scaffolder-react';\n\nexport const entityQueryFilterExpressionSchema = zod.record(\n zod\n .string()\n .or(zod.object({ exists: zod.boolean().optional() }))\n .or(zod.array(zod.string())),\n);\n\nexport const MultiEntityPickerFieldSchema = makeFieldSchema({\n output: z => z.array(z.string()),\n uiOptions: z =>\n z.object({\n defaultKind: z\n .string()\n .optional()\n .describe(\n 'The default entity kind. Options of this kind will not be prefixed.',\n ),\n allowArbitraryValues: z\n .boolean()\n .optional()\n .describe('Whether to allow arbitrary user input. Defaults to true'),\n defaultNamespace: z\n .union([z.string(), z.literal(false)])\n .optional()\n .describe(\n 'The default namespace. Options with this namespace will not be prefixed.',\n ),\n catalogFilter: z\n .array(entityQueryFilterExpressionSchema)\n .or(entityQueryFilterExpressionSchema)\n .optional()\n .describe('List of key-value filter expression for entities'),\n }),\n});\n\n/**\n * The input props that can be specified under `ui:options` for the\n * `EntityPicker` field extension.\n */\nexport type MultiEntityPickerUiOptions = NonNullable<\n (typeof MultiEntityPickerFieldSchema.TProps.uiSchema)['ui:options']\n>;\n\nexport type MultiEntityPickerProps = typeof MultiEntityPickerFieldSchema.TProps;\n\nexport const MultiEntityPickerSchema = MultiEntityPickerFieldSchema.schema;\n\nexport type MultiEntityPickerFilterQuery = zod.TypeOf<\n typeof entityQueryFilterExpressionSchema\n>;\n\nexport type MultiEntityPickerFilterQueryValue =\n MultiEntityPickerFilterQuery[keyof MultiEntityPickerFilterQuery];\n"],"names":["zod"],"mappings":";;;AAkBO,MAAM,oCAAoCA,CAAI,CAAA,MAAA;AAAA,EACnDA,CAAA,CACG,QACA,CAAA,EAAA,CAAGA,EAAI,MAAO,CAAA,EAAE,MAAQ,EAAAA,CAAA,CAAI,OAAQ,EAAA,CAAE,UAAW,EAAC,CAAC,CACnD,CAAA,EAAA,CAAGA,EAAI,KAAM,CAAAA,CAAA,CAAI,MAAO,EAAC,CAAC;AAC/B;AAEO,MAAM,+BAA+B,eAAgB,CAAA;AAAA,EAC1D,QAAQ,CAAK,CAAA,KAAA,CAAA,CAAE,KAAM,CAAA,CAAA,CAAE,QAAQ,CAAA;AAAA,EAC/B,SAAA,EAAW,CACT,CAAA,KAAA,CAAA,CAAE,MAAO,CAAA;AAAA,IACP,WAAa,EAAA,CAAA,CACV,MAAO,EAAA,CACP,UACA,CAAA,QAAA;AAAA,MACC;AAAA,KACF;AAAA,IACF,sBAAsB,CACnB,CAAA,OAAA,GACA,QAAS,EAAA,CACT,SAAS,yDAAyD,CAAA;AAAA,IACrE,gBAAkB,EAAA,CAAA,CACf,KAAM,CAAA,CAAC,EAAE,MAAO,EAAA,EAAG,CAAE,CAAA,OAAA,CAAQ,KAAK,CAAC,CAAC,CAAA,CACpC,UACA,CAAA,QAAA;AAAA,MACC;AAAA,KACF;AAAA,IACF,aAAA,EAAe,CACZ,CAAA,KAAA,CAAM,iCAAiC,CAAA,CACvC,EAAG,CAAA,iCAAiC,CACpC,CAAA,QAAA,EACA,CAAA,QAAA,CAAS,kDAAkD;AAAA,GAC/D;AACL,CAAC;AAYM,MAAM,0BAA0B,4BAA6B,CAAA;;;;"}