@backstage/plugin-scaffolder 1.36.3-next.1 → 1.37.0-next.2
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.
- package/CHANGELOG.md +64 -0
- package/dist/alpha/api/FormDecoratorsApi.esm.js.map +1 -1
- package/dist/alpha/api/ref.esm.js.map +1 -1
- package/dist/alpha/components/TemplateEditorPage/CustomFieldExplorer.esm.js +4 -4
- package/dist/alpha/components/TemplateEditorPage/CustomFieldExplorer.esm.js.map +1 -1
- package/dist/alpha/components/TemplateEditorPage/CustomFieldPlayground.esm.js +5 -5
- package/dist/alpha/components/TemplateEditorPage/CustomFieldPlayground.esm.js.map +1 -1
- package/dist/alpha/components/TemplateListPage/TemplateListPage.esm.js +14 -14
- package/dist/alpha/components/TemplateListPage/TemplateListPage.esm.js.map +1 -1
- package/dist/alpha/components/TemplatesSubPage.esm.js +20 -10
- package/dist/alpha/components/TemplatesSubPage.esm.js.map +1 -1
- package/dist/alpha/extensions.esm.js +28 -2
- package/dist/alpha/extensions.esm.js.map +1 -1
- package/dist/alpha/hooks/useFormDecorators.esm.js +34 -3
- package/dist/alpha/hooks/useFormDecorators.esm.js.map +1 -1
- package/dist/alpha/lib/createGroupsWithOther.esm.js +13 -0
- package/dist/alpha/lib/createGroupsWithOther.esm.js.map +1 -0
- package/dist/alpha.d.ts +14 -4
- package/dist/components/TemplateTypePicker/TemplateTypePicker.esm.js +4 -4
- package/dist/components/TemplateTypePicker/TemplateTypePicker.esm.js.map +1 -1
- package/dist/components/TemplatingExtensionsPage/TemplatingExtensionsPage.esm.js +4 -4
- package/dist/components/TemplatingExtensionsPage/TemplatingExtensionsPage.esm.js.map +1 -1
- package/dist/components/fields/Autocomplete/Autocomplete.esm.js +23 -0
- package/dist/components/fields/Autocomplete/Autocomplete.esm.js.map +1 -0
- package/dist/components/fields/EntityNamePicker/EntityNamePicker.esm.js +23 -2
- package/dist/components/fields/EntityNamePicker/EntityNamePicker.esm.js.map +1 -1
- package/dist/components/fields/EntityPicker/EntityPicker.esm.js +125 -9
- package/dist/components/fields/EntityPicker/EntityPicker.esm.js.map +1 -1
- package/dist/components/fields/EntityTagsPicker/EntityTagsPicker.esm.js +106 -7
- package/dist/components/fields/EntityTagsPicker/EntityTagsPicker.esm.js.map +1 -1
- package/dist/components/fields/MultiEntityPicker/MultiEntityPicker.esm.js +128 -10
- package/dist/components/fields/MultiEntityPicker/MultiEntityPicker.esm.js.map +1 -1
- package/dist/components/fields/MyGroupsPicker/MyGroupsPicker.esm.js +66 -6
- package/dist/components/fields/MyGroupsPicker/MyGroupsPicker.esm.js.map +1 -1
- package/dist/components/fields/OwnedEntityPicker/OwnedEntityPicker.esm.js +29 -6
- package/dist/components/fields/OwnedEntityPicker/OwnedEntityPicker.esm.js.map +1 -1
- package/dist/components/fields/OwnedEntityPicker/schema.esm.js +1 -0
- package/dist/components/fields/OwnedEntityPicker/schema.esm.js.map +1 -1
- package/dist/components/fields/RepoBranchPicker/BitbucketRepoBranchPicker.esm.js +29 -5
- package/dist/components/fields/RepoBranchPicker/BitbucketRepoBranchPicker.esm.js.map +1 -1
- package/dist/components/fields/RepoBranchPicker/DefaultRepoBranchPicker.esm.js +20 -3
- package/dist/components/fields/RepoBranchPicker/DefaultRepoBranchPicker.esm.js.map +1 -1
- package/dist/components/fields/RepoBranchPicker/GitHubRepoBranchPicker.esm.js +29 -5
- package/dist/components/fields/RepoBranchPicker/GitHubRepoBranchPicker.esm.js.map +1 -1
- package/dist/components/fields/RepoBranchPicker/RepoBranchPicker.esm.js +18 -6
- package/dist/components/fields/RepoBranchPicker/RepoBranchPicker.esm.js.map +1 -1
- package/dist/components/fields/RepoOwnerPicker/DefaultRepoOwnerPicker.esm.js +20 -3
- package/dist/components/fields/RepoOwnerPicker/DefaultRepoOwnerPicker.esm.js.map +1 -1
- package/dist/components/fields/RepoOwnerPicker/GitHubRepoOwnerPicker.esm.js +29 -5
- package/dist/components/fields/RepoOwnerPicker/GitHubRepoOwnerPicker.esm.js.map +1 -1
- package/dist/components/fields/RepoOwnerPicker/RepoOwnerPicker.esm.js +28 -31
- package/dist/components/fields/RepoOwnerPicker/RepoOwnerPicker.esm.js.map +1 -1
- package/dist/components/fields/RepoUrlPicker/AzureRepoPicker.esm.js +86 -4
- package/dist/components/fields/RepoUrlPicker/AzureRepoPicker.esm.js.map +1 -1
- package/dist/components/fields/RepoUrlPicker/BitbucketRepoPicker.esm.js +107 -11
- package/dist/components/fields/RepoUrlPicker/BitbucketRepoPicker.esm.js.map +1 -1
- package/dist/components/fields/RepoUrlPicker/GerritRepoPicker.esm.js +33 -3
- package/dist/components/fields/RepoUrlPicker/GerritRepoPicker.esm.js.map +1 -1
- package/dist/components/fields/RepoUrlPicker/GiteaRepoPicker.esm.js +42 -5
- package/dist/components/fields/RepoUrlPicker/GiteaRepoPicker.esm.js.map +1 -1
- package/dist/components/fields/RepoUrlPicker/GithubRepoPicker.esm.js +52 -7
- package/dist/components/fields/RepoUrlPicker/GithubRepoPicker.esm.js.map +1 -1
- package/dist/components/fields/RepoUrlPicker/GitlabRepoPicker.esm.js +60 -16
- package/dist/components/fields/RepoUrlPicker/GitlabRepoPicker.esm.js.map +1 -1
- package/dist/components/fields/RepoUrlPicker/RepoUrlPicker.esm.js +23 -9
- package/dist/components/fields/RepoUrlPicker/RepoUrlPicker.esm.js.map +1 -1
- package/dist/components/fields/RepoUrlPicker/RepoUrlPickerHost.esm.js +27 -3
- package/dist/components/fields/RepoUrlPicker/RepoUrlPickerHost.esm.js.map +1 -1
- package/dist/components/fields/RepoUrlPicker/RepoUrlPickerRepoName.esm.js +60 -6
- package/dist/components/fields/RepoUrlPicker/RepoUrlPickerRepoName.esm.js.map +1 -1
- package/dist/components/fields/SecretInput/SecretInput.esm.js +57 -2
- package/dist/components/fields/SecretInput/SecretInput.esm.js.map +1 -1
- package/dist/components/fields/buiChipStyles.esm.js +25 -0
- package/dist/components/fields/buiChipStyles.esm.js.map +1 -0
- package/dist/components/fields/scaffolderFieldOverrides.module.css.esm.js +8 -0
- package/dist/components/fields/scaffolderFieldOverrides.module.css.esm.js.map +1 -0
- package/dist/index.esm.js +2 -0
- package/dist/index.esm.js.map +1 -1
- package/dist/node_modules_dist/style-inject/dist/style-inject.es.esm.js +29 -0
- package/dist/node_modules_dist/style-inject/dist/style-inject.es.esm.js.map +1 -0
- package/dist/plugins/scaffolder/package.json.esm.js +3 -1
- package/dist/plugins/scaffolder/package.json.esm.js.map +1 -1
- package/package.json +9 -7
|
@@ -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 Autocomplete, {\n AutocompleteChangeReason,\n createFilterOptions,\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// AutocompleteChangeReason events that can be triggered when a user inputs a freeSolo option\nconst FREE_SOLO_EVENTS: readonly AutocompleteChangeReason[] = [\n 'blur',\n 'create-option',\n];\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 the ref is not a string, then it was a selected option in the picker\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\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 (\n // If value already matches what exists in form data, allow it\n formData?.includes(ref) ||\n // If arbitrary values are allowed and the reason is a free solo event, allow it\n (allowArbitraryValues && FREE_SOLO_EVENTS.includes(reason))\n ) {\n return entityRef;\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 filterOptions={createFilterOptions<Entity>({\n stringify: option =>\n entities?.entityRefToPresentation.get(stringifyEntityRef(option))\n ?.primaryTitle!,\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":";;;;;;;;;;;;;;;AAqDA,MAAM,gBAAA,GAAwD;AAAA,EAC5D,MAAA;AAAA,EACA;AACF,CAAA;AAMO,MAAM,iBAAA,GAAoB,CAAC,KAAA,KAAkC;AAClE,EAAA,MAAM,EAAE,CAAA,EAAE,GAAI,iBAAA,CAAkB,wBAAwB,CAAA;AACxD,EAAA,MAAM;AAAA,IACJ,QAAA;AAAA,IACA,MAAA,EAAQ;AAAA,MACN,KAAA,GAAQ,EAAE,gCAAgC,CAAA;AAAA,MAC1C,WAAA,GAAc,EAAE,sCAAsC;AAAA,KACxD;AAAA,IACA,QAAA;AAAA,IACA,QAAA;AAAA,IACA,SAAA;AAAA,IACA,QAAA;AAAA,IACA,QAAA;AAAA,IACA;AAAA,GACF,GAAI,KAAA;AAEJ,EAAA,MAAM,aAAA,GAAgB,mBAAmB,QAAQ,CAAA;AACjD,EAAA,MAAM,WAAA,GAAc,QAAA,CAAS,YAAY,CAAA,EAAG,WAAA;AAC5C,EAAA,MAAM,gBAAA,GACJ,QAAA,CAAS,YAAY,CAAA,EAAG,gBAAA,IAAoB,MAAA;AAC9C,EAAA,MAAM,UAAA,GAAa,QAAA,GAAW,aAAa,CAAA,IAAK,KAAA;AAChD,EAAA,MAAM,CAAC,iBAAA,EAAmB,oBAAoB,CAAA,GAAI,SAAS,CAAC,CAAA;AAE5D,EAAA,MAAM,UAAA,GAAa,OAAO,aAAa,CAAA;AACvC,EAAA,MAAM,qBAAA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AA;AAAA,EACtD;AAEA,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 createFilterOptions,\n} from '@material-ui/lab/Autocomplete';\nimport { type Key, useCallback, useEffect, useMemo, 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 {\n ScaffolderField,\n useScaffolderTheme,\n} from '@backstage/plugin-scaffolder-react/alpha';\nimport { useTranslationRef } from '@backstage/frontend-plugin-api';\nimport { scaffolderTranslationRef } from '../../../translation';\nimport { Autocomplete as BuiAutocomplete } from '../Autocomplete';\nimport { chipStyle, chipRemoveStyle } from '../buiChipStyles';\n\nexport { MultiEntityPickerSchema } from './schema';\n\n// AutocompleteChangeReason events that can be triggered when a user inputs a freeSolo option\nconst FREE_SOLO_EVENTS: readonly AutocompleteChangeReason[] = [\n 'blur',\n 'create-option',\n];\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 theme = useScaffolderTheme();\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 allowArbitraryValues =\n uiSchema['ui:options']?.allowArbitraryValues ?? true;\n const maxItems = props.schema.maxItems;\n\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\n const onSelect = useCallback(\n (_: any, refs: (string | Entity)[], reason: AutocompleteChangeReason) => {\n const values = refs\n .map(ref => {\n // If the ref is not a string, then it was a selected option in the picker\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\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 (\n // If value already matches what exists in form data, allow it\n formData?.includes(ref) ||\n // If arbitrary values are allowed and the reason is a free solo event, allow it\n (allowArbitraryValues && FREE_SOLO_EVENTS.includes(reason))\n ) {\n return entityRef;\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 // BUI: options and selection state\n const allOptions = useMemo(\n () =>\n (entities?.entities || []).map(entity => {\n const entityRef = stringifyEntityRef(entity);\n const presentation = entities?.entityRefToPresentation.get(entityRef);\n return {\n value: entityRef,\n label: presentation?.primaryTitle || entityRef,\n };\n }),\n [entities],\n );\n\n const selectedValues = useMemo(() => formData || [], [formData]);\n const availableOptions = useMemo(\n () => allOptions.filter(o => !selectedValues.includes(o.value)),\n [allOptions, selectedValues],\n );\n\n const [inputValue, setInputValue] = useState('');\n\n const atMaxItems =\n maxItems !== undefined && selectedValues.length >= maxItems;\n\n const handleSelectionChange = useCallback(\n (key: Key | null) => {\n if (atMaxItems) return;\n\n if (key !== null) {\n const newValue = String(key);\n if (!selectedValues.includes(newValue)) {\n onChange([...selectedValues, newValue]);\n }\n } else if (allowArbitraryValues && inputValue) {\n let entityRef = inputValue;\n try {\n entityRef = stringifyEntityRef(\n parseEntityRef(inputValue, { defaultKind, defaultNamespace }),\n );\n } catch {\n // If the input isn't a valid entity ref, use it as-is\n }\n if (!selectedValues.includes(entityRef)) {\n onChange([...selectedValues, entityRef]);\n }\n }\n setInputValue('');\n },\n [\n atMaxItems,\n selectedValues,\n onChange,\n allowArbitraryValues,\n inputValue,\n defaultKind,\n defaultNamespace,\n ],\n );\n\n const handleRemove = useCallback(\n (value: string) => {\n onChange(selectedValues.filter(v => v !== value));\n },\n [selectedValues, onChange],\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 if (theme === 'bui') {\n const isAutoSelected =\n required && !allowArbitraryValues && entities?.entities?.length === 1;\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 <div>\n {selectedValues.length > 0 && (\n <div\n style={{\n display: 'flex',\n flexWrap: 'wrap',\n gap: 'var(--bui-space-1)',\n marginBottom: 'var(--bui-space-2)',\n }}\n >\n {selectedValues.map(value => {\n const opt = allOptions.find(o => o.value === value);\n return (\n <span key={value} style={chipStyle}>\n {opt?.label || value}\n {!isDisabled && !isAutoSelected && (\n <button\n type=\"button\"\n onClick={() => handleRemove(value)}\n style={chipRemoveStyle}\n aria-label={`Remove ${opt?.label || value}`}\n >\n ×\n </button>\n )}\n </span>\n );\n })}\n </div>\n )}\n <BuiAutocomplete\n id={idSchema?.$id}\n label={title}\n isRequired={required}\n isDisabled={isDisabled || isAutoSelected || atMaxItems}\n selectedKey={null}\n inputValue={inputValue}\n onInputChange={setInputValue}\n onSelectionChange={handleSelectionChange}\n isLoading={loading}\n options={availableOptions}\n allowsCustomValue={allowArbitraryValues}\n isInvalid={rawErrors && rawErrors.length > 0}\n />\n </div>\n </ScaffolderField>\n );\n }\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 filterOptions={createFilterOptions<Entity>({\n stringify: option =>\n entities?.entityRefToPresentation.get(stringifyEntityRef(option))\n ?.primaryTitle!,\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":["BuiAutocomplete","Autocomplete","TextField"],"mappings":";;;;;;;;;;;;;;;;;AA0DA,MAAM,gBAAA,GAAwD;AAAA,EAC5D,MAAA;AAAA,EACA;AACF,CAAA;AAMO,MAAM,iBAAA,GAAoB,CAAC,KAAA,KAAkC;AAClE,EAAA,MAAM,QAAQ,kBAAA,EAAmB;AACjC,EAAA,MAAM,EAAE,CAAA,EAAE,GAAI,iBAAA,CAAkB,wBAAwB,CAAA;AACxD,EAAA,MAAM;AAAA,IACJ,QAAA;AAAA,IACA,MAAA,EAAQ;AAAA,MACN,KAAA,GAAQ,EAAE,gCAAgC,CAAA;AAAA,MAC1C,WAAA,GAAc,EAAE,sCAAsC;AAAA,KACxD;AAAA,IACA,QAAA;AAAA,IACA,QAAA;AAAA,IACA,SAAA;AAAA,IACA,QAAA;AAAA,IACA,QAAA;AAAA,IACA;AAAA,GACF,GAAI,KAAA;AAEJ,EAAA,MAAM,aAAA,GAAgB,mBAAmB,QAAQ,CAAA;AACjD,EAAA,MAAM,WAAA,GAAc,QAAA,CAAS,YAAY,CA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AAG,CAAA,GAAI,KAAA;AAAA,IACf,CAAA,MAAO;AACL,MAAA,KAAA,CAAM,GAAG,CAAA,GAAI,gBAAA,CAAiB,KAAK,CAAA;AAAA,IACrC;AAAA,EACF;AAEA,EAAA,OAAO,KAAA;AACT;AASA,SAAS,mBACP,QAAA,EAC+B;AAC/B,EAAA,MAAM,aAAA,GACJ,QAAA,CAAS,YAAY,CAAA,EAAG,aAAA;AAE1B,EAAA,IAAI,CAAC,aAAA,EAAe;AAClB,IAAA,OAAO,MAAA;AAAA,EACT;AAEA,EAAA,IAAI,KAAA,CAAM,OAAA,CAAQ,aAAa,CAAA,EAAG;AAChC,IAAA,OAAO,aAAA,CAAc,IAAI,2BAA2B,CAAA;AAAA,EACtD;AAEA,EAAA,OAAO,4BAA4B,aAAa,CAAA;AAClD;;;;"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { jsx } from 'react/jsx-runtime';
|
|
2
|
-
import { useEffect } from 'react';
|
|
2
|
+
import { useMemo, useState, useEffect, useCallback } from 'react';
|
|
3
3
|
import { useApi, identityApiRef, errorApiRef } from '@backstage/core-plugin-api';
|
|
4
|
-
import
|
|
4
|
+
import MuiTextField from '@material-ui/core/TextField';
|
|
5
5
|
export { MyGroupsPickerSchema } from './schema.esm.js';
|
|
6
|
-
import
|
|
6
|
+
import MuiAutocomplete, { createFilterOptions } from '@material-ui/lab/Autocomplete';
|
|
7
7
|
import { catalogApiRef, entityPresentationApiRef, EntityDisplayName } from '@backstage/plugin-catalog-react';
|
|
8
8
|
import { NotFoundError } from '@backstage/errors';
|
|
9
9
|
import useAsync from 'react-use/esm/useAsync';
|
|
@@ -11,9 +11,11 @@ import { stringifyEntityRef } from '@backstage/catalog-model';
|
|
|
11
11
|
import { VirtualizedListbox } from '../VirtualizedListbox.esm.js';
|
|
12
12
|
import { useTranslationRef } from '@backstage/core-plugin-api/alpha';
|
|
13
13
|
import { scaffolderTranslationRef } from '../../../translation.esm.js';
|
|
14
|
-
import { ScaffolderField } from '@backstage/plugin-scaffolder-react/alpha';
|
|
14
|
+
import { useScaffolderTheme, ScaffolderField } from '@backstage/plugin-scaffolder-react/alpha';
|
|
15
|
+
import { Autocomplete } from '../Autocomplete/Autocomplete.esm.js';
|
|
15
16
|
|
|
16
17
|
const MyGroupsPicker = (props) => {
|
|
18
|
+
const theme = useScaffolderTheme();
|
|
17
19
|
const { t } = useTranslationRef(scaffolderTranslationRef);
|
|
18
20
|
const {
|
|
19
21
|
schema: {
|
|
@@ -25,6 +27,7 @@ const MyGroupsPicker = (props) => {
|
|
|
25
27
|
onChange,
|
|
26
28
|
formData,
|
|
27
29
|
uiSchema,
|
|
30
|
+
idSchema,
|
|
28
31
|
errors
|
|
29
32
|
} = props;
|
|
30
33
|
const identityApi = useApi(identityApiRef);
|
|
@@ -58,11 +61,68 @@ const MyGroupsPicker = (props) => {
|
|
|
58
61
|
onChange(value ? stringifyEntityRef(value) : "");
|
|
59
62
|
};
|
|
60
63
|
const selectedEntity = groups?.catalogEntities.find((e) => stringifyEntityRef(e) === formData) || null;
|
|
64
|
+
const buiOptions = useMemo(
|
|
65
|
+
() => (groups?.catalogEntities || []).map((entity) => {
|
|
66
|
+
const entityRef = stringifyEntityRef(entity);
|
|
67
|
+
const presentation = groups?.entityRefToPresentation.get(entityRef);
|
|
68
|
+
return {
|
|
69
|
+
value: entityRef,
|
|
70
|
+
label: presentation?.primaryTitle || entityRef
|
|
71
|
+
};
|
|
72
|
+
}),
|
|
73
|
+
[groups]
|
|
74
|
+
);
|
|
75
|
+
const [inputValue, setInputValue] = useState("");
|
|
76
|
+
useEffect(() => {
|
|
77
|
+
if (formData) {
|
|
78
|
+
const opt = buiOptions.find((o) => o.value === formData);
|
|
79
|
+
setInputValue(opt?.label || formData);
|
|
80
|
+
} else {
|
|
81
|
+
setInputValue("");
|
|
82
|
+
}
|
|
83
|
+
}, [formData, buiOptions]);
|
|
84
|
+
const selectedKey = formData && buiOptions.some((o) => o.value === formData) ? formData : null;
|
|
85
|
+
const handleSelectionChange = useCallback(
|
|
86
|
+
(key) => {
|
|
87
|
+
onChange(key !== null ? String(key) : "");
|
|
88
|
+
},
|
|
89
|
+
[onChange]
|
|
90
|
+
);
|
|
61
91
|
useEffect(() => {
|
|
62
92
|
if (required && groups?.catalogEntities.length === 1 && !selectedEntity) {
|
|
63
93
|
onChange(stringifyEntityRef(groups.catalogEntities[0]));
|
|
64
94
|
}
|
|
65
95
|
}, [groups, onChange, selectedEntity, required]);
|
|
96
|
+
if (theme === "bui") {
|
|
97
|
+
const isAutoSelected = required && groups?.catalogEntities.length === 1;
|
|
98
|
+
return /* @__PURE__ */ jsx(
|
|
99
|
+
ScaffolderField,
|
|
100
|
+
{
|
|
101
|
+
rawErrors,
|
|
102
|
+
rawDescription: uiSchema["ui:description"] ?? description,
|
|
103
|
+
required,
|
|
104
|
+
disabled: isDisabled,
|
|
105
|
+
errors,
|
|
106
|
+
children: /* @__PURE__ */ jsx(
|
|
107
|
+
Autocomplete,
|
|
108
|
+
{
|
|
109
|
+
id: idSchema?.$id,
|
|
110
|
+
label: title,
|
|
111
|
+
isRequired: required,
|
|
112
|
+
isDisabled: isDisabled || isAutoSelected,
|
|
113
|
+
selectedKey,
|
|
114
|
+
inputValue,
|
|
115
|
+
onInputChange: setInputValue,
|
|
116
|
+
onSelectionChange: handleSelectionChange,
|
|
117
|
+
isLoading: loading,
|
|
118
|
+
options: buiOptions,
|
|
119
|
+
allowsCustomValue: false,
|
|
120
|
+
isInvalid: rawErrors && rawErrors.length > 0
|
|
121
|
+
}
|
|
122
|
+
)
|
|
123
|
+
}
|
|
124
|
+
);
|
|
125
|
+
}
|
|
66
126
|
return /* @__PURE__ */ jsx(
|
|
67
127
|
ScaffolderField,
|
|
68
128
|
{
|
|
@@ -72,7 +132,7 @@ const MyGroupsPicker = (props) => {
|
|
|
72
132
|
disabled: isDisabled,
|
|
73
133
|
errors,
|
|
74
134
|
children: /* @__PURE__ */ jsx(
|
|
75
|
-
|
|
135
|
+
MuiAutocomplete,
|
|
76
136
|
{
|
|
77
137
|
disabled: required && groups?.catalogEntities.length === 1,
|
|
78
138
|
id: "OwnershipEntityRefPicker-dropdown",
|
|
@@ -83,7 +143,7 @@ const MyGroupsPicker = (props) => {
|
|
|
83
143
|
getOptionLabel: (option) => groups?.entityRefToPresentation.get(stringifyEntityRef(option))?.primaryTitle,
|
|
84
144
|
autoSelect: true,
|
|
85
145
|
renderInput: (params) => /* @__PURE__ */ jsx(
|
|
86
|
-
|
|
146
|
+
MuiTextField,
|
|
87
147
|
{
|
|
88
148
|
...params,
|
|
89
149
|
label: title,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MyGroupsPicker.esm.js","sources":["../../../../src/components/fields/MyGroupsPicker/MyGroupsPicker.tsx"],"sourcesContent":["/*\n * Copyright 2023 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 */\n\nimport { ChangeEvent, useEffect } from 'react';\nimport {\n errorApiRef,\n identityApiRef,\n useApi,\n} from '@backstage/core-plugin-api';\nimport TextField from '@material-ui/core/TextField';\nimport { MyGroupsPickerProps, MyGroupsPickerSchema } from './schema';\nimport Autocomplete, {\n createFilterOptions,\n} from '@material-ui/lab/Autocomplete';\nimport {\n catalogApiRef,\n EntityDisplayName,\n entityPresentationApiRef,\n EntityRefPresentationSnapshot,\n} from '@backstage/plugin-catalog-react';\nimport { NotFoundError } from '@backstage/errors';\nimport useAsync from 'react-use/esm/useAsync';\nimport { Entity, stringifyEntityRef } from '@backstage/catalog-model';\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 { MyGroupsPickerSchema };\n\nexport const MyGroupsPicker = (props: MyGroupsPickerProps) => {\n const { t } = useTranslationRef(scaffolderTranslationRef);\n const {\n schema: {\n title = t('fields.myGroupsPicker.title'),\n description = t('fields.myGroupsPicker.description'),\n },\n required,\n rawErrors,\n onChange,\n formData,\n uiSchema,\n errors,\n } = props;\n\n const identityApi = useApi(identityApiRef);\n const catalogApi = useApi(catalogApiRef);\n const errorApi = useApi(errorApiRef);\n const entityPresentationApi = useApi(entityPresentationApiRef);\n const isDisabled = uiSchema?.['ui:disabled'] ?? false;\n\n const { value: groups, loading } = useAsync(async () => {\n const { userEntityRef } = await identityApi.getBackstageIdentity();\n\n if (!userEntityRef) {\n errorApi.post(new NotFoundError('No user entity ref found'));\n return { catalogEntities: [], entityRefToPresentation: new Map() };\n }\n\n const { items } = await catalogApi.getEntities({\n filter: {\n kind: 'Group',\n ['relations.hasMember']: [userEntityRef],\n },\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 updateChange = (_: ChangeEvent<{}>, value: Entity | null) => {\n onChange(value ? stringifyEntityRef(value) : '');\n };\n\n const selectedEntity =\n groups?.catalogEntities.find(e => stringifyEntityRef(e) === formData) ||\n null;\n\n useEffect(() => {\n if (required && groups?.catalogEntities.length === 1 && !selectedEntity) {\n onChange(stringifyEntityRef(groups.catalogEntities[0]));\n }\n }, [groups, onChange, selectedEntity, required]);\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={required && groups?.catalogEntities.length === 1}\n id=\"OwnershipEntityRefPicker-dropdown\"\n options={groups?.catalogEntities || []}\n value={selectedEntity}\n loading={loading}\n onChange={updateChange}\n getOptionLabel={option =>\n groups?.entityRefToPresentation.get(stringifyEntityRef(option))\n ?.primaryTitle!\n }\n autoSelect\n renderInput={params => (\n <TextField\n {...params}\n label={title}\n margin=\"dense\"\n FormHelperTextProps={{ margin: 'dense', style: { marginLeft: 0 } }}\n variant=\"outlined\"\n required={required}\n InputProps={params.InputProps}\n />\n )}\n renderOption={option => <EntityDisplayName entityRef={option} />}\n filterOptions={createFilterOptions<Entity>({\n stringify: option =>\n groups?.entityRefToPresentation.get(stringifyEntityRef(option))\n ?.primaryTitle!,\n })}\n ListboxComponent={VirtualizedListbox}\n />\n </ScaffolderField>\n );\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;;AA2CO,MAAM,cAAA,GAAiB,CAAC,KAAA,KAA+B;AAC5D,EAAA,MAAM,EAAE,CAAA,EAAE,GAAI,iBAAA,CAAkB,wBAAwB,CAAA;AACxD,EAAA,MAAM;AAAA,IACJ,MAAA,EAAQ;AAAA,MACN,KAAA,GAAQ,EAAE,6BAA6B,CAAA;AAAA,MACvC,WAAA,GAAc,EAAE,mCAAmC;AAAA,KACrD;AAAA,IACA,QAAA;AAAA,IACA,SAAA;AAAA,IACA,QAAA;AAAA,IACA,QAAA;AAAA,IACA,QAAA;AAAA,IACA;AAAA,GACF,GAAI,KAAA;AAEJ,EAAA,MAAM,WAAA,GAAc,OAAO,cAAc,CAAA;AACzC,EAAA,MAAM,UAAA,GAAa,OAAO,aAAa,CAAA;AACvC,EAAA,MAAM,QAAA,GAAW,OAAO,WAAW,CAAA;AACnC,EAAA,MAAM,qBAAA,GAAwB,OAAO,wBAAwB,CAAA;AAC7D,EAAA,MAAM,UAAA,GAAa,QAAA,GAAW,aAAa,CAAA,IAAK,KAAA;AAEhD,EAAA,MAAM,EAAE,KAAA,EAAO,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AO;AAAA;AAAA,WACrB;AAAA,UAEF,YAAA,EAAc,CAAA,MAAA,qBAAU,GAAA,CAAC,iBAAA,EAAA,EAAkB,WAAW,MAAA,EAAQ,CAAA;AAAA,UAC9D,eAAe,mBAAA,CAA4B;AAAA,YACzC,SAAA,EAAW,YACT,MAAA,EAAQ,uBAAA,CAAwB,IAAI,kBAAA,CAAmB,MAAM,CAAC,CAAA,EAC1D;AAAA,WACP,CAAA;AAAA,UACD,gBAAA,EAAkB;AAAA;AAAA;AACpB;AAAA,GACF;AAEJ;;;;"}
|
|
1
|
+
{"version":3,"file":"MyGroupsPicker.esm.js","sources":["../../../../src/components/fields/MyGroupsPicker/MyGroupsPicker.tsx"],"sourcesContent":["/*\n * Copyright 2023 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 */\n\nimport {\n type Key,\n ChangeEvent,\n useCallback,\n useEffect,\n useMemo,\n useState,\n} from 'react';\nimport {\n errorApiRef,\n identityApiRef,\n useApi,\n} from '@backstage/core-plugin-api';\nimport TextField from '@material-ui/core/TextField';\nimport { MyGroupsPickerProps, MyGroupsPickerSchema } from './schema';\nimport Autocomplete, {\n createFilterOptions,\n} from '@material-ui/lab/Autocomplete';\nimport {\n catalogApiRef,\n EntityDisplayName,\n entityPresentationApiRef,\n EntityRefPresentationSnapshot,\n} from '@backstage/plugin-catalog-react';\nimport { NotFoundError } from '@backstage/errors';\nimport useAsync from 'react-use/esm/useAsync';\nimport { Entity, stringifyEntityRef } from '@backstage/catalog-model';\nimport { VirtualizedListbox } from '../VirtualizedListbox';\nimport { useTranslationRef } from '@backstage/core-plugin-api/alpha';\nimport { scaffolderTranslationRef } from '../../../translation';\nimport {\n ScaffolderField,\n useScaffolderTheme,\n} from '@backstage/plugin-scaffolder-react/alpha';\nimport { Autocomplete as BuiAutocomplete } from '../Autocomplete';\n\nexport { MyGroupsPickerSchema };\n\nexport const MyGroupsPicker = (props: MyGroupsPickerProps) => {\n const theme = useScaffolderTheme();\n const { t } = useTranslationRef(scaffolderTranslationRef);\n const {\n schema: {\n title = t('fields.myGroupsPicker.title'),\n description = t('fields.myGroupsPicker.description'),\n },\n required,\n rawErrors,\n onChange,\n formData,\n uiSchema,\n idSchema,\n errors,\n } = props;\n\n const identityApi = useApi(identityApiRef);\n const catalogApi = useApi(catalogApiRef);\n const errorApi = useApi(errorApiRef);\n const entityPresentationApi = useApi(entityPresentationApiRef);\n const isDisabled = uiSchema?.['ui:disabled'] ?? false;\n\n const { value: groups, loading } = useAsync(async () => {\n const { userEntityRef } = await identityApi.getBackstageIdentity();\n\n if (!userEntityRef) {\n errorApi.post(new NotFoundError('No user entity ref found'));\n return { catalogEntities: [], entityRefToPresentation: new Map() };\n }\n\n const { items } = await catalogApi.getEntities({\n filter: {\n kind: 'Group',\n ['relations.hasMember']: [userEntityRef],\n },\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 // MUI: update handler\n const updateChange = (_: ChangeEvent<{}>, value: Entity | null) => {\n onChange(value ? stringifyEntityRef(value) : '');\n };\n\n const selectedEntity =\n groups?.catalogEntities.find(e => stringifyEntityRef(e) === formData) ||\n null;\n\n // BUI: options\n const buiOptions = useMemo(\n () =>\n (groups?.catalogEntities || []).map(entity => {\n const entityRef = stringifyEntityRef(entity);\n const presentation = groups?.entityRefToPresentation.get(entityRef);\n return {\n value: entityRef,\n label: presentation?.primaryTitle || entityRef,\n };\n }),\n [groups],\n );\n\n const [inputValue, setInputValue] = useState('');\n\n useEffect(() => {\n if (formData) {\n const opt = buiOptions.find(o => o.value === formData);\n setInputValue(opt?.label || formData);\n } else {\n setInputValue('');\n }\n }, [formData, buiOptions]);\n\n const selectedKey =\n formData && buiOptions.some(o => o.value === formData) ? formData : null;\n\n const handleSelectionChange = useCallback(\n (key: Key | null) => {\n onChange(key !== null ? String(key) : '');\n },\n [onChange],\n );\n\n useEffect(() => {\n if (required && groups?.catalogEntities.length === 1 && !selectedEntity) {\n onChange(stringifyEntityRef(groups.catalogEntities[0]));\n }\n }, [groups, onChange, selectedEntity, required]);\n\n if (theme === 'bui') {\n const isAutoSelected = required && groups?.catalogEntities.length === 1;\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 <BuiAutocomplete\n id={idSchema?.$id}\n label={title}\n isRequired={required}\n isDisabled={isDisabled || isAutoSelected}\n selectedKey={selectedKey}\n inputValue={inputValue}\n onInputChange={setInputValue}\n onSelectionChange={handleSelectionChange}\n isLoading={loading}\n options={buiOptions}\n allowsCustomValue={false}\n isInvalid={rawErrors && rawErrors.length > 0}\n />\n </ScaffolderField>\n );\n }\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={required && groups?.catalogEntities.length === 1}\n id=\"OwnershipEntityRefPicker-dropdown\"\n options={groups?.catalogEntities || []}\n value={selectedEntity}\n loading={loading}\n onChange={updateChange}\n getOptionLabel={option =>\n groups?.entityRefToPresentation.get(stringifyEntityRef(option))\n ?.primaryTitle!\n }\n autoSelect\n renderInput={params => (\n <TextField\n {...params}\n label={title}\n margin=\"dense\"\n FormHelperTextProps={{ margin: 'dense', style: { marginLeft: 0 } }}\n variant=\"outlined\"\n required={required}\n InputProps={params.InputProps}\n />\n )}\n renderOption={option => <EntityDisplayName entityRef={option} />}\n filterOptions={createFilterOptions<Entity>({\n stringify: option =>\n groups?.entityRefToPresentation.get(stringifyEntityRef(option))\n ?.primaryTitle!,\n })}\n ListboxComponent={VirtualizedListbox}\n />\n </ScaffolderField>\n );\n};\n"],"names":["BuiAutocomplete","Autocomplete","TextField"],"mappings":";;;;;;;;;;;;;;;;AAsDO,MAAM,cAAA,GAAiB,CAAC,KAAA,KAA+B;AAC5D,EAAA,MAAM,QAAQ,kBAAA,EAAmB;AACjC,EAAA,MAAM,EAAE,CAAA,EAAE,GAAI,iBAAA,CAAkB,wBAAwB,CAAA;AACxD,EAAA,MAAM;AAAA,IACJ,MAAA,EAAQ;AAAA,MACN,KAAA,GAAQ,EAAE,6BAA6B,CAAA;AAAA,MACvC,WAAA,GAAc,EAAE,mCAAmC;AAAA,KACrD;AAAA,IACA,QAAA;AAAA,IACA,SAAA;AAAA,IACA,QAAA;AAAA,IACA,QAAA;AAAA,IACA,QAAA;AAAA,IACA,QAAA;AAAA,IACA;AAAA,GACF,GAAI,KAAA;AAEJ,EAAA,MAAM,WAAA,GAAc,OAAO,cAAc,CAAA;AACzC,EAAA,MAAM,UAAA,GAAa,OAAO,aAAa,CAAA;AACvC,EAAA,MAAM,QAAA,GAAW,OAAO,WAAW,CAAA;AACnC,EAAA,MAAM,qBAAA,GAAwB,OAAO,wBAAwB,CAAA;AAC7D,EAAA,MAAM,UAAA,GAAa,QAAA,GAAW,aAAa,CAAA,IAAK,KAAA;AAEhD,EAAA,MAAM,EAAE,KAAA,EAAO,MAAA,EAAQ,OAAA,EAAQ,GAAI,SAAS,YAAY;AACtD,IAAA,MAAM,EAAE,aAAA,EAAc,GAAI,MAAM,YAAY,oBAAA,EAAqB;AAEjE,IAAA,IAAI,CAAC,aAAA,EAAe;AAClB,MAAA,QAAA,CAAS,IAAA,CAAK,IAAI,aAAA,CAAc,0BAA0B,CAAC,CAAA;AA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,cAAA;AAAA,UACP,OAAA;AAAA,UACA,QAAA,EAAU,YAAA;AAAA,UACV,cAAA,EAAgB,YACd,MAAA,EAAQ,uBAAA,CAAwB,IAAI,kBAAA,CAAmB,MAAM,CAAC,CAAA,EAC1D,YAAA;AAAA,UAEN,UAAA,EAAU,IAAA;AAAA,UACV,aAAa,CAAA,MAAA,qBACX,GAAA;AAAA,YAACC,YAAA;AAAA,YAAA;AAAA,cACE,GAAG,MAAA;AAAA,cACJ,KAAA,EAAO,KAAA;AAAA,cACP,MAAA,EAAO,OAAA;AAAA,cACP,mBAAA,EAAqB,EAAE,MAAA,EAAQ,OAAA,EAAS,OAAO,EAAE,UAAA,EAAY,GAAE,EAAE;AAAA,cACjE,OAAA,EAAQ,UAAA;AAAA,cACR,QAAA;AAAA,cACA,YAAY,MAAA,CAAO;AAAA;AAAA,WACrB;AAAA,UAEF,YAAA,EAAc,CAAA,MAAA,qBAAU,GAAA,CAAC,iBAAA,EAAA,EAAkB,WAAW,MAAA,EAAQ,CAAA;AAAA,UAC9D,eAAe,mBAAA,CAA4B;AAAA,YACzC,SAAA,EAAW,YACT,MAAA,EAAQ,uBAAA,CAAwB,IAAI,kBAAA,CAAmB,MAAM,CAAC,CAAA,EAC1D;AAAA,WACP,CAAA;AAAA,UACD,gBAAA,EAAkB;AAAA;AAAA;AACpB;AAAA,GACF;AAEJ;;;;"}
|
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
import { jsx } from 'react/jsx-runtime';
|
|
2
2
|
import { RELATION_OWNED_BY } from '@backstage/catalog-model';
|
|
3
3
|
import { useApi, identityApiRef } from '@backstage/core-plugin-api';
|
|
4
|
-
import
|
|
5
|
-
import
|
|
4
|
+
import MuiTextField from '@material-ui/core/TextField';
|
|
5
|
+
import MuiAutocomplete from '@material-ui/lab/Autocomplete';
|
|
6
6
|
import useAsync from 'react-use/esm/useAsync';
|
|
7
7
|
import { EntityPicker } from '../EntityPicker/EntityPicker.esm.js';
|
|
8
8
|
import { useTranslationRef } from '@backstage/core-plugin-api/alpha';
|
|
9
9
|
import { scaffolderTranslationRef } from '../../../translation.esm.js';
|
|
10
|
-
import { ScaffolderField } from '@backstage/plugin-scaffolder-react/alpha';
|
|
10
|
+
import { useScaffolderTheme, ScaffolderField } from '@backstage/plugin-scaffolder-react/alpha';
|
|
11
|
+
import { Autocomplete } from '../Autocomplete/Autocomplete.esm.js';
|
|
11
12
|
export { OwnedEntityPickerSchema } from './schema.esm.js';
|
|
12
13
|
|
|
13
14
|
const OwnedEntityPicker = (props) => {
|
|
14
15
|
const { t } = useTranslationRef(scaffolderTranslationRef);
|
|
16
|
+
const theme = useScaffolderTheme();
|
|
15
17
|
const {
|
|
16
18
|
schema: {
|
|
17
19
|
title = t("fields.ownedEntityPicker.title"),
|
|
@@ -25,7 +27,27 @@ const OwnedEntityPicker = (props) => {
|
|
|
25
27
|
const identity = await identityApi.getBackstageIdentity();
|
|
26
28
|
return identity.ownershipEntityRefs;
|
|
27
29
|
});
|
|
28
|
-
if (loading)
|
|
30
|
+
if (loading) {
|
|
31
|
+
if (theme === "bui") {
|
|
32
|
+
return /* @__PURE__ */ jsx(
|
|
33
|
+
ScaffolderField,
|
|
34
|
+
{
|
|
35
|
+
rawDescription: uiSchema["ui:description"] ?? description,
|
|
36
|
+
required,
|
|
37
|
+
disabled: uiSchema["ui:disabled"],
|
|
38
|
+
children: /* @__PURE__ */ jsx(
|
|
39
|
+
Autocomplete,
|
|
40
|
+
{
|
|
41
|
+
label: title,
|
|
42
|
+
isRequired: required,
|
|
43
|
+
isLoading: true,
|
|
44
|
+
options: [],
|
|
45
|
+
isDisabled: true
|
|
46
|
+
}
|
|
47
|
+
)
|
|
48
|
+
}
|
|
49
|
+
);
|
|
50
|
+
}
|
|
29
51
|
return /* @__PURE__ */ jsx(
|
|
30
52
|
ScaffolderField,
|
|
31
53
|
{
|
|
@@ -33,11 +55,11 @@ const OwnedEntityPicker = (props) => {
|
|
|
33
55
|
required,
|
|
34
56
|
disabled: uiSchema["ui:disabled"],
|
|
35
57
|
children: /* @__PURE__ */ jsx(
|
|
36
|
-
|
|
58
|
+
MuiAutocomplete,
|
|
37
59
|
{
|
|
38
60
|
loading,
|
|
39
61
|
renderInput: (params) => /* @__PURE__ */ jsx(
|
|
40
|
-
|
|
62
|
+
MuiTextField,
|
|
41
63
|
{
|
|
42
64
|
...params,
|
|
43
65
|
label: title,
|
|
@@ -56,6 +78,7 @@ const OwnedEntityPicker = (props) => {
|
|
|
56
78
|
)
|
|
57
79
|
}
|
|
58
80
|
);
|
|
81
|
+
}
|
|
59
82
|
const entityPickerUISchema = buildEntityPickerUISchema(
|
|
60
83
|
uiSchema,
|
|
61
84
|
identityRefs
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OwnedEntityPicker.esm.js","sources":["../../../../src/components/fields/OwnedEntityPicker/OwnedEntityPicker.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 { RELATION_OWNED_BY } from '@backstage/catalog-model';\nimport { identityApiRef, useApi } from '@backstage/core-plugin-api';\nimport TextField from '@material-ui/core/TextField';\nimport
|
|
1
|
+
{"version":3,"file":"OwnedEntityPicker.esm.js","sources":["../../../../src/components/fields/OwnedEntityPicker/OwnedEntityPicker.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 { RELATION_OWNED_BY } from '@backstage/catalog-model';\nimport { identityApiRef, useApi } from '@backstage/core-plugin-api';\nimport TextField from '@material-ui/core/TextField';\nimport MuiAutocomplete from '@material-ui/lab/Autocomplete';\nimport useAsync from 'react-use/esm/useAsync';\nimport { EntityPicker } from '../EntityPicker/EntityPicker';\n\nimport { OwnedEntityPickerProps } from './schema';\nimport { EntityPickerProps } from '../EntityPicker/schema';\nimport { useTranslationRef } from '@backstage/core-plugin-api/alpha';\nimport { scaffolderTranslationRef } from '../../../translation';\nimport {\n ScaffolderField,\n useScaffolderTheme,\n} from '@backstage/plugin-scaffolder-react/alpha';\nimport { Autocomplete as BuiAutocomplete } from '../Autocomplete';\n\nexport { OwnedEntityPickerSchema } from './schema';\n\n/**\n * The underlying component that is rendered in the form for the `OwnedEntityPicker`\n * field extension.\n *\n * @public\n */\nexport const OwnedEntityPicker = (props: OwnedEntityPickerProps) => {\n const { t } = useTranslationRef(scaffolderTranslationRef);\n const theme = useScaffolderTheme();\n const {\n schema: {\n title = t('fields.ownedEntityPicker.title'),\n description = t('fields.ownedEntityPicker.description'),\n },\n uiSchema,\n required,\n } = props;\n\n const identityApi = useApi(identityApiRef);\n const { loading, value: identityRefs } = useAsync(async () => {\n const identity = await identityApi.getBackstageIdentity();\n return identity.ownershipEntityRefs;\n });\n\n if (loading) {\n if (theme === 'bui') {\n return (\n <ScaffolderField\n rawDescription={uiSchema['ui:description'] ?? description}\n required={required}\n disabled={uiSchema['ui:disabled']}\n >\n <BuiAutocomplete\n label={title}\n isRequired={required}\n isLoading\n options={[]}\n isDisabled\n />\n </ScaffolderField>\n );\n }\n return (\n <ScaffolderField\n rawDescription={uiSchema['ui:description'] ?? description}\n required={required}\n disabled={uiSchema['ui:disabled']}\n >\n <MuiAutocomplete\n loading={loading}\n renderInput={params => (\n <TextField\n {...params}\n label={title}\n margin=\"dense\"\n FormHelperTextProps={{\n margin: 'dense',\n style: { marginLeft: 0 },\n }}\n variant=\"outlined\"\n required={required}\n InputProps={params.InputProps}\n />\n )}\n options={[]}\n />\n </ScaffolderField>\n );\n }\n\n const entityPickerUISchema = buildEntityPickerUISchema(\n uiSchema,\n identityRefs,\n );\n\n return <EntityPicker {...props} uiSchema={entityPickerUISchema} />;\n};\n\n/**\n * Builds a `uiSchema` for an `EntityPicker` from a parent `OwnedEntityPicker`.\n * Migrates deprecated parameters such as `allowedKinds` to `catalogFilter` structure.\n *\n * @param uiSchema The `uiSchema` of an `OwnedEntityPicker` component.\n * @param identityRefs The user and group entities that the user claims ownership through.\n * @returns The `uiSchema` for an `EntityPicker` component.\n */\nfunction buildEntityPickerUISchema(\n uiSchema: OwnedEntityPickerProps['uiSchema'],\n identityRefs: string[] | undefined,\n): EntityPickerProps['uiSchema'] {\n // Note: This is typed to avoid es-lint rule TS2698\n const uiOptions: EntityPickerProps['uiSchema']['ui:options'] =\n uiSchema?.['ui:options'] || {};\n const { allowedKinds, ...extraOptions } = uiOptions;\n\n const catalogFilter = asArray(uiOptions.catalogFilter).map(e => ({\n ...e,\n ...(allowedKinds ? { kind: allowedKinds } : {}),\n [`relations.${RELATION_OWNED_BY}`]: identityRefs || [],\n }));\n\n return {\n 'ui:options': {\n ...extraOptions,\n catalogFilter,\n },\n 'ui:disabled': uiSchema['ui:disabled'],\n };\n}\n\nfunction asArray(catalogFilter: any): any[] {\n if (catalogFilter) {\n return Array.isArray(catalogFilter) ? catalogFilter : [catalogFilter];\n }\n return [{}];\n}\n"],"names":["BuiAutocomplete","TextField"],"mappings":";;;;;;;;;;;;;AAwCO,MAAM,iBAAA,GAAoB,CAAC,KAAA,KAAkC;AAClE,EAAA,MAAM,EAAE,CAAA,EAAE,GAAI,iBAAA,CAAkB,wBAAwB,CAAA;AACxD,EAAA,MAAM,QAAQ,kBAAA,EAAmB;AACjC,EAAA,MAAM;AAAA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Q,aAAa,CAAA,GAAI,aAAA,GAAgB,CAAC,aAAa,CAAA;AAAA,EACtE;AACA,EAAA,OAAO,CAAC,EAAE,CAAA;AACZ;;;;"}
|
|
@@ -11,6 +11,7 @@ import '../VirtualizedListbox.esm.js';
|
|
|
11
11
|
import '@backstage/core-plugin-api/alpha';
|
|
12
12
|
import '../../../translation.esm.js';
|
|
13
13
|
import '@backstage/plugin-scaffolder-react/alpha';
|
|
14
|
+
import '../Autocomplete/Autocomplete.esm.js';
|
|
14
15
|
import { EntityPickerFieldSchema } from '../EntityPicker/schema.esm.js';
|
|
15
16
|
|
|
16
17
|
const OwnedEntityPickerFieldSchema = EntityPickerFieldSchema;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.esm.js","sources":["../../../../src/components/fields/OwnedEntityPicker/schema.ts"],"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 { EntityPickerFieldSchema } from '../EntityPicker';\n\n/**\n * @public\n */\nexport const OwnedEntityPickerFieldSchema = EntityPickerFieldSchema;\n\n/**\n * The input props that can be specified under `ui:options` for the\n * `OwnedEntityPicker` field extension.\n * @public\n */\nexport type OwnedEntityPickerUiOptions = NonNullable<\n (typeof OwnedEntityPickerFieldSchema.TProps.uiSchema)['ui:options']\n>;\n\nexport type OwnedEntityPickerProps = typeof OwnedEntityPickerFieldSchema.TProps;\n\nexport const OwnedEntityPickerSchema = OwnedEntityPickerFieldSchema.schema;\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"schema.esm.js","sources":["../../../../src/components/fields/OwnedEntityPicker/schema.ts"],"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 { EntityPickerFieldSchema } from '../EntityPicker';\n\n/**\n * @public\n */\nexport const OwnedEntityPickerFieldSchema = EntityPickerFieldSchema;\n\n/**\n * The input props that can be specified under `ui:options` for the\n * `OwnedEntityPicker` field extension.\n * @public\n */\nexport type OwnedEntityPickerUiOptions = NonNullable<\n (typeof OwnedEntityPickerFieldSchema.TProps.uiSchema)['ui:options']\n>;\n\nexport type OwnedEntityPickerProps = typeof OwnedEntityPickerFieldSchema.TProps;\n\nexport const OwnedEntityPickerSchema = OwnedEntityPickerFieldSchema.schema;\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAoBO,MAAM,4BAAA,GAA+B;AAarC,MAAM,0BAA0B,4BAAA,CAA6B;;;;"}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
2
2
|
import { useApi } from '@backstage/core-plugin-api';
|
|
3
3
|
import { scaffolderApiRef } from '@backstage/plugin-scaffolder-react';
|
|
4
4
|
import FormControl from '@material-ui/core/FormControl';
|
|
5
5
|
import FormHelperText from '@material-ui/core/FormHelperText';
|
|
6
|
-
import
|
|
7
|
-
import
|
|
6
|
+
import MuiTextField from '@material-ui/core/TextField';
|
|
7
|
+
import MuiAutocomplete from '@material-ui/lab/Autocomplete';
|
|
8
8
|
import { useState, useCallback } from 'react';
|
|
9
9
|
import useDebounce from 'react-use/esm/useDebounce';
|
|
10
|
+
import { useScaffolderTheme } from '@backstage/plugin-scaffolder-react/alpha';
|
|
11
|
+
import { Autocomplete } from '../Autocomplete/Autocomplete.esm.js';
|
|
10
12
|
|
|
11
13
|
const BitbucketRepoBranchPicker = ({
|
|
12
14
|
onChange,
|
|
@@ -16,6 +18,7 @@ const BitbucketRepoBranchPicker = ({
|
|
|
16
18
|
isDisabled,
|
|
17
19
|
required
|
|
18
20
|
}) => {
|
|
21
|
+
const theme = useScaffolderTheme();
|
|
19
22
|
const { host, workspace, repository, branch } = state;
|
|
20
23
|
const [availableBranches, setAvailableBranches] = useState([]);
|
|
21
24
|
const scaffolderApi = useApi(scaffolderApiRef);
|
|
@@ -36,6 +39,27 @@ const BitbucketRepoBranchPicker = ({
|
|
|
36
39
|
});
|
|
37
40
|
}, [host, workspace, repository, accessToken, scaffolderApi]);
|
|
38
41
|
useDebounce(updateAvailableBranches, 500, [updateAvailableBranches]);
|
|
42
|
+
if (theme === "bui") {
|
|
43
|
+
const options = availableBranches.map((b) => ({ label: b, value: b }));
|
|
44
|
+
return /* @__PURE__ */ jsx(
|
|
45
|
+
Autocomplete,
|
|
46
|
+
{
|
|
47
|
+
label: "Branch",
|
|
48
|
+
description: "The branch of the repository",
|
|
49
|
+
inputValue: branch ?? "",
|
|
50
|
+
onInputChange: (value) => onChange({ branch: value }),
|
|
51
|
+
onSelectionChange: (key) => {
|
|
52
|
+
if (key !== null) {
|
|
53
|
+
onChange({ branch: String(key) });
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
options,
|
|
57
|
+
isDisabled,
|
|
58
|
+
isRequired: required,
|
|
59
|
+
isInvalid: rawErrors?.length > 0 && !branch
|
|
60
|
+
}
|
|
61
|
+
);
|
|
62
|
+
}
|
|
39
63
|
return /* @__PURE__ */ jsxs(
|
|
40
64
|
FormControl,
|
|
41
65
|
{
|
|
@@ -44,7 +68,7 @@ const BitbucketRepoBranchPicker = ({
|
|
|
44
68
|
error: rawErrors?.length > 0 && !branch,
|
|
45
69
|
children: [
|
|
46
70
|
/* @__PURE__ */ jsx(
|
|
47
|
-
|
|
71
|
+
MuiAutocomplete,
|
|
48
72
|
{
|
|
49
73
|
value: branch,
|
|
50
74
|
onChange: (_, newValue) => {
|
|
@@ -53,7 +77,7 @@ const BitbucketRepoBranchPicker = ({
|
|
|
53
77
|
disabled: isDisabled,
|
|
54
78
|
options: availableBranches,
|
|
55
79
|
renderInput: (params) => /* @__PURE__ */ jsx(
|
|
56
|
-
|
|
80
|
+
MuiTextField,
|
|
57
81
|
{
|
|
58
82
|
...params,
|
|
59
83
|
label: "Branch",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BitbucketRepoBranchPicker.esm.js","sources":["../../../../src/components/fields/RepoBranchPicker/BitbucketRepoBranchPicker.tsx"],"sourcesContent":["/*\n * Copyright 2024 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 */\n\nimport { useApi } from '@backstage/core-plugin-api';\nimport { scaffolderApiRef } from '@backstage/plugin-scaffolder-react';\nimport FormControl from '@material-ui/core/FormControl';\nimport FormHelperText from '@material-ui/core/FormHelperText';\nimport
|
|
1
|
+
{"version":3,"file":"BitbucketRepoBranchPicker.esm.js","sources":["../../../../src/components/fields/RepoBranchPicker/BitbucketRepoBranchPicker.tsx"],"sourcesContent":["/*\n * Copyright 2024 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 */\n\nimport { useApi } from '@backstage/core-plugin-api';\nimport { scaffolderApiRef } from '@backstage/plugin-scaffolder-react';\nimport FormControl from '@material-ui/core/FormControl';\nimport FormHelperText from '@material-ui/core/FormHelperText';\nimport MuiTextField from '@material-ui/core/TextField';\nimport MuiAutocomplete from '@material-ui/lab/Autocomplete';\nimport { useCallback, useState } from 'react';\nimport useDebounce from 'react-use/esm/useDebounce';\nimport { BaseRepoBranchPickerProps } from './types';\nimport { useScaffolderTheme } from '@backstage/plugin-scaffolder-react/alpha';\nimport { Autocomplete as BuiAutocomplete } from '../Autocomplete';\nimport type { Key } from 'react-aria-components';\n\n/**\n * The underlying component that is rendered in the form for the `BitbucketRepoBranchPicker`\n * field extension.\n *\n * @public\n *\n */\nexport const BitbucketRepoBranchPicker = ({\n onChange,\n state,\n rawErrors,\n accessToken,\n isDisabled,\n required,\n}: BaseRepoBranchPickerProps<{\n accessToken?: string;\n}>) => {\n const theme = useScaffolderTheme();\n const { host, workspace, repository, branch } = state;\n\n const [availableBranches, setAvailableBranches] = useState<string[]>([]);\n\n const scaffolderApi = useApi(scaffolderApiRef);\n\n const updateAvailableBranches = useCallback(() => {\n if (\n !scaffolderApi.autocomplete ||\n !workspace ||\n !repository ||\n !accessToken ||\n host !== 'bitbucket.org'\n ) {\n setAvailableBranches([]);\n return;\n }\n\n scaffolderApi\n .autocomplete({\n token: accessToken,\n resource: 'branches',\n context: { workspace, repository },\n provider: 'bitbucket-cloud',\n })\n .then(({ results }) => {\n setAvailableBranches(results.map(r => r.id));\n })\n .catch(() => {\n setAvailableBranches([]);\n });\n }, [host, workspace, repository, accessToken, scaffolderApi]);\n\n useDebounce(updateAvailableBranches, 500, [updateAvailableBranches]);\n\n if (theme === 'bui') {\n const options = availableBranches.map(b => ({ label: b, value: b }));\n\n return (\n <BuiAutocomplete\n label=\"Branch\"\n description=\"The branch of the repository\"\n inputValue={branch ?? ''}\n onInputChange={value => onChange({ branch: value })}\n onSelectionChange={(key: Key | null) => {\n if (key !== null) {\n onChange({ branch: String(key) });\n }\n }}\n options={options}\n isDisabled={isDisabled}\n isRequired={required}\n isInvalid={rawErrors?.length > 0 && !branch}\n />\n );\n }\n\n return (\n <FormControl\n margin=\"normal\"\n required={required}\n error={rawErrors?.length > 0 && !branch}\n >\n <MuiAutocomplete\n value={branch}\n onChange={(_, newValue) => {\n onChange({ branch: newValue || '' });\n }}\n disabled={isDisabled}\n options={availableBranches}\n renderInput={params => (\n <MuiTextField\n {...params}\n label=\"Branch\"\n disabled={isDisabled}\n required={required}\n />\n )}\n freeSolo\n autoSelect\n />\n <FormHelperText>The branch of the repository</FormHelperText>\n </FormControl>\n );\n};\n"],"names":["BuiAutocomplete"],"mappings":";;;;;;;;;;;;AAoCO,MAAM,4BAA4B,CAAC;AAAA,EACxC,QAAA;AAAA,EACA,KAAA;AAAA,EACA,SAAA;AAAA,EACA,WAAA;AAAA,EACA,UAAA;AAAA,EACA;AACF,CAAA,KAEO;AACL,EAAA,MAAM,QAAQ,kBAAA,EAAmB;AACjC,EAAA,MAAM,EAAE,IAAA,EAAM,SAAA,EAAW,UAAA,EAAY,QAAO,GAAI,KAAA;AAEhD,EAAA,MAAM,CAAC,iBAAA,EAAmB,oBAAoB,CAAA,GAAI,QAAA,CAAmB,EAAE,CAAA;AAEvE,EAAA,MAAM,aAAA,GAAgB,OAAO,gBAAgB,CAAA;AAE7C,EAAA,MAAM,uBAAA,GAA0B,YAAY,MAAM;AAChD,IAAA,IACE,CAAC,aAAA,CAAc,YAAA,IACf,CAAC,SAAA,IACD,CAAC,UAAA,IACD,CAAC,WAAA,IACD,IAAA,KAAS,eAAA,EACT;AACA,MAAA,oBAAA,CAAqB,EAAE,CAAA;AACvB,MAAA;AAAA,IACF;AAEA,IAAA,aAAA,CACG,YAAA,CAAa;AAAA,MACZ,KAAA,EAAO,WAAA;AAAA,MACP,QAAA,EAAU,UAAA;AAAA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vC;AAAA,EAEJ;AAEA,EAAA,uBACE,IAAA;AAAA,IAAC,WAAA;AAAA,IAAA;AAAA,MACC,MAAA,EAAO,QAAA;AAAA,MACP,QAAA;AAAA,MACA,KAAA,EAAO,SAAA,EAAW,MAAA,GAAS,CAAA,IAAK,CAAC,MAAA;AAAA,MAEjC,QAAA,EAAA;AAAA,wBAAA,GAAA;AAAA,UAAC,eAAA;AAAA,UAAA;AAAA,YACC,KAAA,EAAO,MAAA;AAAA,YACP,QAAA,EAAU,CAAC,CAAA,EAAG,QAAA,KAAa;AACzB,cAAA,QAAA,CAAS,EAAE,MAAA,EAAQ,QAAA,IAAY,EAAA,EAAI,CAAA;AAAA,YACrC,CAAA;AAAA,YACA,QAAA,EAAU,UAAA;AAAA,YACV,OAAA,EAAS,iBAAA;AAAA,YACT,aAAa,CAAA,MAAA,qBACX,GAAA;AAAA,cAAC,YAAA;AAAA,cAAA;AAAA,gBACE,GAAG,MAAA;AAAA,gBACJ,KAAA,EAAM,QAAA;AAAA,gBACN,QAAA,EAAU,UAAA;AAAA,gBACV;AAAA;AAAA,aACF;AAAA,YAEF,QAAA,EAAQ,IAAA;AAAA,YACR,UAAA,EAAU;AAAA;AAAA,SACZ;AAAA,wBACA,GAAA,CAAC,kBAAe,QAAA,EAAA,8BAAA,EAA4B;AAAA;AAAA;AAAA,GAC9C;AAEJ;;;;"}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
2
2
|
import FormControl from '@material-ui/core/FormControl';
|
|
3
3
|
import FormHelperText from '@material-ui/core/FormHelperText';
|
|
4
|
-
import
|
|
4
|
+
import MuiTextField from '@material-ui/core/TextField';
|
|
5
|
+
import { useScaffolderTheme } from '@backstage/plugin-scaffolder-react/alpha';
|
|
6
|
+
import { TextField } from '@backstage/ui';
|
|
5
7
|
|
|
6
8
|
const DefaultRepoBranchPicker = ({
|
|
7
9
|
onChange,
|
|
@@ -10,7 +12,22 @@ const DefaultRepoBranchPicker = ({
|
|
|
10
12
|
isDisabled,
|
|
11
13
|
required
|
|
12
14
|
}) => {
|
|
15
|
+
const theme = useScaffolderTheme();
|
|
13
16
|
const { branch } = state;
|
|
17
|
+
if (theme === "bui") {
|
|
18
|
+
return /* @__PURE__ */ jsx(
|
|
19
|
+
TextField,
|
|
20
|
+
{
|
|
21
|
+
label: "Branch",
|
|
22
|
+
description: "The branch of the repository",
|
|
23
|
+
isDisabled,
|
|
24
|
+
onChange: (value) => onChange({ branch: value }),
|
|
25
|
+
value: branch ?? "",
|
|
26
|
+
isInvalid: rawErrors?.length > 0 && !branch,
|
|
27
|
+
isRequired: required
|
|
28
|
+
}
|
|
29
|
+
);
|
|
30
|
+
}
|
|
14
31
|
return /* @__PURE__ */ jsxs(
|
|
15
32
|
FormControl,
|
|
16
33
|
{
|
|
@@ -19,7 +36,7 @@ const DefaultRepoBranchPicker = ({
|
|
|
19
36
|
error: rawErrors?.length > 0 && !branch,
|
|
20
37
|
children: [
|
|
21
38
|
/* @__PURE__ */ jsx(
|
|
22
|
-
|
|
39
|
+
MuiTextField,
|
|
23
40
|
{
|
|
24
41
|
id: "branchInput",
|
|
25
42
|
label: "Branch",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DefaultRepoBranchPicker.esm.js","sources":["../../../../src/components/fields/RepoBranchPicker/DefaultRepoBranchPicker.tsx"],"sourcesContent":["/*\n * Copyright 2024 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 */\n\nimport FormControl from '@material-ui/core/FormControl';\nimport FormHelperText from '@material-ui/core/FormHelperText';\nimport
|
|
1
|
+
{"version":3,"file":"DefaultRepoBranchPicker.esm.js","sources":["../../../../src/components/fields/RepoBranchPicker/DefaultRepoBranchPicker.tsx"],"sourcesContent":["/*\n * Copyright 2024 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 */\n\nimport FormControl from '@material-ui/core/FormControl';\nimport FormHelperText from '@material-ui/core/FormHelperText';\nimport MuiTextField from '@material-ui/core/TextField';\n\nimport { BaseRepoBranchPickerProps } from './types';\nimport { useScaffolderTheme } from '@backstage/plugin-scaffolder-react/alpha';\nimport { TextField as BuiTextField } from '@backstage/ui';\n\n/**\n * The underlying component that is rendered in the form for the `DefaultRepoBranchPicker`\n * field extension.\n *\n * @public\n *\n */\nexport const DefaultRepoBranchPicker = ({\n onChange,\n state,\n rawErrors,\n isDisabled,\n required,\n}: BaseRepoBranchPickerProps) => {\n const theme = useScaffolderTheme();\n const { branch } = state;\n\n if (theme === 'bui') {\n return (\n <BuiTextField\n label=\"Branch\"\n description=\"The branch of the repository\"\n isDisabled={isDisabled}\n onChange={value => onChange({ branch: value })}\n value={branch ?? ''}\n isInvalid={rawErrors?.length > 0 && !branch}\n isRequired={required}\n />\n );\n }\n\n return (\n <FormControl\n margin=\"normal\"\n required={required}\n error={rawErrors?.length > 0 && !branch}\n >\n <MuiTextField\n id=\"branchInput\"\n label=\"Branch\"\n disabled={isDisabled}\n onChange={e => onChange({ branch: e.target.value })}\n value={branch}\n />\n <FormHelperText>The branch of the repository</FormHelperText>\n </FormControl>\n );\n};\n"],"names":["BuiTextField"],"mappings":";;;;;;;AA+BO,MAAM,0BAA0B,CAAC;AA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
|
|
2
2
|
import { useApi } from '@backstage/core-plugin-api';
|
|
3
3
|
import { scaffolderApiRef } from '@backstage/plugin-scaffolder-react';
|
|
4
4
|
import FormControl from '@material-ui/core/FormControl';
|
|
5
5
|
import FormHelperText from '@material-ui/core/FormHelperText';
|
|
6
|
-
import
|
|
7
|
-
import
|
|
6
|
+
import MuiTextField from '@material-ui/core/TextField';
|
|
7
|
+
import MuiAutocomplete from '@material-ui/lab/Autocomplete';
|
|
8
8
|
import { useState, useCallback } from 'react';
|
|
9
9
|
import useDebounce from 'react-use/esm/useDebounce';
|
|
10
|
+
import { useScaffolderTheme } from '@backstage/plugin-scaffolder-react/alpha';
|
|
11
|
+
import { Autocomplete } from '../Autocomplete/Autocomplete.esm.js';
|
|
10
12
|
|
|
11
13
|
const GitHubRepoBranchPicker = ({
|
|
12
14
|
onChange,
|
|
@@ -16,6 +18,7 @@ const GitHubRepoBranchPicker = ({
|
|
|
16
18
|
isDisabled,
|
|
17
19
|
required
|
|
18
20
|
}) => {
|
|
21
|
+
const theme = useScaffolderTheme();
|
|
19
22
|
const { host, owner, repository, branch } = state;
|
|
20
23
|
const [availableBranches, setAvailableBranches] = useState([]);
|
|
21
24
|
const scaffolderApi = useApi(scaffolderApiRef);
|
|
@@ -36,6 +39,27 @@ const GitHubRepoBranchPicker = ({
|
|
|
36
39
|
});
|
|
37
40
|
}, [host, owner, repository, accessToken, scaffolderApi]);
|
|
38
41
|
useDebounce(updateAvailableBranches, 500, [updateAvailableBranches]);
|
|
42
|
+
if (theme === "bui") {
|
|
43
|
+
const options = availableBranches.map((b) => ({ label: b, value: b }));
|
|
44
|
+
return /* @__PURE__ */ jsx(
|
|
45
|
+
Autocomplete,
|
|
46
|
+
{
|
|
47
|
+
label: "Branch",
|
|
48
|
+
description: "The branch of the repository",
|
|
49
|
+
inputValue: branch ?? "",
|
|
50
|
+
onInputChange: (value) => onChange({ branch: value }),
|
|
51
|
+
onSelectionChange: (key) => {
|
|
52
|
+
if (key !== null) {
|
|
53
|
+
onChange({ branch: String(key) });
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
options,
|
|
57
|
+
isDisabled,
|
|
58
|
+
isRequired: required,
|
|
59
|
+
isInvalid: rawErrors?.length > 0 && !branch
|
|
60
|
+
}
|
|
61
|
+
);
|
|
62
|
+
}
|
|
39
63
|
return /* @__PURE__ */ jsxs(
|
|
40
64
|
FormControl,
|
|
41
65
|
{
|
|
@@ -44,7 +68,7 @@ const GitHubRepoBranchPicker = ({
|
|
|
44
68
|
error: rawErrors?.length > 0 && !branch,
|
|
45
69
|
children: [
|
|
46
70
|
/* @__PURE__ */ jsx(
|
|
47
|
-
|
|
71
|
+
MuiAutocomplete,
|
|
48
72
|
{
|
|
49
73
|
value: branch,
|
|
50
74
|
onChange: (_, newValue) => {
|
|
@@ -53,7 +77,7 @@ const GitHubRepoBranchPicker = ({
|
|
|
53
77
|
disabled: isDisabled,
|
|
54
78
|
options: availableBranches,
|
|
55
79
|
renderInput: (params) => /* @__PURE__ */ jsx(
|
|
56
|
-
|
|
80
|
+
MuiTextField,
|
|
57
81
|
{
|
|
58
82
|
...params,
|
|
59
83
|
label: "Branch",
|