From 759edf17841b91c39b9f5e07538bceaca773cabe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elias=20Feij=C3=B3=20de=20Almeida=20Pereira=20Lima?= Date: Wed, 21 Jun 2023 13:13:51 -0300 Subject: [PATCH 1/9] feat: jamie conditions feature env config --- .env.development | 5 ++++- src/constants/env.ts | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.env.development b/.env.development index dbc6490..03b6bab 100644 --- a/.env.development +++ b/.env.development @@ -2,4 +2,7 @@ JAMIE_UI_BASE_URL=http://localhost:3000 JAMIE_KEYCLOAK_BASE_URL=http://localhost:8080 -JAMIE_API_BASE_URL=https://api.jamie.g6tech.com.br \ No newline at end of file +JAMIE_API_BASE_URL=https://api.jamie.g6tech.com.br + +# The conditions feature requires FeatWS to be installed and configured. +# JAMIE_FEATURE_CONDITIONS=true \ No newline at end of file diff --git a/src/constants/env.ts b/src/constants/env.ts index d261b3b..c77a46a 100644 --- a/src/constants/env.ts +++ b/src/constants/env.ts @@ -9,3 +9,6 @@ const getConfig = varname => { export const JAMIE_UI_BASE_URL = getConfig('${JAMIE_UI_BASE_URL}'); export const JAMIE_KEYCLOAK_BASE_URL = getConfig('${JAMIE_KEYCLOAK_BASE_URL}'); export const JAMIE_API_BASE_URL = getConfig('${JAMIE_API_BASE_URL}'); + +// The conditions feature requires FeatWS to be installed and configured. +export const JAMIE_FEATURE_CONDITIONS = getConfig('${JAMIE_FEATURE_CONDITIONS}'); From c12d211ae8cb0b3a83e3ddba89544ec7ba270959 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elias=20Feij=C3=B3=20de=20Almeida=20Pereira=20Lima?= Date: Wed, 21 Jun 2023 13:24:47 -0300 Subject: [PATCH 2/9] feat: MenuForm hasConditions prop --- src/api/services/MenuService.ts | 1 + src/components/Menu/Form/Form.tsx | 4 ++++ src/pages/Menu/Create/Create.tsx | 6 +++++- src/pages/Menu/Edit/Edit.tsx | 5 +++++ src/types/model.ts | 1 + 5 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/api/services/MenuService.ts b/src/api/services/MenuService.ts index e046f21..9a2c0fe 100644 --- a/src/api/services/MenuService.ts +++ b/src/api/services/MenuService.ts @@ -4,6 +4,7 @@ export const ALL_MENU_PROPERTIES = ` id name mustDeferChanges +hasConditions createdAt updatedAt version diff --git a/src/components/Menu/Form/Form.tsx b/src/components/Menu/Form/Form.tsx index deef871..b07c3e0 100644 --- a/src/components/Menu/Form/Form.tsx +++ b/src/components/Menu/Form/Form.tsx @@ -59,6 +59,8 @@ interface Props { setMustDeferChanges: (mustDeferChanges: boolean) => void; meta: IMenuMetaWithErrors[]; setMeta: (meta: IMenuMetaWithErrors[]) => void; + hasConditions: boolean; + setHasConditions: (hasConditions: boolean) => void; loadingSubmit: boolean; onSubmit: () => void; onBack: () => void; @@ -74,6 +76,8 @@ export const MenuForm = ({ setMustDeferChanges, meta, setMeta, + hasConditions, + setHasConditions, loadingSubmit, onSubmit, onBack, diff --git a/src/pages/Menu/Create/Create.tsx b/src/pages/Menu/Create/Create.tsx index 0e6291e..589e3dc 100644 --- a/src/pages/Menu/Create/Create.tsx +++ b/src/pages/Menu/Create/Create.tsx @@ -30,6 +30,8 @@ export const CreateMenu = () => { const [loadingSubmit, setLoadingSubmit] = React.useState(false); + const [hasConditions, setHasConditions] = React.useState(false); + const [createMenu] = useMutation(MenuService.CREATE_MENU); const onBackClickHandler = () => { @@ -46,7 +48,7 @@ export const CreateMenu = () => { return rest; }); createMenu({ - variables: { menu: { name, mustDeferChanges, meta } }, + variables: { menu: { name, mustDeferChanges, meta, hasConditions } }, onCompleted: data => { setLoadingSubmit(false); dispatch({ @@ -92,6 +94,8 @@ export const CreateMenu = () => { setMustDeferChanges={setMustDeferChanges} meta={metaWithErrors} setMeta={setMetaWithErrors} + hasConditions={hasConditions} + setHasConditions={setHasConditions} loadingSubmit={loadingSubmit} onSubmit={onSubmit} onBack={onBackClickHandler} diff --git a/src/pages/Menu/Edit/Edit.tsx b/src/pages/Menu/Edit/Edit.tsx index f7efa15..b5aea6f 100644 --- a/src/pages/Menu/Edit/Edit.tsx +++ b/src/pages/Menu/Edit/Edit.tsx @@ -35,6 +35,8 @@ export const EditMenu = () => { const [mustDeferChanges, setMustDeferChanges] = React.useState(false); + const [hasConditions, setHasConditions] = React.useState(false); + const [metaWithErrors, setMetaWithErrors] = React.useState([]); const [loadingSubmit, setLoadingSubmit] = React.useState(false); @@ -45,6 +47,7 @@ export const EditMenu = () => { if (loaded || !data) return; setName(data.menu.name); setMustDeferChanges(data.menu.mustDeferChanges); + setHasConditions(data.menu.hasConditions); setMetaWithErrors( data?.menu.meta .map(m => { @@ -148,6 +151,8 @@ export const EditMenu = () => { setNameError={setNameError} mustDeferChanges={mustDeferChanges} setMustDeferChanges={setMustDeferChanges} + hasConditions={hasConditions} + setHasConditions={setHasConditions} meta={metaWithErrors} setMeta={setMetaWithErrors} loadingSubmit={loadingSubmit} diff --git a/src/types/model.ts b/src/types/model.ts index 60cd5b0..4ea0376 100644 --- a/src/types/model.ts +++ b/src/types/model.ts @@ -6,6 +6,7 @@ export interface IMenu { id: number; name: string; mustDeferChanges: boolean; + hasConditions: boolean; meta: IMenuMeta[]; items: IMenuItem[]; template?: string; From e0e4462c9b3302a44b10f98581addb3fecb40178 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elias=20Feij=C3=B3=20de=20Almeida=20Pereira=20Lima?= Date: Wed, 21 Jun 2023 13:41:45 -0300 Subject: [PATCH 3/9] feat: MenuForm hasConditions checkbox --- src/components/Menu/Form/Form.tsx | 27 ++++++++++++++++++++++++- src/i18n/locales/en/translation.json | 1 + src/i18n/locales/pt-BR/translation.json | 1 + 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/components/Menu/Form/Form.tsx b/src/components/Menu/Form/Form.tsx index b07c3e0..9f1554f 100644 --- a/src/components/Menu/Form/Form.tsx +++ b/src/components/Menu/Form/Form.tsx @@ -26,7 +26,7 @@ import { useTranslation } from 'react-i18next'; import { DatePicker, LocalizationProvider } from '@mui/x-date-pickers'; import { AdapterLuxon } from '@mui/x-date-pickers/AdapterLuxon'; import { DateTime } from 'luxon'; -import { MENU_VALIDATION } from '../../../constants'; +import { JAMIE_FEATURE_CONDITIONS, MENU_VALIDATION } from '../../../constants'; import { EnumInputAction, FormAction, IMenuMetaWithErrors, MenuMetaType } from '../../../types'; import './styles.css'; @@ -429,6 +429,30 @@ export const MenuForm = ({ )} )); + + const renderHasConditionCheckbox = () => { + if (!JAMIE_FEATURE_CONDITIONS) return null; + return ( + + ) => { + const { checked } = e.target; + setHasConditions(checked); + }} + color="primary" + /> + } + label={`${t('menu.fields.hasConditions')}?`} + /> + + ); + }; + return (
@@ -473,6 +497,7 @@ export const MenuForm = ({ label={t('menu.fields.mustDeferChanges')} /> + {renderHasConditionCheckbox()} {t('menu.fields.meta.title', { count: 2 })} diff --git a/src/i18n/locales/en/translation.json b/src/i18n/locales/en/translation.json index 4f8acdc..853dac8 100644 --- a/src/i18n/locales/en/translation.json +++ b/src/i18n/locales/en/translation.json @@ -201,6 +201,7 @@ "fields": { "name": "Name", "mustDeferChanges": "Mandatory deferral", + "hasConditions": "Has Conditions", "items": "Items", "template": "Template", "templateFormat": { diff --git a/src/i18n/locales/pt-BR/translation.json b/src/i18n/locales/pt-BR/translation.json index 0599d01..b32ff9a 100644 --- a/src/i18n/locales/pt-BR/translation.json +++ b/src/i18n/locales/pt-BR/translation.json @@ -201,6 +201,7 @@ "fields": { "name": "Nome", "mustDeferChanges": "Deferimento obrigatório", + "hasConditions": "Tem Condições", "items": "Itens", "template": "Template", "templateFormat": { From 546ad4016d32d0dd8312b1ea93e585b6b449ea16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elias=20Feij=C3=B3=20de=20Almeida=20Pereira=20Lima?= Date: Wed, 21 Jun 2023 13:51:42 -0300 Subject: [PATCH 4/9] feat: Menu Show has conditions --- src/pages/Menu/Show/Show.tsx | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/pages/Menu/Show/Show.tsx b/src/pages/Menu/Show/Show.tsx index 9a9211c..fe8e72c 100644 --- a/src/pages/Menu/Show/Show.tsx +++ b/src/pages/Menu/Show/Show.tsx @@ -14,6 +14,7 @@ import { NotificationContext, openDefaultErrorNotification, } from '../../../contexts/NotificationContext'; +import { JAMIE_FEATURE_CONDITIONS } from '../../../constants'; export const ShowMenu = () => { const { t, i18n } = useTranslation(); @@ -124,6 +125,21 @@ export const ShowMenu = () => { )); }; + + const renderHasConditions = () => { + if (!JAMIE_FEATURE_CONDITIONS) return null; + return ( + + + {t('menu.fields.hasConditions')}? + + + {data?.menu.hasConditions ? t('common.yes') : t('common.no')} + + + ); + }; + if (loading) return ; if (error) @@ -216,6 +232,7 @@ export const ShowMenu = () => { {data?.menu.mustDeferChanges ? t('common.yes') : t('common.no')} + {renderHasConditions()} From cb22c4ff52980c1663557a9debcaab8a637f0162 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elias=20Feij=C3=B3=20de=20Almeida=20Pereira=20Lima?= Date: Wed, 21 Jun 2023 14:41:02 -0300 Subject: [PATCH 5/9] feat: Menu Items OperationScreen renderConditions --- src/components/Menu/Items/OperationScreen.tsx | 70 +++++++++++++++++++ src/i18n/locales/en/translation.json | 3 + src/i18n/locales/pt-BR/translation.json | 3 + src/types/model.ts | 5 +- 4 files changed, 80 insertions(+), 1 deletion(-) diff --git a/src/components/Menu/Items/OperationScreen.tsx b/src/components/Menu/Items/OperationScreen.tsx index e61a5cc..9ed3bb2 100644 --- a/src/components/Menu/Items/OperationScreen.tsx +++ b/src/components/Menu/Items/OperationScreen.tsx @@ -487,6 +487,75 @@ export const OperationScreen = ({ )); }; + const renderConditions = () => { + if (!data.menu.hasConditions) return null; + return ( + + + {t('menu.preview.conditions.title')} + + { + setLabelError(''); + setEditingNode({ ...editingNode, features: e.target.value }); + }} + sx={{ + mt: '2rem', + width: '100%', + }} + /> + { + setLabelError(''); + setEditingNode({ ...editingNode, parameters: e.target.value }); + }} + sx={{ + mt: '2rem', + width: '100%', + }} + /> + { + setLabelError(''); + setEditingNode({ ...editingNode, rules: e.target.value }); + }} + sx={{ + mt: '2rem', + width: '100%', + }} + /> + + ); + }; + switch (operationScreen) { case EnumInputActionScreen.SELECTING_ACTION: return ( @@ -912,6 +981,7 @@ export const OperationScreen = ({ )} + {renderConditions()} Date: Wed, 21 Jun 2023 15:03:07 -0300 Subject: [PATCH 6/9] fix: update menu include conditions --- src/api/services/MenuService.ts | 3 +++ src/components/Menu/Items/OperationScreen.tsx | 21 +++++++------------ 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/api/services/MenuService.ts b/src/api/services/MenuService.ts index 9a2c0fe..808a9bb 100644 --- a/src/api/services/MenuService.ts +++ b/src/api/services/MenuService.ts @@ -65,6 +65,9 @@ items { createdAt updatedAt version + features + parameters + rules } `; diff --git a/src/components/Menu/Items/OperationScreen.tsx b/src/components/Menu/Items/OperationScreen.tsx index 9ed3bb2..6e42c7d 100644 --- a/src/components/Menu/Items/OperationScreen.tsx +++ b/src/components/Menu/Items/OperationScreen.tsx @@ -111,6 +111,9 @@ export const OperationScreen = ({ menuId, defaultTemplate, action, + features, + parameters, + rules, ...rest } = node; let meta = Object.keys(rest.meta).reduce((acc, key) => { @@ -166,6 +169,9 @@ export const OperationScreen = ({ startPublication, endPublication, meta, + features, + parameters, + rules, children: children && formatNodes(children), id: id === -1 ? undefined : id, }; @@ -491,19 +497,7 @@ export const OperationScreen = ({ if (!data.menu.hasConditions) return null; return ( - - {t('menu.preview.conditions.title')} - + {t('menu.preview.inputs.conditions.title')} )} + {renderConditions()} Date: Wed, 21 Jun 2023 21:59:58 -0300 Subject: [PATCH 7/9] refactor: Menu Item OperationScreen rules only --- src/api/services/MenuService.ts | 3 +- src/components/Menu/Items/OperationScreen.tsx | 36 ------------------- src/types/model.ts | 3 +- 3 files changed, 2 insertions(+), 40 deletions(-) diff --git a/src/api/services/MenuService.ts b/src/api/services/MenuService.ts index 808a9bb..68d6691 100644 --- a/src/api/services/MenuService.ts +++ b/src/api/services/MenuService.ts @@ -5,6 +5,7 @@ id name mustDeferChanges hasConditions +parameters createdAt updatedAt version @@ -65,8 +66,6 @@ items { createdAt updatedAt version - features - parameters rules } `; diff --git a/src/components/Menu/Items/OperationScreen.tsx b/src/components/Menu/Items/OperationScreen.tsx index 6e42c7d..2a6bf1a 100644 --- a/src/components/Menu/Items/OperationScreen.tsx +++ b/src/components/Menu/Items/OperationScreen.tsx @@ -111,8 +111,6 @@ export const OperationScreen = ({ menuId, defaultTemplate, action, - features, - parameters, rules, ...rest } = node; @@ -169,8 +167,6 @@ export const OperationScreen = ({ startPublication, endPublication, meta, - features, - parameters, rules, children: children && formatNodes(children), id: id === -1 ? undefined : id, @@ -498,38 +494,6 @@ export const OperationScreen = ({ return ( {t('menu.preview.inputs.conditions.title')} - { - setLabelError(''); - setEditingNode({ ...editingNode, features: e.target.value }); - }} - sx={{ - mt: '2rem', - width: '100%', - }} - /> - { - setLabelError(''); - setEditingNode({ ...editingNode, parameters: e.target.value }); - }} - sx={{ - mt: '2rem', - width: '100%', - }} - /> Date: Wed, 21 Jun 2023 22:10:56 -0300 Subject: [PATCH 8/9] feat: Menu Form parameters prop --- src/components/Menu/Form/Form.tsx | 4 ++++ src/pages/Menu/Create/Create.tsx | 6 +++++- src/pages/Menu/Edit/Edit.tsx | 9 ++++++++- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/components/Menu/Form/Form.tsx b/src/components/Menu/Form/Form.tsx index 9f1554f..1e2e6a2 100644 --- a/src/components/Menu/Form/Form.tsx +++ b/src/components/Menu/Form/Form.tsx @@ -61,6 +61,8 @@ interface Props { setMeta: (meta: IMenuMetaWithErrors[]) => void; hasConditions: boolean; setHasConditions: (hasConditions: boolean) => void; + parameters: string; + setParameters: (parameters: string) => void; loadingSubmit: boolean; onSubmit: () => void; onBack: () => void; @@ -77,6 +79,8 @@ export const MenuForm = ({ meta, setMeta, hasConditions, + parameters, + setParameters, setHasConditions, loadingSubmit, onSubmit, diff --git a/src/pages/Menu/Create/Create.tsx b/src/pages/Menu/Create/Create.tsx index 589e3dc..e7d2555 100644 --- a/src/pages/Menu/Create/Create.tsx +++ b/src/pages/Menu/Create/Create.tsx @@ -32,6 +32,8 @@ export const CreateMenu = () => { const [hasConditions, setHasConditions] = React.useState(false); + const [parameters, setParameters] = React.useState(); + const [createMenu] = useMutation(MenuService.CREATE_MENU); const onBackClickHandler = () => { @@ -48,7 +50,7 @@ export const CreateMenu = () => { return rest; }); createMenu({ - variables: { menu: { name, mustDeferChanges, meta, hasConditions } }, + variables: { menu: { name, mustDeferChanges, meta, hasConditions, parameters } }, onCompleted: data => { setLoadingSubmit(false); dispatch({ @@ -96,6 +98,8 @@ export const CreateMenu = () => { setMeta={setMetaWithErrors} hasConditions={hasConditions} setHasConditions={setHasConditions} + parameters={parameters} + setParameters={setParameters} loadingSubmit={loadingSubmit} onSubmit={onSubmit} onBack={onBackClickHandler} diff --git a/src/pages/Menu/Edit/Edit.tsx b/src/pages/Menu/Edit/Edit.tsx index b5aea6f..4f10ca8 100644 --- a/src/pages/Menu/Edit/Edit.tsx +++ b/src/pages/Menu/Edit/Edit.tsx @@ -37,6 +37,8 @@ export const EditMenu = () => { const [hasConditions, setHasConditions] = React.useState(false); + const [parameters, setParameters] = React.useState(); + const [metaWithErrors, setMetaWithErrors] = React.useState([]); const [loadingSubmit, setLoadingSubmit] = React.useState(false); @@ -48,6 +50,7 @@ export const EditMenu = () => { setName(data.menu.name); setMustDeferChanges(data.menu.mustDeferChanges); setHasConditions(data.menu.hasConditions); + setParameters(data.menu.parameters); setMetaWithErrors( data?.menu.meta .map(m => { @@ -86,7 +89,9 @@ export const EditMenu = () => { }); const updatedName = name !== data.menu.name ? name : undefined; updateMenu({ - variables: { menu: { id: Number(id), name: updatedName, mustDeferChanges, meta } }, + variables: { + menu: { id: Number(id), name: updatedName, mustDeferChanges, meta, parameters }, + }, onCompleted: data => { setLoadingSubmit(false); dispatch({ @@ -153,6 +158,8 @@ export const EditMenu = () => { setMustDeferChanges={setMustDeferChanges} hasConditions={hasConditions} setHasConditions={setHasConditions} + parameters={parameters} + setParameters={setParameters} meta={metaWithErrors} setMeta={setMetaWithErrors} loadingSubmit={loadingSubmit} From 7af65a741c013bbb7d1d72c478c639d712b8e27d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elias=20Feij=C3=B3=20de=20Almeida=20Pereira=20Lima?= Date: Fri, 30 Jun 2023 15:29:42 -0300 Subject: [PATCH 9/9] feat: parameters on MenuForm --- src/components/Menu/Form/Form.tsx | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/components/Menu/Form/Form.tsx b/src/components/Menu/Form/Form.tsx index 1e2e6a2..4f2a5e7 100644 --- a/src/components/Menu/Form/Form.tsx +++ b/src/components/Menu/Form/Form.tsx @@ -79,9 +79,9 @@ export const MenuForm = ({ meta, setMeta, hasConditions, + setHasConditions, parameters, setParameters, - setHasConditions, loadingSubmit, onSubmit, onBack, @@ -457,6 +457,28 @@ export const MenuForm = ({ ); }; + const renderParameters = () => { + if (!hasConditions) return null; + return ( + ) => { + const { value } = e.target; + setParameters(value); + }} + InputLabelProps={{ + shrink: true, + }} + sx={{ width: '16rem' }} + className="bg-white" + /> + ); + }; + return ( @@ -502,6 +524,7 @@ export const MenuForm = ({ /> {renderHasConditionCheckbox()} + {renderParameters()} {t('menu.fields.meta.title', { count: 2 })}