Enforce front project structure through ESLINT (#7863)

Fixes: https://github.com/twentyhq/twenty/issues/7329
This commit is contained in:
Charles Bochet
2024-10-20 20:20:19 +02:00
committed by GitHub
parent f801f3aa9f
commit eccf0bf8ba
260 changed files with 500 additions and 290 deletions

View File

@ -0,0 +1,70 @@
import { CoreObjectNameSingular } from '@/object-metadata/types/CoreObjectNameSingular';
import { useFindManyRecords } from '@/object-record/hooks/useFindManyRecords';
import { useFindOneRecord } from '@/object-record/hooks/useFindOneRecord';
import {
Workflow,
WorkflowVersion,
WorkflowWithCurrentVersion,
} from '@/workflow/types/Workflow';
import { useMemo } from 'react';
import { isDefined } from 'twenty-ui';
export const useWorkflowWithCurrentVersion = (
workflowId: string | undefined,
): WorkflowWithCurrentVersion | undefined => {
const { record: workflow } = useFindOneRecord<Workflow>({
objectNameSingular: CoreObjectNameSingular.Workflow,
objectRecordId: workflowId,
recordGqlFields: {
id: true,
name: true,
statuses: true,
versions: {
totalCount: true,
},
},
skip: !isDefined(workflowId),
});
const {
records: mostRecentWorkflowVersions,
loading: loadingMostRecentWorkflowVersions,
} = useFindManyRecords<WorkflowVersion>({
objectNameSingular: CoreObjectNameSingular.WorkflowVersion,
filter: {
workflowId: {
eq: workflowId,
},
},
orderBy: [
{
createdAt: 'DescNullsLast',
},
],
skip: !isDefined(workflowId),
});
const workflowWithCurrentVersion = useMemo(() => {
if (!isDefined(workflow) || loadingMostRecentWorkflowVersions) {
return undefined;
}
const draftVersion = mostRecentWorkflowVersions.find(
(workflowVersion) => workflowVersion.status === 'DRAFT',
);
const latestVersion = mostRecentWorkflowVersions[0];
const currentVersion = draftVersion ?? latestVersion;
if (!isDefined(currentVersion)) {
return undefined;
}
return {
...workflow,
currentVersion,
};
}, [loadingMostRecentWorkflowVersions, mostRecentWorkflowVersions, workflow]);
return workflowWithCurrentVersion;
};