Skip to content

Commit

Permalink
removes unused function concatenates conditionals and moves function …
Browse files Browse the repository at this point in the history
…to same file is is used in
  • Loading branch information
cammiida committed Dec 3, 2024
1 parent 307a9bc commit b7480c3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 42 deletions.
22 changes: 21 additions & 1 deletion src/components/wrappers/ProcessWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ import { PresentationComponent } from 'src/components/presentation/Presentation'
import classes from 'src/components/wrappers/ProcessWrapper.module.css';
import { Loader } from 'src/core/loading/Loader';
import { useAppName, useAppOwner } from 'src/core/texts/appTexts';
import { useApplicationMetadata } from 'src/features/applicationMetadata/ApplicationMetadataProvider';
import { useCurrentDataModelGuid } from 'src/features/datamodel/useBindingSchema';
import { FormProvider } from 'src/features/form/FormContext';
import { useLayoutSets } from 'src/features/form/layoutSets/LayoutSetsProvider';
import { useGetTaskTypeById, useLaxProcessData, useRealTaskTypeById } from 'src/features/instance/ProcessContext';
import { useGetTaskTypeById, useLaxProcessData, useTaskTypeFromBackend } from 'src/features/instance/ProcessContext';
import { ProcessNavigationProvider } from 'src/features/instance/ProcessNavigationContext';
import { Lang } from 'src/features/language/Lang';
import { useLanguage } from 'src/features/language/useLanguage';
Expand Down Expand Up @@ -232,3 +233,22 @@ export const ComponentRouting = () => {
// If node exists but does not implement sub routing
throw new Error(`Component ${componentId} does not have subRouting`);
};

function useRealTaskTypeById(taskId: string | undefined) {
const isStateless = useApplicationMetadata().isStatelessApp;
const layoutSets = useLayoutSets();
const processData = useLaxProcessData();
const altinnTaskType = useTaskTypeFromBackend();

if (isStateless || behavesLikeDataTask(taskId, layoutSets)) {
// Stateless apps only have data tasks. As soon as they start creating an instance from that stateless step,
// applicationMetadata.isStatelessApp will return false and we'll proceed as normal.
return ProcessTaskType.Data;
}

if (processData?.ended) {
return ProcessTaskType.Archived;
}

return altinnTaskType;
}
43 changes: 2 additions & 41 deletions src/features/instance/ProcessContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ export const useReFetchProcessData = () => useContext(ProcessContext)?.refetch;

/**
* This returns the task type of the current process task, as we got it from the backend
*
* @see useRealTaskType
*/
export function useTaskTypeFromBackend() {
const processData = useLaxProcessData();
Expand All @@ -91,17 +89,6 @@ export function useTaskTypeFromBackend() {
return ProcessTaskType.Unknown;
}

/**
* This returns the task type of the current process task, as we want to use it in the frontend. Some tasks
* are configured to behave like data tasks, and we want to treat them as such.
*
* @see useTaskTypeFromBackend
*/
export function useRealTaskType() {
const taskId = useLaxProcessData()?.currentTask?.elementId;
return useRealTaskTypeById(taskId || undefined);
}

/**
* This hook returns the taskType of a given taskId. If the
* taskId cannot be found in processTasks it will return the
Expand All @@ -121,23 +108,16 @@ export function useGetTaskTypeById() {
? processData?.currentTask
: undefined;

if (isStateless) {
if (isStateless || taskId === TaskKeys.CustomReceipt) {
// Stateless apps only have data tasks. As soon as they start creating an instance from that stateless step,
// applicationMetadata.isStatelessApp will return false and we'll proceed as normal.
return ProcessTaskType.Data;
}

if (taskId === TaskKeys.CustomReceipt) {
return ProcessTaskType.Data;
}

if (taskId === TaskKeys.ProcessEnd) {
if (taskId === TaskKeys.ProcessEnd || processData?.ended) {
return ProcessTaskType.Archived;
}

if (processData?.ended) {
return ProcessTaskType.Archived;
}
if (task === undefined || task?.altinnTaskType === undefined) {
return ProcessTaskType.Unknown;
}
Expand All @@ -148,22 +128,3 @@ export function useGetTaskTypeById() {
[isStateless, layoutSets, processData?.currentTask, processData?.ended, processData?.processTasks],
);
}

export function useRealTaskTypeById(taskId: string | undefined) {
const isStateless = useApplicationMetadata().isStatelessApp;
const layoutSets = useLayoutSets();
const processData = useLaxProcessData();
const altinnTaskType = useTaskTypeFromBackend();

if (isStateless || behavesLikeDataTask(taskId, layoutSets)) {
// Stateless apps only have data tasks. As soon as they start creating an instance from that stateless step,
// applicationMetadata.isStatelessApp will return false and we'll proceed as normal.
return ProcessTaskType.Data;
}

if (processData?.ended) {
return ProcessTaskType.Archived;
}

return altinnTaskType;
}

0 comments on commit b7480c3

Please sign in to comment.