Refactored object operation dispatch for SSE (#17174)
This PR refactors object record operation dispatch through a browser event instead of a state that was registering all operations. This is a cleaner pattern as it is a synchronous event code path instead of relying on a useEffect to watch state change, which is not ideal. We introduce this change first to then rely on this new pattern to dispatch SSE events in a following PR.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { useApolloCoreClient } from '@/object-metadata/hooks/useApolloCoreClient';
|
||||
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
|
||||
import { CoreObjectNameSingular } from '@/object-metadata/types/CoreObjectNameSingular';
|
||||
import { useRegisterObjectOperation } from '@/object-record/hooks/useRegisterObjectOperation';
|
||||
import { dispatchObjectRecordOperationBrowserEvent } from '@/object-record/utils/dispatchObjectRecordOperationBrowserEvent';
|
||||
import { useStopWorkflowRunMutation } from '~/generated-metadata/graphql';
|
||||
|
||||
export const useStopWorkflowRun = () => {
|
||||
@@ -9,7 +9,6 @@ export const useStopWorkflowRun = () => {
|
||||
const [mutate] = useStopWorkflowRunMutation({
|
||||
client: apolloCoreClient,
|
||||
});
|
||||
const { registerObjectOperation } = useRegisterObjectOperation();
|
||||
|
||||
const { objectMetadataItem } = useObjectMetadataItem({
|
||||
objectNameSingular: CoreObjectNameSingular.WorkflowRun,
|
||||
@@ -22,10 +21,16 @@ export const useStopWorkflowRun = () => {
|
||||
},
|
||||
});
|
||||
|
||||
registerObjectOperation(objectMetadataItem, {
|
||||
type: 'update-one',
|
||||
result: {
|
||||
updateInput: { id: workflowRunId },
|
||||
dispatchObjectRecordOperationBrowserEvent({
|
||||
objectMetadataItem,
|
||||
operation: {
|
||||
type: 'update-one',
|
||||
result: {
|
||||
updateInput: {
|
||||
recordId: workflowRunId,
|
||||
updatedFields: [],
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user