From 205fd02faff0bb6aa80a5dcd6a44213cc4192c98 Mon Sep 17 00:00:00 2001 From: Norbert Csaba Herczeg Date: Wed, 3 Jan 2024 12:25:47 +0100 Subject: [PATCH] JNG-5382 post create hook with component proxy params --- .../judo/ui/generator/react/UiActionsHelper.java | 14 ++++++++++++++ .../widget-fragments/binarytypeinput.hbs | 1 + .../src/containers/widget-fragments/button.hbs | 1 + .../containers/widget-fragments/buttongroup.hbs | 1 + .../src/containers/widget-fragments/checkbox.hbs | 1 + .../src/containers/widget-fragments/dateinput.hbs | 1 + .../containers/widget-fragments/datetimeinput.hbs | 1 + .../src/containers/widget-fragments/divider.hbs | 1 + .../widget-fragments/enumerationcombo.hbs | 1 + .../widget-fragments/enumerationradio.hbs | 1 + .../actor/src/containers/widget-fragments/flex.hbs | 1 + .../src/containers/widget-fragments/formatted.hbs | 1 + .../src/containers/widget-fragments/label.hbs | 1 + .../containers/widget-fragments/numericinput.hbs | 1 + .../src/containers/widget-fragments/spacer.hbs | 1 + .../containers/widget-fragments/tabcontroller.hbs | 1 + .../actor/src/containers/widget-fragments/text.hbs | 1 + .../src/containers/widget-fragments/textarea.hbs | 1 + .../src/containers/widget-fragments/textinput.hbs | 1 + .../src/containers/widget-fragments/timeinput.hbs | 1 + .../widget-fragments/trinarylogiccombo.hbs | 1 + .../main/resources/actor/src/dialogs/index.tsx.hbs | 3 +++ .../src/pages/actions/CreateAction.fragment.hbs | 8 ++++++-- 23 files changed, 43 insertions(+), 2 deletions(-) diff --git a/judo-ui-react/src/main/java/hu/blackbelt/judo/ui/generator/react/UiActionsHelper.java b/judo-ui-react/src/main/java/hu/blackbelt/judo/ui/generator/react/UiActionsHelper.java index 711600c8..15dcb2d9 100644 --- a/judo-ui-react/src/main/java/hu/blackbelt/judo/ui/generator/react/UiActionsHelper.java +++ b/judo-ui-react/src/main/java/hu/blackbelt/judo/ui/generator/react/UiActionsHelper.java @@ -105,6 +105,10 @@ public static ActionDefinition getGetTemplateActionDefinitionForContainer(PageCo return (ActionDefinition) container.getPageActionDefinitions().stream().filter(a -> ((ActionDefinition) a).getIsGetTemplateAction()).findFirst().orElse(null); } + public static ActionDefinition getCreateDefinitionForContainer(PageContainer container) { + return (ActionDefinition) container.getPageActionDefinitions().stream().filter(a -> ((ActionDefinition) a).getIsCreateAction()).findFirst().orElse(null); + } + public static ActionDefinition getRefreshActionDefinitionForContainer(PageContainer container) { if (container.isTable()) { return getRefreshActionDefinitionForTable((Table) container.getTables().get(0)); @@ -287,6 +291,16 @@ public static String refreshActionDataParameter(Action action) { return "undefined"; } + public static String postCreateActionParams(PageDefinition page, ActionDefinition actionDefinition) { + List tokens = new ArrayList<>(); + String type = classDataName(getReferenceClassType(page), "Stored"); + tokens.add("data: " + classDataName(getReferenceClassType(page), "")); + tokens.add("res: " + type); + tokens.add("onSubmit: (result?: " + type + ") => Promise"); + tokens.add("onClose: () => Promise"); + return String.join(", ", tokens); + } + public static String postCallOperationActionParams(PageDefinition page, ActionDefinition actionDefinition) { List tokens = new ArrayList<>(); if (actionDefinition.getTargetType() != null) { diff --git a/judo-ui-react/src/main/resources/actor/src/containers/widget-fragments/binarytypeinput.hbs b/judo-ui-react/src/main/resources/actor/src/containers/widget-fragments/binarytypeinput.hbs index 2f6bb5ae..4478ff50 100644 --- a/judo-ui-react/src/main/resources/actor/src/containers/widget-fragments/binarytypeinput.hbs +++ b/judo-ui-react/src/main/resources/actor/src/containers/widget-fragments/binarytypeinput.hbs @@ -8,6 +8,7 @@ editMode={editMode} storeDiff={storeDiff} isLoading={isLoading} + actions={actions} > {{/ if }} {{/ if }} {{# or child.actionDefinition.isCallOperationAction child.actionDefinition.isOpenFormAction }} diff --git a/judo-ui-react/src/main/resources/actor/src/containers/widget-fragments/buttongroup.hbs b/judo-ui-react/src/main/resources/actor/src/containers/widget-fragments/buttongroup.hbs index 7f0e78d0..501b5d3b 100644 --- a/judo-ui-react/src/main/resources/actor/src/containers/widget-fragments/buttongroup.hbs +++ b/judo-ui-react/src/main/resources/actor/src/containers/widget-fragments/buttongroup.hbs @@ -9,6 +9,7 @@ editMode={editMode} storeDiff={storeDiff} isLoading={isLoading} + actions={actions} > {{/ if }} {{# each (featuredButtonsForButtonGroup child) as |button| }} diff --git a/judo-ui-react/src/main/resources/actor/src/containers/widget-fragments/checkbox.hbs b/judo-ui-react/src/main/resources/actor/src/containers/widget-fragments/checkbox.hbs index 7ac4f2a7..b783bec5 100644 --- a/judo-ui-react/src/main/resources/actor/src/containers/widget-fragments/checkbox.hbs +++ b/judo-ui-react/src/main/resources/actor/src/containers/widget-fragments/checkbox.hbs @@ -8,6 +8,7 @@ editMode={editMode} storeDiff={storeDiff} isLoading={isLoading} + actions={actions} > {{/ if }} diff --git a/judo-ui-react/src/main/resources/actor/src/containers/widget-fragments/dateinput.hbs b/judo-ui-react/src/main/resources/actor/src/containers/widget-fragments/dateinput.hbs index 4bb6db92..29deb27e 100644 --- a/judo-ui-react/src/main/resources/actor/src/containers/widget-fragments/dateinput.hbs +++ b/judo-ui-react/src/main/resources/actor/src/containers/widget-fragments/dateinput.hbs @@ -8,6 +8,7 @@ editMode={editMode} storeDiff={storeDiff} isLoading={isLoading} + actions={actions} > {{/ if }} {{/ if }} {{/ if }} diff --git a/judo-ui-react/src/main/resources/actor/src/containers/widget-fragments/enumerationcombo.hbs b/judo-ui-react/src/main/resources/actor/src/containers/widget-fragments/enumerationcombo.hbs index 441e71af..25aaad47 100644 --- a/judo-ui-react/src/main/resources/actor/src/containers/widget-fragments/enumerationcombo.hbs +++ b/judo-ui-react/src/main/resources/actor/src/containers/widget-fragments/enumerationcombo.hbs @@ -8,6 +8,7 @@ editMode={editMode} storeDiff={storeDiff} isLoading={isLoading} + actions={actions} > {{/ if }} {{/ if }} {{/ if }} {{# if this.card }} diff --git a/judo-ui-react/src/main/resources/actor/src/containers/widget-fragments/formatted.hbs b/judo-ui-react/src/main/resources/actor/src/containers/widget-fragments/formatted.hbs index e32136b0..3649cd3e 100644 --- a/judo-ui-react/src/main/resources/actor/src/containers/widget-fragments/formatted.hbs +++ b/judo-ui-react/src/main/resources/actor/src/containers/widget-fragments/formatted.hbs @@ -8,6 +8,7 @@ editMode={editMode} storeDiff={storeDiff} isLoading={isLoading} + actions={actions} > {{/ if }} diff --git a/judo-ui-react/src/main/resources/actor/src/containers/widget-fragments/label.hbs b/judo-ui-react/src/main/resources/actor/src/containers/widget-fragments/label.hbs index 8cd57501..e029d9e5 100644 --- a/judo-ui-react/src/main/resources/actor/src/containers/widget-fragments/label.hbs +++ b/judo-ui-react/src/main/resources/actor/src/containers/widget-fragments/label.hbs @@ -8,6 +8,7 @@ editMode={editMode} storeDiff={storeDiff} isLoading={isLoading} + actions={actions} > {{/ if }} diff --git a/judo-ui-react/src/main/resources/actor/src/containers/widget-fragments/numericinput.hbs b/judo-ui-react/src/main/resources/actor/src/containers/widget-fragments/numericinput.hbs index 91e93b4b..516cc94a 100644 --- a/judo-ui-react/src/main/resources/actor/src/containers/widget-fragments/numericinput.hbs +++ b/judo-ui-react/src/main/resources/actor/src/containers/widget-fragments/numericinput.hbs @@ -8,6 +8,7 @@ editMode={editMode} storeDiff={storeDiff} isLoading={isLoading} + actions={actions} > {{/ if }} {{/ if }} diff --git a/judo-ui-react/src/main/resources/actor/src/containers/widget-fragments/tabcontroller.hbs b/judo-ui-react/src/main/resources/actor/src/containers/widget-fragments/tabcontroller.hbs index 357cee25..cc317312 100644 --- a/judo-ui-react/src/main/resources/actor/src/containers/widget-fragments/tabcontroller.hbs +++ b/judo-ui-react/src/main/resources/actor/src/containers/widget-fragments/tabcontroller.hbs @@ -8,6 +8,7 @@ editMode={editMode} storeDiff={storeDiff} isLoading={isLoading} + actions={actions} > {{/ if }} {{/ if }} diff --git a/judo-ui-react/src/main/resources/actor/src/containers/widget-fragments/textarea.hbs b/judo-ui-react/src/main/resources/actor/src/containers/widget-fragments/textarea.hbs index 2e546737..f6be36f5 100644 --- a/judo-ui-react/src/main/resources/actor/src/containers/widget-fragments/textarea.hbs +++ b/judo-ui-react/src/main/resources/actor/src/containers/widget-fragments/textarea.hbs @@ -8,6 +8,7 @@ editMode={editMode} storeDiff={storeDiff} isLoading={isLoading} + actions={actions} > {{/ if }} {{/ if }} {{/ if }} {{/ if }} Promise; {{/ with }} + {{# with (getCreateDefinitionForContainer page.container) as |createActionDefinition| }} + post{{ firstToUpper (simpleActionDefinitionName createActionDefinition) }}?: ({{{ postCreateActionParams page createActionDefinition }}}) => Promise; + {{/ with }} }; export const {{ camelCaseNameToInterfaceKey (pageName page) }}_ACTIONS_HOOK_INTERFACE_KEY = '{{ containerComponentName page.container }}ActionsHook'; diff --git a/judo-ui-react/src/main/resources/actor/src/pages/actions/CreateAction.fragment.hbs b/judo-ui-react/src/main/resources/actor/src/pages/actions/CreateAction.fragment.hbs index 3fd9462e..bf9d2b38 100644 --- a/judo-ui-react/src/main/resources/actor/src/pages/actions/CreateAction.fragment.hbs +++ b/judo-ui-react/src/main/resources/actor/src/pages/actions/CreateAction.fragment.hbs @@ -2,8 +2,12 @@ const {{ simpleActionDefinitionName action.actionDefinition }} = async () => { try { setIsLoading(true); const res = await {{ getServiceImplForPage page }}.create{{# if action.targetDataElement }}{{ firstToUpper action.targetDataElement.name }}{{/ if }}({{# unless action.ownerDataElement.isAccess }}ownerData, {{/ unless }}payloadDiff.current); - showSuccessSnack(t('judo.action.create.success', { defaultValue: 'Create successful' })); - onSubmit(res); + if (customActions?.post{{ firstToUpper (simpleActionDefinitionName action.actionDefinition) }}) { + await customActions.post{{ firstToUpper (simpleActionDefinitionName action.actionDefinition) }}(data, res, onSubmit, onClose); + } else { + showSuccessSnack(t('judo.action.create.success', { defaultValue: 'Create successful' })); + onSubmit(res); + } } catch (error) { handleError<{{ classDataName (getReferenceClassType page) '' }}>(error, { setValidation }, data); } finally {