Refactor action menu (#7586)

Introduces effects to set the actionMenuEntries
This commit is contained in:
Raphaël Bosi
2024-10-11 15:25:35 +02:00
committed by GitHub
parent 9b9b34f991
commit 3761fbf86f
26 changed files with 447 additions and 319 deletions

View File

@ -1,10 +1,15 @@
import { useAvailableComponentInstanceIdOrThrow } from '@/ui/utilities/state/component-state/hooks/useAvailableComponentInstanceIdOrThrow';
import { ComponentReadOnlySelectorV2 } from '@/ui/utilities/state/component-state/types/ComponentReadOnlySelectorV2';
import { ComponentSelectorV2 } from '@/ui/utilities/state/component-state/types/ComponentSelectorV2';
import { ComponentStateV2 } from '@/ui/utilities/state/component-state/types/ComponentStateV2';
import { globalComponentInstanceContextMap } from '@/ui/utilities/state/component-state/utils/globalComponentInstanceContextMap';
import { useRecoilValue } from 'recoil';
import { RecoilState, RecoilValueReadOnly, useRecoilValue } from 'recoil';
export const useRecoilComponentValueV2 = <StateType>(
componentStateV2: ComponentStateV2<StateType>,
componentStateV2:
| ComponentStateV2<StateType>
| ComponentSelectorV2<StateType>
| ComponentReadOnlySelectorV2<StateType>,
instanceIdFromProps?: string,
) => {
const instanceContext = globalComponentInstanceContextMap.get(
@ -22,5 +27,18 @@ export const useRecoilComponentValueV2 = <StateType>(
instanceIdFromProps,
);
return useRecoilValue(componentStateV2.atomFamily({ instanceId }));
let state: RecoilState<StateType> | RecoilValueReadOnly<StateType>;
if (componentStateV2.type === 'ComponentState') {
state = componentStateV2.atomFamily({ instanceId });
} else if (
componentStateV2.type === 'ComponentSelector' ||
componentStateV2.type === 'ComponentReadOnlySelector'
) {
state = componentStateV2.selectorFamily({ instanceId });
} else {
throw new Error('Invalid component state type');
}
return useRecoilValue(state);
};