refactor: move view recoil states to ui/view-bar folder (#1482)
* refactor: move view recoil states to ui/view-bar folder Closes #1481 * refactor: rename some view related Recoil states and selectors
This commit is contained in:
@ -0,0 +1,6 @@
|
||||
import { atomFamily } from 'recoil';
|
||||
|
||||
export const currentViewIdScopedState = atomFamily<string | undefined, string>({
|
||||
key: 'currentViewIdScopedState',
|
||||
default: undefined,
|
||||
});
|
||||
@ -2,9 +2,9 @@ import { atomFamily } from 'recoil';
|
||||
|
||||
import type { Filter } from '../types/Filter';
|
||||
|
||||
export const savedFiltersScopedState = atomFamily<Filter[], string | undefined>(
|
||||
export const savedFiltersFamilyState = atomFamily<Filter[], string | undefined>(
|
||||
{
|
||||
key: 'savedFiltersScopedState',
|
||||
key: 'savedFiltersFamilyState',
|
||||
default: [],
|
||||
},
|
||||
);
|
||||
@ -2,10 +2,10 @@ import { atomFamily } from 'recoil';
|
||||
|
||||
import type { SelectedSortType } from '../types/interface';
|
||||
|
||||
export const savedSortsScopedState = atomFamily<
|
||||
export const savedSortsFamilyState = atomFamily<
|
||||
SelectedSortType<any>[],
|
||||
string | undefined
|
||||
>({
|
||||
key: 'savedSortsScopedState',
|
||||
key: 'savedSortsFamilyState',
|
||||
default: [],
|
||||
});
|
||||
@ -3,15 +3,15 @@ import { selectorFamily } from 'recoil';
|
||||
import { isDeeplyEqual } from '~/utils/isDeeplyEqual';
|
||||
|
||||
import { filtersScopedState } from '../filtersScopedState';
|
||||
import { savedFiltersScopedState } from '../savedFiltersScopedState';
|
||||
import { savedFiltersFamilyState } from '../savedFiltersFamilyState';
|
||||
|
||||
export const canPersistFiltersScopedSelector = selectorFamily({
|
||||
key: 'canPersistFiltersScopedSelector',
|
||||
export const canPersistFiltersScopedFamilySelector = selectorFamily({
|
||||
key: 'canPersistFiltersScopedFamilySelector',
|
||||
get:
|
||||
([scopeId, viewId]: [string, string | undefined]) =>
|
||||
({ get }) =>
|
||||
!isDeeplyEqual(
|
||||
get(savedFiltersScopedState(viewId)),
|
||||
get(savedFiltersFamilyState(viewId)),
|
||||
get(filtersScopedState(scopeId)),
|
||||
),
|
||||
});
|
||||
@ -2,16 +2,16 @@ import { selectorFamily } from 'recoil';
|
||||
|
||||
import { isDeeplyEqual } from '~/utils/isDeeplyEqual';
|
||||
|
||||
import { savedSortsScopedState } from '../savedSortsScopedState';
|
||||
import { savedSortsFamilyState } from '../savedSortsFamilyState';
|
||||
import { sortsScopedState } from '../sortsScopedState';
|
||||
|
||||
export const canPersistSortsScopedSelector = selectorFamily({
|
||||
key: 'canPersistSortsScopedSelector',
|
||||
export const canPersistSortsScopedFamilySelector = selectorFamily({
|
||||
key: 'canPersistSortsScopedFamilySelector',
|
||||
get:
|
||||
([scopeId, viewId]: [string, string | undefined]) =>
|
||||
({ get }) =>
|
||||
!isDeeplyEqual(
|
||||
get(savedSortsScopedState(viewId)),
|
||||
get(savedSortsFamilyState(viewId)),
|
||||
get(sortsScopedState(scopeId)),
|
||||
),
|
||||
});
|
||||
@ -0,0 +1,21 @@
|
||||
import { selectorFamily } from 'recoil';
|
||||
|
||||
import type { View } from '../../types/View';
|
||||
import { currentViewIdScopedState } from '../currentViewIdScopedState';
|
||||
|
||||
import { viewsByIdScopedSelector } from './viewsByIdScopedSelector';
|
||||
|
||||
export const currentViewScopedSelector = selectorFamily<
|
||||
View | undefined,
|
||||
string
|
||||
>({
|
||||
key: 'currentViewScopedSelector',
|
||||
get:
|
||||
(scopeId) =>
|
||||
({ get }) => {
|
||||
const currentViewId = get(currentViewIdScopedState(scopeId));
|
||||
return currentViewId
|
||||
? get(viewsByIdScopedSelector(scopeId))[currentViewId]
|
||||
: undefined;
|
||||
},
|
||||
});
|
||||
@ -0,0 +1,15 @@
|
||||
import { selectorFamily } from 'recoil';
|
||||
|
||||
import type { Filter } from '../../types/Filter';
|
||||
import { savedFiltersFamilyState } from '../savedFiltersFamilyState';
|
||||
|
||||
export const savedFiltersByKeyFamilySelector = selectorFamily({
|
||||
key: 'savedFiltersByKeyFamilySelector',
|
||||
get:
|
||||
(viewId: string | undefined) =>
|
||||
({ get }) =>
|
||||
get(savedFiltersFamilyState(viewId)).reduce<Record<string, Filter>>(
|
||||
(result, filter) => ({ ...result, [filter.key]: filter }),
|
||||
{},
|
||||
),
|
||||
});
|
||||
@ -1,15 +0,0 @@
|
||||
import { selectorFamily } from 'recoil';
|
||||
|
||||
import type { Filter } from '../../types/Filter';
|
||||
import { savedFiltersScopedState } from '../savedFiltersScopedState';
|
||||
|
||||
export const savedFiltersByKeyScopedSelector = selectorFamily({
|
||||
key: 'savedFiltersByKeyScopedSelector',
|
||||
get:
|
||||
(param: string | undefined) =>
|
||||
({ get }) =>
|
||||
get(savedFiltersScopedState(param)).reduce<Record<string, Filter>>(
|
||||
(result, filter) => ({ ...result, [filter.key]: filter }),
|
||||
{},
|
||||
),
|
||||
});
|
||||
@ -1,14 +1,14 @@
|
||||
import { selectorFamily } from 'recoil';
|
||||
|
||||
import type { SelectedSortType } from '../../types/interface';
|
||||
import { savedSortsScopedState } from '../savedSortsScopedState';
|
||||
import { savedSortsFamilyState } from '../savedSortsFamilyState';
|
||||
|
||||
export const savedSortsByKeyScopedSelector = selectorFamily({
|
||||
key: 'savedSortsByKeyScopedSelector',
|
||||
export const savedSortsByKeyFamilySelector = selectorFamily({
|
||||
key: 'savedSortsByKeyFamilySelector',
|
||||
get:
|
||||
(viewId: string | undefined) =>
|
||||
({ get }) =>
|
||||
get(savedSortsScopedState(viewId)).reduce<
|
||||
get(savedSortsFamilyState(viewId)).reduce<
|
||||
Record<string, SelectedSortType<any>>
|
||||
>((result, sort) => ({ ...result, [sort.key]: sort }), {}),
|
||||
});
|
||||
@ -0,0 +1,18 @@
|
||||
import { selectorFamily } from 'recoil';
|
||||
|
||||
import type { View } from '../../types/View';
|
||||
import { viewsScopedState } from '../viewsScopedState';
|
||||
|
||||
export const viewsByIdScopedSelector = selectorFamily<
|
||||
Record<string, View>,
|
||||
string
|
||||
>({
|
||||
key: 'viewsByIdScopedSelector',
|
||||
get:
|
||||
(scopeId) =>
|
||||
({ get }) =>
|
||||
get(viewsScopedState(scopeId)).reduce<Record<string, View>>(
|
||||
(result, view) => ({ ...result, [view.id]: view }),
|
||||
{},
|
||||
),
|
||||
});
|
||||
@ -0,0 +1,9 @@
|
||||
import { atom } from 'recoil';
|
||||
|
||||
export const viewEditModeState = atom<{
|
||||
mode: 'create' | 'edit' | undefined;
|
||||
viewId: string | undefined;
|
||||
}>({
|
||||
key: 'viewEditModeState',
|
||||
default: { mode: undefined, viewId: undefined },
|
||||
});
|
||||
8
front/src/modules/ui/view-bar/states/viewsScopedState.ts
Normal file
8
front/src/modules/ui/view-bar/states/viewsScopedState.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import { atomFamily } from 'recoil';
|
||||
|
||||
import type { View } from '../types/View';
|
||||
|
||||
export const viewsScopedState = atomFamily<View[], string>({
|
||||
key: 'viewsScopedState',
|
||||
default: [],
|
||||
});
|
||||
1
front/src/modules/ui/view-bar/types/View.ts
Normal file
1
front/src/modules/ui/view-bar/types/View.ts
Normal file
@ -0,0 +1 @@
|
||||
export type View = { id: string; name: string };
|
||||
4
front/src/modules/ui/view-bar/types/ViewsHotkeyScope.ts
Normal file
4
front/src/modules/ui/view-bar/types/ViewsHotkeyScope.ts
Normal file
@ -0,0 +1,4 @@
|
||||
export enum ViewsHotkeyScope {
|
||||
ListDropdown = 'views-list-dropdown',
|
||||
CreateDropdown = 'views-create-dropdown',
|
||||
}
|
||||
Reference in New Issue
Block a user