@backstage/plugin-scaffolder 1.30.0-next.1 → 1.30.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 +51 -0
- package/dist/alpha/components/TemplateEditorPage/CustomFieldExplorer.esm.js +98 -84
- package/dist/alpha/components/TemplateEditorPage/CustomFieldExplorer.esm.js.map +1 -1
- package/dist/alpha/components/TemplateEditorPage/CustomFieldPlaygroud.esm.js +119 -102
- package/dist/alpha/components/TemplateEditorPage/CustomFieldPlaygroud.esm.js.map +1 -1
- package/dist/alpha/components/TemplateEditorPage/CustomFieldsPage.esm.js +13 -10
- package/dist/alpha/components/TemplateEditorPage/CustomFieldsPage.esm.js.map +1 -1
- package/dist/alpha/components/TemplateEditorPage/DirectoryEditorContext.esm.js +4 -3
- package/dist/alpha/components/TemplateEditorPage/DirectoryEditorContext.esm.js.map +1 -1
- package/dist/alpha/components/TemplateEditorPage/DryRunContext.esm.js +3 -2
- package/dist/alpha/components/TemplateEditorPage/DryRunContext.esm.js.map +1 -1
- package/dist/alpha/components/TemplateEditorPage/DryRunResults/DryRunResults.esm.js +22 -15
- package/dist/alpha/components/TemplateEditorPage/DryRunResults/DryRunResults.esm.js.map +1 -1
- package/dist/alpha/components/TemplateEditorPage/DryRunResults/DryRunResultsList.esm.js +49 -44
- package/dist/alpha/components/TemplateEditorPage/DryRunResults/DryRunResultsList.esm.js.map +1 -1
- package/dist/alpha/components/TemplateEditorPage/DryRunResults/DryRunResultsSplitView.esm.js +7 -2
- package/dist/alpha/components/TemplateEditorPage/DryRunResults/DryRunResultsSplitView.esm.js.map +1 -1
- package/dist/alpha/components/TemplateEditorPage/DryRunResults/DryRunResultsView.esm.js +79 -57
- package/dist/alpha/components/TemplateEditorPage/DryRunResults/DryRunResultsView.esm.js.map +1 -1
- package/dist/alpha/components/TemplateEditorPage/DryRunResults/IconLink.esm.js +5 -2
- package/dist/alpha/components/TemplateEditorPage/DryRunResults/IconLink.esm.js.map +1 -1
- package/dist/alpha/components/TemplateEditorPage/DryRunResults/TaskPageLinks.esm.js +6 -6
- package/dist/alpha/components/TemplateEditorPage/DryRunResults/TaskPageLinks.esm.js.map +1 -1
- package/dist/alpha/components/TemplateEditorPage/DryRunResults/TaskStatusStepper.esm.js +40 -36
- package/dist/alpha/components/TemplateEditorPage/DryRunResults/TaskStatusStepper.esm.js.map +1 -1
- package/dist/alpha/components/TemplateEditorPage/TemplateEditor.esm.js +24 -17
- package/dist/alpha/components/TemplateEditorPage/TemplateEditor.esm.js.map +1 -1
- package/dist/alpha/components/TemplateEditorPage/TemplateEditorBrowser.esm.js +50 -42
- package/dist/alpha/components/TemplateEditorPage/TemplateEditorBrowser.esm.js.map +1 -1
- package/dist/alpha/components/TemplateEditorPage/TemplateEditorForm.esm.js +5 -4
- package/dist/alpha/components/TemplateEditorPage/TemplateEditorForm.esm.js.map +1 -1
- package/dist/alpha/components/TemplateEditorPage/TemplateEditorIntro.esm.js +87 -70
- package/dist/alpha/components/TemplateEditorPage/TemplateEditorIntro.esm.js.map +1 -1
- package/dist/alpha/components/TemplateEditorPage/TemplateEditorLayout.esm.js +7 -7
- package/dist/alpha/components/TemplateEditorPage/TemplateEditorLayout.esm.js.map +1 -1
- package/dist/alpha/components/TemplateEditorPage/TemplateEditorPage.esm.js +20 -17
- package/dist/alpha/components/TemplateEditorPage/TemplateEditorPage.esm.js.map +1 -1
- package/dist/alpha/components/TemplateEditorPage/TemplateEditorTextArea.esm.js +52 -45
- package/dist/alpha/components/TemplateEditorPage/TemplateEditorTextArea.esm.js.map +1 -1
- package/dist/alpha/components/TemplateEditorPage/TemplateEditorToolbar.esm.js +76 -60
- package/dist/alpha/components/TemplateEditorPage/TemplateEditorToolbar.esm.js.map +1 -1
- package/dist/alpha/components/TemplateEditorPage/TemplateEditorToolbarFileMenu.esm.js +42 -36
- package/dist/alpha/components/TemplateEditorPage/TemplateEditorToolbarFileMenu.esm.js.map +1 -1
- package/dist/alpha/components/TemplateEditorPage/TemplateEditorToolbarTemplatesMenu.esm.js +42 -38
- package/dist/alpha/components/TemplateEditorPage/TemplateEditorToolbarTemplatesMenu.esm.js.map +1 -1
- package/dist/alpha/components/TemplateEditorPage/TemplateFormPage.esm.js +23 -19
- package/dist/alpha/components/TemplateEditorPage/TemplateFormPage.esm.js.map +1 -1
- package/dist/alpha/components/TemplateEditorPage/TemplateFormPreviewer.esm.js +39 -31
- package/dist/alpha/components/TemplateEditorPage/TemplateFormPreviewer.esm.js.map +1 -1
- package/dist/alpha/components/TemplateEditorPage/TemplateIntroPage.esm.js +14 -10
- package/dist/alpha/components/TemplateEditorPage/TemplateIntroPage.esm.js.map +1 -1
- package/dist/alpha/components/TemplateListPage/RegisterExistingButton.esm.js +6 -6
- package/dist/alpha/components/TemplateListPage/RegisterExistingButton.esm.js.map +1 -1
- package/dist/alpha/components/TemplateListPage/TemplateListPage.esm.js +54 -34
- package/dist/alpha/components/TemplateListPage/TemplateListPage.esm.js.map +1 -1
- package/dist/alpha/components/TemplateWizardPage/TemplateWizardPage.esm.js +29 -24
- package/dist/alpha/components/TemplateWizardPage/TemplateWizardPage.esm.js.map +1 -1
- package/dist/alpha/components/TemplateWizardPage/TemplateWizardPageContextMenu.esm.js +40 -33
- package/dist/alpha/components/TemplateWizardPage/TemplateWizardPageContextMenu.esm.js.map +1 -1
- package/dist/alpha/extensions.esm.js +2 -2
- package/dist/alpha/extensions.esm.js.map +1 -1
- package/dist/alpha/fields/RepoUrlPicker.esm.js +1 -1
- package/dist/alpha.d.ts +12 -12
- package/dist/components/ActionsPage/ActionsPage.esm.js +120 -167
- package/dist/components/ActionsPage/ActionsPage.esm.js.map +1 -1
- package/dist/components/FileBrowser/FileBrowser.esm.js +10 -9
- package/dist/components/FileBrowser/FileBrowser.esm.js.map +1 -1
- package/dist/components/ListTasksPage/ListTasksPage.esm.js +80 -70
- package/dist/components/ListTasksPage/ListTasksPage.esm.js.map +1 -1
- package/dist/components/ListTasksPage/OwnerListPicker.esm.js +29 -23
- package/dist/components/ListTasksPage/OwnerListPicker.esm.js.map +1 -1
- package/dist/components/ListTasksPage/columns/CreatedAtColumn.esm.js +2 -2
- package/dist/components/ListTasksPage/columns/CreatedAtColumn.esm.js.map +1 -1
- package/dist/components/ListTasksPage/columns/OwnerEntityColumn.esm.js +3 -3
- package/dist/components/ListTasksPage/columns/OwnerEntityColumn.esm.js.map +1 -1
- package/dist/components/ListTasksPage/columns/TaskStatusColumn.esm.js +4 -4
- package/dist/components/ListTasksPage/columns/TaskStatusColumn.esm.js.map +1 -1
- package/dist/components/ListTasksPage/columns/TemplateTitleColumn.esm.js +2 -2
- package/dist/components/ListTasksPage/columns/TemplateTitleColumn.esm.js.map +1 -1
- package/dist/components/OngoingTask/ContextMenu.esm.js +80 -58
- package/dist/components/OngoingTask/ContextMenu.esm.js.map +1 -1
- package/dist/components/OngoingTask/OngoingTask.esm.js +95 -76
- package/dist/components/OngoingTask/OngoingTask.esm.js.map +1 -1
- package/dist/components/RenderSchema/RenderSchema.esm.js +379 -0
- package/dist/components/RenderSchema/RenderSchema.esm.js.map +1 -0
- package/dist/components/Router/Router.esm.js +105 -94
- package/dist/components/Router/Router.esm.js.map +1 -1
- package/dist/components/ScaffolderUsageExamplesTable/ScaffolderUsageExamplesTable.esm.js +28 -0
- package/dist/components/ScaffolderUsageExamplesTable/ScaffolderUsageExamplesTable.esm.js.map +1 -0
- package/dist/components/TemplateTypePicker/TemplateTypePicker.esm.js +42 -39
- package/dist/components/TemplateTypePicker/TemplateTypePicker.esm.js.map +1 -1
- package/dist/components/fields/EntityNamePicker/EntityNamePicker.esm.js +2 -2
- package/dist/components/fields/EntityNamePicker/EntityNamePicker.esm.js.map +1 -1
- package/dist/components/fields/EntityPicker/EntityPicker.esm.js +41 -40
- package/dist/components/fields/EntityPicker/EntityPicker.esm.js.map +1 -1
- package/dist/components/fields/EntityTagsPicker/EntityTagsPicker.esm.js +5 -4
- package/dist/components/fields/EntityTagsPicker/EntityTagsPicker.esm.js.map +1 -1
- package/dist/components/fields/MultiEntityPicker/MultiEntityPicker.esm.js +45 -44
- package/dist/components/fields/MultiEntityPicker/MultiEntityPicker.esm.js.map +1 -1
- package/dist/components/fields/MyGroupsPicker/MyGroupsPicker.esm.js +36 -35
- package/dist/components/fields/MyGroupsPicker/MyGroupsPicker.esm.js.map +1 -1
- package/dist/components/fields/OwnedEntityPicker/OwnedEntityPicker.esm.js +4 -4
- package/dist/components/fields/OwnedEntityPicker/OwnedEntityPicker.esm.js.map +1 -1
- package/dist/components/fields/OwnerPicker/OwnerPicker.esm.js +2 -2
- package/dist/components/fields/OwnerPicker/OwnerPicker.esm.js.map +1 -1
- package/dist/components/fields/RepoBranchPicker/BitbucketRepoBranchPicker.esm.js +26 -23
- package/dist/components/fields/RepoBranchPicker/BitbucketRepoBranchPicker.esm.js.map +1 -1
- package/dist/components/fields/RepoBranchPicker/DefaultRepoBranchPicker.esm.js +17 -15
- package/dist/components/fields/RepoBranchPicker/DefaultRepoBranchPicker.esm.js.map +1 -1
- package/dist/components/fields/RepoBranchPicker/GitHubRepoBranchPicker.esm.js +26 -23
- package/dist/components/fields/RepoBranchPicker/GitHubRepoBranchPicker.esm.js.map +1 -1
- package/dist/components/fields/RepoBranchPicker/RepoBranchPicker.esm.js +13 -5
- package/dist/components/fields/RepoBranchPicker/RepoBranchPicker.esm.js.map +1 -1
- package/dist/components/fields/RepoUrlPicker/AzureRepoPicker.esm.js +62 -53
- package/dist/components/fields/RepoUrlPicker/AzureRepoPicker.esm.js.map +1 -1
- package/dist/components/fields/RepoUrlPicker/BitbucketRepoPicker.esm.js +85 -77
- package/dist/components/fields/RepoUrlPicker/BitbucketRepoPicker.esm.js.map +1 -1
- package/dist/components/fields/RepoUrlPicker/GerritRepoPicker.esm.js +28 -25
- package/dist/components/fields/RepoUrlPicker/GerritRepoPicker.esm.js.map +1 -1
- package/dist/components/fields/RepoUrlPicker/GiteaRepoPicker.esm.js +33 -30
- package/dist/components/fields/RepoUrlPicker/GiteaRepoPicker.esm.js.map +1 -1
- package/dist/components/fields/RepoUrlPicker/GithubRepoPicker.esm.js +37 -34
- package/dist/components/fields/RepoUrlPicker/GithubRepoPicker.esm.js.map +1 -1
- package/dist/components/fields/RepoUrlPicker/GitlabRepoPicker.esm.js +41 -37
- package/dist/components/fields/RepoUrlPicker/GitlabRepoPicker.esm.js.map +1 -1
- package/dist/components/fields/RepoUrlPicker/RepoUrlPicker.esm.js +98 -83
- package/dist/components/fields/RepoUrlPicker/RepoUrlPicker.esm.js.map +1 -1
- package/dist/components/fields/RepoUrlPicker/RepoUrlPickerHost.esm.js +22 -19
- package/dist/components/fields/RepoUrlPicker/RepoUrlPickerHost.esm.js.map +1 -1
- package/dist/components/fields/RepoUrlPicker/RepoUrlPickerRepoName.esm.js +42 -39
- package/dist/components/fields/RepoUrlPicker/RepoUrlPickerRepoName.esm.js.map +1 -1
- package/dist/components/fields/SecretInput/SecretInput.esm.js +5 -5
- package/dist/components/fields/SecretInput/SecretInput.esm.js.map +1 -1
- package/dist/components/fields/VirtualizedListbox.esm.js +29 -26
- package/dist/components/fields/VirtualizedListbox.esm.js.map +1 -1
- package/dist/index.d.ts +17 -16
- package/dist/translation.esm.js +12 -10
- package/dist/translation.esm.js.map +1 -1
- package/package.json +17 -17
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Router.esm.js","sources":["../../../src/components/Router/Router.tsx"],"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 React, { PropsWithChildren } from 'react';\nimport { Routes, Route, useOutlet } from 'react-router-dom';\n\nimport {\n FieldExtensionOptions,\n FormProps,\n ReviewStepProps,\n TemplateGroupFilter,\n} from '@backstage/plugin-scaffolder-react';\nimport {\n ScaffolderTaskOutput,\n SecretsContextProvider,\n useCustomFieldExtensions,\n useCustomLayouts,\n} from '@backstage/plugin-scaffolder-react';\n\nimport { TemplateEntityV1beta3 } from '@backstage/plugin-scaffolder-common';\nimport { DEFAULT_SCAFFOLDER_FIELD_EXTENSIONS } from '../../extensions/default';\n\nimport {\n actionsRouteRef,\n editorRouteRef,\n customFieldsRouteRef,\n editRouteRef,\n scaffolderListTaskRouteRef,\n scaffolderTaskRouteRef,\n selectedTemplateRouteRef,\n templateFormRouteRef,\n} from '../../routes';\n\nimport { ActionsPage } from '../../components/ActionsPage';\nimport { ListTasksPage } from '../../components/ListTasksPage';\n\nimport {\n TemplateListPageProps,\n TemplateWizardPageProps,\n} from '@backstage/plugin-scaffolder/alpha';\nimport { TemplateListPage, TemplateWizardPage } from '../../alpha/components';\nimport { OngoingTask } from '../OngoingTask';\nimport {\n TemplateFormPage,\n TemplateIntroPage,\n TemplateEditorPage,\n CustomFieldsPage,\n} from '../../alpha/components/TemplateEditorPage';\nimport { RequirePermission } from '@backstage/plugin-permission-react';\nimport {\n taskReadPermission,\n templateManagementPermission,\n} from '@backstage/plugin-scaffolder-common/alpha';\nimport { useApp } from '@backstage/core-plugin-api';\nimport { FormField, OpaqueFormField } from '@internal/scaffolder';\nimport { useAsync, useMountEffect } from '@react-hookz/web';\n\n/**\n * The Props for the Scaffolder Router\n *\n * @public\n */\nexport type RouterProps = {\n components?: {\n ReviewStepComponent?: React.ComponentType<ReviewStepProps>;\n TemplateCardComponent?: React.ComponentType<{\n template: TemplateEntityV1beta3;\n }>;\n TaskPageComponent?: React.ComponentType<PropsWithChildren<{}>>;\n EXPERIMENTAL_TemplateOutputsComponent?: React.ComponentType<{\n output?: ScaffolderTaskOutput;\n }>;\n EXPERIMENTAL_TemplateListPageComponent?: React.ComponentType<TemplateListPageProps>;\n EXPERIMENTAL_TemplateWizardPageComponent?: React.ComponentType<TemplateWizardPageProps>;\n };\n groups?: TemplateGroupFilter[];\n templateFilter?: (entity: TemplateEntityV1beta3) => boolean;\n headerOptions?: {\n pageTitleOverride?: string;\n title?: string;\n subtitle?: string;\n };\n defaultPreviewTemplate?: string;\n formProps?: FormProps;\n contextMenu?: {\n /** Whether to show a link to the template editor */\n editor?: boolean;\n /** Whether to show a link to the actions documentation */\n actions?: boolean;\n /** Whether to show a link to the tasks page */\n tasks?: boolean;\n /** Whether to show a link to the create page (on /create subroutes) */\n create?: boolean;\n };\n};\n\n/**\n * Internal router with additional props that aren't available in the public API\n * for the old frontend system.\n *\n * @internal\n */\nexport const InternalRouter = (\n props: PropsWithChildren<\n RouterProps & { formFieldLoaders?: Array<() => Promise<FormField>> }\n >,\n) => {\n const {\n components: {\n TemplateCardComponent,\n TaskPageComponent = OngoingTask,\n ReviewStepComponent,\n EXPERIMENTAL_TemplateOutputsComponent: TemplateOutputsComponent,\n EXPERIMENTAL_TemplateListPageComponent:\n TemplateListPageComponent = TemplateListPage,\n EXPERIMENTAL_TemplateWizardPageComponent:\n TemplateWizardPageComponent = TemplateWizardPage,\n } = {},\n } = props;\n const outlet = useOutlet() || props.children;\n const customFieldExtensions = useCustomFieldExtensions(outlet);\n const loadedFieldExtensions = useFormFieldLoaders(props.formFieldLoaders);\n\n const app = useApp();\n const { NotFoundErrorPage } = app.getComponents();\n\n const fieldExtensions = [\n ...customFieldExtensions,\n ...loadedFieldExtensions,\n ...DEFAULT_SCAFFOLDER_FIELD_EXTENSIONS.filter(\n ({ name }) =>\n !customFieldExtensions.some(\n customFieldExtension => customFieldExtension.name === name,\n ),\n ),\n ] as FieldExtensionOptions[];\n\n const customLayouts = useCustomLayouts(outlet);\n\n return (\n <Routes>\n <Route\n path=\"/\"\n element={\n <TemplateListPageComponent\n TemplateCardComponent={TemplateCardComponent}\n contextMenu={props.contextMenu}\n groups={props.groups}\n templateFilter={props.templateFilter}\n headerOptions={props.headerOptions}\n />\n }\n />\n <Route\n path={selectedTemplateRouteRef.path}\n element={\n <SecretsContextProvider>\n <TemplateWizardPageComponent\n headerOptions={props.headerOptions}\n customFieldExtensions={fieldExtensions}\n layouts={customLayouts}\n components={{ ReviewStepComponent }}\n formProps={props.formProps}\n />\n </SecretsContextProvider>\n }\n />\n <Route\n path={scaffolderTaskRouteRef.path}\n element={\n <RequirePermission permission={taskReadPermission}>\n <TaskPageComponent\n TemplateOutputsComponent={TemplateOutputsComponent}\n />\n </RequirePermission>\n }\n />\n <Route\n path={editRouteRef.path}\n element={\n <RequirePermission permission={templateManagementPermission}>\n <SecretsContextProvider>\n <TemplateIntroPage />\n </SecretsContextProvider>\n </RequirePermission>\n }\n />\n <Route\n path={customFieldsRouteRef.path}\n element={\n <RequirePermission permission={templateManagementPermission}>\n <SecretsContextProvider>\n <CustomFieldsPage fieldExtensions={fieldExtensions} />\n </SecretsContextProvider>\n </RequirePermission>\n }\n />\n <Route\n path={templateFormRouteRef.path}\n element={\n <RequirePermission permission={templateManagementPermission}>\n <SecretsContextProvider>\n <TemplateFormPage\n layouts={customLayouts}\n formProps={props.formProps}\n fieldExtensions={fieldExtensions}\n />\n </SecretsContextProvider>\n </RequirePermission>\n }\n />\n\n <Route\n path={actionsRouteRef.path}\n element={<ActionsPage contextMenu={props.contextMenu} />}\n />\n <Route\n path={scaffolderListTaskRouteRef.path}\n element={\n <RequirePermission permission={taskReadPermission}>\n <ListTasksPage contextMenu={props.contextMenu} />\n </RequirePermission>\n }\n />\n <Route\n path={editorRouteRef.path}\n element={\n <RequirePermission permission={templateManagementPermission}>\n <SecretsContextProvider>\n <TemplateEditorPage\n layouts={customLayouts}\n formProps={props.formProps}\n fieldExtensions={fieldExtensions}\n />\n </SecretsContextProvider>\n </RequirePermission>\n }\n />\n <Route path=\"*\" element={<NotFoundErrorPage />} />\n </Routes>\n );\n};\n\n/**\n * The Scaffolder Router\n *\n * @public\n */\nexport const Router = (props: PropsWithChildren<RouterProps>) => {\n return <InternalRouter {...props} />;\n};\n\nfunction useFormFieldLoaders(\n formFieldLoaders?: Array<() => Promise<FormField>>,\n) {\n const [{ result: loadedFieldExtensions }, { execute }] =\n useAsync(async () => {\n const loaded = await Promise.all(\n (formFieldLoaders ?? []).map(loader => loader()),\n );\n return loaded.map(f => OpaqueFormField.toInternal(f));\n }, []);\n useMountEffect(execute);\n return loadedFieldExtensions;\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAkHa,MAAA,cAAA,GAAiB,CAC5B,KAGG,KAAA;AACH,EAAM,MAAA;AAAA,IACJ,UAAY,EAAA;AAAA,MACV,qBAAA;AAAA,MACA,iBAAoB,GAAA,WAAA;AAAA,MACpB,mBAAA;AAAA,MACA,qCAAuC,EAAA,wBAAA;AAAA,MACvC,wCACE,yBAA4B,GAAA,gBAAA;AAAA,MAC9B,0CACE,2BAA8B,GAAA;AAAA,QAC9B;AAAC,GACH,GAAA,KAAA;AACJ,EAAM,MAAA,MAAA,GAAS,SAAU,EAAA,IAAK,KAAM,CAAA,QAAA;AACpC,EAAM,MAAA,qBAAA,GAAwB,yBAAyB,MAAM,CAAA;AAC7D,EAAM,MAAA,qBAAA,GAAwB,mBAAoB,CAAA,KAAA,CAAM,gBAAgB,CAAA;AAExE,EAAA,MAAM,MAAM,MAAO,EAAA;AACnB,EAAA,MAAM,EAAE,iBAAA,EAAsB,GAAA,GAAA,CAAI,aAAc,EAAA;AAEhD,EAAA,MAAM,eAAkB,GAAA;AAAA,IACtB,GAAG,qBAAA;AAAA,IACH,GAAG,qBAAA;AAAA,IACH,GAAG,mCAAoC,CAAA,MAAA;AAAA,MACrC,CAAC,EAAE,IAAK,EAAA,KACN,CAAC,qBAAsB,CAAA,IAAA;AAAA,QACrB,CAAA,oBAAA,KAAwB,qBAAqB,IAAS,KAAA;AAAA;AACxD;AACJ,GACF;AAEA,EAAM,MAAA,aAAA,GAAgB,iBAAiB,MAAM,CAAA;AAE7C,EAAA,2CACG,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version":3,"file":"Router.esm.js","sources":["../../../src/components/Router/Router.tsx"],"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 { ComponentType, PropsWithChildren } from 'react';\nimport { Routes, Route, useOutlet } from 'react-router-dom';\n\nimport {\n FieldExtensionOptions,\n FormProps,\n ReviewStepProps,\n TemplateGroupFilter,\n} from '@backstage/plugin-scaffolder-react';\nimport {\n ScaffolderTaskOutput,\n SecretsContextProvider,\n useCustomFieldExtensions,\n useCustomLayouts,\n} from '@backstage/plugin-scaffolder-react';\n\nimport { TemplateEntityV1beta3 } from '@backstage/plugin-scaffolder-common';\nimport { DEFAULT_SCAFFOLDER_FIELD_EXTENSIONS } from '../../extensions/default';\n\nimport {\n actionsRouteRef,\n editorRouteRef,\n customFieldsRouteRef,\n editRouteRef,\n scaffolderListTaskRouteRef,\n scaffolderTaskRouteRef,\n selectedTemplateRouteRef,\n templateFormRouteRef,\n} from '../../routes';\n\nimport { ActionsPage } from '../../components/ActionsPage';\nimport { ListTasksPage } from '../../components/ListTasksPage';\n\nimport {\n TemplateListPageProps,\n TemplateWizardPageProps,\n} from '@backstage/plugin-scaffolder/alpha';\nimport { TemplateListPage, TemplateWizardPage } from '../../alpha/components';\nimport { OngoingTask } from '../OngoingTask';\nimport {\n TemplateFormPage,\n TemplateIntroPage,\n TemplateEditorPage,\n CustomFieldsPage,\n} from '../../alpha/components/TemplateEditorPage';\nimport { RequirePermission } from '@backstage/plugin-permission-react';\nimport {\n taskReadPermission,\n templateManagementPermission,\n} from '@backstage/plugin-scaffolder-common/alpha';\nimport { useApp } from '@backstage/core-plugin-api';\nimport { FormField, OpaqueFormField } from '@internal/scaffolder';\nimport { useAsync, useMountEffect } from '@react-hookz/web';\n\n/**\n * The Props for the Scaffolder Router\n *\n * @public\n */\nexport type RouterProps = {\n components?: {\n ReviewStepComponent?: ComponentType<ReviewStepProps>;\n TemplateCardComponent?: ComponentType<{\n template: TemplateEntityV1beta3;\n }>;\n TaskPageComponent?: ComponentType<PropsWithChildren<{}>>;\n EXPERIMENTAL_TemplateOutputsComponent?: ComponentType<{\n output?: ScaffolderTaskOutput;\n }>;\n EXPERIMENTAL_TemplateListPageComponent?: ComponentType<TemplateListPageProps>;\n EXPERIMENTAL_TemplateWizardPageComponent?: ComponentType<TemplateWizardPageProps>;\n };\n groups?: TemplateGroupFilter[];\n templateFilter?: (entity: TemplateEntityV1beta3) => boolean;\n headerOptions?: {\n pageTitleOverride?: string;\n title?: string;\n subtitle?: string;\n };\n defaultPreviewTemplate?: string;\n formProps?: FormProps;\n contextMenu?: {\n /** Whether to show a link to the template editor */\n editor?: boolean;\n /** Whether to show a link to the actions documentation */\n actions?: boolean;\n /** Whether to show a link to the tasks page */\n tasks?: boolean;\n /** Whether to show a link to the create page (on /create subroutes) */\n create?: boolean;\n };\n};\n\n/**\n * Internal router with additional props that aren't available in the public API\n * for the old frontend system.\n *\n * @internal\n */\nexport const InternalRouter = (\n props: PropsWithChildren<\n RouterProps & { formFieldLoaders?: Array<() => Promise<FormField>> }\n >,\n) => {\n const {\n components: {\n TemplateCardComponent,\n TaskPageComponent = OngoingTask,\n ReviewStepComponent,\n EXPERIMENTAL_TemplateOutputsComponent: TemplateOutputsComponent,\n EXPERIMENTAL_TemplateListPageComponent:\n TemplateListPageComponent = TemplateListPage,\n EXPERIMENTAL_TemplateWizardPageComponent:\n TemplateWizardPageComponent = TemplateWizardPage,\n } = {},\n } = props;\n const outlet = useOutlet() || props.children;\n const customFieldExtensions = useCustomFieldExtensions(outlet);\n const loadedFieldExtensions = useFormFieldLoaders(props.formFieldLoaders);\n\n const app = useApp();\n const { NotFoundErrorPage } = app.getComponents();\n\n const fieldExtensions = [\n ...customFieldExtensions,\n ...loadedFieldExtensions,\n ...DEFAULT_SCAFFOLDER_FIELD_EXTENSIONS.filter(\n ({ name }) =>\n !customFieldExtensions.some(\n customFieldExtension => customFieldExtension.name === name,\n ),\n ),\n ] as FieldExtensionOptions[];\n\n const customLayouts = useCustomLayouts(outlet);\n\n return (\n <Routes>\n <Route\n path=\"/\"\n element={\n <TemplateListPageComponent\n TemplateCardComponent={TemplateCardComponent}\n contextMenu={props.contextMenu}\n groups={props.groups}\n templateFilter={props.templateFilter}\n headerOptions={props.headerOptions}\n />\n }\n />\n <Route\n path={selectedTemplateRouteRef.path}\n element={\n <SecretsContextProvider>\n <TemplateWizardPageComponent\n headerOptions={props.headerOptions}\n customFieldExtensions={fieldExtensions}\n layouts={customLayouts}\n components={{ ReviewStepComponent }}\n formProps={props.formProps}\n />\n </SecretsContextProvider>\n }\n />\n <Route\n path={scaffolderTaskRouteRef.path}\n element={\n <RequirePermission permission={taskReadPermission}>\n <TaskPageComponent\n TemplateOutputsComponent={TemplateOutputsComponent}\n />\n </RequirePermission>\n }\n />\n <Route\n path={editRouteRef.path}\n element={\n <RequirePermission permission={templateManagementPermission}>\n <SecretsContextProvider>\n <TemplateIntroPage />\n </SecretsContextProvider>\n </RequirePermission>\n }\n />\n <Route\n path={customFieldsRouteRef.path}\n element={\n <RequirePermission permission={templateManagementPermission}>\n <SecretsContextProvider>\n <CustomFieldsPage fieldExtensions={fieldExtensions} />\n </SecretsContextProvider>\n </RequirePermission>\n }\n />\n <Route\n path={templateFormRouteRef.path}\n element={\n <RequirePermission permission={templateManagementPermission}>\n <SecretsContextProvider>\n <TemplateFormPage\n layouts={customLayouts}\n formProps={props.formProps}\n fieldExtensions={fieldExtensions}\n />\n </SecretsContextProvider>\n </RequirePermission>\n }\n />\n\n <Route\n path={actionsRouteRef.path}\n element={<ActionsPage contextMenu={props.contextMenu} />}\n />\n <Route\n path={scaffolderListTaskRouteRef.path}\n element={\n <RequirePermission permission={taskReadPermission}>\n <ListTasksPage contextMenu={props.contextMenu} />\n </RequirePermission>\n }\n />\n <Route\n path={editorRouteRef.path}\n element={\n <RequirePermission permission={templateManagementPermission}>\n <SecretsContextProvider>\n <TemplateEditorPage\n layouts={customLayouts}\n formProps={props.formProps}\n fieldExtensions={fieldExtensions}\n />\n </SecretsContextProvider>\n </RequirePermission>\n }\n />\n <Route path=\"*\" element={<NotFoundErrorPage />} />\n </Routes>\n );\n};\n\n/**\n * The Scaffolder Router\n *\n * @public\n */\nexport const Router = (props: PropsWithChildren<RouterProps>) => {\n return <InternalRouter {...props} />;\n};\n\nfunction useFormFieldLoaders(\n formFieldLoaders?: Array<() => Promise<FormField>>,\n) {\n const [{ result: loadedFieldExtensions }, { execute }] =\n useAsync(async () => {\n const loaded = await Promise.all(\n (formFieldLoaders ?? []).map(loader => loader()),\n );\n return loaded.map(f => OpaqueFormField.toInternal(f));\n }, []);\n useMountEffect(execute);\n return loadedFieldExtensions;\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAkHa,MAAA,cAAA,GAAiB,CAC5B,KAGG,KAAA;AACH,EAAM,MAAA;AAAA,IACJ,UAAY,EAAA;AAAA,MACV,qBAAA;AAAA,MACA,iBAAoB,GAAA,WAAA;AAAA,MACpB,mBAAA;AAAA,MACA,qCAAuC,EAAA,wBAAA;AAAA,MACvC,wCACE,yBAA4B,GAAA,gBAAA;AAAA,MAC9B,0CACE,2BAA8B,GAAA;AAAA,QAC9B;AAAC,GACH,GAAA,KAAA;AACJ,EAAM,MAAA,MAAA,GAAS,SAAU,EAAA,IAAK,KAAM,CAAA,QAAA;AACpC,EAAM,MAAA,qBAAA,GAAwB,yBAAyB,MAAM,CAAA;AAC7D,EAAM,MAAA,qBAAA,GAAwB,mBAAoB,CAAA,KAAA,CAAM,gBAAgB,CAAA;AAExE,EAAA,MAAM,MAAM,MAAO,EAAA;AACnB,EAAA,M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AU,QAAQ;AAAA,KACjD;AACA,IAAA,OAAO,OAAO,GAAI,CAAA,CAAA,CAAA,KAAK,eAAgB,CAAA,UAAA,CAAW,CAAC,CAAC,CAAA;AAAA,GACtD,EAAG,EAAE,CAAA;AACP,EAAA,cAAA,CAAe,OAAO,CAAA;AACtB,EAAO,OAAA,qBAAA;AACT;;;;"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
2
|
+
import { MarkdownContent, CodeSnippet } from '@backstage/core-components';
|
|
3
|
+
import Box from '@material-ui/core/Box';
|
|
4
|
+
import Grid from '@material-ui/core/Grid';
|
|
5
|
+
import { Fragment } from 'react';
|
|
6
|
+
|
|
7
|
+
const ScaffolderUsageExamplesTable = (props) => {
|
|
8
|
+
return /* @__PURE__ */ jsx(Grid, { "data-testid": "examples", container: true, children: props.examples.map((example, index) => {
|
|
9
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
10
|
+
/* @__PURE__ */ jsx(Grid, { "data-testid": `example_desc${index}`, item: true, lg: 3, children: /* @__PURE__ */ jsxs(Box, { padding: 1, style: { overflowX: "auto" }, children: [
|
|
11
|
+
example.description && /* @__PURE__ */ jsx(MarkdownContent, { content: example.description }),
|
|
12
|
+
example.notes?.length && /* @__PURE__ */ jsx(MarkdownContent, { content: example.notes })
|
|
13
|
+
] }) }),
|
|
14
|
+
/* @__PURE__ */ jsx(Grid, { "data-testid": `example_code${index}`, item: true, lg: 9, children: /* @__PURE__ */ jsx(Box, { padding: 1, children: /* @__PURE__ */ jsx(
|
|
15
|
+
CodeSnippet,
|
|
16
|
+
{
|
|
17
|
+
text: example.example?.trim(),
|
|
18
|
+
showLineNumbers: true,
|
|
19
|
+
showCopyCodeButton: true,
|
|
20
|
+
language: "yaml"
|
|
21
|
+
}
|
|
22
|
+
) }) })
|
|
23
|
+
] }, `example-${index}`);
|
|
24
|
+
}) });
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export { ScaffolderUsageExamplesTable };
|
|
28
|
+
//# sourceMappingURL=ScaffolderUsageExamplesTable.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ScaffolderUsageExamplesTable.esm.js","sources":["../../../src/components/ScaffolderUsageExamplesTable/ScaffolderUsageExamplesTable.tsx"],"sourcesContent":["/*\n * Copyright 2025 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 { CodeSnippet, MarkdownContent } from '@backstage/core-components';\nimport { ScaffolderUsageExample } from '@backstage/plugin-scaffolder-react';\nimport Box from '@material-ui/core/Box';\nimport Grid from '@material-ui/core/Grid';\nimport { Fragment } from 'react';\n\nexport const ScaffolderUsageExamplesTable = (props: {\n examples: ScaffolderUsageExample[];\n}) => {\n return (\n <Grid data-testid=\"examples\" container>\n {props.examples.map((example, index) => {\n return (\n <Fragment key={`example-${index}`}>\n <Grid data-testid={`example_desc${index}`} item lg={3}>\n <Box padding={1} style={{ overflowX: 'auto' }}>\n {example.description && (\n <MarkdownContent content={example.description} />\n )}\n {example.notes?.length && (\n <MarkdownContent content={example.notes} />\n )}\n </Box>\n </Grid>\n <Grid data-testid={`example_code${index}`} item lg={9}>\n <Box padding={1}>\n <CodeSnippet\n text={example.example?.trim()}\n showLineNumbers\n showCopyCodeButton\n language=\"yaml\"\n />\n </Box>\n </Grid>\n </Fragment>\n );\n })}\n </Grid>\n );\n};\n"],"names":[],"mappings":";;;;;;AAqBa,MAAA,4BAAA,GAA+B,CAAC,KAEvC,KAAA;AACJ,EACE,uBAAA,GAAA,CAAC,IAAK,EAAA,EAAA,aAAA,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{ jsx, jsxs } from 'react/jsx-runtime';
|
|
2
2
|
import capitalize from 'lodash/capitalize';
|
|
3
3
|
import { Progress } from '@backstage/core-components';
|
|
4
4
|
import Box from '@material-ui/core/Box';
|
|
@@ -15,13 +15,13 @@ import { useApi, alertApiRef } from '@backstage/core-plugin-api';
|
|
|
15
15
|
import { useTranslationRef } from '@backstage/core-plugin-api/alpha';
|
|
16
16
|
import { scaffolderTranslationRef } from '../../translation.esm.js';
|
|
17
17
|
|
|
18
|
-
const icon = /* @__PURE__ */
|
|
19
|
-
const checkedIcon = /* @__PURE__ */
|
|
18
|
+
const icon = /* @__PURE__ */ jsx(CheckBoxOutlineBlankIcon, { fontSize: "small" });
|
|
19
|
+
const checkedIcon = /* @__PURE__ */ jsx(CheckBoxIcon, { fontSize: "small" });
|
|
20
20
|
const TemplateTypePicker = () => {
|
|
21
21
|
const alertApi = useApi(alertApiRef);
|
|
22
22
|
const { error, loading, availableTypes, selectedTypes, setSelectedTypes } = useEntityTypeFilter();
|
|
23
23
|
const { t } = useTranslationRef(scaffolderTranslationRef);
|
|
24
|
-
if (loading) return /* @__PURE__ */
|
|
24
|
+
if (loading) return /* @__PURE__ */ jsx(Progress, {});
|
|
25
25
|
if (!availableTypes) return null;
|
|
26
26
|
if (error) {
|
|
27
27
|
alertApi.post({
|
|
@@ -30,41 +30,44 @@ const TemplateTypePicker = () => {
|
|
|
30
30
|
});
|
|
31
31
|
return null;
|
|
32
32
|
}
|
|
33
|
-
return /* @__PURE__ */
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
{
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
33
|
+
return /* @__PURE__ */ jsxs(Box, { pb: 1, pt: 1, children: [
|
|
34
|
+
/* @__PURE__ */ jsx(
|
|
35
|
+
Typography,
|
|
36
|
+
{
|
|
37
|
+
variant: "button",
|
|
38
|
+
component: "label",
|
|
39
|
+
htmlFor: "categories-picker",
|
|
40
|
+
children: t("templateTypePicker.title")
|
|
41
|
+
}
|
|
42
|
+
),
|
|
43
|
+
/* @__PURE__ */ jsx(
|
|
44
|
+
Autocomplete,
|
|
45
|
+
{
|
|
46
|
+
id: "categories-picker",
|
|
47
|
+
multiple: true,
|
|
48
|
+
options: availableTypes,
|
|
49
|
+
value: selectedTypes,
|
|
50
|
+
onChange: (_, value) => setSelectedTypes(value),
|
|
51
|
+
renderOption: (option, { selected }) => /* @__PURE__ */ jsx(
|
|
52
|
+
FormControlLabel,
|
|
53
|
+
{
|
|
54
|
+
control: /* @__PURE__ */ jsx(
|
|
55
|
+
Checkbox,
|
|
56
|
+
{
|
|
57
|
+
icon,
|
|
58
|
+
checkedIcon,
|
|
59
|
+
checked: selected
|
|
60
|
+
}
|
|
61
|
+
),
|
|
62
|
+
label: capitalize(option)
|
|
63
|
+
}
|
|
64
|
+
),
|
|
65
|
+
size: "small",
|
|
66
|
+
popupIcon: /* @__PURE__ */ jsx(ExpandMoreIcon, { "data-testid": "categories-picker-expand" }),
|
|
67
|
+
renderInput: (params) => /* @__PURE__ */ jsx(TextField, { ...params, variant: "outlined" })
|
|
68
|
+
}
|
|
69
|
+
)
|
|
70
|
+
] });
|
|
68
71
|
};
|
|
69
72
|
|
|
70
73
|
export { TemplateTypePicker };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TemplateTypePicker.esm.js","sources":["../../../src/components/TemplateTypePicker/TemplateTypePicker.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 */\n\nimport
|
|
1
|
+
{"version":3,"file":"TemplateTypePicker.esm.js","sources":["../../../src/components/TemplateTypePicker/TemplateTypePicker.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 */\n\nimport capitalize from 'lodash/capitalize';\nimport { Progress } from '@backstage/core-components';\nimport Box from '@material-ui/core/Box';\nimport Checkbox from '@material-ui/core/Checkbox';\nimport FormControlLabel from '@material-ui/core/FormControlLabel';\nimport TextField from '@material-ui/core/TextField';\nimport Typography from '@material-ui/core/Typography';\nimport CheckBoxIcon from '@material-ui/icons/CheckBox';\nimport CheckBoxOutlineBlankIcon from '@material-ui/icons/CheckBoxOutlineBlank';\nimport ExpandMoreIcon from '@material-ui/icons/ExpandMore';\nimport Autocomplete from '@material-ui/lab/Autocomplete';\nimport { useEntityTypeFilter } from '@backstage/plugin-catalog-react';\nimport { alertApiRef, useApi } from '@backstage/core-plugin-api';\nimport { useTranslationRef } from '@backstage/core-plugin-api/alpha';\nimport { scaffolderTranslationRef } from '../../translation';\n\nconst icon = <CheckBoxOutlineBlankIcon fontSize=\"small\" />;\nconst checkedIcon = <CheckBoxIcon fontSize=\"small\" />;\n\n/**\n * The component to select the `type` of `Template` that you will see in the table.\n *\n * @public\n */\nexport const TemplateTypePicker = () => {\n const alertApi = useApi(alertApiRef);\n const { error, loading, availableTypes, selectedTypes, setSelectedTypes } =\n useEntityTypeFilter();\n const { t } = useTranslationRef(scaffolderTranslationRef);\n\n if (loading) return <Progress />;\n\n if (!availableTypes) return null;\n\n if (error) {\n alertApi.post({\n message: `Failed to load entity types`,\n severity: 'error',\n });\n return null;\n }\n\n return (\n <Box pb={1} pt={1}>\n <Typography\n variant=\"button\"\n component=\"label\"\n htmlFor=\"categories-picker\"\n >\n {t('templateTypePicker.title')}\n </Typography>\n <Autocomplete<string, true>\n id=\"categories-picker\"\n multiple\n options={availableTypes}\n value={selectedTypes}\n onChange={(_: object, value: string[]) => setSelectedTypes(value)}\n renderOption={(option, { selected }) => (\n <FormControlLabel\n control={\n <Checkbox\n icon={icon}\n checkedIcon={checkedIcon}\n checked={selected}\n />\n }\n label={capitalize(option)}\n />\n )}\n size=\"small\"\n popupIcon={<ExpandMoreIcon data-testid=\"categories-picker-expand\" />}\n renderInput={params => <TextField {...params} variant=\"outlined\" />}\n />\n </Box>\n );\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAgCA,MAAM,IAAO,mBAAA,GAAA,CAAC,wBAAyB,EAAA,EAAA,QAAA,EAAS,OAAQ,EAAA,CAAA;AACxD,MAAM,WAAc,mBAAA,GAAA,CAAC,YAAa,EAAA,EAAA,QAAA,EAAS,OAAQ,EAAA,CAAA;AAO5C,MAAM,qBAAqB,MAAM;AACtC,EAAM,MAAA,QAAA,GAAW,OAAO,WAAW,CAAA;AACnC,EAAA,MAAM,EAAE,KAAO,EAAA,OAAA,EAAS,gBAAgB,aAAe,EAAA,gBAAA,KACrD,mBAAoB,EAAA;AACtB,EAAA,MAAM,EAAE,CAAA,EAAM,GAAA,iBAAA,CAAkB,wBAAwB,CAAA;AAExD,EAAI,IAAA,OAAA,EAAgB,uBAAA,GAAA,CAAC,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aAAW,GAAG,MAAA,EAAQ,SAAQ,UAAW,EAAA;AAAA;AAAA;AACnE,GACF,EAAA,CAAA;AAEJ;;;;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
2
|
import TextField from '@material-ui/core/TextField';
|
|
3
3
|
import { useTranslationRef } from '@backstage/core-plugin-api/alpha';
|
|
4
4
|
import { scaffolderTranslationRef } from '../../../translation.esm.js';
|
|
@@ -19,7 +19,7 @@ const EntityNamePicker = (props) => {
|
|
|
19
19
|
idSchema,
|
|
20
20
|
placeholder
|
|
21
21
|
} = props;
|
|
22
|
-
return /* @__PURE__ */
|
|
22
|
+
return /* @__PURE__ */ jsx(
|
|
23
23
|
TextField,
|
|
24
24
|
{
|
|
25
25
|
id: idSchema?.$id,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityNamePicker.esm.js","sources":["../../../../src/components/fields/EntityNamePicker/EntityNamePicker.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
|
|
1
|
+
{"version":3,"file":"EntityNamePicker.esm.js","sources":["../../../../src/components/fields/EntityNamePicker/EntityNamePicker.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 { EntityNamePickerProps } from './schema';\nimport TextField from '@material-ui/core/TextField';\nimport { useTranslationRef } from '@backstage/core-plugin-api/alpha';\nimport { scaffolderTranslationRef } from '../../../translation';\n\nexport { EntityNamePickerSchema } from './schema';\n\n/**\n * EntityName Picker\n */\nexport const EntityNamePicker = (props: EntityNamePickerProps) => {\n const { t } = useTranslationRef(scaffolderTranslationRef);\n const {\n onChange,\n required,\n schema: {\n title = t('fields.entityNamePicker.title'),\n description = t('fields.entityNamePicker.description'),\n },\n rawErrors,\n formData,\n uiSchema: { 'ui:autofocus': autoFocus },\n idSchema,\n placeholder,\n } = props;\n\n return (\n <TextField\n id={idSchema?.$id}\n label={title}\n placeholder={placeholder}\n helperText={description}\n required={required}\n value={formData ?? ''}\n onChange={({ target: { value } }) => onChange(value)}\n margin=\"normal\"\n error={rawErrors?.length > 0 && !formData}\n inputProps={{ autoFocus }}\n FormHelperTextProps={{ margin: 'dense', style: { marginLeft: 0 } }}\n />\n );\n};\n"],"names":[],"mappings":";;;;;;AAyBa,MAAA,gBAAA,GAAmB,CAAC,KAAiC,KAAA;AAChE,EAAA,MAAM,EAAE,CAAA,EAAM,GAAA,iBAAA,CAAkB,wBAAwB,CAAA;AACxD,EAAM,MAAA;AAAA,IACJ,QAAA;AAAA,IACA,QAAA;AAAA,IACA,MAAQ,EAAA;AAAA,MACN,KAAA,GAAQ,EAAE,+BAA+B,CAAA;AAAA,MACzC,WAAA,GAAc,EAAE,qCAAqC;AAAA,KACvD;AAAA,IACA,SAAA;AAAA,IACA,QAAA;AAAA,IACA,QAAA,EAAU,EAAE,cAAA,EAAgB,SAAU,EAAA;AAAA,IACtC,QAAA;AAAA,IACA;AAAA,GACE,GAAA,KAAA;AAEJ,EACE,uBAAA,GAAA;AAAA,IAAC,SAAA;AAAA,IAAA;AAAA,MACC,IAAI,QAAU,EAAA,GAAA;AAAA,MACd,KAAO,EAAA,KAAA;AAAA,MACP,WAAA;AAAA,MACA,UAAY,EAAA,WAAA;AAAA,MACZ,QAAA;AAAA,MACA,OAAO,QAAY,IAAA,EAAA;AAAA,MACnB,QAAA,EAAU,CAAC,EAAE,MAAA,EAAQ,EAAE,KAAM,EAAA,EAAQ,KAAA,QAAA,CAAS,KAAK,CAAA;AAAA,MACnD,MAAO,EAAA,QAAA;AAAA,MACP,KAAO,EAAA,SAAA,EAAW,MAAS,GAAA,CAAA,IAAK,CAAC,QAAA;AAAA,MACjC,UAAA,EAAY,EAAE,SAAU,EAAA;AAAA,MACxB,mBAAA,EAAqB,EAAE,MAAQ,EAAA,OAAA,EAAS,OAAO,EAAE,UAAA,EAAY,GAAI;AAAA;AAAA,GACnE;AAEJ;;;;"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
1
2
|
import { CATALOG_FILTER_EXISTS } from '@backstage/catalog-client';
|
|
2
3
|
import { stringifyEntityRef, parseEntityRef } from '@backstage/catalog-model';
|
|
3
4
|
import { useApi } from '@backstage/core-plugin-api';
|
|
@@ -5,7 +6,7 @@ import { catalogApiRef, entityPresentationApiRef, EntityDisplayName } from '@bac
|
|
|
5
6
|
import TextField from '@material-ui/core/TextField';
|
|
6
7
|
import FormControl from '@material-ui/core/FormControl';
|
|
7
8
|
import Autocomplete, { createFilterOptions } from '@material-ui/lab/Autocomplete';
|
|
8
|
-
import
|
|
9
|
+
import { useCallback, useEffect } from 'react';
|
|
9
10
|
import useAsync from 'react-use/esm/useAsync';
|
|
10
11
|
import { VirtualizedListbox } from '../VirtualizedListbox.esm.js';
|
|
11
12
|
import { useTranslationRef } from '@backstage/core-plugin-api/alpha';
|
|
@@ -97,49 +98,49 @@ const EntityPicker = (props) => {
|
|
|
97
98
|
onChange(stringifyEntityRef(entities.catalogEntities[0]));
|
|
98
99
|
}
|
|
99
100
|
}, [entities, onChange, selectedEntity, required, allowArbitraryValues]);
|
|
100
|
-
return /* @__PURE__ */
|
|
101
|
+
return /* @__PURE__ */ jsx(
|
|
101
102
|
FormControl,
|
|
102
103
|
{
|
|
103
104
|
margin: "normal",
|
|
104
105
|
required,
|
|
105
|
-
error: rawErrors?.length > 0 && !formData
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
106
|
+
error: rawErrors?.length > 0 && !formData,
|
|
107
|
+
children: /* @__PURE__ */ jsx(
|
|
108
|
+
Autocomplete,
|
|
109
|
+
{
|
|
110
|
+
disabled: isDisabled || required && !allowArbitraryValues && entities?.catalogEntities.length === 1,
|
|
111
|
+
id: idSchema?.$id,
|
|
112
|
+
value: selectedEntity,
|
|
113
|
+
loading,
|
|
114
|
+
onChange: onSelect,
|
|
115
|
+
options: entities?.catalogEntities || [],
|
|
116
|
+
getOptionLabel: (option) => (
|
|
117
|
+
// option can be a string due to freeSolo.
|
|
118
|
+
typeof option === "string" ? option : entities?.entityRefToPresentation.get(stringifyEntityRef(option))?.entityRef
|
|
119
|
+
),
|
|
120
|
+
autoSelect: true,
|
|
121
|
+
freeSolo: allowArbitraryValues,
|
|
122
|
+
renderInput: (params) => /* @__PURE__ */ jsx(
|
|
123
|
+
TextField,
|
|
124
|
+
{
|
|
125
|
+
...params,
|
|
126
|
+
label: title,
|
|
127
|
+
margin: "dense",
|
|
128
|
+
helperText: description,
|
|
129
|
+
FormHelperTextProps: { margin: "dense", style: { marginLeft: 0 } },
|
|
130
|
+
variant: "outlined",
|
|
131
|
+
required,
|
|
132
|
+
disabled: isDisabled,
|
|
133
|
+
InputProps: params.InputProps
|
|
134
|
+
}
|
|
135
|
+
),
|
|
136
|
+
renderOption: (option) => /* @__PURE__ */ jsx(EntityDisplayName, { entityRef: option }),
|
|
137
|
+
filterOptions: createFilterOptions({
|
|
138
|
+
stringify: (option) => entities?.entityRefToPresentation.get(stringifyEntityRef(option))?.primaryTitle
|
|
139
|
+
}),
|
|
140
|
+
ListboxComponent: VirtualizedListbox
|
|
141
|
+
}
|
|
142
|
+
)
|
|
143
|
+
}
|
|
143
144
|
);
|
|
144
145
|
};
|
|
145
146
|
function convertOpsValues(value) {
|
|
@@ -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 FormControl from '@material-ui/core/FormControl';\nimport Autocomplete, {\n AutocompleteChangeReason,\n createFilterOptions,\n} from '@material-ui/lab/Autocomplete';\nimport React, { 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';\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 } = 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 'metadata.name',\n 'metadata.namespace',\n 'metadata.title',\n 'kind',\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 <FormControl\n margin=\"normal\"\n required={required}\n error={rawErrors?.length > 0 && !formData}\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 helperText={description}\n FormHelperTextProps={{ margin: 'dense', style: { marginLeft: 0 } }}\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 </FormControl>\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;AAAA,GACE,GAAA,KAAA;AACJ,EAAM,MAAA,aAAA,GAAgB,mBAAmB,QAAQ,CAAA;AACjD,EAAM,MAAA,WAAA,GAAc,QAAS,CAAA,YAAY,CAAG,EAAA,WAAA;AAC5C,EAAA,MAAM,gBACJ,GAAA,QAAA,CAAS,YAAY,CAAA,EAAG,gBAAoB,IAAA,KAAA,CAAA;AAC9C,EAAM,MAAA,UAAA,GAAa,QAAW,GAAA,aAAa,CAAK,IAAA,KAAA;AAEhD,EAAM,MAAA,UAAA,GAAa,OAAO,aAAa,CAAA;AACvC,EAAM,MAAA,qBAAA,GAAwB,OAAO,wBAAwB,CAAA;AAE7D,EAAA,MAAM,EAAE,KAAO,EAAA,QAAA,EAAU,OAAQ,EAAA,GAAI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kBAAmB,CAAA,MAAM,CAAC,CAC5D,EAAA;AAAA,SACP,CAAA;AAAA,QACD,gBAAkB,EAAA;AAAA;AAAA;AACpB,GACF;AAEJ;AAQA,SAAS,iBACP,KACiB,EAAA;AACjB,EAAA,IAAI,OAAO,KAAA,KAAU,QAAY,IAAA,KAAA,CAAM,MAAQ,EAAA;AAC7C,IAAO,OAAA,qBAAA;AAAA;AAET,EAAA,OAAO,OAAO,QAAS,EAAA;AACzB;AAWA,SAAS,4BACP,aACwC,EAAA;AACxC,EAAA,MAAM,QAA2B,EAAC;AAElC,EAAA,KAAA,MAAW,CAAC,GAAK,EAAA,KAAK,KAAK,MAAO,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
|
+
{"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 FormControl from '@material-ui/core/FormControl';\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';\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 } = 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 'metadata.name',\n 'metadata.namespace',\n 'metadata.title',\n 'kind',\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 <FormControl\n margin=\"normal\"\n required={required}\n error={rawErrors?.length > 0 && !formData}\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 helperText={description}\n FormHelperTextProps={{ margin: 'dense', style: { marginLeft: 0 } }}\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 </FormControl>\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,2BAA2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O,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,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { useState } from 'react';
|
|
2
3
|
import useAsync from 'react-use/esm/useAsync';
|
|
3
4
|
import useEffectOnce from 'react-use/esm/useEffectOnce';
|
|
4
5
|
import { makeValidator } from '@backstage/catalog-model';
|
|
@@ -56,7 +57,7 @@ const EntityTagsPicker = (props) => {
|
|
|
56
57
|
}
|
|
57
58
|
};
|
|
58
59
|
useEffectOnce(() => onChange(formData || []));
|
|
59
|
-
return /* @__PURE__ */
|
|
60
|
+
return /* @__PURE__ */ jsx(FormControl, { margin: "normal", children: /* @__PURE__ */ jsx(
|
|
60
61
|
Autocomplete,
|
|
61
62
|
{
|
|
62
63
|
multiple: true,
|
|
@@ -70,7 +71,7 @@ const EntityTagsPicker = (props) => {
|
|
|
70
71
|
options: tagOptions,
|
|
71
72
|
ChipProps: { size: "small" },
|
|
72
73
|
renderOption: (option) => showCounts ? `${option} (${existingTags?.[option]})` : option,
|
|
73
|
-
renderInput: (params) => /* @__PURE__ */
|
|
74
|
+
renderInput: (params) => /* @__PURE__ */ jsx(
|
|
74
75
|
TextField,
|
|
75
76
|
{
|
|
76
77
|
...params,
|
|
@@ -83,7 +84,7 @@ const EntityTagsPicker = (props) => {
|
|
|
83
84
|
}
|
|
84
85
|
)
|
|
85
86
|
}
|
|
86
|
-
));
|
|
87
|
+
) });
|
|
87
88
|
};
|
|
88
89
|
|
|
89
90
|
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
|
|
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;A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