From 96f8bd673b63f164925326434791cd5797f7a895 Mon Sep 17 00:00:00 2001 From: Lykke Axlin Date: Wed, 13 Oct 2021 12:29:00 +0200 Subject: [PATCH] added autocomplete when selecting a project Signed-off-by: Lykke Axlin Co-authored-by: klaraab --- .../AddProjectDialog/AddProjectDialog.tsx | 35 +++++++------ .../ProjectSelector/ProjectSelector.tsx | 50 +++++++------------ 2 files changed, 40 insertions(+), 45 deletions(-) diff --git a/plugins/bazaar/src/components/AddProjectDialog/AddProjectDialog.tsx b/plugins/bazaar/src/components/AddProjectDialog/AddProjectDialog.tsx index 039537029e..921c3fc232 100644 --- a/plugins/bazaar/src/components/AddProjectDialog/AddProjectDialog.tsx +++ b/plugins/bazaar/src/components/AddProjectDialog/AddProjectDialog.tsx @@ -58,25 +58,32 @@ export const AddProjectDialog = ({ setSelectedEntity(entity); }; + const handleCloseDialog = () => { + setSelectedEntity(catalogEntities ? catalogEntities[0] : null); + handleClose(); + }; + const handleSave: SubmitHandler = async ( getValues: any, reset: any, ) => { const formValues = getValues(); - await bazaarApi.updateMetadata( - selectedEntity!, - selectedEntity!.metadata.name, - formValues.community, - formValues.announcement, - formValues.status, - ); + if (selectedEntity) { + await bazaarApi.updateMetadata( + selectedEntity, + selectedEntity.metadata.name, + formValues.community, + formValues.announcement, + formValues.status, + ); - fetchBazaarProjects(); - fetchCatalogEntities(); + fetchBazaarProjects(); + fetchCatalogEntities(); - handleClose(); - reset(defaultValues); + handleClose(); + reset(defaultValues); + } }; return ( @@ -88,13 +95,13 @@ export const AddProjectDialog = ({ open={open} projectSelector={ } - handleClose={handleClose} + handleClose={handleCloseDialog} /> ); }; diff --git a/plugins/bazaar/src/components/ProjectSelector/ProjectSelector.tsx b/plugins/bazaar/src/components/ProjectSelector/ProjectSelector.tsx index a7f9ffc30d..1c2718d403 100644 --- a/plugins/bazaar/src/components/ProjectSelector/ProjectSelector.tsx +++ b/plugins/bazaar/src/components/ProjectSelector/ProjectSelector.tsx @@ -15,11 +15,9 @@ */ import React from 'react'; -import InputLabel from '@material-ui/core/InputLabel'; -import MenuItem from '@material-ui/core/MenuItem'; -import FormControl from '@material-ui/core/FormControl'; -import Select from '@material-ui/core/Select'; import { Entity } from '@backstage/catalog-model'; +import { Autocomplete } from '@material-ui/lab'; +import { TextField } from '@material-ui/core'; type Props = { entities: Entity[]; @@ -35,32 +33,22 @@ export const ProjectSelector = ({ isFormInvalid, }: Props) => { return ( - - - Select a project - - - + option?.metadata?.name} + renderOption={option => {option?.metadata?.name}} + renderInput={params => ( + + )} + onChange={(_, data) => onChange(data!)} + /> ); };