Refactor recoil scope states (#3097)
* Refactor recoil scope states * Complete refactoring * Fix
This commit is contained in:
@ -1,3 +1,5 @@
|
|||||||
|
import { useRecoilValue } from 'recoil';
|
||||||
|
|
||||||
import { IconArrowUpRight } from '@/ui/display/icon';
|
import { IconArrowUpRight } from '@/ui/display/icon';
|
||||||
import { IconComponent } from '@/ui/display/icon/types/IconComponent';
|
import { IconComponent } from '@/ui/display/icon/types/IconComponent';
|
||||||
import { useSelectableList } from '@/ui/layout/selectable-list/hooks/useSelectableList';
|
import { useSelectableList } from '@/ui/layout/selectable-list/hooks/useSelectableList';
|
||||||
@ -30,7 +32,8 @@ export const CommandMenuItem = ({
|
|||||||
Icon = IconArrowUpRight;
|
Icon = IconArrowUpRight;
|
||||||
}
|
}
|
||||||
|
|
||||||
const { isSelectedItemId } = useSelectableList({ itemId: id });
|
const { isSelectedItemIdFamilyState } = useSelectableList();
|
||||||
|
const isSelectedItemId = useRecoilValue(isSelectedItemIdFamilyState(id));
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<MenuItemCommand
|
<MenuItemCommand
|
||||||
|
|||||||
@ -15,9 +15,7 @@ export const useCommandMenu = () => {
|
|||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const setIsCommandMenuOpened = useSetRecoilState(isCommandMenuOpenedState);
|
const setIsCommandMenuOpened = useSetRecoilState(isCommandMenuOpenedState);
|
||||||
const setCommands = useSetRecoilState(commandMenuCommandsState);
|
const setCommands = useSetRecoilState(commandMenuCommandsState);
|
||||||
const { resetSelectedItem } = useSelectableList({
|
const { resetSelectedItem } = useSelectableList('command-menu-list');
|
||||||
selectableListId: 'command-menu-list',
|
|
||||||
});
|
|
||||||
const {
|
const {
|
||||||
setHotkeyScopeAndMemorizePreviousScope,
|
setHotkeyScopeAndMemorizePreviousScope,
|
||||||
goBackToPreviousHotkeyScope,
|
goBackToPreviousHotkeyScope,
|
||||||
|
|||||||
@ -14,69 +14,69 @@ import { hiddenRecordBoardCardFieldsScopedSelector } from '@/object-record/recor
|
|||||||
import { recordBoardCardFieldsByKeyScopedSelector } from '@/object-record/record-board/states/selectors/recordBoardCardFieldsByKeyScopedSelector';
|
import { recordBoardCardFieldsByKeyScopedSelector } from '@/object-record/record-board/states/selectors/recordBoardCardFieldsByKeyScopedSelector';
|
||||||
import { selectedRecordBoardCardIdsScopedSelector } from '@/object-record/record-board/states/selectors/selectedRecordBoardCardIdsScopedSelector';
|
import { selectedRecordBoardCardIdsScopedSelector } from '@/object-record/record-board/states/selectors/selectedRecordBoardCardIdsScopedSelector';
|
||||||
import { visibleRecordBoardCardFieldsScopedSelector } from '@/object-record/record-board/states/selectors/visibleRecordBoardCardFieldsScopedSelector';
|
import { visibleRecordBoardCardFieldsScopedSelector } from '@/object-record/record-board/states/selectors/visibleRecordBoardCardFieldsScopedSelector';
|
||||||
import { getScopedState } from '@/ui/utilities/recoil-scope/utils/getScopedState';
|
import { getScopedStateDeprecated } from '@/ui/utilities/recoil-scope/utils/getScopedStateDeprecated';
|
||||||
|
|
||||||
export const getRecordBoardScopedStates = ({
|
export const getRecordBoardScopedStates = ({
|
||||||
recordBoardScopeId,
|
recordBoardScopeId,
|
||||||
}: {
|
}: {
|
||||||
recordBoardScopeId: string;
|
recordBoardScopeId: string;
|
||||||
}) => {
|
}) => {
|
||||||
const activeCardIdsState = getScopedState(
|
const activeCardIdsState = getScopedStateDeprecated(
|
||||||
activeRecordBoardCardIdsScopedState,
|
activeRecordBoardCardIdsScopedState,
|
||||||
recordBoardScopeId,
|
recordBoardScopeId,
|
||||||
);
|
);
|
||||||
|
|
||||||
const availableBoardCardFieldsState = getScopedState(
|
const availableBoardCardFieldsState = getScopedStateDeprecated(
|
||||||
availableRecordBoardCardFieldsScopedState,
|
availableRecordBoardCardFieldsScopedState,
|
||||||
recordBoardScopeId,
|
recordBoardScopeId,
|
||||||
);
|
);
|
||||||
|
|
||||||
const boardColumnsState = getScopedState(
|
const boardColumnsState = getScopedStateDeprecated(
|
||||||
recordBoardColumnsScopedState,
|
recordBoardColumnsScopedState,
|
||||||
recordBoardScopeId,
|
recordBoardScopeId,
|
||||||
);
|
);
|
||||||
|
|
||||||
const isBoardLoadedState = getScopedState(
|
const isBoardLoadedState = getScopedStateDeprecated(
|
||||||
isRecordBoardLoadedScopedState,
|
isRecordBoardLoadedScopedState,
|
||||||
recordBoardScopeId,
|
recordBoardScopeId,
|
||||||
);
|
);
|
||||||
|
|
||||||
const isCompactViewEnabledState = getScopedState(
|
const isCompactViewEnabledState = getScopedStateDeprecated(
|
||||||
isCompactViewEnabledScopedState,
|
isCompactViewEnabledScopedState,
|
||||||
recordBoardScopeId,
|
recordBoardScopeId,
|
||||||
);
|
);
|
||||||
|
|
||||||
const savedBoardColumnsState = getScopedState(
|
const savedBoardColumnsState = getScopedStateDeprecated(
|
||||||
savedRecordBoardColumnsScopedState,
|
savedRecordBoardColumnsScopedState,
|
||||||
recordBoardScopeId,
|
recordBoardScopeId,
|
||||||
);
|
);
|
||||||
|
|
||||||
const boardFiltersState = getScopedState(
|
const boardFiltersState = getScopedStateDeprecated(
|
||||||
recordBoardFiltersScopedState,
|
recordBoardFiltersScopedState,
|
||||||
recordBoardScopeId,
|
recordBoardScopeId,
|
||||||
);
|
);
|
||||||
|
|
||||||
const boardSortsState = getScopedState(
|
const boardSortsState = getScopedStateDeprecated(
|
||||||
recordBoardSortsScopedState,
|
recordBoardSortsScopedState,
|
||||||
recordBoardScopeId,
|
recordBoardScopeId,
|
||||||
);
|
);
|
||||||
|
|
||||||
const savedCompaniesState = getScopedState(
|
const savedCompaniesState = getScopedStateDeprecated(
|
||||||
savedRecordsScopedState,
|
savedRecordsScopedState,
|
||||||
recordBoardScopeId,
|
recordBoardScopeId,
|
||||||
);
|
);
|
||||||
|
|
||||||
const savedOpportunitiesState = getScopedState(
|
const savedOpportunitiesState = getScopedStateDeprecated(
|
||||||
savedOpportunitiesScopedState,
|
savedOpportunitiesScopedState,
|
||||||
recordBoardScopeId,
|
recordBoardScopeId,
|
||||||
);
|
);
|
||||||
|
|
||||||
const savedPipelineStepsState = getScopedState(
|
const savedPipelineStepsState = getScopedStateDeprecated(
|
||||||
savedPipelineStepsScopedState,
|
savedPipelineStepsScopedState,
|
||||||
recordBoardScopeId,
|
recordBoardScopeId,
|
||||||
);
|
);
|
||||||
|
|
||||||
const onFieldsChangeState = getScopedState(
|
const onFieldsChangeState = getScopedStateDeprecated(
|
||||||
onFieldsChangeScopedState,
|
onFieldsChangeScopedState,
|
||||||
recordBoardScopeId,
|
recordBoardScopeId,
|
||||||
);
|
);
|
||||||
|
|||||||
@ -6,7 +6,7 @@ import { onColumnsChangeScopedState } from '@/object-record/record-table/states/
|
|||||||
import { useScopedHotkeys } from '@/ui/utilities/hotkey/hooks/useScopedHotkeys';
|
import { useScopedHotkeys } from '@/ui/utilities/hotkey/hooks/useScopedHotkeys';
|
||||||
import { useSetHotkeyScope } from '@/ui/utilities/hotkey/hooks/useSetHotkeyScope';
|
import { useSetHotkeyScope } from '@/ui/utilities/hotkey/hooks/useSetHotkeyScope';
|
||||||
import { useAvailableScopeIdOrThrow } from '@/ui/utilities/recoil-scope/scopes-internal/hooks/useAvailableScopeId';
|
import { useAvailableScopeIdOrThrow } from '@/ui/utilities/recoil-scope/scopes-internal/hooks/useAvailableScopeId';
|
||||||
import { getScopedState } from '@/ui/utilities/recoil-scope/utils/getScopedState';
|
import { getScopedStateDeprecated } from '@/ui/utilities/recoil-scope/utils/getScopedStateDeprecated';
|
||||||
import { getSnapshotValue } from '@/ui/utilities/recoil-scope/utils/getSnapshotValue';
|
import { getSnapshotValue } from '@/ui/utilities/recoil-scope/utils/getSnapshotValue';
|
||||||
|
|
||||||
import { FieldMetadata } from '../../field/types/FieldMetadata';
|
import { FieldMetadata } from '../../field/types/FieldMetadata';
|
||||||
@ -63,7 +63,7 @@ export const useRecordTable = (props?: useRecordTableProps) => {
|
|||||||
const onColumnsChange = useRecoilCallback(
|
const onColumnsChange = useRecoilCallback(
|
||||||
({ snapshot }) =>
|
({ snapshot }) =>
|
||||||
(columns: ColumnDefinition<FieldMetadata>[]) => {
|
(columns: ColumnDefinition<FieldMetadata>[]) => {
|
||||||
const onColumnsChangeState = getScopedState(
|
const onColumnsChangeState = getScopedStateDeprecated(
|
||||||
onColumnsChangeScopedState,
|
onColumnsChangeScopedState,
|
||||||
scopeId,
|
scopeId,
|
||||||
);
|
);
|
||||||
@ -80,7 +80,7 @@ export const useRecordTable = (props?: useRecordTableProps) => {
|
|||||||
const onEntityCountChange = useRecoilCallback(
|
const onEntityCountChange = useRecoilCallback(
|
||||||
({ snapshot }) =>
|
({ snapshot }) =>
|
||||||
(count: number) => {
|
(count: number) => {
|
||||||
const onEntityCountChangeState = getScopedState(
|
const onEntityCountChangeState = getScopedStateDeprecated(
|
||||||
onEntityCountChangeScopedState,
|
onEntityCountChangeScopedState,
|
||||||
scopeId,
|
scopeId,
|
||||||
);
|
);
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import { objectMetadataConfigScopedState } from '@/object-record/record-table/states/objectMetadataConfigScopedState';
|
import { objectMetadataConfigScopedState } from '@/object-record/record-table/states/objectMetadataConfigScopedState';
|
||||||
import { tableLastRowVisibleScopedState } from '@/object-record/record-table/states/tableLastRowVisibleScopedState';
|
import { tableLastRowVisibleScopedState } from '@/object-record/record-table/states/tableLastRowVisibleScopedState';
|
||||||
import { getScopedState } from '@/ui/utilities/recoil-scope/utils/getScopedState';
|
import { getScopedStateDeprecated } from '@/ui/utilities/recoil-scope/utils/getScopedStateDeprecated';
|
||||||
|
|
||||||
import { availableTableColumnsScopedState } from '../states/availableTableColumnsScopedState';
|
import { availableTableColumnsScopedState } from '../states/availableTableColumnsScopedState';
|
||||||
import { onColumnsChangeScopedState } from '../states/onColumnsChangeScopedState';
|
import { onColumnsChangeScopedState } from '../states/onColumnsChangeScopedState';
|
||||||
@ -17,27 +17,27 @@ export const getRecordTableScopedStates = ({
|
|||||||
}: {
|
}: {
|
||||||
recordTableScopeId: string;
|
recordTableScopeId: string;
|
||||||
}) => {
|
}) => {
|
||||||
const availableTableColumnsState = getScopedState(
|
const availableTableColumnsState = getScopedStateDeprecated(
|
||||||
availableTableColumnsScopedState,
|
availableTableColumnsScopedState,
|
||||||
recordTableScopeId,
|
recordTableScopeId,
|
||||||
);
|
);
|
||||||
|
|
||||||
const tableFiltersState = getScopedState(
|
const tableFiltersState = getScopedStateDeprecated(
|
||||||
tableFiltersScopedState,
|
tableFiltersScopedState,
|
||||||
recordTableScopeId,
|
recordTableScopeId,
|
||||||
);
|
);
|
||||||
|
|
||||||
const tableSortsState = getScopedState(
|
const tableSortsState = getScopedStateDeprecated(
|
||||||
tableSortsScopedState,
|
tableSortsScopedState,
|
||||||
recordTableScopeId,
|
recordTableScopeId,
|
||||||
);
|
);
|
||||||
|
|
||||||
const tableColumnsState = getScopedState(
|
const tableColumnsState = getScopedStateDeprecated(
|
||||||
tableColumnsScopedState,
|
tableColumnsScopedState,
|
||||||
recordTableScopeId,
|
recordTableScopeId,
|
||||||
);
|
);
|
||||||
|
|
||||||
const objectMetadataConfigState = getScopedState(
|
const objectMetadataConfigState = getScopedStateDeprecated(
|
||||||
objectMetadataConfigScopedState,
|
objectMetadataConfigScopedState,
|
||||||
recordTableScopeId,
|
recordTableScopeId,
|
||||||
);
|
);
|
||||||
@ -51,17 +51,17 @@ export const getRecordTableScopedStates = ({
|
|||||||
const visibleTableColumnsSelector =
|
const visibleTableColumnsSelector =
|
||||||
visibleTableColumnsScopedSelector(recordTableScopeId);
|
visibleTableColumnsScopedSelector(recordTableScopeId);
|
||||||
|
|
||||||
const onColumnsChangeState = getScopedState(
|
const onColumnsChangeState = getScopedStateDeprecated(
|
||||||
onColumnsChangeScopedState,
|
onColumnsChangeScopedState,
|
||||||
recordTableScopeId,
|
recordTableScopeId,
|
||||||
);
|
);
|
||||||
|
|
||||||
const onEntityCountChangeState = getScopedState(
|
const onEntityCountChangeState = getScopedStateDeprecated(
|
||||||
onEntityCountChangeScopedState,
|
onEntityCountChangeScopedState,
|
||||||
recordTableScopeId,
|
recordTableScopeId,
|
||||||
);
|
);
|
||||||
|
|
||||||
const tableLastRowVisibleState = getScopedState(
|
const tableLastRowVisibleState = getScopedStateDeprecated(
|
||||||
tableLastRowVisibleScopedState,
|
tableLastRowVisibleScopedState,
|
||||||
recordTableScopeId,
|
recordTableScopeId,
|
||||||
);
|
);
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import styled from '@emotion/styled';
|
import styled from '@emotion/styled';
|
||||||
|
import { useRecoilValue } from 'recoil';
|
||||||
|
|
||||||
import { EntityForSelect } from '@/object-record/relation-picker/types/EntityForSelect';
|
import { EntityForSelect } from '@/object-record/relation-picker/types/EntityForSelect';
|
||||||
import { SelectableItem } from '@/ui/layout/selectable-list/components/SelectableItem';
|
import { SelectableItem } from '@/ui/layout/selectable-list/components/SelectableItem';
|
||||||
@ -21,10 +22,13 @@ export const SelectableMenuItemSelect = ({
|
|||||||
onEntitySelected,
|
onEntitySelected,
|
||||||
selectedEntity,
|
selectedEntity,
|
||||||
}: SelectableMenuItemSelectProps) => {
|
}: SelectableMenuItemSelectProps) => {
|
||||||
const { isSelectedItemId } = useSelectableList({
|
const { isSelectedItemIdFamilyState } = useSelectableList(
|
||||||
selectableListId: 'single-entity-select-base-list',
|
'single-entity-select-base-list',
|
||||||
itemId: entity.id,
|
);
|
||||||
});
|
|
||||||
|
const isSelectedItemId = useRecoilValue(
|
||||||
|
isSelectedItemIdFamilyState(entity.id),
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<StyledSelectableItem itemId={entity.id} key={entity.id}>
|
<StyledSelectableItem itemId={entity.id} key={entity.id}>
|
||||||
|
|||||||
@ -2,29 +2,29 @@ import { identifiersMapperScopedState } from '@/object-record/relation-picker/st
|
|||||||
import { relationPickerPreselectedIdScopedState } from '@/object-record/relation-picker/states/relationPickerPreselectedIdScopedState';
|
import { relationPickerPreselectedIdScopedState } from '@/object-record/relation-picker/states/relationPickerPreselectedIdScopedState';
|
||||||
import { relationPickerSearchFilterScopedState } from '@/object-record/relation-picker/states/relationPickerSearchFilterScopedState';
|
import { relationPickerSearchFilterScopedState } from '@/object-record/relation-picker/states/relationPickerSearchFilterScopedState';
|
||||||
import { searchQueryScopedState } from '@/object-record/relation-picker/states/searchQueryScopedState';
|
import { searchQueryScopedState } from '@/object-record/relation-picker/states/searchQueryScopedState';
|
||||||
import { getScopedState } from '@/ui/utilities/recoil-scope/utils/getScopedState';
|
import { getScopedStateDeprecated } from '@/ui/utilities/recoil-scope/utils/getScopedStateDeprecated';
|
||||||
|
|
||||||
export const getRelationPickerScopedStates = ({
|
export const getRelationPickerScopedStates = ({
|
||||||
relationPickerScopeId,
|
relationPickerScopeId,
|
||||||
}: {
|
}: {
|
||||||
relationPickerScopeId: string;
|
relationPickerScopeId: string;
|
||||||
}) => {
|
}) => {
|
||||||
const identifiersMapperState = getScopedState(
|
const identifiersMapperState = getScopedStateDeprecated(
|
||||||
identifiersMapperScopedState,
|
identifiersMapperScopedState,
|
||||||
relationPickerScopeId,
|
relationPickerScopeId,
|
||||||
);
|
);
|
||||||
|
|
||||||
const searchQueryState = getScopedState(
|
const searchQueryState = getScopedStateDeprecated(
|
||||||
searchQueryScopedState,
|
searchQueryScopedState,
|
||||||
relationPickerScopeId,
|
relationPickerScopeId,
|
||||||
);
|
);
|
||||||
|
|
||||||
const relationPickerPreselectedIdState = getScopedState(
|
const relationPickerPreselectedIdState = getScopedStateDeprecated(
|
||||||
relationPickerPreselectedIdScopedState,
|
relationPickerPreselectedIdScopedState,
|
||||||
relationPickerScopeId,
|
relationPickerScopeId,
|
||||||
);
|
);
|
||||||
|
|
||||||
const relationPickerSearchFilterState = getScopedState(
|
const relationPickerSearchFilterState = getScopedStateDeprecated(
|
||||||
relationPickerSearchFilterScopedState,
|
relationPickerSearchFilterScopedState,
|
||||||
relationPickerScopeId,
|
relationPickerScopeId,
|
||||||
);
|
);
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
import { useMemo, useState } from 'react';
|
import { useMemo, useState } from 'react';
|
||||||
import styled from '@emotion/styled';
|
import styled from '@emotion/styled';
|
||||||
|
import { useRecoilValue } from 'recoil';
|
||||||
|
|
||||||
import { IconApps } from '@/ui/display/icon';
|
import { IconApps } from '@/ui/display/icon';
|
||||||
import { useIcons } from '@/ui/display/icon/hooks/useIcons';
|
import { useIcons } from '@/ui/display/icon/hooks/useIcons';
|
||||||
@ -60,7 +61,9 @@ const IconPickerIcon = ({
|
|||||||
selectedIconKey,
|
selectedIconKey,
|
||||||
Icon,
|
Icon,
|
||||||
}: IconPickerIconProps) => {
|
}: IconPickerIconProps) => {
|
||||||
const { isSelectedItemId } = useSelectableList({ itemId: iconKey });
|
const { isSelectedItemIdFamilyState } = useSelectableList();
|
||||||
|
|
||||||
|
const isSelectedItemId = useRecoilValue(isSelectedItemIdFamilyState(iconKey));
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<StyledLightIconButton
|
<StyledLightIconButton
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import { ReactNode, useEffect, useRef } from 'react';
|
import { ReactNode, useEffect, useRef } from 'react';
|
||||||
import { useRecoilValue } from 'recoil';
|
import { useRecoilValue } from 'recoil';
|
||||||
|
|
||||||
import { useSelectableListScopedStates } from '@/ui/layout/selectable-list/hooks/internal/useSelectableListScopedStates';
|
import { useSelectableList } from '@/ui/layout/selectable-list/hooks/useSelectableList';
|
||||||
|
|
||||||
export type SelectableItemProps = {
|
export type SelectableItemProps = {
|
||||||
itemId: string;
|
itemId: string;
|
||||||
@ -14,11 +14,9 @@ export const SelectableItem = ({
|
|||||||
children,
|
children,
|
||||||
className,
|
className,
|
||||||
}: SelectableItemProps) => {
|
}: SelectableItemProps) => {
|
||||||
const { isSelectedItemIdSelector } = useSelectableListScopedStates({
|
const { isSelectedItemIdFamilyState } = useSelectableList();
|
||||||
itemId: itemId,
|
|
||||||
});
|
|
||||||
|
|
||||||
const isSelectedItemId = useRecoilValue(isSelectedItemIdSelector);
|
const isSelectedItemId = useRecoilValue(isSelectedItemIdFamilyState(itemId));
|
||||||
|
|
||||||
const scrollRef = useRef<HTMLDivElement>(null);
|
const scrollRef = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
|
|||||||
@ -25,9 +25,8 @@ export const SelectableList = ({
|
|||||||
}: SelectableListProps) => {
|
}: SelectableListProps) => {
|
||||||
useSelectableListHotKeys(selectableListId, hotkeyScope);
|
useSelectableListHotKeys(selectableListId, hotkeyScope);
|
||||||
|
|
||||||
const { setSelectableItemIds, setSelectableListOnEnter } = useSelectableList({
|
const { setSelectableItemIds, setSelectableListOnEnter } =
|
||||||
selectableListId,
|
useSelectableList(selectableListId);
|
||||||
});
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setSelectableListOnEnter(() => onEnter);
|
setSelectableListOnEnter(() => onEnter);
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
import { useRecoilCallback } from 'recoil';
|
import { useRecoilCallback } from 'recoil';
|
||||||
import { Key } from 'ts-key-enum';
|
import { Key } from 'ts-key-enum';
|
||||||
|
|
||||||
import { getSelectableListScopedStates } from '@/ui/layout/selectable-list/utils/internal/getSelectableListScopedStates';
|
import { useSelectableListScopedState } from '@/ui/layout/selectable-list/hooks/internal/useSelectableListScopedState';
|
||||||
|
import { getSelectableListScopeInjectors } from '@/ui/layout/selectable-list/utils/internal/getSelectableListScopeInjectors';
|
||||||
import { useScopedHotkeys } from '@/ui/utilities/hotkey/hooks/useScopedHotkeys';
|
import { useScopedHotkeys } from '@/ui/utilities/hotkey/hooks/useScopedHotkeys';
|
||||||
import { getSnapshotValue } from '@/ui/utilities/recoil-scope/utils/getSnapshotValue';
|
|
||||||
|
|
||||||
type Direction = 'up' | 'down' | 'left' | 'right';
|
type Direction = 'up' | 'down' | 'left' | 'right';
|
||||||
|
|
||||||
@ -27,17 +27,28 @@ export const useSelectableListHotKeys = (
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const { getSelectableListScopedSnapshotValue } = useSelectableListScopedState(
|
||||||
|
{
|
||||||
|
selectableListScopeId: scopeId,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
const handleSelect = useRecoilCallback(
|
const handleSelect = useRecoilCallback(
|
||||||
({ snapshot, set }) =>
|
({ snapshot, set }) =>
|
||||||
(direction: Direction) => {
|
(direction: Direction) => {
|
||||||
const { selectedItemIdState, selectableItemIdsState } =
|
const {
|
||||||
getSelectableListScopedStates({
|
selectedItemIdScopeInjector,
|
||||||
selectableListScopeId: scopeId,
|
selectableItemIdsScopeInjector,
|
||||||
});
|
isSelectedItemIdFamilyScopeInjector,
|
||||||
const selectedItemId = getSnapshotValue(snapshot, selectedItemIdState);
|
} = getSelectableListScopeInjectors();
|
||||||
const selectableItemIds = getSnapshotValue(
|
|
||||||
|
const selectedItemId = getSelectableListScopedSnapshotValue(
|
||||||
snapshot,
|
snapshot,
|
||||||
selectableItemIdsState,
|
selectedItemIdScopeInjector,
|
||||||
|
);
|
||||||
|
const selectableItemIds = getSelectableListScopedSnapshotValue(
|
||||||
|
snapshot,
|
||||||
|
selectableItemIdsScopeInjector,
|
||||||
);
|
);
|
||||||
|
|
||||||
const currentPosition = findPosition(selectableItemIds, selectedItemId);
|
const currentPosition = findPosition(selectableItemIds, selectedItemId);
|
||||||
@ -97,24 +108,19 @@ export const useSelectableListHotKeys = (
|
|||||||
|
|
||||||
if (selectedItemId !== nextId) {
|
if (selectedItemId !== nextId) {
|
||||||
if (nextId) {
|
if (nextId) {
|
||||||
const { isSelectedItemIdSelector } = getSelectableListScopedStates({
|
set(isSelectedItemIdFamilyScopeInjector(scopeId, nextId), true);
|
||||||
selectableListScopeId: scopeId,
|
set(selectedItemIdScopeInjector(scopeId), nextId);
|
||||||
itemId: nextId,
|
|
||||||
});
|
|
||||||
set(isSelectedItemIdSelector, true);
|
|
||||||
set(selectedItemIdState, nextId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (selectedItemId) {
|
if (selectedItemId) {
|
||||||
const { isSelectedItemIdSelector } = getSelectableListScopedStates({
|
set(
|
||||||
selectableListScopeId: scopeId,
|
isSelectedItemIdFamilyScopeInjector(scopeId, selectedItemId),
|
||||||
itemId: selectedItemId,
|
false,
|
||||||
});
|
);
|
||||||
set(isSelectedItemIdSelector, false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[scopeId],
|
[getSelectableListScopedSnapshotValue, scopeId],
|
||||||
);
|
);
|
||||||
|
|
||||||
useScopedHotkeys(Key.ArrowUp, () => handleSelect('up'), hotkeyScope, []);
|
useScopedHotkeys(Key.ArrowUp, () => handleSelect('up'), hotkeyScope, []);
|
||||||
@ -135,25 +141,25 @@ export const useSelectableListHotKeys = (
|
|||||||
useRecoilCallback(
|
useRecoilCallback(
|
||||||
({ snapshot }) =>
|
({ snapshot }) =>
|
||||||
() => {
|
() => {
|
||||||
const { selectedItemIdState, selectableListOnEnterState } =
|
const {
|
||||||
getSelectableListScopedStates({
|
selectedItemIdScopeInjector,
|
||||||
selectableListScopeId: scopeId,
|
selectableListOnEnterScopeInjector,
|
||||||
});
|
} = getSelectableListScopeInjectors();
|
||||||
const selectedItemId = getSnapshotValue(
|
const selectedItemId = getSelectableListScopedSnapshotValue(
|
||||||
snapshot,
|
snapshot,
|
||||||
selectedItemIdState,
|
selectedItemIdScopeInjector,
|
||||||
);
|
);
|
||||||
|
|
||||||
const onEnter = getSnapshotValue(
|
const onEnter = getSelectableListScopedSnapshotValue(
|
||||||
snapshot,
|
snapshot,
|
||||||
selectableListOnEnterState,
|
selectableListOnEnterScopeInjector,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (selectedItemId) {
|
if (selectedItemId) {
|
||||||
onEnter?.(selectedItemId);
|
onEnter?.(selectedItemId);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[scopeId],
|
[getSelectableListScopedSnapshotValue],
|
||||||
),
|
),
|
||||||
hotkeyScope,
|
hotkeyScope,
|
||||||
[],
|
[],
|
||||||
|
|||||||
@ -0,0 +1,31 @@
|
|||||||
|
import { SelectableListScopeInternalContext } from '@/ui/layout/selectable-list/scopes/scope-internal-context/SelectableListScopeInternalContext';
|
||||||
|
import { useAvailableScopeIdOrThrow } from '@/ui/utilities/recoil-scope/scopes-internal/hooks/useAvailableScopeId';
|
||||||
|
import { useScopedState } from '@/ui/utilities/recoil-scope/scopes-internal/hooks/useScopedState';
|
||||||
|
|
||||||
|
type UseSelectableListScopedStatesProps = {
|
||||||
|
selectableListScopeId?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const useSelectableListScopedState = ({
|
||||||
|
selectableListScopeId,
|
||||||
|
}: UseSelectableListScopedStatesProps) => {
|
||||||
|
const scopeId = useAvailableScopeIdOrThrow(
|
||||||
|
SelectableListScopeInternalContext,
|
||||||
|
selectableListScopeId,
|
||||||
|
);
|
||||||
|
|
||||||
|
const {
|
||||||
|
getScopedState,
|
||||||
|
getScopedFamilyState,
|
||||||
|
getScopedSnapshotValue,
|
||||||
|
getScopedFamilySnapshotValue,
|
||||||
|
} = useScopedState(scopeId);
|
||||||
|
|
||||||
|
return {
|
||||||
|
scopeId,
|
||||||
|
getSelectableListScopedState: getScopedState,
|
||||||
|
getSelectableListScopedFamilyState: getScopedFamilyState,
|
||||||
|
getSelectableListScopedSnapshotValue: getScopedSnapshotValue,
|
||||||
|
getSelectableListScopedFamilySnapshotValue: getScopedFamilySnapshotValue,
|
||||||
|
};
|
||||||
|
};
|
||||||
@ -1,36 +0,0 @@
|
|||||||
import { SelectableListScopeInternalContext } from '@/ui/layout/selectable-list/scopes/scope-internal-context/SelectableListScopeInternalContext';
|
|
||||||
import { getSelectableListScopedStates } from '@/ui/layout/selectable-list/utils/internal/getSelectableListScopedStates';
|
|
||||||
import { useAvailableScopeIdOrThrow } from '@/ui/utilities/recoil-scope/scopes-internal/hooks/useAvailableScopeId';
|
|
||||||
|
|
||||||
type UseSelectableListScopedStatesProps = {
|
|
||||||
selectableListScopeId?: string;
|
|
||||||
itemId?: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const useSelectableListScopedStates = (
|
|
||||||
args?: UseSelectableListScopedStatesProps,
|
|
||||||
) => {
|
|
||||||
const { selectableListScopeId, itemId } = args ?? {};
|
|
||||||
const scopeId = useAvailableScopeIdOrThrow(
|
|
||||||
SelectableListScopeInternalContext,
|
|
||||||
selectableListScopeId,
|
|
||||||
);
|
|
||||||
|
|
||||||
const {
|
|
||||||
selectedItemIdState,
|
|
||||||
selectableItemIdsState,
|
|
||||||
isSelectedItemIdSelector,
|
|
||||||
selectableListOnEnterState,
|
|
||||||
} = getSelectableListScopedStates({
|
|
||||||
selectableListScopeId: scopeId,
|
|
||||||
itemId: itemId,
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
|
||||||
scopeId,
|
|
||||||
isSelectedItemIdSelector,
|
|
||||||
selectableItemIdsState,
|
|
||||||
selectedItemIdState,
|
|
||||||
selectableListOnEnterState,
|
|
||||||
};
|
|
||||||
};
|
|
||||||
@ -1,52 +1,48 @@
|
|||||||
import { useRecoilValue, useResetRecoilState, useSetRecoilState } from 'recoil';
|
import { useResetRecoilState, useSetRecoilState } from 'recoil';
|
||||||
|
|
||||||
import { useSelectableListScopedStates } from '@/ui/layout/selectable-list/hooks/internal/useSelectableListScopedStates';
|
import { useSelectableListScopedState } from '@/ui/layout/selectable-list/hooks/internal/useSelectableListScopedState';
|
||||||
import { SelectableListScopeInternalContext } from '@/ui/layout/selectable-list/scopes/scope-internal-context/SelectableListScopeInternalContext';
|
import { getSelectableListScopeInjectors } from '@/ui/layout/selectable-list/utils/internal/getSelectableListScopeInjectors';
|
||||||
import { useAvailableScopeIdOrThrow } from '@/ui/utilities/recoil-scope/scopes-internal/hooks/useAvailableScopeId';
|
|
||||||
|
|
||||||
type UseSelectableListProps = {
|
|
||||||
selectableListId?: string;
|
|
||||||
itemId?: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const useSelectableList = (props?: UseSelectableListProps) => {
|
|
||||||
const scopeId = useAvailableScopeIdOrThrow(
|
|
||||||
SelectableListScopeInternalContext,
|
|
||||||
props?.selectableListId,
|
|
||||||
);
|
|
||||||
|
|
||||||
|
export const useSelectableList = (selectableListScopeId?: string) => {
|
||||||
const {
|
const {
|
||||||
selectableItemIdsState,
|
getSelectableListScopedState,
|
||||||
isSelectedItemIdSelector,
|
getSelectableListScopedFamilyState,
|
||||||
selectableListOnEnterState,
|
scopeId,
|
||||||
selectedItemIdState,
|
} = useSelectableListScopedState({
|
||||||
} = useSelectableListScopedStates({
|
selectableListScopeId,
|
||||||
selectableListScopeId: scopeId,
|
|
||||||
itemId: props?.itemId,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const setSelectableItemIds = useSetRecoilState(selectableItemIdsState);
|
const {
|
||||||
const setSelectableListOnEnter = useSetRecoilState(
|
selectedItemIdScopeInjector,
|
||||||
selectableListOnEnterState,
|
selectableItemIdsScopeInjector,
|
||||||
);
|
selectableListOnEnterScopeInjector,
|
||||||
const isSelectedItemId = useRecoilValue(isSelectedItemIdSelector);
|
isSelectedItemIdFamilyScopeInjector,
|
||||||
|
} = getSelectableListScopeInjectors();
|
||||||
|
|
||||||
const resetSelectedItemIdState = useResetRecoilState(selectedItemIdState);
|
const setSelectableItemIds = useSetRecoilState(
|
||||||
const resetIsSelectedItemIdSelector = useResetRecoilState(
|
getSelectableListScopedState(selectableItemIdsScopeInjector),
|
||||||
isSelectedItemIdSelector,
|
);
|
||||||
|
const setSelectableListOnEnter = useSetRecoilState(
|
||||||
|
getSelectableListScopedState(selectableListOnEnterScopeInjector),
|
||||||
|
);
|
||||||
|
const isSelectedItemIdFamilyState = getSelectableListScopedFamilyState(
|
||||||
|
isSelectedItemIdFamilyScopeInjector,
|
||||||
|
);
|
||||||
|
|
||||||
|
const resetSelectedItemIdState = useResetRecoilState(
|
||||||
|
getSelectableListScopedState(selectedItemIdScopeInjector),
|
||||||
);
|
);
|
||||||
|
|
||||||
const resetSelectedItem = () => {
|
const resetSelectedItem = () => {
|
||||||
resetSelectedItemIdState();
|
resetSelectedItemIdState();
|
||||||
resetIsSelectedItemIdSelector();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
setSelectableItemIds,
|
|
||||||
isSelectedItemId,
|
|
||||||
setSelectableListOnEnter,
|
|
||||||
selectableListId: scopeId,
|
selectableListId: scopeId,
|
||||||
isSelectedItemIdSelector,
|
|
||||||
|
setSelectableItemIds,
|
||||||
|
isSelectedItemIdFamilyState,
|
||||||
|
setSelectableListOnEnter,
|
||||||
resetSelectedItem,
|
resetSelectedItem,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,25 +1,27 @@
|
|||||||
import { selectorFamily } from 'recoil';
|
|
||||||
|
|
||||||
import { isSelectedItemIdMapScopedFamilyState } from '@/ui/layout/selectable-list/states/isSelectedItemIdMapScopedFamilyState';
|
import { isSelectedItemIdMapScopedFamilyState } from '@/ui/layout/selectable-list/states/isSelectedItemIdMapScopedFamilyState';
|
||||||
|
import { createScopedFamilySelector } from '@/ui/utilities/recoil-scope/utils/createScopedFamilySelector';
|
||||||
|
|
||||||
export const isSelectedItemIdScopedFamilySelector = selectorFamily({
|
export const isSelectedItemIdScopedFamilySelector = createScopedFamilySelector<
|
||||||
|
boolean,
|
||||||
|
string
|
||||||
|
>({
|
||||||
key: 'isSelectedItemIdScopedFamilySelector',
|
key: 'isSelectedItemIdScopedFamilySelector',
|
||||||
get:
|
get:
|
||||||
({ scopeId, itemId }: { scopeId: string; itemId: string }) =>
|
({ scopeId, familyKey }: { scopeId: string; familyKey: string }) =>
|
||||||
({ get }) =>
|
({ get }) =>
|
||||||
get(
|
get(
|
||||||
isSelectedItemIdMapScopedFamilyState({
|
isSelectedItemIdMapScopedFamilyState({
|
||||||
scopeId: scopeId,
|
scopeId: scopeId,
|
||||||
familyKey: itemId,
|
familyKey: familyKey,
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
set:
|
set:
|
||||||
({ scopeId, itemId }: { scopeId: string; itemId: string }) =>
|
({ scopeId, familyKey }: { scopeId: string; familyKey: string }) =>
|
||||||
({ set }, newValue) =>
|
({ set }, newValue) =>
|
||||||
set(
|
set(
|
||||||
isSelectedItemIdMapScopedFamilyState({
|
isSelectedItemIdMapScopedFamilyState({
|
||||||
scopeId: scopeId,
|
scopeId: scopeId,
|
||||||
familyKey: itemId,
|
familyKey: familyKey,
|
||||||
}),
|
}),
|
||||||
newValue,
|
newValue,
|
||||||
),
|
),
|
||||||
|
|||||||
@ -0,0 +1,28 @@
|
|||||||
|
import { selectableItemIdsScopedState } from '@/ui/layout/selectable-list/states/selectableItemIdsScopedState';
|
||||||
|
import { selectableListOnEnterScopedState } from '@/ui/layout/selectable-list/states/selectableListOnEnterScopedState';
|
||||||
|
import { selectedItemIdScopedState } from '@/ui/layout/selectable-list/states/selectedItemIdScopedState';
|
||||||
|
import { isSelectedItemIdScopedFamilySelector } from '@/ui/layout/selectable-list/states/selectors/isSelectedItemIdScopedFamilySelector';
|
||||||
|
import { getFamilyScopeInjector } from '@/ui/utilities/recoil-scope/utils/getFamilyScopeInjector';
|
||||||
|
import { getScopeInjector } from '@/ui/utilities/recoil-scope/utils/getScopeInjector';
|
||||||
|
|
||||||
|
export const getSelectableListScopeInjectors = () => {
|
||||||
|
const selectedItemIdScopeInjector = getScopeInjector(
|
||||||
|
selectedItemIdScopedState,
|
||||||
|
);
|
||||||
|
const selectableItemIdsScopeInjector = getScopeInjector(
|
||||||
|
selectableItemIdsScopedState,
|
||||||
|
);
|
||||||
|
const selectableListOnEnterScopeInjector = getScopeInjector(
|
||||||
|
selectableListOnEnterScopedState,
|
||||||
|
);
|
||||||
|
const isSelectedItemIdFamilyScopeInjector = getFamilyScopeInjector(
|
||||||
|
isSelectedItemIdScopedFamilySelector,
|
||||||
|
);
|
||||||
|
|
||||||
|
return {
|
||||||
|
selectedItemIdScopeInjector,
|
||||||
|
selectableItemIdsScopeInjector,
|
||||||
|
selectableListOnEnterScopeInjector,
|
||||||
|
isSelectedItemIdFamilyScopeInjector,
|
||||||
|
};
|
||||||
|
};
|
||||||
@ -1,42 +0,0 @@
|
|||||||
import { selectableItemIdsScopedState } from '@/ui/layout/selectable-list/states/selectableItemIdsScopedState';
|
|
||||||
import { selectableListOnEnterScopedState } from '@/ui/layout/selectable-list/states/selectableListOnEnterScopedState';
|
|
||||||
import { selectedItemIdScopedState } from '@/ui/layout/selectable-list/states/selectedItemIdScopedState';
|
|
||||||
import { isSelectedItemIdScopedFamilySelector } from '@/ui/layout/selectable-list/states/selectors/isSelectedItemIdScopedFamilySelector';
|
|
||||||
import { getScopedState } from '@/ui/utilities/recoil-scope/utils/getScopedState';
|
|
||||||
|
|
||||||
const UNDEFINED_SELECTABLE_ITEM_ID = 'UNDEFINED_SELECTABLE_ITEM_ID';
|
|
||||||
|
|
||||||
export const getSelectableListScopedStates = ({
|
|
||||||
selectableListScopeId,
|
|
||||||
itemId,
|
|
||||||
}: {
|
|
||||||
selectableListScopeId: string;
|
|
||||||
itemId?: string;
|
|
||||||
}) => {
|
|
||||||
const isSelectedItemIdSelector = isSelectedItemIdScopedFamilySelector({
|
|
||||||
scopeId: selectableListScopeId,
|
|
||||||
itemId: itemId ?? UNDEFINED_SELECTABLE_ITEM_ID,
|
|
||||||
});
|
|
||||||
|
|
||||||
const selectedItemIdState = getScopedState(
|
|
||||||
selectedItemIdScopedState,
|
|
||||||
selectableListScopeId,
|
|
||||||
);
|
|
||||||
|
|
||||||
const selectableItemIdsState = getScopedState(
|
|
||||||
selectableItemIdsScopedState,
|
|
||||||
selectableListScopeId,
|
|
||||||
);
|
|
||||||
|
|
||||||
const selectableListOnEnterState = getScopedState(
|
|
||||||
selectableListOnEnterScopedState,
|
|
||||||
selectableListScopeId,
|
|
||||||
);
|
|
||||||
|
|
||||||
return {
|
|
||||||
isSelectedItemIdSelector,
|
|
||||||
selectableItemIdsState,
|
|
||||||
selectedItemIdState,
|
|
||||||
selectableListOnEnterState,
|
|
||||||
};
|
|
||||||
};
|
|
||||||
@ -0,0 +1,38 @@
|
|||||||
|
import { SerializableParam, Snapshot } from 'recoil';
|
||||||
|
|
||||||
|
import { FamilyScopeInjector } from '@/ui/utilities/recoil-scope/utils/getFamilyScopeInjector';
|
||||||
|
import { ScopeInjector } from '@/ui/utilities/recoil-scope/utils/getScopeInjector';
|
||||||
|
import { getSnapshotValue } from '@/ui/utilities/recoil-scope/utils/getSnapshotValue';
|
||||||
|
|
||||||
|
export const useScopedState = (scopeId: string) => {
|
||||||
|
const getScopedState = <StateType>(scopeInjector: ScopeInjector<StateType>) =>
|
||||||
|
scopeInjector(scopeId);
|
||||||
|
|
||||||
|
const getScopedFamilyState =
|
||||||
|
<StateType, FamilyKey extends SerializableParam>(
|
||||||
|
familyScopeInjector: FamilyScopeInjector<StateType, FamilyKey>,
|
||||||
|
) =>
|
||||||
|
(familyKey: FamilyKey) =>
|
||||||
|
familyScopeInjector(scopeId, familyKey);
|
||||||
|
|
||||||
|
const getScopedSnapshotValue = <StateType>(
|
||||||
|
snashot: Snapshot,
|
||||||
|
scopeInjector: ScopeInjector<StateType>,
|
||||||
|
) => getSnapshotValue(snashot, scopeInjector(scopeId));
|
||||||
|
|
||||||
|
const getScopedFamilySnapshotValue =
|
||||||
|
<StateType, FamilyKey extends SerializableParam>(
|
||||||
|
snashot: Snapshot,
|
||||||
|
familyScopeInjector: FamilyScopeInjector<StateType, FamilyKey>,
|
||||||
|
) =>
|
||||||
|
(familyKey: FamilyKey) =>
|
||||||
|
getSnapshotValue(snashot, familyScopeInjector(scopeId, familyKey));
|
||||||
|
|
||||||
|
return {
|
||||||
|
scopeId,
|
||||||
|
getScopedState,
|
||||||
|
getScopedFamilyState,
|
||||||
|
getScopedSnapshotValue,
|
||||||
|
getScopedFamilySnapshotValue,
|
||||||
|
};
|
||||||
|
};
|
||||||
@ -0,0 +1,47 @@
|
|||||||
|
import {
|
||||||
|
DefaultValue,
|
||||||
|
GetCallback,
|
||||||
|
GetRecoilValue,
|
||||||
|
Loadable,
|
||||||
|
RecoilValue,
|
||||||
|
ResetRecoilState,
|
||||||
|
selectorFamily,
|
||||||
|
SerializableParam,
|
||||||
|
SetRecoilState,
|
||||||
|
WrappedValue,
|
||||||
|
} from 'recoil';
|
||||||
|
|
||||||
|
import { ScopedFamilyStateKey } from '../scopes-internal/types/ScopedFamilyStateKey';
|
||||||
|
|
||||||
|
type SelectorGetter<T, P> = (
|
||||||
|
param: P,
|
||||||
|
) => (opts: {
|
||||||
|
get: GetRecoilValue;
|
||||||
|
getCallback: GetCallback;
|
||||||
|
}) => Promise<T> | RecoilValue<T> | Loadable<T> | WrappedValue<T> | T;
|
||||||
|
|
||||||
|
type SelectorSetter<T, P> = (
|
||||||
|
param: P,
|
||||||
|
) => (
|
||||||
|
opts: { set: SetRecoilState; get: GetRecoilValue; reset: ResetRecoilState },
|
||||||
|
newValue: T | DefaultValue,
|
||||||
|
) => void;
|
||||||
|
|
||||||
|
export const createScopedFamilySelector = <
|
||||||
|
ValueType,
|
||||||
|
FamilyKey extends SerializableParam,
|
||||||
|
>({
|
||||||
|
key,
|
||||||
|
get,
|
||||||
|
set,
|
||||||
|
}: {
|
||||||
|
key: string;
|
||||||
|
get: SelectorGetter<ValueType, ScopedFamilyStateKey<FamilyKey>>;
|
||||||
|
set: SelectorSetter<ValueType, ScopedFamilyStateKey<FamilyKey>>;
|
||||||
|
}) => {
|
||||||
|
return selectorFamily<ValueType, ScopedFamilyStateKey<FamilyKey>>({
|
||||||
|
key,
|
||||||
|
get,
|
||||||
|
set,
|
||||||
|
});
|
||||||
|
};
|
||||||
@ -0,0 +1,23 @@
|
|||||||
|
import { RecoilState, SerializableParam } from 'recoil';
|
||||||
|
|
||||||
|
import { ScopedFamilyStateKey } from '../scopes-internal/types/ScopedFamilyStateKey';
|
||||||
|
|
||||||
|
export type FamilyScopeInjector<
|
||||||
|
StateType,
|
||||||
|
FamilyKey extends SerializableParam,
|
||||||
|
> = (scopeId: string, familyKey: FamilyKey) => RecoilState<StateType>;
|
||||||
|
|
||||||
|
export const getFamilyScopeInjector = <
|
||||||
|
StateType,
|
||||||
|
FamilyKey extends SerializableParam,
|
||||||
|
>(
|
||||||
|
scopedFamilyState: (
|
||||||
|
scopedFamilyKey: ScopedFamilyStateKey<FamilyKey>,
|
||||||
|
) => RecoilState<StateType>,
|
||||||
|
) => {
|
||||||
|
return (scopeId: string, familyKey: FamilyKey) =>
|
||||||
|
scopedFamilyState({
|
||||||
|
scopeId,
|
||||||
|
familyKey: familyKey || ('' as FamilyKey),
|
||||||
|
});
|
||||||
|
};
|
||||||
@ -0,0 +1,16 @@
|
|||||||
|
import { RecoilState } from 'recoil';
|
||||||
|
|
||||||
|
import { RecoilScopedState } from '../types/RecoilScopedState';
|
||||||
|
|
||||||
|
export type ScopeInjector<StateType> = (
|
||||||
|
scopeId: string,
|
||||||
|
) => RecoilState<StateType>;
|
||||||
|
|
||||||
|
export const getScopeInjector = <StateType>(
|
||||||
|
scopedState: RecoilScopedState<StateType>,
|
||||||
|
) => {
|
||||||
|
return (scopeId: string) =>
|
||||||
|
scopedState({
|
||||||
|
scopeId,
|
||||||
|
});
|
||||||
|
};
|
||||||
@ -2,7 +2,7 @@ import { RecoilState, SerializableParam } from 'recoil';
|
|||||||
|
|
||||||
import { ScopedFamilyStateKey } from '../scopes-internal/types/ScopedFamilyStateKey';
|
import { ScopedFamilyStateKey } from '../scopes-internal/types/ScopedFamilyStateKey';
|
||||||
|
|
||||||
export const getScopedFamilyState = <
|
export const getScopedFamilyStateDeprecated = <
|
||||||
StateType,
|
StateType,
|
||||||
FamilyKey extends SerializableParam,
|
FamilyKey extends SerializableParam,
|
||||||
>(
|
>(
|
||||||
@ -1,6 +1,6 @@
|
|||||||
import { RecoilScopedSelector } from '../types/RecoilScopedSelector';
|
import { RecoilScopedSelector } from '../types/RecoilScopedSelector';
|
||||||
|
|
||||||
export const getScopedSelector = <StateType>(
|
export const getScopedSelectorDeprecated = <StateType>(
|
||||||
recoilScopedState: RecoilScopedSelector<StateType>,
|
recoilScopedState: RecoilScopedSelector<StateType>,
|
||||||
scopeId: string,
|
scopeId: string,
|
||||||
) => {
|
) => {
|
||||||
@ -1,6 +1,6 @@
|
|||||||
import { RecoilScopedState } from '../types/RecoilScopedState';
|
import { RecoilScopedState } from '../types/RecoilScopedState';
|
||||||
|
|
||||||
export const getScopedState = <StateType>(
|
export const getScopedStateDeprecated = <StateType>(
|
||||||
recoilScopedState: RecoilScopedState<StateType>,
|
recoilScopedState: RecoilScopedState<StateType>,
|
||||||
scopeId: string,
|
scopeId: string,
|
||||||
) => {
|
) => {
|
||||||
@ -1,15 +0,0 @@
|
|||||||
import { Snapshot } from 'recoil';
|
|
||||||
|
|
||||||
import { RecoilScopedSelector } from '../types/RecoilScopedSelector';
|
|
||||||
|
|
||||||
import { getScopedSelector } from './getScopedSelector';
|
|
||||||
|
|
||||||
export const getSnapshotScopedSelector = <StateType>(
|
|
||||||
snapshot: Snapshot,
|
|
||||||
scopedState: RecoilScopedSelector<StateType>,
|
|
||||||
scopeId: string,
|
|
||||||
) => {
|
|
||||||
return snapshot
|
|
||||||
.getLoadable(getScopedSelector(scopedState, scopeId))
|
|
||||||
.getValue();
|
|
||||||
};
|
|
||||||
@ -1,13 +0,0 @@
|
|||||||
import { Snapshot } from 'recoil';
|
|
||||||
|
|
||||||
import { RecoilScopedState } from '../types/RecoilScopedState';
|
|
||||||
|
|
||||||
import { getScopedState } from './getScopedState';
|
|
||||||
|
|
||||||
export const getSnapshotScopedValue = <StateType>(
|
|
||||||
snapshot: Snapshot,
|
|
||||||
scopedState: RecoilScopedState<StateType>,
|
|
||||||
scopeId: string,
|
|
||||||
) => {
|
|
||||||
return snapshot.getLoadable(getScopedState(scopedState, scopeId)).getValue();
|
|
||||||
};
|
|
||||||
@ -1,7 +1,7 @@
|
|||||||
import { useRecoilState } from 'recoil';
|
import { useRecoilState } from 'recoil';
|
||||||
|
|
||||||
import { useAvailableScopeIdOrThrow } from '@/ui/utilities/recoil-scope/scopes-internal/hooks/useAvailableScopeId';
|
import { useAvailableScopeIdOrThrow } from '@/ui/utilities/recoil-scope/scopes-internal/hooks/useAvailableScopeId';
|
||||||
import { getScopedState } from '@/ui/utilities/recoil-scope/utils/getScopedState';
|
import { getScopedStateDeprecated } from '@/ui/utilities/recoil-scope/utils/getScopedStateDeprecated';
|
||||||
|
|
||||||
import { UNDEFINED_FAMILY_ITEM_ID } from '../../constants';
|
import { UNDEFINED_FAMILY_ITEM_ID } from '../../constants';
|
||||||
import { ViewScopeInternalContext } from '../../scopes/scope-internal-context/ViewScopeInternalContext';
|
import { ViewScopeInternalContext } from '../../scopes/scope-internal-context/ViewScopeInternalContext';
|
||||||
@ -18,7 +18,7 @@ export const useViewScopedStates = (args?: { viewScopeId?: string }) => {
|
|||||||
|
|
||||||
// View
|
// View
|
||||||
const [currentViewId] = useRecoilState(
|
const [currentViewId] = useRecoilState(
|
||||||
getScopedState(currentViewIdScopedState, scopeId),
|
getScopedStateDeprecated(currentViewIdScopedState, scopeId),
|
||||||
);
|
);
|
||||||
|
|
||||||
const viewId = currentViewId ?? UNDEFINED_FAMILY_ITEM_ID;
|
const viewId = currentViewId ?? UNDEFINED_FAMILY_ITEM_ID;
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import { Snapshot } from 'recoil';
|
import { Snapshot } from 'recoil';
|
||||||
|
|
||||||
import { getScopedState } from '@/ui/utilities/recoil-scope/utils/getScopedState';
|
import { getScopedStateDeprecated } from '@/ui/utilities/recoil-scope/utils/getScopedStateDeprecated';
|
||||||
import { getSnapshotValue } from '@/ui/utilities/recoil-scope/utils/getSnapshotValue';
|
import { getSnapshotValue } from '@/ui/utilities/recoil-scope/utils/getSnapshotValue';
|
||||||
|
|
||||||
import { UNDEFINED_FAMILY_ITEM_ID } from '../constants';
|
import { UNDEFINED_FAMILY_ITEM_ID } from '../constants';
|
||||||
@ -19,7 +19,7 @@ export const getViewScopedStateValuesFromSnapshot = ({
|
|||||||
}) => {
|
}) => {
|
||||||
const currentViewId = getSnapshotValue(
|
const currentViewId = getSnapshotValue(
|
||||||
snapshot,
|
snapshot,
|
||||||
getScopedState(currentViewIdScopedState, viewScopeId),
|
getScopedStateDeprecated(currentViewIdScopedState, viewScopeId),
|
||||||
);
|
);
|
||||||
|
|
||||||
const familyItemId = viewId ?? currentViewId ?? UNDEFINED_FAMILY_ITEM_ID;
|
const familyItemId = viewId ?? currentViewId ?? UNDEFINED_FAMILY_ITEM_ID;
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import { Snapshot } from 'recoil';
|
import { Snapshot } from 'recoil';
|
||||||
|
|
||||||
import { getScopedState } from '@/ui/utilities/recoil-scope/utils/getScopedState';
|
import { getScopedStateDeprecated } from '@/ui/utilities/recoil-scope/utils/getScopedStateDeprecated';
|
||||||
import { getSnapshotValue } from '@/ui/utilities/recoil-scope/utils/getSnapshotValue';
|
import { getSnapshotValue } from '@/ui/utilities/recoil-scope/utils/getSnapshotValue';
|
||||||
|
|
||||||
import { UNDEFINED_FAMILY_ITEM_ID } from '../constants';
|
import { UNDEFINED_FAMILY_ITEM_ID } from '../constants';
|
||||||
@ -19,7 +19,7 @@ export const getViewScopedStatesFromSnapshot = ({
|
|||||||
}) => {
|
}) => {
|
||||||
const currentViewId = getSnapshotValue(
|
const currentViewId = getSnapshotValue(
|
||||||
snapshot,
|
snapshot,
|
||||||
getScopedState(currentViewIdScopedState, viewScopeId),
|
getScopedStateDeprecated(currentViewIdScopedState, viewScopeId),
|
||||||
);
|
);
|
||||||
|
|
||||||
const usedViewId = viewId ?? currentViewId ?? UNDEFINED_FAMILY_ITEM_ID;
|
const usedViewId = viewId ?? currentViewId ?? UNDEFINED_FAMILY_ITEM_ID;
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import { getScopedFamilyState } from '@/ui/utilities/recoil-scope/utils/getScopedFamilyState';
|
import { getScopedFamilyStateDeprecated } from '@/ui/utilities/recoil-scope/utils/getScopedFamilyStateDeprecated';
|
||||||
import { getScopedSelector } from '@/ui/utilities/recoil-scope/utils/getScopedSelector';
|
import { getScopedSelectorDeprecated } from '@/ui/utilities/recoil-scope/utils/getScopedSelectorDeprecated';
|
||||||
import { getScopedState } from '@/ui/utilities/recoil-scope/utils/getScopedState';
|
import { getScopedStateDeprecated } from '@/ui/utilities/recoil-scope/utils/getScopedStateDeprecated';
|
||||||
import { currentViewIdScopedState } from '@/views/states/currentViewIdScopedState';
|
import { currentViewIdScopedState } from '@/views/states/currentViewIdScopedState';
|
||||||
import { isPersistingViewScopedState } from '@/views/states/isPersistingViewScopedState';
|
import { isPersistingViewScopedState } from '@/views/states/isPersistingViewScopedState';
|
||||||
import { currentViewScopedSelector } from '@/views/states/selectors/currentViewScopedSelector';
|
import { currentViewScopedSelector } from '@/views/states/selectors/currentViewScopedSelector';
|
||||||
@ -36,43 +36,46 @@ export const getViewScopedStates = ({
|
|||||||
viewScopeId: string;
|
viewScopeId: string;
|
||||||
viewId: string;
|
viewId: string;
|
||||||
}) => {
|
}) => {
|
||||||
const viewEditModeState = getScopedState(
|
const viewEditModeState = getScopedStateDeprecated(
|
||||||
viewEditModeScopedState,
|
viewEditModeScopedState,
|
||||||
viewScopeId,
|
viewScopeId,
|
||||||
);
|
);
|
||||||
|
|
||||||
const viewsState = getScopedState(viewsScopedState, viewScopeId);
|
const viewsState = getScopedStateDeprecated(viewsScopedState, viewScopeId);
|
||||||
|
|
||||||
const viewObjectMetadataIdState = getScopedState(
|
const viewObjectMetadataIdState = getScopedStateDeprecated(
|
||||||
viewObjectMetadataIdScopeState,
|
viewObjectMetadataIdScopeState,
|
||||||
viewScopeId,
|
viewScopeId,
|
||||||
);
|
);
|
||||||
|
|
||||||
const viewTypeState = getScopedState(viewTypeScopedState, viewScopeId);
|
const viewTypeState = getScopedStateDeprecated(
|
||||||
|
viewTypeScopedState,
|
||||||
|
viewScopeId,
|
||||||
|
);
|
||||||
|
|
||||||
const entityCountInCurrentViewState = getScopedState(
|
const entityCountInCurrentViewState = getScopedStateDeprecated(
|
||||||
entityCountInCurrentViewScopedState,
|
entityCountInCurrentViewScopedState,
|
||||||
viewScopeId,
|
viewScopeId,
|
||||||
);
|
);
|
||||||
|
|
||||||
const isViewBarExpandedState = getScopedState(
|
const isViewBarExpandedState = getScopedStateDeprecated(
|
||||||
isViewBarExpandedScopedState,
|
isViewBarExpandedScopedState,
|
||||||
viewScopeId,
|
viewScopeId,
|
||||||
);
|
);
|
||||||
|
|
||||||
const isPersistingViewState = getScopedState(
|
const isPersistingViewState = getScopedStateDeprecated(
|
||||||
isPersistingViewScopedState,
|
isPersistingViewScopedState,
|
||||||
viewScopeId,
|
viewScopeId,
|
||||||
);
|
);
|
||||||
|
|
||||||
// ViewSorts
|
// ViewSorts
|
||||||
const currentViewSortsState = getScopedFamilyState(
|
const currentViewSortsState = getScopedFamilyStateDeprecated(
|
||||||
currentViewSortsScopedFamilyState,
|
currentViewSortsScopedFamilyState,
|
||||||
viewScopeId,
|
viewScopeId,
|
||||||
viewId,
|
viewId,
|
||||||
);
|
);
|
||||||
|
|
||||||
const savedViewSortsState = getScopedFamilyState(
|
const savedViewSortsState = getScopedFamilyStateDeprecated(
|
||||||
savedViewSortsScopedFamilyState,
|
savedViewSortsScopedFamilyState,
|
||||||
viewScopeId,
|
viewScopeId,
|
||||||
viewId,
|
viewId,
|
||||||
@ -83,7 +86,7 @@ export const getViewScopedStates = ({
|
|||||||
viewId: viewId,
|
viewId: viewId,
|
||||||
});
|
});
|
||||||
|
|
||||||
const availableSortDefinitionsState = getScopedState(
|
const availableSortDefinitionsState = getScopedStateDeprecated(
|
||||||
availableSortDefinitionsScopedState,
|
availableSortDefinitionsScopedState,
|
||||||
viewScopeId,
|
viewScopeId,
|
||||||
);
|
);
|
||||||
@ -94,13 +97,13 @@ export const getViewScopedStates = ({
|
|||||||
});
|
});
|
||||||
|
|
||||||
// ViewFilters
|
// ViewFilters
|
||||||
const currentViewFiltersState = getScopedFamilyState(
|
const currentViewFiltersState = getScopedFamilyStateDeprecated(
|
||||||
currentViewFiltersScopedFamilyState,
|
currentViewFiltersScopedFamilyState,
|
||||||
viewScopeId,
|
viewScopeId,
|
||||||
viewId,
|
viewId,
|
||||||
);
|
);
|
||||||
|
|
||||||
const savedViewFiltersState = getScopedFamilyState(
|
const savedViewFiltersState = getScopedFamilyStateDeprecated(
|
||||||
savedViewFiltersScopedFamilyState,
|
savedViewFiltersScopedFamilyState,
|
||||||
viewScopeId,
|
viewScopeId,
|
||||||
viewId,
|
viewId,
|
||||||
@ -112,7 +115,7 @@ export const getViewScopedStates = ({
|
|||||||
viewId: viewId,
|
viewId: viewId,
|
||||||
});
|
});
|
||||||
|
|
||||||
const availableFilterDefinitionsState = getScopedState(
|
const availableFilterDefinitionsState = getScopedStateDeprecated(
|
||||||
availableFilterDefinitionsScopedState,
|
availableFilterDefinitionsScopedState,
|
||||||
viewScopeId,
|
viewScopeId,
|
||||||
);
|
);
|
||||||
@ -123,18 +126,18 @@ export const getViewScopedStates = ({
|
|||||||
});
|
});
|
||||||
|
|
||||||
// ViewFields
|
// ViewFields
|
||||||
const availableFieldDefinitionsState = getScopedState(
|
const availableFieldDefinitionsState = getScopedStateDeprecated(
|
||||||
availableFieldDefinitionsScopedState,
|
availableFieldDefinitionsScopedState,
|
||||||
viewScopeId,
|
viewScopeId,
|
||||||
);
|
);
|
||||||
|
|
||||||
const currentViewFieldsState = getScopedFamilyState(
|
const currentViewFieldsState = getScopedFamilyStateDeprecated(
|
||||||
currentViewFieldsScopedFamilyState,
|
currentViewFieldsScopedFamilyState,
|
||||||
viewScopeId,
|
viewScopeId,
|
||||||
viewId,
|
viewId,
|
||||||
);
|
);
|
||||||
|
|
||||||
const savedViewFieldsState = getScopedFamilyState(
|
const savedViewFieldsState = getScopedFamilyStateDeprecated(
|
||||||
savedViewFieldsScopedFamilyState,
|
savedViewFieldsScopedFamilyState,
|
||||||
viewScopeId,
|
viewScopeId,
|
||||||
viewId,
|
viewId,
|
||||||
@ -146,27 +149,27 @@ export const getViewScopedStates = ({
|
|||||||
});
|
});
|
||||||
|
|
||||||
// ViewChangeHandlers
|
// ViewChangeHandlers
|
||||||
const onViewSortsChangeState = getScopedState(
|
const onViewSortsChangeState = getScopedStateDeprecated(
|
||||||
onViewSortsChangeScopedState,
|
onViewSortsChangeScopedState,
|
||||||
viewScopeId,
|
viewScopeId,
|
||||||
);
|
);
|
||||||
|
|
||||||
const onViewFiltersChangeState = getScopedState(
|
const onViewFiltersChangeState = getScopedStateDeprecated(
|
||||||
onViewFiltersChangeScopedState,
|
onViewFiltersChangeScopedState,
|
||||||
viewScopeId,
|
viewScopeId,
|
||||||
);
|
);
|
||||||
|
|
||||||
const onViewFieldsChangeState = getScopedState(
|
const onViewFieldsChangeState = getScopedStateDeprecated(
|
||||||
onViewFieldsChangeScopedState,
|
onViewFieldsChangeScopedState,
|
||||||
viewScopeId,
|
viewScopeId,
|
||||||
);
|
);
|
||||||
|
|
||||||
const currentViewIdState = getScopedState(
|
const currentViewIdState = getScopedStateDeprecated(
|
||||||
currentViewIdScopedState,
|
currentViewIdScopedState,
|
||||||
viewScopeId,
|
viewScopeId,
|
||||||
);
|
);
|
||||||
|
|
||||||
const currentViewSelector = getScopedSelector(
|
const currentViewSelector = getScopedSelectorDeprecated(
|
||||||
currentViewScopedSelector,
|
currentViewScopedSelector,
|
||||||
viewScopeId,
|
viewScopeId,
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user