Skip to content

Commit

Permalink
JNG-4838 add singleton access page
Browse files Browse the repository at this point in the history
  • Loading branch information
noherczeg committed Oct 26, 2023
1 parent 7977a6c commit 8508c0f
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,22 @@ const {{ simpleActionDefinitionName action.actionDefinition }} = async (queryCus
{{# if page.container.table }}
return {{ getServiceImplForPage page }}.list({{# if (pageHasSignedId page) }}{{# if page.openInDialog }}data{{ else }}{ __signedIdentifier: signedIdentifier } as JudoIdentifiable<any>{{/ if }}{{ else }}undefined{{/ if }}, queryCustomizer);
{{ else }}
const result = await {{ getServiceImplForPage page }}.refresh({{# if (pageHasSignedId page) }}{{# if page.openInDialog }}targetData{{ else }}{ __signedIdentifier: signedIdentifier } as JudoIdentifiable<any>{{/ if }}{{ else }}undefined{{/ if }}, pageQueryCustomizer);
const result = await {{ getServiceImplForPage page }}.refresh(
{{# if (pageHasSignedId page) }}
{{# if page.openInDialog }}
targetData
{{ else }}
{ __signedIdentifier: signedIdentifier } as JudoIdentifiable<any>
{{/ if }}
{{ else }}
{{# if (isSingleAccessPage page) }}
singletonHost.current
{{ else }}
undefined
{{/ if }}
{{/ if }},
pageQueryCustomizer
);

setData(result);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ export default function {{ pageName page }}() {
const [validation, setValidation] = useState<Map<keyof {{ classDataName (getReferenceClassType page) '' }}, string>>(new Map<keyof {{ classDataName (getReferenceClassType page) '' }}, string>());

// Ref section
{{# if (isSingleAccessPage page) }}
const singletonHost = useRef<{ __signedIdentifier: string }>({} as unknown as { __signedIdentifier: string });
{{/ if }}
const payloadDiff = useRef<Record<keyof {{ classDataName (getReferenceClassType page) 'Stored' }}, any>>({} as unknown as Record<keyof {{ classDataName (getReferenceClassType page) 'Stored' }}, any>);

// Callback section
Expand Down Expand Up @@ -123,6 +126,13 @@ export default function {{ pageName page }}() {
{{# each page.actions as |action| }}
{{> (getActionTemplate action) }}
{{/ each }}
{{# if (isSingleAccessPage page) }}
const getSingletonPayload = async (): Promise<JudoIdentifiable<any>> => {
return await {{ getServiceImplForPage page }}.refreshFor{{ firstToUpper page.dataElement.name }}({
_mask: '{}',
});
}
{{/ if }}

const actions: {{ containerComponentName page.container }}PageActions = {
{{# each page.actions as |action| }}
Expand All @@ -133,7 +143,18 @@ export default function {{ pageName page }}() {
// Effect section
{{# if (pageShouldInitialize page) }}
useEffect(() => {
actions.{{ simpleActionDefinitionName page.container.onInit }}!({{# if page.container.view }}pageQueryCustomizer{{/ if }});
(async () => {
{{# if (isSingleAccessPage page) }}
const res = await getSingletonPayload();
if (res?.__signedIdentifier) {
singletonHost.current = res;
} else {
navigate('*');
return;
}
{{/ if }}
await actions.{{ simpleActionDefinitionName page.container.onInit }}!({{# if page.container.view }}pageQueryCustomizer{{/ if }});
})();
}, []);
{{/ if }}
{{/ unless }}
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@

<judo-meta-ui-version>1.1.0.20231024_175354_d92dd516_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.20231020_233253_3788a60f_feature_JNG_4838_SeparatePageContainerAndDefinition</judo-ui-typescript-rest-version>
<judo-ui-typescript-rest-version>1.0.0.20231026_150611_b39a761b_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 8508c0f

Please sign in to comment.