Skip to content

Commit

Permalink
Fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasbordeau committed Sep 18, 2024
1 parent 867d990 commit 5327b3d
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 14 deletions.
17 changes: 11 additions & 6 deletions packages/twenty-front/src/effect-components/PageChangeEffect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { useRequestFreshCaptchaToken } from '@/captcha/hooks/useRequestFreshCapt
import { isCaptchaScriptLoadedState } from '@/captcha/states/isCaptchaScriptLoadedState';
import { useCommandMenu } from '@/command-menu/hooks/useCommandMenu';
import { CommandType } from '@/command-menu/types/Command';
import { useNonSystemActiveObjectMetadataItems } from '@/object-metadata/hooks/useNonSystemActiveObjectMetadataItems';
import { objectMetadataItemsState } from '@/object-metadata/states/objectMetadataItemsState';
import { CoreObjectNameSingular } from '@/object-metadata/types/CoreObjectNameSingular';
import { TableHotkeyScope } from '@/object-record/record-table/types/TableHotkeyScope';
Expand Down Expand Up @@ -41,7 +42,7 @@ export const PageChangeEffect = () => {

const eventTracker = useEventTracker();

const { addToCommandMenu, setToInitialCommandMenu } = useCommandMenu();
const { addToCommandMenu, setObjectsInCommandMenu } = useCommandMenu();

const objectMetadataItems = useRecoilValue(objectMetadataItemsState);

Expand Down Expand Up @@ -146,12 +147,15 @@ export const PageChangeEffect = () => {
}
}, [isMatchingLocation, setHotkeyScope]);

const { nonSystemActiveObjectMetadataItems } =
useNonSystemActiveObjectMetadataItems();

useEffect(() => {
const nonSystemActiveObjects = objectMetadataItems.filter(
(object) => !object.isSystem && object.isActive,
console.log(
'nonSystemActiveObjectMetadataItems',
nonSystemActiveObjectMetadataItems,
);

setToInitialCommandMenu(nonSystemActiveObjects);
setObjectsInCommandMenu(nonSystemActiveObjectMetadataItems);

addToCommandMenu([
{
Expand All @@ -167,8 +171,9 @@ export const PageChangeEffect = () => {
},
]);
}, [
nonSystemActiveObjectMetadataItems,
addToCommandMenu,
setToInitialCommandMenu,
setObjectsInCommandMenu,
openCreateActivity,
objectMetadataItems,
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const meta: Meta<typeof CommandMenu> = {
);
const objectMetadataItems = useRecoilValue(objectMetadataItemsState);

const { addToCommandMenu, setToInitialCommandMenu, openCommandMenu } =
const { addToCommandMenu, setObjectsInCommandMenu, openCommandMenu } =
useCommandMenu();

setCurrentWorkspace(mockDefaultWorkspace);
Expand All @@ -49,7 +49,7 @@ const meta: Meta<typeof CommandMenu> = {
(object) => !object.isSystem && object.isActive,
);

setToInitialCommandMenu(nonSystemActiveObjects);
setObjectsInCommandMenu(nonSystemActiveObjects);

addToCommandMenu([
{
Expand All @@ -72,7 +72,7 @@ const meta: Meta<typeof CommandMenu> = {
openCommandMenu();
}, [
addToCommandMenu,
setToInitialCommandMenu,
setObjectsInCommandMenu,
openCommandMenu,
objectMetadataItems,
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,17 @@ describe('useCommandMenu', () => {
expect(onClickMock).toHaveBeenCalledTimes(1);
});

it('should setToInitialCommandMenu command menu', () => {
it('should setObjectsInCommandMenu command menu', () => {
const { result } = renderHooks();

act(() => {
result.current.commandMenu.setToInitialCommandMenu([]);
result.current.commandMenu.setObjectsInCommandMenu([]);
});

expect(result.current.commandMenuCommands.length).toBe(0);

act(() => {
result.current.commandMenu.setToInitialCommandMenu([
result.current.commandMenu.setObjectsInCommandMenu([
{
id: 'b88745ce-9021-4316-a018-8884e02d05ca',
nameSingular: 'task',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export const useCommandMenu = () => {
[setCommands],
);

const setToInitialCommandMenu = (menuItems: ObjectMetadataItem[]) => {
const setObjectsInCommandMenu = (menuItems: ObjectMetadataItem[]) => {
const formattedItems = [
...menuItems.map(
(item) =>
Expand Down Expand Up @@ -115,6 +115,6 @@ export const useCommandMenu = () => {
toggleCommandMenu,
addToCommandMenu,
onItemClick,
setToInitialCommandMenu,
setObjectsInCommandMenu,
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { objectMetadataItemsState } from '@/object-metadata/states/objectMetadataItemsState';
import { useMemo } from 'react';
import { useRecoilValue } from 'recoil';

export const useNonSystemActiveObjectMetadataItems = () => {
const objectMetadataItems = useRecoilValue(objectMetadataItemsState);

const nonSystemActiveObjectMetadataItems = useMemo(
() =>
objectMetadataItems.filter(
(objectMetadataItem) =>
!objectMetadataItem.isSystem && objectMetadataItem.isActive,
),
[objectMetadataItems],
);

return {
nonSystemActiveObjectMetadataItems,
};
};

0 comments on commit 5327b3d

Please sign in to comment.