Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/helper-modules/user-task-helper/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export type UserTaskInfo = {
/**
* - the time at which execution of the element ended
*/
endTime?: number;
endTime?: number | null;
/**
* - the current execution state of the user task
*/
Expand Down Expand Up @@ -143,7 +143,7 @@ export type InstanceInfo = {
* @type {object}
* @property {string} id - the id of the user task
* @property {number} startTime - the time at which execution of the element started
* @property {number} [endTime] - the time at which execution of the element ended
* @property {number | null} [endTime] - the time at which execution of the element ended
* @property {string} state - the current execution state of the user task
* @property {{ [key: string]: number }} [milestones] - the values of the milestones of the user task
* @property {{ [key: string]: any }} [variableChanges] - the variables that were changed by the user task
Expand Down
2 changes: 1 addition & 1 deletion src/helper-modules/user-task-helper/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const { getMilestonesFromElementById } = require('@proceed/bpmn-helper/src/gette
* @type {object}
* @property {string} id - the id of the user task
* @property {number} startTime - the time at which execution of the element started
* @property {number} [endTime] - the time at which execution of the element ended
* @property {number | null} [endTime] - the time at which execution of the element ended
* @property {string} state - the current execution state of the user task
* @property {{ [key: string]: number }} [milestones] - the values of the milestones of the user task
* @property {{ [key: string]: any }} [variableChanges] - the variables that were changed by the user task
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ const DashboardLayout = async (
});
}

let pollingInterval = 10000;
let pollingInterval = 1000;

if (Number.isInteger(automationSettings.taskPollingInterval)) {
pollingInterval = automationSettings.taskPollingInterval;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const TasklistPage = async (props: { params: Promise<{ environmentId: string }>
return notFound();
}

let pollingInterval = 5000;
let pollingInterval = 1000;
if (Number.isInteger(automationSettings.tasklist?.pollingInterval)) {
pollingInterval = automationSettings.tasklist.pollingInterval;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ const Tasklist: React.FC<TasklistProps> = ({ userId, pollingInterval }) => {
return (a: ExtendedTaskListEntry, b: ExtendedTaskListEntry) => {
// tiebreak equal value by comparing the startTime
if (a[key] === b[key]) {
return selectedSortItem.ascending ? a.startTime - b.startTime : b.startTime - a.startTime;
return selectedSortItem.ascending
? a.startTime.getTime() - b.startTime.getTime()
: b.startTime.getTime() - a.startTime.getTime();
}

if (key === 'state') {
Expand All @@ -92,6 +94,12 @@ const Tasklist: React.FC<TasklistProps> = ({ userId, pollingInterval }) => {
return selectedSortItem.ascending ? indexA - indexB : indexB - indexA;
}

if (key === 'startTime' || key === 'endTime') {
return selectedSortItem.ascending
? (a[key]?.getTime() || 0) - (b[key]?.getTime() || 0)
: (b[key]?.getTime() || 0) - (a[key]?.getTime() || 0);
}

return selectedSortItem.ascending
? (a[key] || 0) - (b[key] || 0)
: (b[key] || 0) - (a[key] || 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,14 @@ import styles from './user-task-view.module.scss';

import { App, Skeleton } from 'antd';
import { ExtendedTaskListEntry } from '@/lib/user-task-schema';
import useUserTasks from '@/lib/use-user-tasks';
import {
addOwnerToTaskListEntry,
completeTasklistEntry,
getTasklistEntryHTML,
setTasklistEntryVariableValues,
setTasklistMilestoneValues,
submitFile,
} from '@/lib/tasks/server-actions';

type UserTaskFormProps = {
html?: string;
Expand Down Expand Up @@ -98,21 +105,12 @@ const TaskListUserTaskForm: React.FC<TaskListUserTaskFormProps> = ({ task, userI

const { message } = App.useApp();

const {
completeEntry,
setMilestoneValues,
setVariableValues,
addOwner,
getTaskListEntryHtml,
submitFile,
} = useUserTasks(space, Infinity);

const { data: html } = useQuery({
queryFn: async () => {
if (!task) return null;
const html = await wrapServerCall({
fn: async () => {
const html = await getTaskListEntryHtml(task.id, task.fileName);
const html = await getTasklistEntryHTML(space.spaceId, task.id);

return html || null;
},
Expand Down Expand Up @@ -147,21 +145,21 @@ const TaskListUserTaskForm: React.FC<TaskListUserTaskFormProps> = ({ task, userI
await wrapServerCall({
fn: async () => {
if (!task?.actualOwner.some((owner) => owner.id === userId)) {
const updatedOwners = await addOwner(task.id, userId);
const updatedOwners = await addOwnerToTaskListEntry(space.spaceId, task.id, userId);
if ('error' in updatedOwners) return updatedOwners;
}
return await completeEntry(task.id, variables);
return await completeTasklistEntry(space.spaceId, task.id, variables);
},
});
}}
onMilestoneUpdate={async (newValues) => {
await wrapServerCall({
fn: async () => {
if (!task?.actualOwner.some((owner) => owner.id === userId)) {
const updatedOwners = await addOwner(task.id, userId);
const updatedOwners = await addOwnerToTaskListEntry(space.spaceId, task.id, userId);
if ('error' in updatedOwners) return updatedOwners;
}
return await setMilestoneValues(task.id, newValues);
return await setTasklistMilestoneValues(space.spaceId, task.id, newValues);
},
onSuccess: () => {},
});
Expand All @@ -170,17 +168,21 @@ const TaskListUserTaskForm: React.FC<TaskListUserTaskFormProps> = ({ task, userI
wrapServerCall({
fn: async () => {
if (!task?.actualOwner.some((owner) => owner.id === userId)) {
const updatedOwners = await addOwner(task.id, userId);
const updatedOwners = await addOwnerToTaskListEntry(space.spaceId, task.id, userId);
if ('error' in updatedOwners) return updatedOwners;
}
return await setVariableValues(task.id, newValues);
return await setTasklistEntryVariableValues(space.spaceId, task.id, newValues);
},
onSuccess: () => {},
});
}}
onFileSubmit={async (file) => {
const path = await wrapServerCall({
fn: async () => submitFile(task.id, file),
fn: async () => {
const formData = new FormData();
formData.append('file', file);
return submitFile(space.spaceId, task.id, formData);
},
onSuccess: false,
onError: () =>
message.error(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const UserTaskCard = ({
const endTime = userTaskData.endTime;

const durationValues = transformMilisecondsToDurationValues(
(endTime || +new Date()) - userTaskData.startTime,
(endTime?.getTime() || +new Date()) - userTaskData.startTime.getTime(),
true,
);

Expand Down Expand Up @@ -106,7 +106,7 @@ const UserTaskCard = ({
<span>{userTaskData.name}</span>
<Progress type="circle" percent={userTaskData.progress} size={30} />
</div>
{userTaskData.offline && !userTaskData.endTime && (
{userTaskData.offline && !userTaskData.endTime?.getTime() && (
<Tooltip title="The engine this user task is running on is currently not reachable!">
<Typography.Text style={{ fontSize: '0.9em' }} italic type="warning">
Offline
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,8 @@ const FormList: React.FC<FormListProps> = ({ data }) => {
id: v4(),
name: task.name,
taskId: '',
instanceID: '',
instanceID: null,
environmentId: space.spaceId,
fileName: '',
state: 'READY',
machineId: 'ms-local',
Expand All @@ -206,7 +207,9 @@ const FormList: React.FC<FormListProps> = ({ data }) => {
startTime: Date.now(),
html,
milestones: [],
milestonesChanges: {},
initialVariables: {},
variableChanges: {},
};
} else {
message.error(`Failed to get the form data for ${task.name}.`);
Expand Down
86 changes: 0 additions & 86 deletions src/management-system-v2/lib/data/db/user-tasks.ts

This file was deleted.

22 changes: 19 additions & 3 deletions src/management-system-v2/lib/data/engines.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
import Ability, { UnauthorizedError } from '@/lib/ability/abilityHelper';
import { SpaceEngineInput, SpaceEngineInputSchema } from '@/lib/space-engine-schema';
import { getCurrentEnvironment, getCurrentUser } from '@/components/auth';
import { getErrorMessage, permissionDenied, schemaValidationError, userError } from '../user-error';
import {
getErrorMessage,
isUserErrorResponse,
permissionDenied,
schemaValidationError,
userError,
} from '../user-error';
import { savedEnginesToEngines } from '../engines/saved-engines-helpers';
import { Engine, SpaceEngine } from '../engines/types';
import { SystemAdmin } from '@prisma/client';
Expand Down Expand Up @@ -98,9 +104,13 @@ export async function getAvailableSpaceEngines(spaceId: string) {
}
}

export async function getAllAvailableEngines(spaceId: string, ability?: Ability) {
export async function getAllAvailableEngines(
spaceId: string,
ability?: Ability,
skipAbilityCheck = false,
) {
try {
if (!ability) ({ ability } = await getCurrentEnvironment(spaceId));
if (!ability && !skipAbilityCheck) ({ ability } = await getCurrentEnvironment(spaceId));

let engines: Engine[] = [];
const [proceedEngines, spaceEngines] = await Promise.allSettled([
Expand All @@ -118,6 +128,12 @@ export async function getAllAvailableEngines(spaceId: string, ability?: Ability)
}
}

export async function getEngineIfAvailable(environmentId: string, engineId: string) {
const engines = await getAvailableSpaceEngines(environmentId);
if (isUserErrorResponse(engines)) return engines;
return engines.find((e) => e.id === engineId);
}

const SpaceEngineArraySchema = SpaceEngineInputSchema.array();
export async function addDbEngines(enginesInput: SpaceEngineInput[], environmentId: string | null) {
const newEngines = SpaceEngineArraySchema.safeParse(enginesInput);
Expand Down
14 changes: 10 additions & 4 deletions src/management-system-v2/lib/data/processes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,13 @@ export const getProcessBPMN = async (
spaceId: string,
versionId?: string,
ability?: Ability,
skipAbilityCheck = false,
) => {
const error = await checkValidity(definitionId, 'view', spaceId, ability);
if (!skipAbilityCheck) {
const error = await checkValidity(definitionId, 'view', spaceId, ability);

if (error) return error;
if (error) return error;
}

return await getBpmnVersion(definitionId, versionId);
};
Expand Down Expand Up @@ -700,10 +703,13 @@ export const getProcessHtmlFormHTML = async (
fileName: string,
spaceId: string,
ability?: Ability,
skipAbilityCheck = false,
) => {
const error = await checkValidity(definitionId, 'view', spaceId, ability);
if (!skipAbilityCheck) {
const error = await checkValidity(definitionId, 'view', spaceId, ability);

if (error) return error;
if (error) return error;
}

try {
return await _getHtmlForm(definitionId, fileName);
Expand Down
Loading
Loading