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:
@ -4,10 +4,10 @@ import type { ViewFieldMetadata } from '@/ui/editable-field/types/ViewField';
|
||||
|
||||
import type { ColumnDefinition } from '../types/ColumnDefinition';
|
||||
|
||||
export const savedTableColumnsScopedState = atomFamily<
|
||||
export const savedTableColumnsFamilyState = atomFamily<
|
||||
ColumnDefinition<ViewFieldMetadata>[],
|
||||
string | undefined
|
||||
>({
|
||||
key: 'savedTableColumnsScopedState',
|
||||
key: 'savedTableColumnsFamilyState',
|
||||
default: [],
|
||||
});
|
||||
@ -2,16 +2,16 @@ import { selectorFamily } from 'recoil';
|
||||
|
||||
import { isDeeplyEqual } from '~/utils/isDeeplyEqual';
|
||||
|
||||
import { savedTableColumnsScopedState } from '../savedTableColumnsScopedState';
|
||||
import { savedTableColumnsFamilyState } from '../savedTableColumnsFamilyState';
|
||||
import { tableColumnsScopedState } from '../tableColumnsScopedState';
|
||||
|
||||
export const canPersistTableColumnsScopedSelector = selectorFamily({
|
||||
key: 'canPersistTableColumnsScopedSelector',
|
||||
export const canPersistTableColumnsScopedFamilySelector = selectorFamily({
|
||||
key: 'canPersistTableColumnsScopedFamilySelector',
|
||||
get:
|
||||
([scopeId, viewId]: [string, string | undefined]) =>
|
||||
({ get }) =>
|
||||
!isDeeplyEqual(
|
||||
get(savedTableColumnsScopedState(viewId)),
|
||||
get(savedTableColumnsFamilyState(viewId)),
|
||||
get(tableColumnsScopedState(scopeId)),
|
||||
),
|
||||
});
|
||||
@ -3,14 +3,14 @@ import { selectorFamily } from 'recoil';
|
||||
import type { ViewFieldMetadata } from '@/ui/editable-field/types/ViewField';
|
||||
|
||||
import type { ColumnDefinition } from '../../types/ColumnDefinition';
|
||||
import { savedTableColumnsScopedState } from '../savedTableColumnsScopedState';
|
||||
import { savedTableColumnsFamilyState } from '../savedTableColumnsFamilyState';
|
||||
|
||||
export const savedTableColumnsByKeyScopedSelector = selectorFamily({
|
||||
key: 'savedTableColumnsByKeyScopedSelector',
|
||||
export const savedTableColumnsByKeyFamilySelector = selectorFamily({
|
||||
key: 'savedTableColumnsByKeyFamilySelector',
|
||||
get:
|
||||
(viewId: string | undefined) =>
|
||||
({ get }) =>
|
||||
get(savedTableColumnsScopedState(viewId)).reduce<
|
||||
get(savedTableColumnsFamilyState(viewId)).reduce<
|
||||
Record<string, ColumnDefinition<ViewFieldMetadata>>
|
||||
>((result, column) => ({ ...result, [column.key]: column }), {}),
|
||||
});
|
||||
@ -1,50 +0,0 @@
|
||||
import { atom, atomFamily, selectorFamily } from 'recoil';
|
||||
|
||||
export type TableView = { id: string; name: string };
|
||||
|
||||
export const tableViewsState = atomFamily<TableView[], string>({
|
||||
key: 'tableViewsState',
|
||||
default: [],
|
||||
});
|
||||
|
||||
export const tableViewsByIdState = selectorFamily<
|
||||
Record<string, TableView>,
|
||||
string
|
||||
>({
|
||||
key: 'tableViewsByIdState',
|
||||
get:
|
||||
(scopeId) =>
|
||||
({ get }) =>
|
||||
get(tableViewsState(scopeId)).reduce<Record<string, TableView>>(
|
||||
(result, view) => ({ ...result, [view.id]: view }),
|
||||
{},
|
||||
),
|
||||
});
|
||||
|
||||
export const currentTableViewIdState = atomFamily<string | undefined, string>({
|
||||
key: 'currentTableViewIdState',
|
||||
default: undefined,
|
||||
});
|
||||
|
||||
export const currentTableViewState = selectorFamily<
|
||||
TableView | undefined,
|
||||
string
|
||||
>({
|
||||
key: 'currentTableViewState',
|
||||
get:
|
||||
(scopeId) =>
|
||||
({ get }) => {
|
||||
const currentViewId = get(currentTableViewIdState(scopeId));
|
||||
return currentViewId
|
||||
? get(tableViewsByIdState(scopeId))[currentViewId]
|
||||
: undefined;
|
||||
},
|
||||
});
|
||||
|
||||
export const tableViewEditModeState = atom<{
|
||||
mode: 'create' | 'edit' | undefined;
|
||||
viewId: string | undefined;
|
||||
}>({
|
||||
key: 'tableViewEditModeState',
|
||||
default: { mode: undefined, viewId: undefined },
|
||||
});
|
||||
Reference in New Issue
Block a user