From 08a22913ff3f3478dca868d6715ecf87c015774a Mon Sep 17 00:00:00 2001 From: swarajsaaj Date: Sun, 3 Oct 2021 20:24:51 +0530 Subject: [PATCH] [react] map for loop for enums Map for loop for enums instead of generated code Follows #16475 --- .../webapp/app/entities/entity-update.tsx.ejs | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/generators/entity-client/templates/react/src/main/webapp/app/entities/entity-update.tsx.ejs b/generators/entity-client/templates/react/src/main/webapp/app/entities/entity-update.tsx.ejs index 5ecf4092486..19de8389512 100644 --- a/generators/entity-client/templates/react/src/main/webapp/app/entities/entity-update.tsx.ejs +++ b/generators/entity-client/templates/react/src/main/webapp/app/entities/entity-update.tsx.ejs @@ -102,6 +102,10 @@ import { convertDateTimeFromServer, convertDateTimeToServer, displayDefaultDateT import { mapIdList } from 'app/shared/util/entity-utils'; <%_ } _%> import { useAppDispatch, useAppSelector } from 'app/config/store'; +<%_ const enumImports = generateEntityClientEnumImports(fields); _%> +<%_ enumImports.forEach( (importedPath, importedType) => { _%> +import { <%- importedType %> } from '<%- importedPath %>'; +<%_ }); _%> export const <%= entityReactName %>Update = (props: RouteComponentProps<{id: string}>) => { const dispatch = useAppDispatch(); @@ -115,7 +119,9 @@ export const <%= entityReactName %>Update = (props: RouteComponentProps<{id: str const loading = useAppSelector(state => state.<%= entityInstance %>.loading); const updating = useAppSelector(state => state.<%= entityInstance %>.updating); const updateSuccess = useAppSelector(state => state.<%= entityInstance %>.updateSuccess); - + <%_ enumImports.forEach( (importedPath, importedType) => { _%> + const <%- _.lowerFirst(importedType) %>Values = Object.keys(<%- importedType %>); + <%_ }); _%> const handleClose = () => { props.history.push('/<%= entityFileName %>'<%_ if (paginationPagination) { _%> + props.location.search<%_ } _%>); } @@ -265,21 +271,18 @@ _%> type="date" <%- include('react_validators'); %> /> - <%_ } else if (field.fieldIsEnum) { - const enumValues = field.enumValues; - _%> + <%_ } else if (field.fieldIsEnum) {_%> type="select" > - <%_ const enumPrefix = frontendAppName + '.'+ fieldType; - enumValues.forEach(enumValue => { _%> - - <%_ }); _%> + ))} <%_ } else if (field.fieldTypeNumeric) { _%> type="text"