Skip to content

Commit

Permalink
JNG-5382 post create hook with component proxy params
Browse files Browse the repository at this point in the history
  • Loading branch information
noherczeg committed Jan 3, 2024
1 parent bf7d0b5 commit 205fd02
Show file tree
Hide file tree
Showing 23 changed files with 43 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -287,6 +291,16 @@ public static String refreshActionDataParameter(Action action) {
return "undefined";
}

public static String postCreateActionParams(PageDefinition page, ActionDefinition actionDefinition) {
List<String> 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<void>");
tokens.add("onClose: () => Promise<void>");
return String.join(", ", tokens);
}

public static String postCallOperationActionParams(PageDefinition page, ActionDefinition actionDefinition) {
List<String> tokens = new ArrayList<>();
if (actionDefinition.getTargetType() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
editMode={editMode}
storeDiff={storeDiff}
isLoading={isLoading}
actions={actions}
>
{{/ if }}
<BinaryInput
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
editMode={editMode}
storeDiff={storeDiff}
isLoading={isLoading}
actions={actions}
>
{{/ if }}
{{# or child.actionDefinition.isCallOperationAction child.actionDefinition.isOpenFormAction }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
editMode={editMode}
storeDiff={storeDiff}
isLoading={isLoading}
actions={actions}
>
{{/ if }}
{{# each (featuredButtonsForButtonGroup child) as |button| }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
editMode={editMode}
storeDiff={storeDiff}
isLoading={isLoading}
actions={actions}
>
{{/ if }}
<FormControl error={!!validation.get('{{ child.attributeType.name }}')}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
editMode={editMode}
storeDiff={storeDiff}
isLoading={isLoading}
actions={actions}
>
{{/ if }}
<DatePicker
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
editMode={editMode}
storeDiff={storeDiff}
isLoading={isLoading}
actions={actions}
>
{{/ if }}
<DateTimePicker
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
editMode={editMode}
storeDiff={storeDiff}
isLoading={isLoading}
actions={actions}
>
{{/ if }}
<Grid container sx={ { height: DIVIDER_HEIGHT } } alignItems="center">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
editMode={editMode}
storeDiff={storeDiff}
isLoading={isLoading}
actions={actions}
>
{{/ if }}
<TextField
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
editMode={editMode}
storeDiff={storeDiff}
isLoading={isLoading}
actions={actions}
>
{{/ if }}
<FormControl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
editMode={editMode}
storeDiff={storeDiff}
isLoading={isLoading}
actions={actions}
>
{{/ if }}
{{# if this.card }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
editMode={editMode}
storeDiff={storeDiff}
isLoading={isLoading}
actions={actions}
>
{{/ if }}
<Grid container direction="row" alignItems="center" {{# if child.icon }}spacing={2}{{/ if }}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
editMode={editMode}
storeDiff={storeDiff}
isLoading={isLoading}
actions={actions}
>
{{/ if }}
<Grid container direction="row" alignItems="center" justifyContent="flex-start">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
editMode={editMode}
storeDiff={storeDiff}
isLoading={isLoading}
actions={actions}
>
{{/ if }}
<NumericInput
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
editMode={editMode}
storeDiff={storeDiff}
isLoading={isLoading}
actions={actions}
>
{{/ if }}
<Grid container sx={ { height: DIVIDER_HEIGHT } } id="{{ getXMIID child }}"></Grid>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
editMode={editMode}
storeDiff={storeDiff}
isLoading={isLoading}
actions={actions}
>
{{/ if }}
<ModeledTabs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
editMode={editMode}
storeDiff={storeDiff}
isLoading={isLoading}
actions={actions}
>
{{/ if }}
<Typography id="{{ getXMIID child }}">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
editMode={editMode}
storeDiff={storeDiff}
isLoading={isLoading}
actions={actions}
>
{{/ if }}
<TextField
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
editMode={editMode}
storeDiff={storeDiff}
isLoading={isLoading}
actions={actions}
>
{{/ if }}
<TextField
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
editMode={editMode}
storeDiff={storeDiff}
isLoading={isLoading}
actions={actions}
>
{{/ if }}
<TimePicker
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
editMode={editMode}
storeDiff={storeDiff}
isLoading={isLoading}
actions={actions}
>
{{/ if }}
<TrinaryLogicCombobox
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ import { {{# unless page.container.table }}useCallback, useEffect, useRef, {{/ u
{{# with (getGetTemplateActionDefinitionForContainer page.container) as |getTemplateActionDefinition| }}
post{{ firstToUpper (simpleActionDefinitionName getTemplateActionDefinition) }}?: ({{{ postGetTemplateActionParams page getTemplateActionDefinition }}}) => Promise<void>;
{{/ with }}
{{# with (getCreateDefinitionForContainer page.container) as |createActionDefinition| }}
post{{ firstToUpper (simpleActionDefinitionName createActionDefinition) }}?: ({{{ postCreateActionParams page createActionDefinition }}}) => Promise<void>;
{{/ with }}
};

export const {{ camelCaseNameToInterfaceKey (pageName page) }}_ACTIONS_HOOK_INTERFACE_KEY = '{{ containerComponentName page.container }}ActionsHook';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 205fd02

Please sign in to comment.