Skip to content

Commit

Permalink
JNG-4838 add update action impl
Browse files Browse the repository at this point in the history
  • Loading branch information
noherczeg committed Oct 11, 2023
1 parent 5364971 commit 9d84791
Show file tree
Hide file tree
Showing 7 changed files with 799 additions and 760 deletions.
1,486 changes: 743 additions & 743 deletions judo-ui-react-itest/ActionGroupTest/model/ActionGroupTest-ui.model

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.List;
import java.util.stream.Collectors;

import static hu.blackbelt.judo.ui.generator.react.UiWidgetHelper.collectVisualElementsMatchingCondition;
import static hu.blackbelt.judo.ui.generator.react.UiWidgetHelper.getReferenceClassType;
import static hu.blackbelt.judo.ui.generator.typescript.rest.commons.UiCommonsHelper.*;
import static java.util.Arrays.stream;
Expand Down Expand Up @@ -644,15 +645,15 @@ public static boolean pageShouldInitialize(PageDefinition pageDefinition) {
// public static boolean pageShouldOpenInDialog(PageDefinition pageDefinition) {
// return pageDefinition.isOpenInDialog();
// }
//
// public static boolean hasPageRequiredBy(PageDefinition pageDefinition) {
// return !(getRequiredByWidgetsForPage(pageDefinition).isEmpty());
// }
//
// public static List<VisualElement> getRequiredByWidgetsForPage(PageDefinition pageDefinition) {
// Set<VisualElement> elements = new LinkedHashSet<>();
// collectVisualElementsMatchingCondition(pageDefinition.getOriginalPageContainer(), (element) -> element.getRequiredBy() != null, elements);
//
// return elements.stream().sorted(Comparator.comparing(NamedElement::getFQName)).collect(Collectors.toList());
// }

public static boolean hasPageRequiredBy(PageDefinition pageDefinition) {
return !(getRequiredByWidgetsForPage(pageDefinition).isEmpty());
}

public static List<VisualElement> getRequiredByWidgetsForPage(PageDefinition pageDefinition) {
Set<VisualElement> elements = new LinkedHashSet<>();
collectVisualElementsMatchingCondition(pageDefinition.getContainer(), (element) -> element.getRequiredBy() != null, elements);

return elements.stream().sorted(Comparator.comparing(NamedElement::getFQName)).collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const requiredByRecord: Record<string, boolean> = {
{{/ each }}
};

const result = passesLocalValidation<{{ classDataName page.dataElement.target '' }}>(data, requiredByRecord, t, setValidation);
const result = passesLocalValidation<{{ classDataName (getReferenceClassType page) '' }}>(data, requiredByRecord, t, setValidation);

if (!result) {
return;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const {{ simpleActionDefinitionName action.actionDefinition }} = async (queryCustomizer: {{ classDataName (getReferenceClassType page) 'QueryCustomizer' }}): Promise<{{ classDataName (getReferenceClassType page) 'Stored' }}{{# if page.container.table }}[]{{/ if }}> => {
// alert('RefreshAction');
try {
setIsLoading(true);
setEditMode(false);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
const {{ simpleActionDefinitionName action.actionDefinition }} = async () => {
alert('UpdateAction');
{{# if (hasPageRequiredBy page) }}
{{> actor/src/fragments/page/local-validate.fragment.hbs }}
{{/ if }}

setIsLoading(true);

try {
const res = await {{ getServiceImplForPage page }}.update({{# unless page.dataElement.isAccess }}{ __signedIdentifier: signedIdentifier! }, {{/ unless }}payloadDiff.current);

if (res) {
enqueueSnackbar(t('judo.action.save.success', { defaultValue: 'Changes saved' }), {
variant: 'success',
...toastConfig.success,
});
setValidation(new Map<keyof {{ classDataName (getReferenceClassType page) '' }}, string>());
{{# with (getRefreshActionDefinitionForContainer page.container) as |actionDefinition| }}
await actions.{{ simpleActionDefinitionName actionDefinition }}!(pageQueryCustomizer);
{{/ with }}
setEditMode(false);
}
} catch (error) {
handleUpdateError(error, { setValidation }, data);
} finally {
setIsLoading(false);
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,20 @@ import { useCallback, useEffect, useRef, useState, lazy, Suspense } from 'react'
import type { JudoIdentifiable } from '@judo/data-api-common';
import { useTranslation } from 'react-i18next';
import { useParams } from 'react-router-dom';
import { useSnackbar } from 'notistack';
{{# if page.container.table }}
import type { GridFilterModel } from '@mui/x-data-grid{{ getMUIDataGridPlanSuffix }}';
import type { Filter } from '~/components-api';
{{/ if }}
import { useJudoNavigation } from '~/components';
import { uiDateToServiceDate, uiTimeToServiceTime, useErrorHandler, ERROR_PROCESSOR_HOOK_INTERFACE_KEY } from '~/utilities';
import { toastConfig } from '~/config';
import {
passesLocalValidation,
uiDateToServiceDate,
uiTimeToServiceTime,
useErrorHandler,
ERROR_PROCESSOR_HOOK_INTERFACE_KEY,
} from '~/utilities';
import { PageContainerTransition } from '~/theme/animations';
{{# each (getRelatedPages page) as |relatedPage| }}
import { routeTo{{ pageName relatedPage }} } from '~/routes';
Expand Down Expand Up @@ -40,8 +48,15 @@ import { useCallback, useEffect, useRef, useState, lazy, Suspense } from 'react'
export default function {{ pageName page }}() {
{{# unless (containerIsEmptyDashboard page.container) }}
const { t } = useTranslation();
const { enqueueSnackbar } = useSnackbar();
const { navigate, back } = useJudoNavigation();
const handleFetchError = useErrorHandler(`(&(${OBJECTCLASS}=${ERROR_PROCESSOR_HOOK_INTERFACE_KEY})(operation=Fetch))`);
{{# if page.dataElement.isUpdatable }}
const handleUpdateError = useErrorHandler<{{ classDataName (getReferenceClassType page) '' }}>(`(&(${OBJECTCLASS}=${ERROR_PROCESSOR_HOOK_INTERFACE_KEY})(operation=Update)(component={{ pageName page }}))`);
{{/ if }}
{{# if page.dataElement.isDeletable }}
const handleDeleteError = useErrorHandler<{{ classDataName (getReferenceClassType page) '' }}>(`(&(${OBJECTCLASS}=${ERROR_PROCESSOR_HOOK_INTERFACE_KEY})(operation=Delete)(component={{ pageName page }}))`);
{{/ if }}
{{# if (pageHasSignedId page) }}
const { signedIdentifier } = useParams();
{{/ if }}
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@
<node-version>18.14.2</node-version>
<pnpm-version>8.5.1</pnpm-version>

<judo-meta-ui-version>1.1.0-SNAPSHOT</judo-meta-ui-version>
<judo-meta-ui-version>1.1.0.20231011_143440_62adaf9c_feature_JNG_4838_SeparatePageContainerAndDefinition</judo-meta-ui-version>
<judo-generator-commons-version>1.0.0.20230826_230139_c0dd2610_develop</judo-generator-commons-version>
<judo-ui-typescript-rest-version>1.0.0.20231010_135708_f916574d_feature_JNG_4838_SeparatePageContainerAndDefinition</judo-ui-typescript-rest-version>
<judo-ui-typescript-rest-version>1.0.0.20231011_153046_1afebe97_feature_JNG_4838_SeparatePageContainerAndDefinition</judo-ui-typescript-rest-version>

<surefire-version>3.0.0-M7</surefire-version>
<!--suppress UnresolvedMavenProperty -->
Expand Down

0 comments on commit 9d84791

Please sign in to comment.