fix entity picker single result behavior
Signed-off-by: Stephen Glass <stephen@stephen.glass>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-scaffolder': patch
|
||||
---
|
||||
|
||||
Change behavior of scaffolder entity pickers (EntityPicker, MultiEntityPicker, MyGroupsPicker) to not auto-fill and disable the field if there is only a single value option.
|
||||
@@ -35,7 +35,7 @@ import Autocomplete, {
|
||||
AutocompleteChangeReason,
|
||||
createFilterOptions,
|
||||
} from '@material-ui/lab/Autocomplete';
|
||||
import React, { useCallback, useEffect } from 'react';
|
||||
import React, { useCallback } from 'react';
|
||||
import useAsync from 'react-use/esm/useAsync';
|
||||
import {
|
||||
EntityPickerFilterQueryValue,
|
||||
@@ -166,12 +166,6 @@ export const EntityPicker = (props: EntityPickerProps) => {
|
||||
entities?.catalogEntities.find(e => stringifyEntityRef(e) === formData) ??
|
||||
(allowArbitraryValues && formData ? getLabel(formData) : '');
|
||||
|
||||
useEffect(() => {
|
||||
if (entities?.catalogEntities.length === 1 && selectedEntity === '') {
|
||||
onChange(stringifyEntityRef(entities.catalogEntities[0]));
|
||||
}
|
||||
}, [entities, onChange, selectedEntity]);
|
||||
|
||||
return (
|
||||
<FormControl
|
||||
margin="normal"
|
||||
@@ -179,7 +173,6 @@ export const EntityPicker = (props: EntityPickerProps) => {
|
||||
error={rawErrors?.length > 0 && !formData}
|
||||
>
|
||||
<Autocomplete
|
||||
disabled={entities?.catalogEntities.length === 1}
|
||||
id={idSchema?.$id}
|
||||
value={selectedEntity}
|
||||
loading={loading}
|
||||
|
||||
@@ -34,7 +34,7 @@ import FormControl from '@material-ui/core/FormControl';
|
||||
import Autocomplete, {
|
||||
AutocompleteChangeReason,
|
||||
} from '@material-ui/lab/Autocomplete';
|
||||
import React, { useCallback, useEffect, useState } from 'react';
|
||||
import React, { useCallback, useState } from 'react';
|
||||
import useAsync from 'react-use/esm/useAsync';
|
||||
import { FieldValidation } from '@rjsf/utils';
|
||||
import {
|
||||
@@ -135,12 +135,6 @@ export const MultiEntityPicker = (props: MultiEntityPickerProps) => {
|
||||
[onChange, formData, defaultKind, defaultNamespace, allowArbitraryValues],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (entities?.entities?.length === 1) {
|
||||
onChange([stringifyEntityRef(entities?.entities[0])]);
|
||||
}
|
||||
}, [entities, onChange]);
|
||||
|
||||
return (
|
||||
<FormControl
|
||||
margin="normal"
|
||||
@@ -150,7 +144,6 @@ export const MultiEntityPicker = (props: MultiEntityPickerProps) => {
|
||||
<Autocomplete
|
||||
multiple
|
||||
filterSelectedOptions
|
||||
disabled={entities?.entities?.length === 1}
|
||||
id={idSchema?.$id}
|
||||
defaultValue={formData}
|
||||
loading={loading}
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import React, { useEffect } from 'react';
|
||||
import React from 'react';
|
||||
import {
|
||||
errorApiRef,
|
||||
identityApiRef,
|
||||
@@ -101,12 +101,6 @@ export const MyGroupsPicker = (props: MyGroupsPickerProps) => {
|
||||
groups?.catalogEntities.find(e => stringifyEntityRef(e) === formData) ||
|
||||
null;
|
||||
|
||||
useEffect(() => {
|
||||
if (groups?.catalogEntities.length === 1 && !selectedEntity) {
|
||||
onChange(stringifyEntityRef(groups.catalogEntities[0]));
|
||||
}
|
||||
}, [groups, onChange, selectedEntity]);
|
||||
|
||||
return (
|
||||
<FormControl
|
||||
margin="normal"
|
||||
@@ -114,7 +108,6 @@ export const MyGroupsPicker = (props: MyGroupsPickerProps) => {
|
||||
error={rawErrors?.length > 0}
|
||||
>
|
||||
<Autocomplete
|
||||
disabled={groups?.catalogEntities.length === 1}
|
||||
id="OwnershipEntityRefPicker-dropdown"
|
||||
options={groups?.catalogEntities || []}
|
||||
value={selectedEntity}
|
||||
|
||||
Reference in New Issue
Block a user