Skip to content

Commit d99b9ea

Browse files
authored
Merge pull request #775 from PROCEED-Labs/fix/caching-related-bugs
Fix: Caching Related Bugs
2 parents 4894c3a + 49d0ff8 commit d99b9ea

13 files changed

Lines changed: 196 additions & 140 deletions

File tree

src/management-system-v2/app/(dashboard)/[environmentId]/(automation)/executions/[processId]/process-deployment-view.tsx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -302,13 +302,18 @@ export default function ProcessDeploymentView({ processId }: { processId: string
302302
<ToolbarGroup>
303303
<Select
304304
value={currentInstance?.processInstanceId}
305+
loading={!!selectedInstanceId && !currentInstance}
305306
variant="borderless"
306307
onSelect={(value) => setSelectedInstanceId(value)}
307308
options={versionInstances?.map((instance, idx) => ({
308309
value: instance.processInstanceId,
309310
label: `${idx + 1}. Instance: ${new Date(instance.globalStartTime).toLocaleString()}`,
310311
}))}
311-
placeholder="Select an instance"
312+
placeholder={
313+
!!selectedInstanceId && !currentInstance
314+
? 'Fetching Instance Data'
315+
: 'Select an instance'
316+
}
312317
/>
313318

314319
{currentInstance?.offline && (
@@ -429,16 +434,14 @@ export default function ProcessDeploymentView({ processId }: { processId: string
429434

430435
setStartForm(startForm);
431436
} else {
432-
return startInstance(spaceId, processId, versionId);
437+
return startInstance(spaceId, processId, versionId, undefined, true);
433438
}
434439
},
435440
onSuccess: async (instanceId) => {
436441
if (instanceId) {
437442
await refetchDeployments();
438-
setTimeout(async () => {
439-
await refetchInstances();
440-
setSelectedInstanceId(instanceId);
441-
}, 1000);
443+
await refetchInstances();
444+
setSelectedInstanceId(instanceId);
442445
}
443446
},
444447
});
@@ -680,10 +683,12 @@ export default function ProcessDeploymentView({ processId }: { processId: string
680683
currentVersion.processId,
681684
currentVersion.id,
682685
mappedVariables,
686+
true,
683687
);
684688
},
685689
onSuccess: async (instanceId) => {
686690
await refetchDeployments();
691+
await refetchInstances();
687692
setSelectedInstanceId(instanceId);
688693
setStartForm('');
689694
},
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import React, { ReactNode } from 'react';
2+
import { statusToType } from './instance-helpers';
3+
import type { ElementLike } from 'diagram-js/lib/core/Types';
4+
import { ExtendedInstanceInfo } from '@/lib/data/instance';
5+
import {
6+
CheckCircleOutlined,
7+
ClockCircleOutlined,
8+
CloseCircleOutlined,
9+
ExclamationCircleOutlined,
10+
SyncOutlined,
11+
} from '@ant-design/icons';
12+
import { Tag } from 'antd';
13+
14+
export const StatusTag = ({
15+
processId,
16+
element,
17+
instance,
18+
}: {
19+
processId: string;
20+
element?: ElementLike;
21+
instance?: ExtendedInstanceInfo;
22+
}) => {
23+
// Element status
24+
const isRootElement = element && element.type === 'bpmn:Process';
25+
let status = undefined;
26+
if (isRootElement && instance) {
27+
status = instance.instanceState.reduce((overallState, state) => {
28+
return ['ENDED', 'STOPPED'].includes(overallState) ? state : overallState;
29+
});
30+
} else if (element && instance) {
31+
const elementInfo = instance.log.find((l) => l.flowElementId == element.id);
32+
if (elementInfo) {
33+
status = elementInfo.executionState;
34+
} else {
35+
const tokenInfo = instance.tokens.find((l) => l.currentFlowElementId == element.id);
36+
status = tokenInfo ? tokenInfo.currentFlowNodeState : 'WAITING';
37+
}
38+
}
39+
const statusType = status && statusToType(status);
40+
const presets: Record<string, ReactNode> = {
41+
READY: <CheckCircleOutlined />,
42+
COMPLETED: <CheckCircleOutlined />,
43+
RUNNING: <SyncOutlined spin />,
44+
info: <ExclamationCircleOutlined />,
45+
warning: <ExclamationCircleOutlined />,
46+
STOPPED: <CloseCircleOutlined />,
47+
WAITING: <ClockCircleOutlined />,
48+
};
49+
return (
50+
status &&
51+
statusType && (
52+
<Tag
53+
key={status}
54+
color={statusType}
55+
icon={status ? presets[status] : <ClockCircleOutlined />}
56+
>
57+
{status}
58+
</Tag>
59+
)
60+
);
61+
};

src/management-system-v2/app/(dashboard)/[environmentId]/(automation)/executions/deployments-view.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ const DeploymentsView = ({
108108
space.spaceId,
109109
'dynamic',
110110
forceEngine,
111+
true,
111112
);
112113
queryClient.removeQueries({
113114
queryKey: ['processDeployments', space.spaceId, process.id],

src/management-system-v2/app/(dashboard)/[environmentId]/tasklist/tasklist.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ const Tasklist: React.FC<TasklistProps> = ({ userId, pollingInterval }) => {
5757

5858
const space = useEnvironment();
5959

60-
const { userTasks } = useUserTasks(space, pollingInterval, {
60+
const { userTasks, refetch } = useUserTasks(space, pollingInterval, {
6161
hideNonOwnableTasks: true,
6262
hideUnassignedTasks: false,
6363
});
@@ -291,7 +291,7 @@ const Tasklist: React.FC<TasklistProps> = ({ userId, pollingInterval }) => {
291291
)}
292292
</div>
293293
{(selectedUserTaskID ?? breakpoint.xl) && (
294-
<UserTaskView userId={userId} task={selectedUserTask} />
294+
<UserTaskView userId={userId} task={selectedUserTask} refetch={refetch} />
295295
)}
296296
</div>
297297
);

src/management-system-v2/app/(dashboard)/[environmentId]/tasklist/user-task-view.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,10 @@ export const UserTaskForm: React.FC<UserTaskFormProps> = ({
125125
type TaskListUserTaskFormProps = {
126126
userId: string;
127127
task?: ExtendedTaskListEntry;
128+
refetch?: () => {};
128129
};
129130

130-
const TaskListUserTaskForm: React.FC<TaskListUserTaskFormProps> = ({ task, userId }) => {
131+
const TaskListUserTaskForm: React.FC<TaskListUserTaskFormProps> = ({ task, userId, refetch }) => {
131132
const space = useEnvironment();
132133

133134
const { message } = App.useApp();
@@ -175,7 +176,9 @@ const TaskListUserTaskForm: React.FC<TaskListUserTaskFormProps> = ({ task, userI
175176
const updatedOwners = await addOwnerToTaskListEntry(space.spaceId, task.id, userId);
176177
if ('error' in updatedOwners) return updatedOwners;
177178
}
178-
return await completeTasklistEntry(space.spaceId, task.id, variables);
179+
const res = await completeTasklistEntry(space.spaceId, task.id, variables, true);
180+
refetch?.();
181+
return res;
179182
},
180183
});
181184
}}

src/management-system-v2/lib/data/deployment.ts

Lines changed: 1 addition & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
'use server';
22

33
import db from '@/lib/data/db';
4-
import { DeploymentInput, DeploymentInputSchema } from '../deployment-schema';
54
import { getCurrentEnvironment } from '@/components/auth';
65
import { SuccessType, UserErrorType, userError } from '../user-error';
76
import Ability from '../ability/abilityHelper';
8-
import { cacheLife, cacheTag, revalidateTag } from 'next/cache';
7+
import { cacheLife, cacheTag } from 'next/cache';
98

109
export async function getDeployedProcesses(environmentId: string, withArchived = false) {
1110
const { ability } = await getCurrentEnvironment(environmentId);
@@ -123,52 +122,3 @@ export async function getProcessDeployments(
123122
export type StoredDeployment = SuccessType<
124123
Awaited<ReturnType<typeof getProcessDeployments>>
125124
>[number];
126-
127-
export async function addDeployment(
128-
spaceId: string,
129-
processId: string,
130-
input: DeploymentInput,
131-
ability?: Ability,
132-
) {
133-
if (!ability) ({ ability } = await getCurrentEnvironment(spaceId));
134-
135-
if (!ability.can('create', 'Execution'))
136-
return userError('Invalid Permissions', UserErrorType.PermissionError);
137-
138-
const data = DeploymentInputSchema.parse(input);
139-
140-
const res = await db.processDeployment.createManyAndReturn({
141-
data: data.engineIds.map((engineId) => ({ ...data, engineIds: undefined, engineId })),
142-
});
143-
144-
revalidateTag(`space/${spaceId}/deployments`, 'max');
145-
revalidateTag(`deployments/process/${processId}`, 'max');
146-
147-
return res;
148-
}
149-
150-
export async function updateDeployment(
151-
spaceId: string,
152-
processId: string,
153-
deploymentId: string,
154-
input: Partial<DeploymentInput>,
155-
ability?: Ability,
156-
) {
157-
if (!ability) ({ ability } = await getCurrentEnvironment(spaceId));
158-
159-
if (!ability.can('update', 'Execution')) {
160-
return userError('Invalid Permissions', UserErrorType.PermissionError);
161-
}
162-
163-
const data = DeploymentInputSchema.partial().strict().parse(input);
164-
165-
const result = await db.processDeployment.update({
166-
where: { id: deploymentId },
167-
data,
168-
});
169-
170-
revalidateTag(`space/${spaceId}/deployments`, 'max');
171-
revalidateTag(`deployments/process/${processId}`, 'max');
172-
173-
return result;
174-
}

src/management-system-v2/lib/data/instance.ts

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -353,35 +353,6 @@ export async function getInstances(spaceId: string, ability: Ability) {
353353
return instances.map(({ id }) => id);
354354
}
355355

356-
export async function addInstance(
357-
spaceId: string,
358-
instance: InstanceInput,
359-
skipAbilityCheck = false,
360-
) {
361-
if (!skipAbilityCheck) {
362-
const { ability } = await getCurrentEnvironment(spaceId);
363-
364-
if (!ability.can('create', 'Execution'))
365-
return userError('Invalid Permissions', UserErrorType.PermissionError);
366-
}
367-
368-
const data = InstanceInputSchema.parse(instance);
369-
370-
const res = await db.processInstance.create({
371-
data: {
372-
...data,
373-
engines: {
374-
connect: data.engines.map((id) => ({ id })),
375-
},
376-
},
377-
});
378-
379-
revalidateTag(`space/${spaceId}/instances`, 'max');
380-
revalidateTag(`deployments/process/${instance.state.processId}`, 'max');
381-
382-
return res;
383-
}
384-
385356
export async function updateInstance(
386357
spaceId: string,
387358
instanceId: string,

src/management-system-v2/lib/deployment-schema.ts

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)