corrected targetableobject being undefined when clicked on create task in command menu (#6635)
Issue #6630 It seems this bug is caused by `targetableObjects` being assigned an empty array, which then leads to an error due to it being undefined. I've made some changes that should address the issue, but I would appreciate any feedback or suggestions on alternative solutions. Please let me know if there is a better approach to resolving this. Thank you! https://github.com/user-attachments/assets/d6409798-3320-49b3-834f-2b6888847ed8
This commit is contained in:
@ -16,10 +16,10 @@ import { AppPath } from '@/types/AppPath';
|
|||||||
import { PageHotkeyScope } from '@/types/PageHotkeyScope';
|
import { PageHotkeyScope } from '@/types/PageHotkeyScope';
|
||||||
import { SettingsPath } from '@/types/SettingsPath';
|
import { SettingsPath } from '@/types/SettingsPath';
|
||||||
import { useSetHotkeyScope } from '@/ui/utilities/hotkey/hooks/useSetHotkeyScope';
|
import { useSetHotkeyScope } from '@/ui/utilities/hotkey/hooks/useSetHotkeyScope';
|
||||||
|
import { useCleanRecoilState } from '~/hooks/useCleanRecoilState';
|
||||||
import { useIsMatchingLocation } from '~/hooks/useIsMatchingLocation';
|
import { useIsMatchingLocation } from '~/hooks/useIsMatchingLocation';
|
||||||
import { usePageChangeEffectNavigateLocation } from '~/hooks/usePageChangeEffectNavigateLocation';
|
import { usePageChangeEffectNavigateLocation } from '~/hooks/usePageChangeEffectNavigateLocation';
|
||||||
import { isDefined } from '~/utils/isDefined';
|
import { isDefined } from '~/utils/isDefined';
|
||||||
import { useCleanRecoilState } from '~/hooks/useCleanRecoilState';
|
|
||||||
|
|
||||||
// TODO: break down into smaller functions and / or hooks
|
// TODO: break down into smaller functions and / or hooks
|
||||||
// - moved usePageChangeEffectNavigateLocation into dedicated hook
|
// - moved usePageChangeEffectNavigateLocation into dedicated hook
|
||||||
@ -153,7 +153,10 @@ export const PageChangeEffect = () => {
|
|||||||
label: 'Create Task',
|
label: 'Create Task',
|
||||||
type: CommandType.Create,
|
type: CommandType.Create,
|
||||||
Icon: IconCheckbox,
|
Icon: IconCheckbox,
|
||||||
onCommandClick: () => openCreateActivity({ targetableObjects: [] }),
|
onCommandClick: () =>
|
||||||
|
openCreateActivity({
|
||||||
|
targetableObjects: [],
|
||||||
|
}),
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
}, [addToCommandMenu, setToInitialCommandMenu, openCreateActivity]);
|
}, [addToCommandMenu, setToInitialCommandMenu, openCreateActivity]);
|
||||||
|
|||||||
@ -68,24 +68,40 @@ export const useOpenCreateActivityDrawer = ({
|
|||||||
assigneeId: customAssignee?.id,
|
assigneeId: customAssignee?.id,
|
||||||
});
|
});
|
||||||
|
|
||||||
const targetableObjectRelationIdName = `${targetableObjects[0].targetObjectNameSingular}Id`;
|
if (targetableObjects.length > 0) {
|
||||||
|
const targetableObjectRelationIdName = `${targetableObjects[0].targetObjectNameSingular}Id`;
|
||||||
|
|
||||||
await createOneActivityTarget({
|
await createOneActivityTarget({
|
||||||
taskId:
|
taskId:
|
||||||
activityObjectNameSingular === CoreObjectNameSingular.Task
|
activityObjectNameSingular === CoreObjectNameSingular.Task
|
||||||
? activity.id
|
? activity.id
|
||||||
: undefined,
|
: undefined,
|
||||||
noteId:
|
noteId:
|
||||||
activityObjectNameSingular === CoreObjectNameSingular.Note
|
activityObjectNameSingular === CoreObjectNameSingular.Note
|
||||||
? activity.id
|
? activity.id
|
||||||
: undefined,
|
: undefined,
|
||||||
[targetableObjectRelationIdName]: targetableObjects[0].id,
|
[targetableObjectRelationIdName]: targetableObjects[0].id,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
setActivityTargetableEntityArray(targetableObjects);
|
||||||
|
} else {
|
||||||
|
await createOneActivityTarget({
|
||||||
|
taskId:
|
||||||
|
activityObjectNameSingular === CoreObjectNameSingular.Task
|
||||||
|
? activity.id
|
||||||
|
: undefined,
|
||||||
|
noteId:
|
||||||
|
activityObjectNameSingular === CoreObjectNameSingular.Note
|
||||||
|
? activity.id
|
||||||
|
: undefined,
|
||||||
|
});
|
||||||
|
|
||||||
|
setActivityTargetableEntityArray([]);
|
||||||
|
}
|
||||||
|
|
||||||
setHotkeyScope(RightDrawerHotkeyScope.RightDrawer, { goto: false });
|
setHotkeyScope(RightDrawerHotkeyScope.RightDrawer, { goto: false });
|
||||||
setViewableRecordId(activity.id);
|
setViewableRecordId(activity.id);
|
||||||
setViewableRecordNameSingular(activityObjectNameSingular);
|
setViewableRecordNameSingular(activityObjectNameSingular);
|
||||||
setActivityTargetableEntityArray(targetableObjects ?? []);
|
|
||||||
|
|
||||||
openRightDrawer(RightDrawerPages.ViewRecord);
|
openRightDrawer(RightDrawerPages.ViewRecord);
|
||||||
setIsUpsertingActivityInDB(false);
|
setIsUpsertingActivityInDB(false);
|
||||||
|
|||||||
Reference in New Issue
Block a user