From 90fbd943deb1560bb9acff3c99aa217eecc0ef3c Mon Sep 17 00:00:00 2001 From: lukzerom Date: Sat, 11 Dec 2021 00:35:19 +0100 Subject: [PATCH 01/17] Basic select api changes and adjustments ready Signed-off-by: lukzerom --- .../src/components/Select/Select.tsx | 55 +++++++---- .../src/components/Select/index.tsx | 7 +- .../fields/RepoUrlPicker/RepoUrlPicker.tsx | 93 ++++++++++--------- 3 files changed, 96 insertions(+), 59 deletions(-) diff --git a/packages/core-components/src/components/Select/Select.tsx b/packages/core-components/src/components/Select/Select.tsx index a0e3aba94b..53a9a4800a 100644 --- a/packages/core-components/src/components/Select/Select.tsx +++ b/packages/core-components/src/components/Select/Select.tsx @@ -21,13 +21,13 @@ import FormControl from '@material-ui/core/FormControl'; import InputBase from '@material-ui/core/InputBase'; import MenuItem from '@material-ui/core/MenuItem'; import Select from '@material-ui/core/Select'; -import Typography from '@material-ui/core/Typography'; import { createStyles, makeStyles, Theme, withStyles, } from '@material-ui/core/styles'; +import Typography from '@material-ui/core/Typography'; import React, { useEffect, useState } from 'react'; import ClosedDropdown from './static/ClosedDropdown'; import OpenedDropdown from './static/OpenedDropdown'; @@ -92,7 +92,14 @@ const useStyles = makeStyles( chip: { margin: 2, }, + checkbox: {}, + select: { + '&:hover': { + cursor: 'not-allowed', + }, + }, + root: { display: 'flex', flexDirection: 'column', @@ -101,12 +108,12 @@ const useStyles = makeStyles( { name: 'BackstageSelect' }, ); -type Item = { +export type Item = { label: string; value: string | number; }; -type Selection = string | string[] | number | number[]; +export type Selection = string | string[] | number | number[]; export type SelectProps = { multiple?: boolean; @@ -116,6 +123,8 @@ export type SelectProps = { selected?: Selection; onChange: (arg: Selection) => void; triggerReset?: boolean; + native?: boolean; + disabled?: boolean; }; export function SelectComponent(props: SelectProps) { @@ -127,6 +136,8 @@ export function SelectComponent(props: SelectProps) { selected, onChange, triggerReset, + native = false, + disabled = false, } = props; const classes = useStyles(); const [value, setValue] = useState( @@ -150,6 +161,9 @@ export function SelectComponent(props: SelectProps) { }; const handleClick = (event: React.ChangeEvent) => { + // if (disabled) { + // return event.preventDefault(); + // } setOpen(previous => { if (multiple && !(event.target instanceof HTMLElement)) { return true; @@ -175,6 +189,8 @@ export function SelectComponent(props: SelectProps) { diff --git a/packages/core-components/src/components/Select/index.tsx b/packages/core-components/src/components/Select/index.tsx index 0f149f05b5..8c9ae28ac8 100644 --- a/packages/core-components/src/components/Select/index.tsx +++ b/packages/core-components/src/components/Select/index.tsx @@ -15,6 +15,11 @@ */ export { SelectComponent as Select } from './Select'; -export type { SelectClassKey, SelectInputBaseClassKey } from './Select'; +export type { + Item, + SelectClassKey, + SelectInputBaseClassKey, + Selection, +} from './Select'; export type { ClosedDropdownClassKey } from './static/ClosedDropdown'; export type { OpenedDropdownClassKey } from './static/OpenedDropdown'; diff --git a/plugins/scaffolder/src/components/fields/RepoUrlPicker/RepoUrlPicker.tsx b/plugins/scaffolder/src/components/fields/RepoUrlPicker/RepoUrlPicker.tsx index c4b1e79262..42e24cc998 100644 --- a/plugins/scaffolder/src/components/fields/RepoUrlPicker/RepoUrlPicker.tsx +++ b/plugins/scaffolder/src/components/fields/RepoUrlPicker/RepoUrlPicker.tsx @@ -13,19 +13,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import React, { useCallback, useEffect } from 'react'; -import { FieldProps } from '@rjsf/core'; -import { scaffolderApiRef } from '../../../api'; +import { Item, Progress, Select, Selection } from '@backstage/core-components'; +import { useApi } from '@backstage/core-plugin-api'; import { scmIntegrationsApiRef } from '@backstage/integration-react'; -import { useAsync } from 'react-use'; -import Select from '@material-ui/core/Select'; -import InputLabel from '@material-ui/core/InputLabel'; -import Input from '@material-ui/core/Input'; import FormControl from '@material-ui/core/FormControl'; import FormHelperText from '@material-ui/core/FormHelperText'; - -import { useApi } from '@backstage/core-plugin-api'; -import { Progress } from '@backstage/core-components'; +import Input from '@material-ui/core/Input'; +import InputLabel from '@material-ui/core/InputLabel'; +import { FieldProps } from '@rjsf/core'; +import React, { useCallback, useEffect } from 'react'; +import { useAsync } from 'react-use'; +import { scaffolderApiRef } from '../../../api'; function splitFormData(url: string | undefined, allowedOwners?: string[]) { let host = undefined; @@ -106,10 +104,10 @@ export const RepoUrlPicker = ({ allowedOwners, ); const updateHost = useCallback( - (evt: React.ChangeEvent<{ name?: string; value: unknown }>) => { + (value: Selection) => { onChange( serializeFormData({ - host: evt.target.value as string, + host: value as string, owner, repo, organization, @@ -121,6 +119,21 @@ export const RepoUrlPicker = ({ [onChange, owner, repo, organization, workspace, project], ); + const updateOwnerSelect = useCallback( + (value: Selection) => + onChange( + serializeFormData({ + host, + owner: value as string, + repo, + organization, + workspace, + project, + }), + ), + [onChange, host, repo, organization, workspace, project], + ); + const updateOwner = useCallback( (evt: React.ChangeEvent<{ name?: string; value: unknown }>) => onChange( @@ -224,6 +237,16 @@ export const RepoUrlPicker = ({ return ; } + const hostsOptions: Item[] = integrations + ? integrations + .filter(i => allowedHosts?.includes(i.host)) + .map(i => ({ label: i.title, value: i.host })) + : [{ label: 'Loading...', value: 'loading' }]; + + const ownersOptions: Item[] = allowedOwners + ? allowedOwners.map(i => ({ label: i, value: i })) + : [{ label: 'Loading...', value: 'loading' }]; + return ( <> 0 && !host} > - Host - + - {allowedOwners ? ( - allowedOwners.map(i => ( - - )) - ) : ( -

loading

- )} - ; - + label="Owner Available" + onChange={updateOwnerSelect} + disabled={ownersOptions.length === 1} + selected={owner} + items={ownersOptions} + /> + The organization, user or project that this repo will belong to From 919ffa9b539b7f295ccea4a1217027a2e9e9f1a8 Mon Sep 17 00:00:00 2001 From: lukzerom Date: Sat, 11 Dec 2021 00:36:46 +0100 Subject: [PATCH 02/17] click handler adjustment Signed-off-by: lukzerom --- packages/core-components/src/components/Select/Select.tsx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/core-components/src/components/Select/Select.tsx b/packages/core-components/src/components/Select/Select.tsx index 53a9a4800a..02e45c8334 100644 --- a/packages/core-components/src/components/Select/Select.tsx +++ b/packages/core-components/src/components/Select/Select.tsx @@ -161,9 +161,10 @@ export function SelectComponent(props: SelectProps) { }; const handleClick = (event: React.ChangeEvent) => { - // if (disabled) { - // return event.preventDefault(); - // } + if (disabled) { + event.preventDefault(); + return; + } setOpen(previous => { if (multiple && !(event.target instanceof HTMLElement)) { return true; From 56a5466790e3b8d4cbe21e5ae861a23bcfa51d93 Mon Sep 17 00:00:00 2001 From: lukzerom Date: Sat, 11 Dec 2021 00:51:26 +0100 Subject: [PATCH 03/17] eslint adjustments Signed-off-by: lukzerom --- .../fields/EntityPicker/EntityPicker.tsx | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/plugins/scaffolder/src/components/fields/EntityPicker/EntityPicker.tsx b/plugins/scaffolder/src/components/fields/EntityPicker/EntityPicker.tsx index a8ef524a13..d491af1da4 100644 --- a/plugins/scaffolder/src/components/fields/EntityPicker/EntityPicker.tsx +++ b/plugins/scaffolder/src/components/fields/EntityPicker/EntityPicker.tsx @@ -22,7 +22,7 @@ import { TextField } from '@material-ui/core'; import FormControl from '@material-ui/core/FormControl'; import Autocomplete from '@material-ui/lab/Autocomplete'; import { FieldProps } from '@rjsf/core'; -import React from 'react'; +import React, { useCallback, useEffect } from 'react'; import { useAsync } from 'react-use'; export const EntityPicker = ({ @@ -48,9 +48,18 @@ export const EntityPicker = ({ formatEntityRefTitle(e, { defaultKind }), ); - const onSelect = (_: any, value: string | null) => { - onChange(value || ''); - }; + const onSelect = useCallback( + (_: any, value: string | null) => { + onChange(value || ''); + }, + [onChange], + ); + + useEffect(() => { + if (entityRefs?.length === 1) { + onSelect('', entityRefs[0]); + } + }, [entityRefs, onSelect]); return ( 0 && !formData} > Date: Sat, 11 Dec 2021 01:07:35 +0100 Subject: [PATCH 04/17] Select changeset Signed-off-by: lukzerom --- .changeset/curvy-walls-itch.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/curvy-walls-itch.md diff --git a/.changeset/curvy-walls-itch.md b/.changeset/curvy-walls-itch.md new file mode 100644 index 0000000000..18f35a6e24 --- /dev/null +++ b/.changeset/curvy-walls-itch.md @@ -0,0 +1,5 @@ +--- +'@backstage/core-components': minor +--- + +Select component has extended API with few more props From 7b5d40c2410556378abddf20e1cae0f367174e82 Mon Sep 17 00:00:00 2001 From: lukzerom Date: Sat, 11 Dec 2021 01:12:24 +0100 Subject: [PATCH 05/17] changeset scaffolder Signed-off-by: lukzerom --- .changeset/beige-balloons-grin.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/beige-balloons-grin.md diff --git a/.changeset/beige-balloons-grin.md b/.changeset/beige-balloons-grin.md new file mode 100644 index 0000000000..9ce1e0b6b5 --- /dev/null +++ b/.changeset/beige-balloons-grin.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-scaffolder': minor +--- + +When user will have one option available in hostUrl or owner - autoselect and select component should be readonly From 625240c4baa57eea9e82f3b147139edad0a9712c Mon Sep 17 00:00:00 2001 From: lukzerom Date: Sat, 11 Dec 2021 01:14:13 +0100 Subject: [PATCH 06/17] clean Signed-off-by: lukzerom --- packages/core-components/src/components/Select/Select.tsx | 6 ------ 1 file changed, 6 deletions(-) diff --git a/packages/core-components/src/components/Select/Select.tsx b/packages/core-components/src/components/Select/Select.tsx index 02e45c8334..3b6582865c 100644 --- a/packages/core-components/src/components/Select/Select.tsx +++ b/packages/core-components/src/components/Select/Select.tsx @@ -92,13 +92,7 @@ const useStyles = makeStyles( chip: { margin: 2, }, - checkbox: {}, - select: { - '&:hover': { - cursor: 'not-allowed', - }, - }, root: { display: 'flex', From 846773cf453aaf3e4c947f7b9dd6d03792f6b807 Mon Sep 17 00:00:00 2001 From: lukzerom Date: Sun, 12 Dec 2021 13:13:55 +0100 Subject: [PATCH 07/17] added docs Signed-off-by: lukzerom --- packages/core-components/api-report.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/packages/core-components/api-report.md b/packages/core-components/api-report.md index d098403113..72d47b494c 100644 --- a/packages/core-components/api-report.md +++ b/packages/core-components/api-report.md @@ -528,6 +528,14 @@ export type InfoCardVariants = 'flex' | 'fullHeight' | 'gridItem'; // @public (undocumented) export function IntroCard(props: IntroCardProps): JSX.Element; +// Warning: (ae-missing-release-tag) "Item" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) +// +// @public (undocumented) +export type Item = { + label: string; + value: string | number; +}; + // Warning: (tsdoc-malformed-html-name) Invalid HTML element: Expecting an HTML name // Warning: (tsdoc-escape-greater-than) The ">" character should be escaped using a backslash to avoid confusion with an HTML tag // Warning: (ae-forgotten-export) The symbol "ItemCardProps" needs to be exported by the entry point index.d.ts @@ -835,6 +843,12 @@ export type SelectClassKey = // @public (undocumented) export type SelectInputBaseClassKey = 'root' | 'input'; +// Warning: (ae-missing-release-tag) "Selection" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) +// +// @public (undocumented) +type Selection_2 = string | string[] | number | number[]; +export { Selection_2 as Selection }; + // Warning: (ae-forgotten-export) The symbol "Props" needs to be exported by the entry point index.d.ts // Warning: (ae-missing-release-tag) "Sidebar" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // From 45ddfa099b1d5c18ce20860eceda09116d3b14e0 Mon Sep 17 00:00:00 2001 From: lukzerom Date: Sun, 12 Dec 2021 13:16:13 +0100 Subject: [PATCH 08/17] added autoselect to vocab txt Signed-off-by: lukzerom --- .github/styles/vocab.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/styles/vocab.txt b/.github/styles/vocab.txt index 4ec62923d8..a1bc30d73a 100644 --- a/.github/styles/vocab.txt +++ b/.github/styles/vocab.txt @@ -12,6 +12,7 @@ Atlassian automations autoscaling Autoscaling +autoselect Avro backrub Bigtable From faaa7f009cb0645a793452710972441e3811faf1 Mon Sep 17 00:00:00 2001 From: lukzerom Date: Tue, 14 Dec 2021 17:49:16 +0100 Subject: [PATCH 09/17] changed type name to select item Signed-off-by: lukzerom --- .../core-components/src/components/Select/Select.tsx | 4 ++-- .../core-components/src/components/Select/index.tsx | 2 +- .../components/fields/RepoUrlPicker/RepoUrlPicker.tsx | 11 ++++++++--- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/packages/core-components/src/components/Select/Select.tsx b/packages/core-components/src/components/Select/Select.tsx index 3b6582865c..b5a641acd4 100644 --- a/packages/core-components/src/components/Select/Select.tsx +++ b/packages/core-components/src/components/Select/Select.tsx @@ -102,7 +102,7 @@ const useStyles = makeStyles( { name: 'BackstageSelect' }, ); -export type Item = { +export type SelectItem = { label: string; value: string | number; }; @@ -111,7 +111,7 @@ export type Selection = string | string[] | number | number[]; export type SelectProps = { multiple?: boolean; - items: Item[]; + items: SelectItem[]; label: string; placeholder?: string; selected?: Selection; diff --git a/packages/core-components/src/components/Select/index.tsx b/packages/core-components/src/components/Select/index.tsx index 8c9ae28ac8..293d626ee6 100644 --- a/packages/core-components/src/components/Select/index.tsx +++ b/packages/core-components/src/components/Select/index.tsx @@ -16,10 +16,10 @@ export { SelectComponent as Select } from './Select'; export type { - Item, SelectClassKey, SelectInputBaseClassKey, Selection, + SelectItem, } from './Select'; export type { ClosedDropdownClassKey } from './static/ClosedDropdown'; export type { OpenedDropdownClassKey } from './static/OpenedDropdown'; diff --git a/plugins/scaffolder/src/components/fields/RepoUrlPicker/RepoUrlPicker.tsx b/plugins/scaffolder/src/components/fields/RepoUrlPicker/RepoUrlPicker.tsx index 42e24cc998..e4d6f280f4 100644 --- a/plugins/scaffolder/src/components/fields/RepoUrlPicker/RepoUrlPicker.tsx +++ b/plugins/scaffolder/src/components/fields/RepoUrlPicker/RepoUrlPicker.tsx @@ -13,7 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { Item, Progress, Select, Selection } from '@backstage/core-components'; +import { + Progress, + Select, + Selection, + SelectItem, +} from '@backstage/core-components'; import { useApi } from '@backstage/core-plugin-api'; import { scmIntegrationsApiRef } from '@backstage/integration-react'; import FormControl from '@material-ui/core/FormControl'; @@ -237,13 +242,13 @@ export const RepoUrlPicker = ({ return ; } - const hostsOptions: Item[] = integrations + const hostsOptions: SelectItem[] = integrations ? integrations .filter(i => allowedHosts?.includes(i.host)) .map(i => ({ label: i.title, value: i.host })) : [{ label: 'Loading...', value: 'loading' }]; - const ownersOptions: Item[] = allowedOwners + const ownersOptions: SelectItem[] = allowedOwners ? allowedOwners.map(i => ({ label: i, value: i })) : [{ label: 'Loading...', value: 'loading' }]; From 31c0106a4e991f367637fba883897ce11168e902 Mon Sep 17 00:00:00 2001 From: lukzerom Date: Tue, 14 Dec 2021 17:51:02 +0100 Subject: [PATCH 10/17] on change instead of on select in entitypicker Signed-off-by: lukzerom --- .../src/components/fields/EntityPicker/EntityPicker.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/scaffolder/src/components/fields/EntityPicker/EntityPicker.tsx b/plugins/scaffolder/src/components/fields/EntityPicker/EntityPicker.tsx index d491af1da4..452a5d97b1 100644 --- a/plugins/scaffolder/src/components/fields/EntityPicker/EntityPicker.tsx +++ b/plugins/scaffolder/src/components/fields/EntityPicker/EntityPicker.tsx @@ -57,9 +57,9 @@ export const EntityPicker = ({ useEffect(() => { if (entityRefs?.length === 1) { - onSelect('', entityRefs[0]); + onChange(entityRefs[0]); } - }, [entityRefs, onSelect]); + }, [entityRefs, onChange]); return ( Date: Tue, 14 Dec 2021 18:09:02 +0100 Subject: [PATCH 11/17] Delete old changeset Signed-off-by: lukzerom --- .changeset/beige-balloons-grin.md | 5 ----- .changeset/curvy-walls-itch.md | 5 ----- 2 files changed, 10 deletions(-) delete mode 100644 .changeset/beige-balloons-grin.md delete mode 100644 .changeset/curvy-walls-itch.md diff --git a/.changeset/beige-balloons-grin.md b/.changeset/beige-balloons-grin.md deleted file mode 100644 index 9ce1e0b6b5..0000000000 --- a/.changeset/beige-balloons-grin.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'@backstage/plugin-scaffolder': minor ---- - -When user will have one option available in hostUrl or owner - autoselect and select component should be readonly diff --git a/.changeset/curvy-walls-itch.md b/.changeset/curvy-walls-itch.md deleted file mode 100644 index 18f35a6e24..0000000000 --- a/.changeset/curvy-walls-itch.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'@backstage/core-components': minor ---- - -Select component has extended API with few more props From 14d0bc908104c7a9396859257102dbe585731643 Mon Sep 17 00:00:00 2001 From: lukzerom Date: Tue, 14 Dec 2021 18:14:11 +0100 Subject: [PATCH 12/17] updated docs Signed-off-by: lukzerom --- packages/core-components/api-report.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/core-components/api-report.md b/packages/core-components/api-report.md index 72d47b494c..3a19dcba0d 100644 --- a/packages/core-components/api-report.md +++ b/packages/core-components/api-report.md @@ -528,14 +528,6 @@ export type InfoCardVariants = 'flex' | 'fullHeight' | 'gridItem'; // @public (undocumented) export function IntroCard(props: IntroCardProps): JSX.Element; -// Warning: (ae-missing-release-tag) "Item" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) -// -// @public (undocumented) -export type Item = { - label: string; - value: string | number; -}; - // Warning: (tsdoc-malformed-html-name) Invalid HTML element: Expecting an HTML name // Warning: (tsdoc-escape-greater-than) The ">" character should be escaped using a backslash to avoid confusion with an HTML tag // Warning: (ae-forgotten-export) The symbol "ItemCardProps" needs to be exported by the entry point index.d.ts @@ -849,6 +841,14 @@ export type SelectInputBaseClassKey = 'root' | 'input'; type Selection_2 = string | string[] | number | number[]; export { Selection_2 as Selection }; +// Warning: (ae-missing-release-tag) "SelectItem" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) +// +// @public (undocumented) +export type SelectItem = { + label: string; + value: string | number; +}; + // Warning: (ae-forgotten-export) The symbol "Props" needs to be exported by the entry point index.d.ts // Warning: (ae-missing-release-tag) "Sidebar" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // From b646a73fe048e81e21aa73c9d73ea96efa8b9032 Mon Sep 17 00:00:00 2001 From: lukzerom Date: Tue, 14 Dec 2021 18:22:52 +0100 Subject: [PATCH 13/17] changeset fix Signed-off-by: lukzerom --- .changeset/ten-candles-call.md | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 .changeset/ten-candles-call.md diff --git a/.changeset/ten-candles-call.md b/.changeset/ten-candles-call.md new file mode 100644 index 0000000000..d14020b9c8 --- /dev/null +++ b/.changeset/ten-candles-call.md @@ -0,0 +1,9 @@ +--- +'@backstage/core-components': minor +'@backstage/plugin-scaffolder': minor +--- + +In @backstage/plugin-scaffolder - When user will have one option available in hostUrl or owner - autoselect and select component should be readonly. + +in @backstage/core-components - Select component has extended API with few more props: native : boolean, disabled: boolean. native - if set to true - Select component will use native browser select picker (not rendered by Material UI lib ). +disabled - if set to true - action on component will not be possible. From 8ecfac35fda4aa9bec329230cf06bd056cf05ede Mon Sep 17 00:00:00 2001 From: lukzerom Date: Tue, 14 Dec 2021 23:37:16 +0100 Subject: [PATCH 14/17] patch instead of minor Signed-off-by: lukzerom --- .changeset/ten-candles-call.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.changeset/ten-candles-call.md b/.changeset/ten-candles-call.md index d14020b9c8..8907da06bd 100644 --- a/.changeset/ten-candles-call.md +++ b/.changeset/ten-candles-call.md @@ -1,6 +1,6 @@ --- -'@backstage/core-components': minor -'@backstage/plugin-scaffolder': minor +'@backstage/core-components': patch +'@backstage/plugin-scaffolder': patch --- In @backstage/plugin-scaffolder - When user will have one option available in hostUrl or owner - autoselect and select component should be readonly. From aec8c678c8b111955af200d5d4ba584101b7fbab Mon Sep 17 00:00:00 2001 From: lukzerom Date: Tue, 14 Dec 2021 23:40:30 +0100 Subject: [PATCH 15/17] selected items instead of selection Signed-off-by: lukzerom --- .../core-components/src/components/Select/Select.tsx | 12 ++++++------ .../core-components/src/components/Select/index.tsx | 2 +- .../fields/RepoUrlPicker/RepoUrlPicker.tsx | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/core-components/src/components/Select/Select.tsx b/packages/core-components/src/components/Select/Select.tsx index b5a641acd4..82be078cd0 100644 --- a/packages/core-components/src/components/Select/Select.tsx +++ b/packages/core-components/src/components/Select/Select.tsx @@ -107,15 +107,15 @@ export type SelectItem = { value: string | number; }; -export type Selection = string | string[] | number | number[]; +export type SelectedItems = string | string[] | number | number[]; export type SelectProps = { multiple?: boolean; items: SelectItem[]; label: string; placeholder?: string; - selected?: Selection; - onChange: (arg: Selection) => void; + selected?: SelectedItems; + onChange: (arg: SelectedItems) => void; triggerReset?: boolean; native?: boolean; disabled?: boolean; @@ -134,7 +134,7 @@ export function SelectComponent(props: SelectProps) { disabled = false, } = props; const classes = useStyles(); - const [value, setValue] = useState( + const [value, setValue] = useState( selected || (multiple ? [] : ''), ); const [isOpen, setOpen] = useState(false); @@ -150,8 +150,8 @@ export function SelectComponent(props: SelectProps) { }, [selected]); const handleChange = (event: React.ChangeEvent<{ value: unknown }>) => { - setValue(event.target.value as Selection); - onChange(event.target.value as Selection); + setValue(event.target.value as SelectedItems); + onChange(event.target.value as SelectedItems); }; const handleClick = (event: React.ChangeEvent) => { diff --git a/packages/core-components/src/components/Select/index.tsx b/packages/core-components/src/components/Select/index.tsx index 293d626ee6..870c2a0899 100644 --- a/packages/core-components/src/components/Select/index.tsx +++ b/packages/core-components/src/components/Select/index.tsx @@ -17,8 +17,8 @@ export { SelectComponent as Select } from './Select'; export type { SelectClassKey, + SelectedItems, SelectInputBaseClassKey, - Selection, SelectItem, } from './Select'; export type { ClosedDropdownClassKey } from './static/ClosedDropdown'; diff --git a/plugins/scaffolder/src/components/fields/RepoUrlPicker/RepoUrlPicker.tsx b/plugins/scaffolder/src/components/fields/RepoUrlPicker/RepoUrlPicker.tsx index e4d6f280f4..92261b6cac 100644 --- a/plugins/scaffolder/src/components/fields/RepoUrlPicker/RepoUrlPicker.tsx +++ b/plugins/scaffolder/src/components/fields/RepoUrlPicker/RepoUrlPicker.tsx @@ -16,7 +16,7 @@ import { Progress, Select, - Selection, + SelectedItems, SelectItem, } from '@backstage/core-components'; import { useApi } from '@backstage/core-plugin-api'; @@ -109,7 +109,7 @@ export const RepoUrlPicker = ({ allowedOwners, ); const updateHost = useCallback( - (value: Selection) => { + (value: SelectedItems) => { onChange( serializeFormData({ host: value as string, @@ -125,7 +125,7 @@ export const RepoUrlPicker = ({ ); const updateOwnerSelect = useCallback( - (value: Selection) => + (value: SelectedItems) => onChange( serializeFormData({ host, From 2d244da5c49903c50b91a5e49bb168daf21c4fc9 Mon Sep 17 00:00:00 2001 From: lukzerom Date: Tue, 14 Dec 2021 23:59:22 +0100 Subject: [PATCH 16/17] public adnotation Signed-off-by: lukzerom --- packages/core-components/src/components/Select/Select.tsx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/core-components/src/components/Select/Select.tsx b/packages/core-components/src/components/Select/Select.tsx index 82be078cd0..022df0a7ad 100644 --- a/packages/core-components/src/components/Select/Select.tsx +++ b/packages/core-components/src/components/Select/Select.tsx @@ -32,6 +32,7 @@ import React, { useEffect, useState } from 'react'; import ClosedDropdown from './static/ClosedDropdown'; import OpenedDropdown from './static/OpenedDropdown'; +/** @public */ export type SelectInputBaseClassKey = 'root' | 'input'; const BootstrapInput = withStyles( @@ -60,6 +61,7 @@ const BootstrapInput = withStyles( { name: 'BackstageSelectInputBase' }, )(InputBase); +/** @public */ export type SelectClassKey = | 'formControl' | 'label' @@ -102,11 +104,13 @@ const useStyles = makeStyles( { name: 'BackstageSelect' }, ); +/** @public */ export type SelectItem = { label: string; value: string | number; }; +/** @public */ export type SelectedItems = string | string[] | number | number[]; export type SelectProps = { @@ -121,6 +125,7 @@ export type SelectProps = { disabled?: boolean; }; +/** @public */ export function SelectComponent(props: SelectProps) { const { multiple, From b040d62e8e2b5bb8efe2634fe1c1bb42a4f928e0 Mon Sep 17 00:00:00 2001 From: lukzerom Date: Wed, 15 Dec 2021 00:03:42 +0100 Subject: [PATCH 17/17] docs update Signed-off-by: lukzerom --- packages/core-components/api-report.md | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/packages/core-components/api-report.md b/packages/core-components/api-report.md index 3a19dcba0d..086a0bc632 100644 --- a/packages/core-components/api-report.md +++ b/packages/core-components/api-report.md @@ -814,13 +814,10 @@ export type ResponseErrorPanelClassKey = 'text' | 'divider'; export function RoutedTabs(props: { routes: SubRoute_2[] }): JSX.Element; // Warning: (ae-forgotten-export) The symbol "SelectProps" needs to be exported by the entry point index.d.ts -// Warning: (ae-missing-release-tag) "SelectComponent" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // // @public (undocumented) export function Select(props: SelectProps): JSX.Element; -// Warning: (ae-missing-release-tag) "SelectClassKey" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) -// // @public (undocumented) export type SelectClassKey = | 'formControl' @@ -830,19 +827,12 @@ export type SelectClassKey = | 'checkbox' | 'root'; -// Warning: (ae-missing-release-tag) "SelectInputBaseClassKey" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) -// +// @public (undocumented) +export type SelectedItems = string | string[] | number | number[]; + // @public (undocumented) export type SelectInputBaseClassKey = 'root' | 'input'; -// Warning: (ae-missing-release-tag) "Selection" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) -// -// @public (undocumented) -type Selection_2 = string | string[] | number | number[]; -export { Selection_2 as Selection }; - -// Warning: (ae-missing-release-tag) "SelectItem" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) -// // @public (undocumented) export type SelectItem = { label: string;