@backstage/plugin-scaffolder 1.30.0-next.0 → 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 +72 -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 +18 -18
|
@@ -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 from '@material-ui/lab/Autocomplete';
|
|
8
|
-
import
|
|
9
|
+
import { useState, useCallback, useEffect } from 'react';
|
|
9
10
|
import useAsync from 'react-use/esm/useAsync';
|
|
10
11
|
import { VirtualizedListbox } from '../VirtualizedListbox.esm.js';
|
|
11
12
|
export { MultiEntityPickerSchema } from './schema.esm.js';
|
|
@@ -76,55 +77,55 @@ const MultiEntityPicker = (props) => {
|
|
|
76
77
|
onChange([stringifyEntityRef(entities?.entities[0])]);
|
|
77
78
|
}
|
|
78
79
|
}, [entities, onChange, required, allowArbitraryValues]);
|
|
79
|
-
return /* @__PURE__ */
|
|
80
|
+
return /* @__PURE__ */ jsx(
|
|
80
81
|
FormControl,
|
|
81
82
|
{
|
|
82
83
|
margin: "normal",
|
|
83
84
|
required,
|
|
84
|
-
error: rawErrors?.length > 0 && !formData
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
disabled: isDisabled,
|
|
111
|
-
margin: "dense",
|
|
112
|
-
helperText: description,
|
|
113
|
-
FormHelperTextProps: {
|
|
85
|
+
error: rawErrors?.length > 0 && !formData,
|
|
86
|
+
children: /* @__PURE__ */ jsx(
|
|
87
|
+
Autocomplete,
|
|
88
|
+
{
|
|
89
|
+
multiple: true,
|
|
90
|
+
filterSelectedOptions: true,
|
|
91
|
+
disabled: isDisabled || required && !allowArbitraryValues && entities?.entities?.length === 1,
|
|
92
|
+
id: idSchema?.$id,
|
|
93
|
+
defaultValue: formData,
|
|
94
|
+
loading,
|
|
95
|
+
onChange: onSelect,
|
|
96
|
+
options: entities?.entities || [],
|
|
97
|
+
renderOption: (option) => /* @__PURE__ */ jsx(EntityDisplayName, { entityRef: option }),
|
|
98
|
+
getOptionLabel: (option) => (
|
|
99
|
+
// option can be a string due to freeSolo.
|
|
100
|
+
typeof option === "string" ? option : entities?.entityRefToPresentation.get(stringifyEntityRef(option))?.entityRef
|
|
101
|
+
),
|
|
102
|
+
getOptionDisabled: (_options) => maxItems ? noOfItemsSelected >= maxItems : false,
|
|
103
|
+
autoSelect: true,
|
|
104
|
+
freeSolo: allowArbitraryValues,
|
|
105
|
+
renderInput: (params) => /* @__PURE__ */ jsx(
|
|
106
|
+
TextField,
|
|
107
|
+
{
|
|
108
|
+
...params,
|
|
109
|
+
label: title,
|
|
110
|
+
disabled: isDisabled,
|
|
114
111
|
margin: "dense",
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
required
|
|
112
|
+
helperText: description,
|
|
113
|
+
FormHelperTextProps: {
|
|
114
|
+
margin: "dense",
|
|
115
|
+
style: { marginLeft: 0 }
|
|
116
|
+
},
|
|
117
|
+
variant: "outlined",
|
|
118
|
+
required,
|
|
119
|
+
InputProps: {
|
|
120
|
+
...params.InputProps,
|
|
121
|
+
required: formData?.length === 0 && required
|
|
122
|
+
}
|
|
122
123
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
124
|
+
),
|
|
125
|
+
ListboxComponent: VirtualizedListbox
|
|
126
|
+
}
|
|
127
|
+
)
|
|
128
|
+
}
|
|
128
129
|
);
|
|
129
130
|
};
|
|
130
131
|
const validateMultiEntityPickerValidation = (values, validation) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MultiEntityPicker.esm.js","sources":["../../../../src/components/fields/MultiEntityPicker/MultiEntityPicker.tsx"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport {\n type EntityFilterQuery,\n CATALOG_FILTER_EXISTS,\n} from '@backstage/catalog-client';\nimport {\n Entity,\n parseEntityRef,\n stringifyEntityRef,\n} from '@backstage/catalog-model';\nimport { useApi } from '@backstage/core-plugin-api';\nimport {\n catalogApiRef,\n entityPresentationApiRef,\n EntityDisplayName,\n EntityRefPresentationSnapshot,\n} from '@backstage/plugin-catalog-react';\nimport TextField from '@material-ui/core/TextField';\nimport FormControl from '@material-ui/core/FormControl';\nimport Autocomplete, {\n AutocompleteChangeReason,\n} from '@material-ui/lab/Autocomplete';\nimport React, { useCallback, useEffect, useState } from 'react';\nimport useAsync from 'react-use/esm/useAsync';\nimport { FieldValidation } from '@rjsf/utils';\nimport {\n MultiEntityPickerFilterQueryValue,\n MultiEntityPickerProps,\n MultiEntityPickerUiOptions,\n MultiEntityPickerFilterQuery,\n} from './schema';\nimport { VirtualizedListbox } from '../VirtualizedListbox';\n\nexport { MultiEntityPickerSchema } from './schema';\n\n/**\n * The underlying component that is rendered in the form for the `MultiEntityPicker`\n * field extension.\n */\nexport const MultiEntityPicker = (props: MultiEntityPickerProps) => {\n const {\n onChange,\n schema: { title = 'Entity', description = 'An entity from the catalog' },\n required,\n uiSchema,\n rawErrors,\n formData,\n idSchema,\n } = props;\n\n const catalogFilter = buildCatalogFilter(uiSchema);\n const defaultKind = uiSchema['ui:options']?.defaultKind;\n const defaultNamespace =\n uiSchema['ui:options']?.defaultNamespace || undefined;\n const isDisabled = uiSchema?.['ui:disabled'] ?? false;\n const [noOfItemsSelected, setNoOfItemsSelected] = useState(0);\n\n const catalogApi = useApi(catalogApiRef);\n const entityPresentationApi = useApi(entityPresentationApiRef);\n const { value: entities, loading } = useAsync(async () => {\n const { items } = await catalogApi.getEntities(\n catalogFilter ? { filter: catalogFilter } : undefined,\n );\n const entityRefToPresentation = new Map<\n string,\n EntityRefPresentationSnapshot\n >(\n await Promise.all(\n items.map(async item => {\n const presentation = await entityPresentationApi.forEntity(item)\n .promise;\n return [stringifyEntityRef(item), presentation] as [\n string,\n EntityRefPresentationSnapshot,\n ];\n }),\n ),\n );\n return { entities: items, entityRefToPresentation };\n });\n const allowArbitraryValues =\n uiSchema['ui:options']?.allowArbitraryValues ?? true;\n\n // if not specified, maxItems defaults to undefined\n const maxItems = props.schema.maxItems;\n\n const onSelect = useCallback(\n (_: any, refs: (string | Entity)[], reason: AutocompleteChangeReason) => {\n const values = refs\n .map(ref => {\n if (typeof ref !== 'string') {\n // if ref does not exist: pass 'undefined' to trigger validation for required value\n return ref ? stringifyEntityRef(ref as Entity) : undefined;\n }\n if (reason === 'blur' || reason === 'create-option') {\n // Add in default namespace, etc.\n let entityRef = ref;\n try {\n // Attempt to parse the entity ref into it's full form.\n entityRef = stringifyEntityRef(\n parseEntityRef(ref as string, {\n defaultKind,\n defaultNamespace,\n }),\n );\n } catch (err) {\n // If the passed in value isn't an entity ref, do nothing.\n }\n\n // We need to check against formData here as that's the previous value for this field.\n if (formData?.includes(ref) || allowArbitraryValues) {\n return entityRef;\n }\n }\n\n return undefined;\n })\n .filter(ref => ref !== undefined) as string[];\n\n setNoOfItemsSelected(values.length);\n onChange(values);\n },\n [onChange, formData, defaultKind, defaultNamespace, allowArbitraryValues],\n );\n\n useEffect(() => {\n if (required && !allowArbitraryValues && entities?.entities?.length === 1) {\n onChange([stringifyEntityRef(entities?.entities[0])]);\n }\n }, [entities, onChange, required, allowArbitraryValues]);\n\n return (\n <FormControl\n margin=\"normal\"\n required={required}\n error={rawErrors?.length > 0 && !formData}\n >\n <Autocomplete\n multiple\n filterSelectedOptions\n disabled={\n isDisabled ||\n (required &&\n !allowArbitraryValues &&\n entities?.entities?.length === 1)\n }\n id={idSchema?.$id}\n defaultValue={formData}\n loading={loading}\n onChange={onSelect}\n options={entities?.entities || []}\n renderOption={option => <EntityDisplayName entityRef={option} />}\n getOptionLabel={option =>\n // option can be a string due to freeSolo.\n typeof option === 'string'\n ? option\n : entities?.entityRefToPresentation.get(stringifyEntityRef(option))\n ?.entityRef!\n }\n getOptionDisabled={_options =>\n maxItems ? noOfItemsSelected >= maxItems : false\n }\n autoSelect\n freeSolo={allowArbitraryValues}\n renderInput={params => (\n <TextField\n {...params}\n label={title}\n disabled={isDisabled}\n margin=\"dense\"\n helperText={description}\n FormHelperTextProps={{\n margin: 'dense',\n style: { marginLeft: 0 },\n }}\n variant=\"outlined\"\n required={required}\n InputProps={{\n ...params.InputProps,\n required: formData?.length === 0 && required,\n }}\n />\n )}\n ListboxComponent={VirtualizedListbox}\n />\n </FormControl>\n );\n};\n\nexport const validateMultiEntityPickerValidation = (\n values: string[],\n validation: FieldValidation,\n) => {\n values.forEach(value => {\n try {\n parseEntityRef(value);\n } catch {\n validation.addError(`${value} is not a valid entity ref`);\n }\n });\n};\n\n/**\n * Converts a special `{exists: true}` value to the `CATALOG_FILTER_EXISTS` symbol.\n *\n * @param value - The value to convert.\n * @returns The converted value.\n */\nfunction convertOpsValues(\n value: Exclude<MultiEntityPickerFilterQueryValue, Array<any>>,\n): string | symbol {\n if (typeof value === 'object' && value.exists) {\n return CATALOG_FILTER_EXISTS;\n }\n return value?.toString();\n}\n\n/**\n * Converts schema filters to entity filter query, replacing `{exists:true}` values\n * with the constant `CATALOG_FILTER_EXISTS`.\n *\n * @param schemaFilters - An object containing schema filters with keys as filter names\n * and values as filter values.\n * @returns An object with the same keys as the input object, but with `{exists:true}` values\n * transformed to `CATALOG_FILTER_EXISTS` symbol.\n */\nfunction convertSchemaFiltersToQuery(\n schemaFilters: MultiEntityPickerFilterQuery,\n): Exclude<EntityFilterQuery, Array<any>> {\n const query: EntityFilterQuery = {};\n\n for (const [key, value] of Object.entries(schemaFilters)) {\n if (Array.isArray(value)) {\n query[key] = value;\n } else {\n query[key] = convertOpsValues(value);\n }\n }\n\n return query;\n}\n\n/**\n * Builds an `EntityFilterQuery` based on the `uiSchema` passed in.\n * If `catalogFilter` is specified in the `uiSchema`, it is converted to a `EntityFilterQuery`.\n *\n * @param uiSchema The `uiSchema` of an `EntityPicker` component.\n * @returns An `EntityFilterQuery` based on the `uiSchema`, or `undefined` if `catalogFilter` is not specified in the `uiSchema`.\n */\nfunction buildCatalogFilter(\n uiSchema: MultiEntityPickerProps['uiSchema'],\n): EntityFilterQuery | undefined {\n const catalogFilter: MultiEntityPickerUiOptions['catalogFilter'] | undefined =\n uiSchema['ui:options']?.catalogFilter;\n\n if (!catalogFilter) {\n return undefined;\n }\n\n if (Array.isArray(catalogFilter)) {\n return catalogFilter.map(convertSchemaFiltersToQuery);\n }\n\n return convertSchemaFiltersToQuery(catalogFilter);\n}\n"],"names":[],"mappings":";;;;;;;;;;;;AAqDa,MAAA,iBAAA,GAAoB,CAAC,KAAkC,KAAA;AAClE,EAAM,MAAA;AAAA,IACJ,QAAA;AAAA,IACA,MAAQ,EAAA,EAAE,KAAQ,GAAA,QAAA,EAAU,cAAc,4BAA6B,EAAA;AAAA,IACvE,QAAA;AAAA,IACA,QAAA;AAAA,IACA,SAAA;AAAA,IACA,QAAA;AAAA,IACA;AAAA,GACE,GAAA,KAAA;AAEJ,EAAM,MAAA,aAAA,GAAgB,mBAAmB,QAAQ,CAAA;AACjD,EAAM,MAAA,WAAA,GAAc,QAAS,CAAA,YAAY,CAAG,EAAA,WAAA;AAC5C,EAAA,MAAM,gBACJ,GAAA,QAAA,CAAS,YAAY,CAAA,EAAG,gBAAoB,IAAA,KAAA,CAAA;AAC9C,EAAM,MAAA,UAAA,GAAa,QAAW,GAAA,aAAa,CAAK,IAAA,KAAA;AAChD,EAAA,MAAM,CAAC,iBAAA,EAAmB,oBAAoB,CAAA,GAAI,SAAS,CAAC,CAAA;AAE5D,EAAM,MAAA,UAAA,GAAa,OAAO,aAAa,CAAA;AACvC,EAAM,MAAA,qBAAA,GAAwB,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AQ,CAAS,KAAA,KAAA;AACtB,IAAI,IAAA;AACF,MAAA,cAAA,CAAe,KAAK,CAAA;AAAA,KACd,CAAA,MAAA;AACN,MAAW,UAAA,CAAA,QAAA,CAAS,CAAG,EAAA,KAAK,CAA4B,0BAAA,CAAA,CAAA;AAAA;AAC1D,GACD,CAAA;AACH;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;AASA,SAAS,mBACP,QAC+B,EAAA;AAC/B,EAAM,MAAA,aAAA,GACJ,QAAS,CAAA,YAAY,CAAG,EAAA,aAAA;AAE1B,EAAA,IAAI,CAAC,aAAe,EAAA;AAClB,IAAO,OAAA,KAAA,CAAA;AAAA;AAGT,EAAI,IAAA,KAAA,CAAM,OAAQ,CAAA,aAAa,CAAG,EAAA;AAChC,IAAO,OAAA,aAAA,CAAc,IAAI,2BAA2B,CAAA;AAAA;AAGtD,EAAA,OAAO,4BAA4B,aAAa,CAAA;AAClD;;;;"}
|
|
1
|
+
{"version":3,"file":"MultiEntityPicker.esm.js","sources":["../../../../src/components/fields/MultiEntityPicker/MultiEntityPicker.tsx"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport {\n type EntityFilterQuery,\n CATALOG_FILTER_EXISTS,\n} from '@backstage/catalog-client';\nimport {\n Entity,\n parseEntityRef,\n stringifyEntityRef,\n} from '@backstage/catalog-model';\nimport { useApi } from '@backstage/core-plugin-api';\nimport {\n catalogApiRef,\n entityPresentationApiRef,\n EntityDisplayName,\n EntityRefPresentationSnapshot,\n} from '@backstage/plugin-catalog-react';\nimport TextField from '@material-ui/core/TextField';\nimport FormControl from '@material-ui/core/FormControl';\nimport Autocomplete, {\n AutocompleteChangeReason,\n} from '@material-ui/lab/Autocomplete';\nimport { useCallback, useEffect, useState } from 'react';\nimport useAsync from 'react-use/esm/useAsync';\nimport { FieldValidation } from '@rjsf/utils';\nimport {\n MultiEntityPickerFilterQueryValue,\n MultiEntityPickerProps,\n MultiEntityPickerUiOptions,\n MultiEntityPickerFilterQuery,\n} from './schema';\nimport { VirtualizedListbox } from '../VirtualizedListbox';\n\nexport { MultiEntityPickerSchema } from './schema';\n\n/**\n * The underlying component that is rendered in the form for the `MultiEntityPicker`\n * field extension.\n */\nexport const MultiEntityPicker = (props: MultiEntityPickerProps) => {\n const {\n onChange,\n schema: { title = 'Entity', description = 'An entity from the catalog' },\n required,\n uiSchema,\n rawErrors,\n formData,\n idSchema,\n } = props;\n\n const catalogFilter = buildCatalogFilter(uiSchema);\n const defaultKind = uiSchema['ui:options']?.defaultKind;\n const defaultNamespace =\n uiSchema['ui:options']?.defaultNamespace || undefined;\n const isDisabled = uiSchema?.['ui:disabled'] ?? false;\n const [noOfItemsSelected, setNoOfItemsSelected] = useState(0);\n\n const catalogApi = useApi(catalogApiRef);\n const entityPresentationApi = useApi(entityPresentationApiRef);\n const { value: entities, loading } = useAsync(async () => {\n const { items } = await catalogApi.getEntities(\n catalogFilter ? { filter: catalogFilter } : undefined,\n );\n const entityRefToPresentation = new Map<\n string,\n EntityRefPresentationSnapshot\n >(\n await Promise.all(\n items.map(async item => {\n const presentation = await entityPresentationApi.forEntity(item)\n .promise;\n return [stringifyEntityRef(item), presentation] as [\n string,\n EntityRefPresentationSnapshot,\n ];\n }),\n ),\n );\n return { entities: items, entityRefToPresentation };\n });\n const allowArbitraryValues =\n uiSchema['ui:options']?.allowArbitraryValues ?? true;\n\n // if not specified, maxItems defaults to undefined\n const maxItems = props.schema.maxItems;\n\n const onSelect = useCallback(\n (_: any, refs: (string | Entity)[], reason: AutocompleteChangeReason) => {\n const values = refs\n .map(ref => {\n if (typeof ref !== 'string') {\n // if ref does not exist: pass 'undefined' to trigger validation for required value\n return ref ? stringifyEntityRef(ref as Entity) : undefined;\n }\n if (reason === 'blur' || reason === 'create-option') {\n // Add in default namespace, etc.\n let entityRef = ref;\n try {\n // Attempt to parse the entity ref into it's full form.\n entityRef = stringifyEntityRef(\n parseEntityRef(ref as string, {\n defaultKind,\n defaultNamespace,\n }),\n );\n } catch (err) {\n // If the passed in value isn't an entity ref, do nothing.\n }\n\n // We need to check against formData here as that's the previous value for this field.\n if (formData?.includes(ref) || allowArbitraryValues) {\n return entityRef;\n }\n }\n\n return undefined;\n })\n .filter(ref => ref !== undefined) as string[];\n\n setNoOfItemsSelected(values.length);\n onChange(values);\n },\n [onChange, formData, defaultKind, defaultNamespace, allowArbitraryValues],\n );\n\n useEffect(() => {\n if (required && !allowArbitraryValues && entities?.entities?.length === 1) {\n onChange([stringifyEntityRef(entities?.entities[0])]);\n }\n }, [entities, onChange, required, allowArbitraryValues]);\n\n return (\n <FormControl\n margin=\"normal\"\n required={required}\n error={rawErrors?.length > 0 && !formData}\n >\n <Autocomplete\n multiple\n filterSelectedOptions\n disabled={\n isDisabled ||\n (required &&\n !allowArbitraryValues &&\n entities?.entities?.length === 1)\n }\n id={idSchema?.$id}\n defaultValue={formData}\n loading={loading}\n onChange={onSelect}\n options={entities?.entities || []}\n renderOption={option => <EntityDisplayName entityRef={option} />}\n getOptionLabel={option =>\n // option can be a string due to freeSolo.\n typeof option === 'string'\n ? option\n : entities?.entityRefToPresentation.get(stringifyEntityRef(option))\n ?.entityRef!\n }\n getOptionDisabled={_options =>\n maxItems ? noOfItemsSelected >= maxItems : false\n }\n autoSelect\n freeSolo={allowArbitraryValues}\n renderInput={params => (\n <TextField\n {...params}\n label={title}\n disabled={isDisabled}\n margin=\"dense\"\n helperText={description}\n FormHelperTextProps={{\n margin: 'dense',\n style: { marginLeft: 0 },\n }}\n variant=\"outlined\"\n required={required}\n InputProps={{\n ...params.InputProps,\n required: formData?.length === 0 && required,\n }}\n />\n )}\n ListboxComponent={VirtualizedListbox}\n />\n </FormControl>\n );\n};\n\nexport const validateMultiEntityPickerValidation = (\n values: string[],\n validation: FieldValidation,\n) => {\n values.forEach(value => {\n try {\n parseEntityRef(value);\n } catch {\n validation.addError(`${value} is not a valid entity ref`);\n }\n });\n};\n\n/**\n * Converts a special `{exists: true}` value to the `CATALOG_FILTER_EXISTS` symbol.\n *\n * @param value - The value to convert.\n * @returns The converted value.\n */\nfunction convertOpsValues(\n value: Exclude<MultiEntityPickerFilterQueryValue, Array<any>>,\n): string | symbol {\n if (typeof value === 'object' && value.exists) {\n return CATALOG_FILTER_EXISTS;\n }\n return value?.toString();\n}\n\n/**\n * Converts schema filters to entity filter query, replacing `{exists:true}` values\n * with the constant `CATALOG_FILTER_EXISTS`.\n *\n * @param schemaFilters - An object containing schema filters with keys as filter names\n * and values as filter values.\n * @returns An object with the same keys as the input object, but with `{exists:true}` values\n * transformed to `CATALOG_FILTER_EXISTS` symbol.\n */\nfunction convertSchemaFiltersToQuery(\n schemaFilters: MultiEntityPickerFilterQuery,\n): Exclude<EntityFilterQuery, Array<any>> {\n const query: EntityFilterQuery = {};\n\n for (const [key, value] of Object.entries(schemaFilters)) {\n if (Array.isArray(value)) {\n query[key] = value;\n } else {\n query[key] = convertOpsValues(value);\n }\n }\n\n return query;\n}\n\n/**\n * Builds an `EntityFilterQuery` based on the `uiSchema` passed in.\n * If `catalogFilter` is specified in the `uiSchema`, it is converted to a `EntityFilterQuery`.\n *\n * @param uiSchema The `uiSchema` of an `EntityPicker` component.\n * @returns An `EntityFilterQuery` based on the `uiSchema`, or `undefined` if `catalogFilter` is not specified in the `uiSchema`.\n */\nfunction buildCatalogFilter(\n uiSchema: MultiEntityPickerProps['uiSchema'],\n): EntityFilterQuery | undefined {\n const catalogFilter: MultiEntityPickerUiOptions['catalogFilter'] | undefined =\n uiSchema['ui:options']?.catalogFilter;\n\n if (!catalogFilter) {\n return undefined;\n }\n\n if (Array.isArray(catalogFilter)) {\n return catalogFilter.map(convertSchemaFiltersToQuery);\n }\n\n return convertSchemaFiltersToQuery(catalogFilter);\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;AAqDa,MAAA,iBAAA,GAAoB,CAAC,KAAkC,KAAA;AAClE,EAAM,MAAA;AAAA,IACJ,QAAA;AAAA,IACA,MAAQ,EAAA,EAAE,KAAQ,GAAA,QAAA,EAAU,cAAc,4BAA6B,EAAA;AAAA,IACvE,QAAA;AAAA,IACA,QAAA;AAAA,IACA,SAAA;AAAA,IACA,QAAA;AAAA,IACA;AAAA,GACE,GAAA,KAAA;AAEJ,EAAM,MAAA,aAAA,GAAgB,mBAAmB,QAAQ,CAAA;AACjD,EAAM,MAAA,WAAA,GAAc,QAAS,CAAA,YAAY,CAAG,EAAA,WAAA;AAC5C,EAAA,MAAM,gBACJ,GAAA,QAAA,CAAS,YAAY,CAAA,EAAG,gBAAoB,IAAA,KAAA,CAAA;AAC9C,EAAM,MAAA,UAAA,GAAa,QAAW,GAAA,aAAa,CAAK,IAAA,KAAA;AAChD,EAAA,MAAM,CAAC,iBAAA,EAAmB,o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
|
|
1
|
-
import
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { useEffect } from 'react';
|
|
2
3
|
import { useApi, identityApiRef, errorApiRef } from '@backstage/core-plugin-api';
|
|
3
4
|
import TextField from '@material-ui/core/TextField';
|
|
4
5
|
import FormControl from '@material-ui/core/FormControl';
|
|
@@ -59,44 +60,44 @@ const MyGroupsPicker = (props) => {
|
|
|
59
60
|
onChange(stringifyEntityRef(groups.catalogEntities[0]));
|
|
60
61
|
}
|
|
61
62
|
}, [groups, onChange, selectedEntity, required]);
|
|
62
|
-
return /* @__PURE__ */
|
|
63
|
+
return /* @__PURE__ */ jsx(
|
|
63
64
|
FormControl,
|
|
64
65
|
{
|
|
65
66
|
margin: "normal",
|
|
66
67
|
required,
|
|
67
|
-
error: rawErrors?.length > 0
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
68
|
+
error: rawErrors?.length > 0,
|
|
69
|
+
children: /* @__PURE__ */ jsx(
|
|
70
|
+
Autocomplete,
|
|
71
|
+
{
|
|
72
|
+
disabled: required && groups?.catalogEntities.length === 1,
|
|
73
|
+
id: "OwnershipEntityRefPicker-dropdown",
|
|
74
|
+
options: groups?.catalogEntities || [],
|
|
75
|
+
value: selectedEntity,
|
|
76
|
+
loading,
|
|
77
|
+
onChange: updateChange,
|
|
78
|
+
getOptionLabel: (option) => groups?.entityRefToPresentation.get(stringifyEntityRef(option))?.primaryTitle,
|
|
79
|
+
autoSelect: true,
|
|
80
|
+
renderInput: (params) => /* @__PURE__ */ jsx(
|
|
81
|
+
TextField,
|
|
82
|
+
{
|
|
83
|
+
...params,
|
|
84
|
+
label: title,
|
|
85
|
+
margin: "dense",
|
|
86
|
+
helperText: description,
|
|
87
|
+
FormHelperTextProps: { margin: "dense", style: { marginLeft: 0 } },
|
|
88
|
+
variant: "outlined",
|
|
89
|
+
required,
|
|
90
|
+
InputProps: params.InputProps
|
|
91
|
+
}
|
|
92
|
+
),
|
|
93
|
+
renderOption: (option) => /* @__PURE__ */ jsx(EntityDisplayName, { entityRef: option }),
|
|
94
|
+
filterOptions: createFilterOptions({
|
|
95
|
+
stringify: (option) => groups?.entityRefToPresentation.get(stringifyEntityRef(option))?.primaryTitle
|
|
96
|
+
}),
|
|
97
|
+
ListboxComponent: VirtualizedListbox
|
|
98
|
+
}
|
|
99
|
+
)
|
|
100
|
+
}
|
|
100
101
|
);
|
|
101
102
|
};
|
|
102
103
|
|
|
@@ -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
|
|
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 FormControl from '@material-ui/core/FormControl';\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';\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 } = props;\n\n const identityApi = useApi(identityApiRef);\n const catalogApi = useApi(catalogApiRef);\n const errorApi = useApi(errorApiRef);\n const entityPresentationApi = useApi(entityPresentationApiRef);\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 <FormControl\n margin=\"normal\"\n required={required}\n error={rawErrors?.length > 0}\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 helperText={description}\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 </FormControl>\n );\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;;AA2Ca,MAAA,cAAA,GAAiB,CAAC,KAA+B,KAAA;AAC5D,EAAA,MAAM,EAAE,CAAA,EAAM,GAAA,iBAAA,CAAkB,wBAAwB,CAAA;AACxD,EAAM,MAAA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A,YAAA;AAAA,UAEN,UAAU,EAAA,IAAA;AAAA,UACV,aAAa,CACX,MAAA,qBAAA,GAAA;AAAA,YAAC,SAAA;AAAA,YAAA;AAAA,cACE,GAAG,MAAA;AAAA,cACJ,KAAO,EAAA,KAAA;AAAA,cACP,MAAO,EAAA,OAAA;AAAA,cACP,UAAY,EAAA,WAAA;AAAA,cACZ,mBAAA,EAAqB,EAAE,MAAQ,EAAA,OAAA,EAAS,OAAO,EAAE,UAAA,EAAY,GAAI,EAAA;AAAA,cACjE,OAAQ,EAAA,UAAA;AAAA,cACR,QAAA;AAAA,cACA,YAAY,MAAO,CAAA;AAAA;AAAA,WACrB;AAAA,UAEF,YAAc,EAAA,CAAA,MAAA,qBAAW,GAAA,CAAA,iBAAA,EAAA,EAAkB,WAAW,MAAQ,EAAA,CAAA;AAAA,UAC9D,eAAe,mBAA4B,CAAA;AAAA,YACzC,SAAA,EAAW,YACT,MAAQ,EAAA,uBAAA,CAAwB,IAAI,kBAAmB,CAAA,MAAM,CAAC,CAC1D,EAAA;AAAA,WACP,CAAA;AAAA,UACD,gBAAkB,EAAA;AAAA;AAAA;AACpB;AAAA,GACF;AAEJ;;;;"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
1
2
|
import { RELATION_OWNED_BY } from '@backstage/catalog-model';
|
|
2
3
|
import { useApi, identityApiRef } from '@backstage/core-plugin-api';
|
|
3
4
|
import TextField from '@material-ui/core/TextField';
|
|
4
5
|
import Autocomplete from '@material-ui/lab/Autocomplete';
|
|
5
|
-
import React from 'react';
|
|
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';
|
|
@@ -25,11 +25,11 @@ const OwnedEntityPicker = (props) => {
|
|
|
25
25
|
return identity.ownershipEntityRefs;
|
|
26
26
|
});
|
|
27
27
|
if (loading)
|
|
28
|
-
return /* @__PURE__ */
|
|
28
|
+
return /* @__PURE__ */ jsx(
|
|
29
29
|
Autocomplete,
|
|
30
30
|
{
|
|
31
31
|
loading,
|
|
32
|
-
renderInput: (params) => /* @__PURE__ */
|
|
32
|
+
renderInput: (params) => /* @__PURE__ */ jsx(
|
|
33
33
|
TextField,
|
|
34
34
|
{
|
|
35
35
|
...params,
|
|
@@ -49,7 +49,7 @@ const OwnedEntityPicker = (props) => {
|
|
|
49
49
|
uiSchema,
|
|
50
50
|
identityRefs
|
|
51
51
|
);
|
|
52
|
-
return /* @__PURE__ */
|
|
52
|
+
return /* @__PURE__ */ jsx(EntityPicker, { ...props, uiSchema: entityPickerUISchema });
|
|
53
53
|
};
|
|
54
54
|
function buildEntityPickerUISchema(uiSchema, identityRefs) {
|
|
55
55
|
const uiOptions = uiSchema?.["ui:options"] || {};
|
|
@@ -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 Autocomplete from '@material-ui/lab/Autocomplete';\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 Autocomplete 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';\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 {\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 return (\n <Autocomplete\n loading={loading}\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 InputProps={params.InputProps}\n />\n )}\n options={[]}\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 };\n}\n\nfunction asArray(catalogFilter: any): any[] {\n if (catalogFilter) {\n return Array.isArray(catalogFilter) ? catalogFilter : [catalogFilter];\n }\n return [{}];\n}\n"],"names":[],"mappings":";;;;;;;;;;;AAmCa,MAAA,iBAAA,GAAoB,CAAC,KAAkC,KAAA;AAClE,EAAA,MAAM,EAAE,CAAA,EAAM,GAAA,iBAAA,CAAkB,wBAAwB,CAAA;AACxD,EAAM,MAAA;AAAA,IACJ,MAAQ,EAAA;AAAA,MACN,KAAA,GAAQ,EAAE,gCAAgC,CAAA;AAAA,MAC1C,WAAA,GAAc,EAAE,sCAAsC;AAAA,KACxD;AAAA,IACA,QAAA;AAAA,IACA;AAAA,GACE,GAAA,KAAA;AAEJ,EAAM,MAAA,WAAA,GAAc,OAAO,cAAc,CAAA;AACzC,EAAA,MAAM,EAAE,OAAS,EAAA,KAAA,EAAO,YAAa,EAAA,GAAI,SAAS,YAAY;AAC5D,IAAM,MAAA,QAAA,GAAW,MAAM,WAAA,CAA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;AAAA,IACL,YAAc,EAAA;AAAA,MACZ,GAAG,YAAA;AAAA,MACH;AAAA;AACF,GACF;AACF;AAEA,SAAS,QAAQ,aAA2B,EAAA;AAC1C,EAAA,IAAI,aAAe,EAAA;AACjB,IAAA,OAAO,MAAM,OAAQ,CAAA,aAAa,CAAI,GAAA,aAAA,GAAgB,CAAC,aAAa,CAAA;AAAA;AAEtE,EAAO,OAAA,CAAC,EAAE,CAAA;AACZ;;;;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
2
|
import { EntityPicker } from '../EntityPicker/EntityPicker.esm.js';
|
|
3
3
|
import { useTranslationRef } from '@backstage/core-plugin-api/alpha';
|
|
4
4
|
import { scaffolderTranslationRef } from '../../../translation.esm.js';
|
|
@@ -28,7 +28,7 @@ const OwnerPicker = (props) => {
|
|
|
28
28
|
...defaultNamespace !== void 0 ? { defaultNamespace } : {}
|
|
29
29
|
}
|
|
30
30
|
};
|
|
31
|
-
return /* @__PURE__ */
|
|
31
|
+
return /* @__PURE__ */ jsx(
|
|
32
32
|
EntityPicker,
|
|
33
33
|
{
|
|
34
34
|
...restProps,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OwnerPicker.esm.js","sources":["../../../../src/components/fields/OwnerPicker/OwnerPicker.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":"OwnerPicker.esm.js","sources":["../../../../src/components/fields/OwnerPicker/OwnerPicker.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 { EntityPicker } from '../EntityPicker/EntityPicker';\nimport { OwnerPickerProps } from './schema';\nimport { useTranslationRef } from '@backstage/core-plugin-api/alpha';\nimport { scaffolderTranslationRef } from '../../../translation';\n\nexport { OwnerPickerSchema } from './schema';\n\n/**\n * The underlying component that is rendered in the form for the `OwnerPicker`\n * field extension.\n *\n * @public\n */\nexport const OwnerPicker = (props: OwnerPickerProps) => {\n const { t } = useTranslationRef(scaffolderTranslationRef);\n const {\n schema: {\n title = t('fields.ownerPicker.title'),\n description = t('fields.ownerPicker.description'),\n },\n uiSchema,\n ...restProps\n } = props;\n\n const defaultNamespace = uiSchema['ui:options']?.defaultNamespace;\n const allowedKinds = uiSchema['ui:options']?.allowedKinds;\n\n const catalogFilter = uiSchema['ui:options']?.catalogFilter || {\n kind: allowedKinds || ['Group', 'User'],\n };\n\n const ownerUiSchema = {\n ...uiSchema,\n 'ui:options': {\n catalogFilter,\n defaultKind: 'Group',\n allowArbitraryValues:\n uiSchema['ui:options']?.allowArbitraryValues ?? true,\n ...(defaultNamespace !== undefined ? { defaultNamespace } : {}),\n },\n };\n\n return (\n <EntityPicker\n {...restProps}\n schema={{ title, description }}\n uiSchema={ownerUiSchema}\n />\n );\n};\n"],"names":[],"mappings":";;;;;;AA4Ba,MAAA,WAAA,GAAc,CAAC,KAA4B,KAAA;AACtD,EAAA,MAAM,EAAE,CAAA,EAAM,GAAA,iBAAA,CAAkB,wBAAwB,CAAA;AACxD,EAAM,MAAA;AAAA,IACJ,MAAQ,EAAA;AAAA,MACN,KAAA,GAAQ,EAAE,0BAA0B,CAAA;AAAA,MACpC,WAAA,GAAc,EAAE,gCAAgC;AAAA,KAClD;AAAA,IACA,QAAA;AAAA,IACA,GAAG;AAAA,GACD,GAAA,KAAA;AAEJ,EAAM,MAAA,gBAAA,GAAmB,QAAS,CAAA,YAAY,CAAG,EAAA,gBAAA;AACjD,EAAM,MAAA,YAAA,GAAe,QAAS,CAAA,YAAY,CAAG,EAAA,YAAA;AAE7C,EAAA,MAAM,aAAgB,GAAA,QAAA,CAAS,YAAY,CAAA,EAAG,aAAiB,IAAA;AAAA,IAC7D,IAAM,EAAA,YAAA,IAAgB,CAAC,OAAA,EAAS,MAAM;AAAA,GACxC;AAEA,EAAA,MAAM,aAAgB,GAAA;AAAA,IACpB,GAAG,QAAA;AAAA,IACH,YAAc,EAAA;AAAA,MACZ,aAAA;AAAA,MACA,WAAa,EAAA,OAAA;AAAA,MACb,oBACE,EAAA,QAAA,CAAS,YAAY,CAAA,EAAG,oBAAwB,IAAA,IAAA;AAAA,MAClD,GAAI,gBAAqB,KAAA,KAAA,CAAA,GAAY,EAAE,gBAAA,KAAqB;AAAC;AAC/D,GACF;AAEA,EACE,uBAAA,GAAA;AAAA,IAAC,YAAA;AAAA,IAAA;AAAA,MACE,GAAG,SAAA;AAAA,MACJ,MAAA,EAAQ,EAAE,KAAA,EAAO,WAAY,EAAA;AAAA,MAC7B,QAAU,EAAA;AAAA;AAAA,GACZ;AAEJ;;;;"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
1
2
|
import { useApi } from '@backstage/core-plugin-api';
|
|
2
3
|
import { scaffolderApiRef } from '@backstage/plugin-scaffolder-react';
|
|
3
4
|
import FormControl from '@material-ui/core/FormControl';
|
|
4
5
|
import FormHelperText from '@material-ui/core/FormHelperText';
|
|
5
6
|
import TextField from '@material-ui/core/TextField';
|
|
6
7
|
import Autocomplete from '@material-ui/lab/Autocomplete';
|
|
7
|
-
import
|
|
8
|
+
import { useState, useCallback } from 'react';
|
|
8
9
|
import useDebounce from 'react-use/esm/useDebounce';
|
|
9
10
|
|
|
10
11
|
const BitbucketRepoBranchPicker = ({
|
|
@@ -35,36 +36,38 @@ const BitbucketRepoBranchPicker = ({
|
|
|
35
36
|
});
|
|
36
37
|
}, [host, workspace, repository, accessToken, scaffolderApi]);
|
|
37
38
|
useDebounce(updateAvailableBranches, 500, [updateAvailableBranches]);
|
|
38
|
-
return /* @__PURE__ */
|
|
39
|
+
return /* @__PURE__ */ jsxs(
|
|
39
40
|
FormControl,
|
|
40
41
|
{
|
|
41
42
|
margin: "normal",
|
|
42
43
|
required,
|
|
43
|
-
error: rawErrors?.length > 0 && !branch
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
{
|
|
48
|
-
value: branch,
|
|
49
|
-
onChange: (_, newValue) => {
|
|
50
|
-
onChange({ branch: newValue || "" });
|
|
51
|
-
},
|
|
52
|
-
disabled: isDisabled,
|
|
53
|
-
options: availableBranches,
|
|
54
|
-
renderInput: (params) => /* @__PURE__ */ React.createElement(
|
|
55
|
-
TextField,
|
|
44
|
+
error: rawErrors?.length > 0 && !branch,
|
|
45
|
+
children: [
|
|
46
|
+
/* @__PURE__ */ jsx(
|
|
47
|
+
Autocomplete,
|
|
56
48
|
{
|
|
57
|
-
|
|
58
|
-
|
|
49
|
+
value: branch,
|
|
50
|
+
onChange: (_, newValue) => {
|
|
51
|
+
onChange({ branch: newValue || "" });
|
|
52
|
+
},
|
|
59
53
|
disabled: isDisabled,
|
|
60
|
-
|
|
54
|
+
options: availableBranches,
|
|
55
|
+
renderInput: (params) => /* @__PURE__ */ jsx(
|
|
56
|
+
TextField,
|
|
57
|
+
{
|
|
58
|
+
...params,
|
|
59
|
+
label: "Branch",
|
|
60
|
+
disabled: isDisabled,
|
|
61
|
+
required
|
|
62
|
+
}
|
|
63
|
+
),
|
|
64
|
+
freeSolo: true,
|
|
65
|
+
autoSelect: true
|
|
61
66
|
}
|
|
62
67
|
),
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
),
|
|
67
|
-
/* @__PURE__ */ React.createElement(FormHelperText, null, "The branch of the repository")
|
|
68
|
+
/* @__PURE__ */ jsx(FormHelperText, { children: "The branch of the repository" })
|
|
69
|
+
]
|
|
70
|
+
}
|
|
68
71
|
);
|
|
69
72
|
};
|
|
70
73
|
|
|
@@ -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 TextField from '@material-ui/core/TextField';\nimport Autocomplete from '@material-ui/lab/Autocomplete';\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 TextField from '@material-ui/core/TextField';\nimport Autocomplete from '@material-ui/lab/Autocomplete';\nimport { useCallback, useState } from 'react';\nimport useDebounce from 'react-use/esm/useDebounce';\nimport { BaseRepoBranchPickerProps } from './types';\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 { 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 return (\n <FormControl\n margin=\"normal\"\n required={required}\n error={rawErrors?.length > 0 && !branch}\n >\n <Autocomplete\n value={branch}\n onChange={(_, newValue) => {\n onChange({ branch: newValue || '' });\n }}\n disabled={isDisabled}\n options={availableBranches}\n renderInput={params => (\n <TextField\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</F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AA;AAAA,IAAC,WAAA;AAAA,IAAA;AAAA,MACC,MAAO,EAAA,QAAA;AAAA,MACP,QAAA;AAAA,MACA,KAAO,EAAA,SAAA,EAAW,MAAS,GAAA,CAAA,IAAK,CAAC,MAAA;AAAA,MAEjC,QAAA,EAAA;AAAA,wBAAA,GAAA;AAAA,UAAC,YAAA;AAAA,UAAA;AAAA,YACC,KAAO,EAAA,MAAA;AAAA,YACP,QAAA,EAAU,CAAC,CAAA,EAAG,QAAa,KAAA;AACzB,cAAA,QAAA,CAAS,EAAE,MAAA,EAAQ,QAAY,IAAA,EAAA,EAAI,CAAA;AAAA,aACrC;AAAA,YACA,QAAU,EAAA,UAAA;AAAA,YACV,OAAS,EAAA,iBAAA;AAAA,YACT,aAAa,CACX,MAAA,qBAAA,GAAA;AAAA,cAAC,SAAA;AAAA,cAAA;AAAA,gBACE,GAAG,MAAA;AAAA,gBACJ,KAAM,EAAA,QAAA;AAAA,gBACN,QAAU,EAAA,UAAA;AAAA,gBACV;AAAA;AAAA,aACF;AAAA,YAEF,QAAQ,EAAA,IAAA;AAAA,YACR,UAAU,EAAA;AAAA;AAAA,SACZ;AAAA,wBACA,GAAA,CAAC,kBAAe,QAA4B,EAAA,8BAAA,EAAA;AAAA;AAAA;AAAA,GAC9C;AAEJ;;;;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
1
2
|
import FormControl from '@material-ui/core/FormControl';
|
|
2
|
-
import React from 'react';
|
|
3
3
|
import FormHelperText from '@material-ui/core/FormHelperText';
|
|
4
4
|
import TextField from '@material-ui/core/TextField';
|
|
5
5
|
|
|
@@ -11,24 +11,26 @@ const DefaultRepoBranchPicker = ({
|
|
|
11
11
|
required
|
|
12
12
|
}) => {
|
|
13
13
|
const { branch } = state;
|
|
14
|
-
return /* @__PURE__ */
|
|
14
|
+
return /* @__PURE__ */ jsxs(
|
|
15
15
|
FormControl,
|
|
16
16
|
{
|
|
17
17
|
margin: "normal",
|
|
18
18
|
required,
|
|
19
|
-
error: rawErrors?.length > 0 && !branch
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
19
|
+
error: rawErrors?.length > 0 && !branch,
|
|
20
|
+
children: [
|
|
21
|
+
/* @__PURE__ */ jsx(
|
|
22
|
+
TextField,
|
|
23
|
+
{
|
|
24
|
+
id: "branchInput",
|
|
25
|
+
label: "Branch",
|
|
26
|
+
disabled: isDisabled,
|
|
27
|
+
onChange: (e) => onChange({ branch: e.target.value }),
|
|
28
|
+
value: branch
|
|
29
|
+
}
|
|
30
|
+
),
|
|
31
|
+
/* @__PURE__ */ jsx(FormHelperText, { children: "The branch of the repository" })
|
|
32
|
+
]
|
|
33
|
+
}
|
|
32
34
|
);
|
|
33
35
|
};
|
|
34
36
|
|
|
@@ -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
|
|
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 TextField from '@material-ui/core/TextField';\n\nimport { BaseRepoBranchPickerProps } from './types';\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 { branch } = state;\n\n return (\n <FormControl\n margin=\"normal\"\n required={required}\n error={rawErrors?.length > 0 && !branch}\n >\n <TextField\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":[],"mappings":";;;;;AA6BO,MAAM,0BAA0B,CAAC;AAAA,EACtC,QAAA;AAAA,EACA,KAAA;AAAA,EACA,SAAA;AAAA,EACA,UAAA;AAAA,EACA;AACF,CAAiC,KAAA;AAC/B,EAAM,MAAA,EAAE,QAAW,GAAA,KAAA;AAEnB,EACE,uBAAA,IAAA;AAAA,IAAC,WAAA;AAAA,IAAA;AAAA,MACC,MAAO,EAAA,QAAA;AAAA,MACP,QAAA;AAAA,MACA,KAAO,EAAA,SAAA,EAAW,MAAS,GAAA,CAAA,IAAK,CAAC,MAAA;AAAA,MAEjC,QAAA,EAAA;AAAA,wBAAA,GAAA;AAAA,UAAC,SAAA;AAAA,UAAA;AAAA,YACC,EAAG,EAAA,aAAA;AAAA,YACH,KAAM,EAAA,QAAA;AAAA,YACN,QAAU,EAAA,UAAA;AAAA,YACV,QAAA,EAAU,OAAK,QAAS,CAAA,EAAE,QAAQ,CAAE,CAAA,MAAA,CAAO,OAAO,CAAA;AAAA,YAClD,KAAO,EAAA;AAAA;AAAA,SACT;AAAA,wBACA,GAAA,CAAC,kBAAe,QAA4B,EAAA,8BAAA,EAAA;AAAA;AAAA;AAAA,GAC9C;AAEJ;;;;"}
|