@ -1,7 +1,11 @@
|
||||
import { useSelectedRecordIdOrThrow } from '@/action-menu/actions/record-actions/single-record/hooks/useSelectedRecordIdOrThrow';
|
||||
import { useSeeVersionsWorkflowSingleRecordAction } from '@/action-menu/actions/record-actions/single-record/workflow-actions/hooks/useSeeVersionsWorkflowSingleRecordAction';
|
||||
import { ActionHookWithoutObjectMetadataItem } from '@/action-menu/actions/types/ActionHook';
|
||||
import { CoreObjectNamePlural } from '@/object-metadata/types/CoreObjectNamePlural';
|
||||
import { recordStoreFamilyState } from '@/object-record/record-store/states/recordStoreFamilyState';
|
||||
import { ViewFilterOperand } from '@/views/types/ViewFilterOperand';
|
||||
import { useWorkflowWithCurrentVersion } from '@/workflow/hooks/useWorkflowWithCurrentVersion';
|
||||
import qs from 'qs';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { useRecoilValue } from 'recoil';
|
||||
import { isDefined } from 'twenty-ui';
|
||||
|
||||
@ -11,13 +15,34 @@ export const useSeeVersionsWorkflowVersionSingleRecordAction: ActionHookWithoutO
|
||||
|
||||
const workflowVersion = useRecoilValue(recordStoreFamilyState(recordId));
|
||||
|
||||
if (!isDefined(workflowVersion)) {
|
||||
throw new Error('Workflow version not found');
|
||||
}
|
||||
const workflowWithCurrentVersion = useWorkflowWithCurrentVersion(
|
||||
workflowVersion?.workflowId,
|
||||
);
|
||||
|
||||
// TODO: Add recordIds to the hook
|
||||
const { shouldBeRegistered, onClick } =
|
||||
useSeeVersionsWorkflowSingleRecordAction();
|
||||
const navigate = useNavigate();
|
||||
|
||||
const shouldBeRegistered = isDefined(workflowWithCurrentVersion);
|
||||
|
||||
const onClick = () => {
|
||||
if (!shouldBeRegistered) {
|
||||
return;
|
||||
}
|
||||
|
||||
const filterQueryParams = {
|
||||
filter: {
|
||||
workflow: {
|
||||
[ViewFilterOperand.Is]: {
|
||||
selectedRecordIds: [workflowWithCurrentVersion.id],
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
const filterLinkHref = `/objects/${CoreObjectNamePlural.WorkflowVersion}?${qs.stringify(
|
||||
filterQueryParams,
|
||||
)}`;
|
||||
|
||||
navigate(filterLinkHref);
|
||||
};
|
||||
|
||||
return {
|
||||
shouldBeRegistered,
|
||||
|
||||
Reference in New Issue
Block a user