3157 refactor scoped states to move to v3 (#3180)
* renaming * renaming * create getDropdownScopeInjectors * update useDropdown * create internal hooks folder * update record-table states to be scoped states * update record-table selectors to be scoped selectors * create utils scope injector * refactor record-table wip * refactor record-table wip * wip * inject scopeId in selectors * update intenal hooks * update intenal hooks * update intenal hooks * update intenal hooks * update intenal hooks * update intenal hooks * update internal hooks * update internal hooks * update internal hooks * update internal hooks * update useTableColumns * update states and hooks * refactoring * refactoring * refactoring * refactoring * refactoring * refactoring * refactoring * refactoring * refactoring * fix scopeId not in context * fix lint errors * fix error in story * fix errors: wip * fix errors * fix error * fix jest test * fix scopeId not defined * fix jest test * Bug fixes --------- Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
@ -67,10 +67,6 @@ export const useSetHotkeyScope = () =>
|
||||
scopesToSet.push(AppHotkeyScope.CommandMenu);
|
||||
}
|
||||
|
||||
if (newHotkeyScope.customScopes?.commandMenuOpen) {
|
||||
scopesToSet.push(AppHotkeyScope.CommandMenuOpen);
|
||||
}
|
||||
|
||||
if (newHotkeyScope?.customScopes?.goto) {
|
||||
scopesToSet.push(AppHotkeyScope.Goto);
|
||||
}
|
||||
|
||||
@ -2,12 +2,17 @@ import { SerializableParam, Snapshot } from 'recoil';
|
||||
|
||||
import { FamilyScopeInjector } from '@/ui/utilities/recoil-scope/utils/getFamilyScopeInjector';
|
||||
import { ScopeInjector } from '@/ui/utilities/recoil-scope/utils/getScopeInjector';
|
||||
import { SelectorScopeInjector } from '@/ui/utilities/recoil-scope/utils/getSelectorScopeInjector';
|
||||
import { getSnapshotValue } from '@/ui/utilities/recoil-scope/utils/getSnapshotValue';
|
||||
|
||||
export const useScopedState = (scopeId: string) => {
|
||||
const getScopedState = <StateType>(scopeInjector: ScopeInjector<StateType>) =>
|
||||
scopeInjector(scopeId);
|
||||
|
||||
const getScopedSelector = <StateType>(
|
||||
scopeInjector: SelectorScopeInjector<StateType>,
|
||||
) => scopeInjector(scopeId);
|
||||
|
||||
const getScopedFamilyState =
|
||||
<StateType, FamilyKey extends SerializableParam>(
|
||||
familyScopeInjector: FamilyScopeInjector<StateType, FamilyKey>,
|
||||
@ -16,23 +21,30 @@ export const useScopedState = (scopeId: string) => {
|
||||
familyScopeInjector(scopeId, familyKey);
|
||||
|
||||
const getScopedSnapshotValue = <StateType>(
|
||||
snashot: Snapshot,
|
||||
snapshot: Snapshot,
|
||||
scopeInjector: ScopeInjector<StateType>,
|
||||
) => getSnapshotValue(snashot, scopeInjector(scopeId));
|
||||
) => getSnapshotValue(snapshot, scopeInjector(scopeId));
|
||||
|
||||
const getScopedSelectorSnapshotValue = <StateType>(
|
||||
snapshot: Snapshot,
|
||||
scopeInjector: SelectorScopeInjector<StateType>,
|
||||
) => getSnapshotValue(snapshot, scopeInjector(scopeId));
|
||||
|
||||
const getScopedFamilySnapshotValue =
|
||||
<StateType, FamilyKey extends SerializableParam>(
|
||||
snashot: Snapshot,
|
||||
snapshot: Snapshot,
|
||||
familyScopeInjector: FamilyScopeInjector<StateType, FamilyKey>,
|
||||
) =>
|
||||
(familyKey: FamilyKey) =>
|
||||
getSnapshotValue(snashot, familyScopeInjector(scopeId, familyKey));
|
||||
getSnapshotValue(snapshot, familyScopeInjector(scopeId, familyKey));
|
||||
|
||||
return {
|
||||
scopeId,
|
||||
getScopedState,
|
||||
getScopedSelector,
|
||||
getScopedFamilyState,
|
||||
getScopedSnapshotValue,
|
||||
getScopedSelectorSnapshotValue,
|
||||
getScopedFamilySnapshotValue,
|
||||
};
|
||||
};
|
||||
|
||||
@ -8,7 +8,7 @@ export type ScopeInjector<StateType> = (
|
||||
|
||||
export const getScopeInjector = <StateType>(
|
||||
scopedState: RecoilScopedState<StateType>,
|
||||
) => {
|
||||
): ScopeInjector<StateType> => {
|
||||
return (scopeId: string) =>
|
||||
scopedState({
|
||||
scopeId,
|
||||
|
||||
@ -0,0 +1,16 @@
|
||||
import { RecoilValueReadOnly } from 'recoil';
|
||||
|
||||
import { RecoilScopedSelector } from '@/ui/utilities/recoil-scope/types/RecoilScopedSelector';
|
||||
|
||||
export type SelectorScopeInjector<StateType> = (
|
||||
scopeId: string,
|
||||
) => RecoilValueReadOnly<StateType>;
|
||||
|
||||
export const getSelectorScopeInjector = <StateType>(
|
||||
scopedSelector: RecoilScopedSelector<StateType>,
|
||||
): SelectorScopeInjector<StateType> => {
|
||||
return (scopeId: string) =>
|
||||
scopedSelector({
|
||||
scopeId,
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user