Skip to content

Commit

Permalink
JNG-4838 fix build issues, refactor generated folder to services
Browse files Browse the repository at this point in the history
  • Loading branch information
noherczeg committed Nov 6, 2023
1 parent 6988370 commit c2a89c0
Show file tree
Hide file tree
Showing 16 changed files with 114 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ public static List<String> getApiImportsForReferenceType(ReferenceType reference
public static List<String> getApiImportsForPage(PageDefinition pageDefinition) {
Set<String> res = new HashSet<>();

if (pageDefinition.getDataElement() instanceof ReferenceType) {
res.addAll(getApiImportsForReferenceType((ReferenceType) pageDefinition.getDataElement()));
if (pageDefinition.getDataElement() instanceof ReferenceType referenceType) {
res.addAll(getApiImportsForReferenceType(referenceType));
}

for (Object table: pageDefinition.getContainer().getTables()) {
Expand Down Expand Up @@ -174,9 +174,29 @@ public static List<String> getApiImportsForPage(PageDefinition pageDefinition) {
}
}

if (isPageForOperationParameterType(pageDefinition) && pageHasOutputTarget(pageDefinition)) {
res.add(classDataName(getPageOutputTarget(pageDefinition), ""));
res.add(classDataName(getPageOutputTarget(pageDefinition), "Stored"));
if (pageDefinition.getContainer().isIsSelector()) {
if (pageDefinition.getDataElement() instanceof OperationType operationType) {
if (operationType.getInput() != null) {
res.add(classDataName(operationType.getInput().getTarget(), "Stored"));
}
if (operationType.getOutput() != null) {
res.add(classDataName(operationType.getOutput().getTarget(), "Stored"));
}
} else if (pageDefinition.getDataElement() instanceof RelationType relationType) {
res.add(classDataName(relationType.getTarget(), "Stored"));
}
}
if (pageDefinition.getDataElement() instanceof OperationParameterType operationParameterType) {
res.add(classDataName(operationParameterType.getTarget(), "Stored"));

if (operationParameterType.eContainer() instanceof OperationType operationType) {
if (operationType.getOutput() != null) {
res.add(classDataName(operationType.getOutput().getTarget(), "Stored"));
}
}
}
if (pageDefinition.getDataElement() instanceof RelationType relationType) {
res.add(classDataName(relationType.getTarget(), "Stored"));
}

getEnumAttributesForPage(pageDefinition).forEach(a -> {
Expand All @@ -189,7 +209,8 @@ public static List<String> getApiImportsForPage(PageDefinition pageDefinition) {
public static List<PageDefinition> getRelatedPages(PageDefinition pageDefinition) {
Set<PageDefinition> res = new HashSet<>();
try {
for (Action action : pageDefinition.getActions().stream().filter(a -> a.getIsOpenPageAction() && !a.getTargetPageDefinition().isOpenInDialog()).toList()) {
// a.getTargetPageDefinition() != null check is for the case where the target view is not present because it was most likely empty
for (Action action : pageDefinition.getActions().stream().filter(a -> a.getIsOpenPageAction() && a.getTargetPageDefinition() != null && !a.getTargetPageDefinition().isOpenInDialog()).toList()) {
res.add(action.getTargetPageDefinition());
}
} catch (Exception e) {
Expand Down Expand Up @@ -282,19 +303,47 @@ public static boolean isPageForOperationParameterType(PageDefinition page) {
}

public static boolean pageHasOutputTarget(PageDefinition page) {
OperationParameterType type = (OperationParameterType) page.getDataElement();
if (type.eContainer() instanceof OperationType) {
return ((OperationType) type.eContainer()).getOutput() != null;
if (page.getDataElement() instanceof OperationType operationType) {
return operationType.getOutput() != null;
}
if (page.getDataElement() instanceof OperationParameterType operationParameterType) {
if (operationParameterType.eContainer() instanceof OperationType operationType) {
return operationType.getOutput() != null;
}
}
return false;
}

public static ClassType getPageOutputTarget(PageDefinition page) {
OperationParameterType type = (OperationParameterType) page.getDataElement();
return ((OperationType) type.eContainer()).getOutput().getTarget();
if (page.getDataElement() instanceof OperationType operationType) {
return operationType.getOutput().getTarget();
}
if (page.getDataElement() instanceof OperationParameterType operationParameterType) {
if (operationParameterType.eContainer() instanceof OperationType operationType) {
return operationType.getOutput().getTarget();
}
}
return null;
}

public static boolean dialogHasResult(PageDefinition page) {
return !isPageForOperationParameterType(page) || pageHasOutputTarget(page);
}

public static String dialogDataType(PageDefinition page) {
if (page.getContainer().isIsSelector()) {
if (page.getDataElement() instanceof OperationType operationType) {
return classDataName(operationType.getInput().getTarget(), "Stored");
} else if (page.getDataElement() instanceof RelationType relationType) {
return classDataName(relationType.getTarget(), "Stored");
}
}
if (page.getDataElement() instanceof OperationParameterType operationParameterType) {
return classDataName(operationParameterType.getTarget(), "Stored");
}
if (page.getDataElement() instanceof RelationType relationType) {
return classDataName(relationType.getTarget(), "Stored");
}
return "void";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import { createContext, useContext, useState, useEffect } from 'react';
import type { ReactNode } from 'react';
import { useAuth } from 'react-oidc-context';
import { {{ classDataName application.principal 'Stored' }} } from '../generated/data-api';
import { accessServiceImpl } from '../generated/data-axios';
import { {{ classDataName application.principal 'Stored' }} } from '~/services/data-api';
import { accessServiceImpl } from '~/services/data-axios';

export interface PrincipalContext {
principal: {{ classDataName application.principal 'Stored' }};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import {
CollectionAssociationButton,
TrinaryLogicCombobox,
} from '~/components/widgets';
import { StringOperation } from '~/generated/data-api';
import { StringOperation } from '~/services/data-api';
import type {
{{ getLinkAPIImports link container }}
} from '~/generated/data-api';
} from '~/services/data-api';

export interface {{ componentName link }}ActionDefinitions {
{{# each link.actionDefinitions as |actionDefinition| }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import type { Filter, FilterOption } from '~/components-api';
import { FilterType } from '~/components-api';
import type {
{{ getTableAPIImports table container }}
} from '~/generated/data-api';
} from '~/services/data-api';
import { useL10N } from '~/l10n/l10n-context';
import {
{{# if container.isSelector }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
{{# unless (containerIsEmptyDashboard container) }}
import { {{# each (getContainerApiImports container) as |imp| }}
{{ imp }},
{{/ each }} } from '~/generated/data-api';
{{/ each }} } from '~/services/data-api';
{{/ unless }}
{{# each container.tables as |table| }}
import type { {{ componentName table }}ActionDefinitions } from './components/{{ componentName table }}';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { useConfirmDialog } from '~/components/dialog';
{{ classDataName container.dataElement '' }},
{{ classDataName container.dataElement 'Stored' }},
{{ classDataName container.dataElement 'QueryCustomizer' }}
} from '~/generated/data-api';
} from '~/services/data-api';
{{/ unless }}

{{# unless (containerIsEmptyDashboard container) }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { mainContainerPadding } from '~/theme';
{{ classDataName container.dataElement '' }},
{{ classDataName container.dataElement 'Stored' }},
{{ classDataName container.dataElement 'QueryCustomizer' }}
} from '~/generated/data-api';
} from '~/services/data-api';
{{/ unless }}

{{# unless (containerIsEmptyDashboard container) }}
Expand Down
16 changes: 8 additions & 8 deletions judo-ui-react/src/main/resources/actor/src/dialogs/index.tsx.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,18 @@ import { useCallback, useEffect, useRef, useState, lazy, Suspense } from 'react'
{{# each (getApiImportsForPage page) as |imp| }}
{{ imp }},
{{/ each }}
} from '~/generated/data-api';
} from '~/services/data-api';
{{# if (getServiceImplForPage page) }}
import { {{ getServiceImplForPage page }} } from '~/generated/data-axios';
import { {{ getServiceImplForPage page }} } from '~/services/data-axios';
{{/ if }}
{{/ unless }}

{{# unless (containerIsEmptyDashboard page.container) }}
export const use{{ pageName page }} = (): ({{{ getDialogOpenParameters page }}}) => Promise<DialogResult<
{{# if (isPageForOperationParameterType page) }}
{{# if (pageHasOutputTarget page) }}
{{# if (pageHasOutputTarget page) }}{{ classDataName (getPageOutputTarget page) 'Stored' }}{{ else }}void{{/ if }}
{{ else }}
{{ classDataName (getReferenceClassType page) 'Stored' }}{{# if page.container.table }}[]{{/ if }}
{{ dialogDataType page }}{{# if page.container.table }}[]{{/ if }}
{{/ if }}
>> => {
const [createDialog, closeDialog] = useDialog();
Expand Down Expand Up @@ -103,10 +103,10 @@ export interface {{ pageName page }}Props {
ownerData: any;
{{# if page.container.isRelationSelector }}alreadySelected: {{ classDataName (getReferenceClassType page) 'Stored' }}[]{{/ if }}
onClose: () => void;
{{# if (isPageForOperationParameterType page) }}
{{# if (pageHasOutputTarget page) }}
onSubmit: ({{# if (pageHasOutputTarget page) }}result?: {{ classDataName (getPageOutputTarget page) 'Stored' }}{{/ if }}) => void;
{{ else }}
onSubmit: (result?: {{ classDataName (getReferenceClassType page) 'Stored' }}{{# if page.container.table }}[]{{/ if }}) => void;
onSubmit: (result?: {{ dialogDataType page }}{{# if page.container.table }}[]{{/ if }}) => void;
{{/ if }}
}

Expand All @@ -129,9 +129,9 @@ export default function {{ pageName page }}(props: {{ pageName page }}Props) {
const [isLoading, setIsLoading] = useState<boolean>(false);
const [editMode, setEditMode] = useState<boolean>({{# if page.container.form }}true{{ else }}false{{/ if }});
const [refreshCounter, setRefreshCounter] = useState<number>(0);
const [data, setData] = useState<{{ classDataName (getReferenceClassType page) 'Stored' }}{{# if page.container.table }}[]{{/ if }}>({{# if page.container.table }}[]{{ else }}{} as {{ classDataName (getReferenceClassType page) 'Stored' }}{{/ if }});
const [data, setData] = useState<{{ dialogDataType page }}{{# if page.container.table }}[]{{/ if }}>({{# if page.container.table }}[]{{ else }}{} as {{ classDataName (getReferenceClassType page) 'Stored' }}{{/ if }});
{{# if page.container.isSelector }}
const [selectionDiff, setSelectionDiff] = useState<{{ classDataName (getReferenceClassType page) 'Stored' }}[]>([]);
const [selectionDiff, setSelectionDiff] = useState<{{ dialogDataType page }}[]>([]);
{{/ if }}
{{# unless page.container.table }}
const [validation, setValidation] = useState<Map<keyof {{ classDataName (getReferenceClassType page) '' }}, string>>(new Map<keyof {{ classDataName (getReferenceClassType page) '' }}, string>());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { LoadingButton } from '@mui/lab';
import { OBJECTCLASS } from '@pandino/pandino-api';
import type { JudoIdentifiable } from '@judo/data-api-common';
import { ComponentProxy } from '@pandino/react-hooks';
import clsx from 'clsx';
import { clsx } from 'clsx';
import { Box, Container, Grid, {{ getMuiMaterialImportsForPageContainer container }} } from '@mui/material';
import type {
GridFilterModel,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useTheme } from '@mui/material/styles';
import { Box, Typography, useMediaQuery } from '@mui/material';
{{# if application.authentication }}
import { usePrincipal } from '~/auth';
import { {{ classDataName application.principal 'Stored' }} } from '~/generated/data-api';
import { {{ classDataName application.principal 'Stored' }} } from '~/services/data-api';
{{/ if }}
import { useConfig } from '~/hooks';
import { MenuOrientation } from '~/config';
Expand Down
2 changes: 1 addition & 1 deletion judo-ui-react/src/main/resources/actor/src/main.tsx.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { PandinoProvider } from '@pandino/react-hooks';
import { ThemeCustomization } from './theme';
import { applicationCustomizer } from './custom';
import { L10NProvider } from './l10n/l10n-context';
import { accessServiceImpl, judoAxiosProvider } from './generated/data-axios';
import { accessServiceImpl, judoAxiosProvider } from '~/services/data-axios';
import App from './App';
import { routes } from './routes';
import { RootErrorBoundary } from './components/RootErrorBoundary';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@ const {{ simpleActionDefinitionName action.actionDefinition }} = async (target?:
{{/ if }}
{{/ with }}
{{ else }}
{{# if (pageHasSignedId action.targetPageDefinition) }}
// if the `target` is missing we are likely navigating to a relation table page, in which case we need the owner's id
{{/ if }}
navigate(routeTo{{ pageName action.targetPageDefinition }}({{# if (pageHasSignedId action.targetPageDefinition) }}(target{{# if page.container.view }} || data{{ else }}!{{/ if }}).__signedIdentifier{{/ if }}));
{{# if page.openInDialog }}
onClose();
{{# if action.targetPageDefinition }}
{{# if (pageHasSignedId action.targetPageDefinition) }}
// if the `target` is missing we are likely navigating to a relation table page, in which case we need the owner's id
{{/ if }}
navigate(routeTo{{ pageName action.targetPageDefinition }}({{# if (pageHasSignedId action.targetPageDefinition) }}(target{{# if page.container.view }} || data{{ else }}!{{/ if }}).__signedIdentifier{{/ if }}));
{{# if page.openInDialog }}
onClose();
{{/ if }}
{{ else }}
// There was no .targetPageDefinition for this action. Target Page is most likely empty in the model!
{{/ if }}
{{/ if }}
};
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
{{# if action.targetDataElement }}
const {{ simpleActionDefinitionName action.actionDefinition }} = async (queryCustomizer: {{ classDataName action.targetDataElement.target 'QueryCustomizer' }}): Promise<{{ classDataName action.targetDataElement.target 'Stored' }}{{# if action.targetDataElement.isCollection }}[]{{/ if }}> => {
return {{ getServiceImplForPage page }}.list{{ firstToUpper action.targetDataElement.name }}(
{{# if (pageHasSignedId page) }}
{{# if page.openInDialog }}
ownerData
{{ else }}
{ __signedIdentifier: signedIdentifier } as JudoIdentifiable<any>
{{/ if }}
{{ else }}
{{# if (isSingleAccessPage page) }}
singletonHost.current
{{ else }}
undefined
{{/ if }}
{{/ if }},
queryCustomizer
);
}
{{ else }}
const {{ simpleActionDefinitionName action.actionDefinition }} = async (queryCustomizer: {{ classDataName (getReferenceClassType page) 'QueryCustomizer' }}): Promise<{{ classDataName (getReferenceClassType page) 'Stored' }}{{# if page.container.table }}[]{{/ if }}> => {
try {
setIsLoading(true);
Expand Down Expand Up @@ -42,3 +62,4 @@ const {{ simpleActionDefinitionName action.actionDefinition }} = async (queryCus
setRefreshCounter((prevCounter) => prevCounter + 1);
}
};
{{/ if }}
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ import { useCallback, useEffect, useRef, useState, lazy, Suspense } from 'react'
{{# each (getApiImportsForPage page) as |imp| }}
{{ imp }},
{{/ each }}
} from '~/generated/data-api';
} from '~/services/data-api';
{{# if (getServiceImplForPage page) }}
import { {{ getServiceImplForPage page }} } from '~/generated/data-axios';
import { {{ getServiceImplForPage page }} } from '~/services/data-axios';
{{/ if }}
{{/ unless }}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Box, Button, DialogActions, DialogContent, DialogTitle, IconButton } fr
import { useTranslation } from 'react-i18next';
import { MdiIcon } from '~/components';
import { useDialog } from '~/components/dialog';
import { accessServiceImpl } from '../generated/data-axios';
import { accessServiceImpl } from '~/services/data-axios';

export type FileHandlingHook = () => {
downloadFile: (data: any, attributeName: string, disposition: 'inline' | 'attachment') => Promise<void>,
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.20231030_135435_74f2ff9b_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-SNAPSHOT</judo-ui-typescript-rest-version>
<judo-ui-typescript-rest-version>1.0.0.20231106_163414_a38dfb6f_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 c2a89c0

Please sign in to comment.