Improve Jotai work (#18205)

This commit is contained in:
Charles Bochet
2026-02-24 20:38:30 +01:00
committed by GitHub
parent b339c93699
commit eaf9fe27b2
210 changed files with 1714 additions and 1662 deletions
@@ -25,12 +25,12 @@ export const useDuplicatePageLayoutTab = (pageLayoutIdFromProps?: string) => {
pageLayoutIdFromProps,
);
const pageLayoutDraftAtom = useRecoilComponentStateCallbackStateV2(
const pageLayoutDraft = useRecoilComponentStateCallbackStateV2(
pageLayoutDraftComponentState,
pageLayoutId,
);
const pageLayoutCurrentLayoutsAtom = useRecoilComponentStateCallbackStateV2(
const pageLayoutCurrentLayouts = useRecoilComponentStateCallbackStateV2(
pageLayoutCurrentLayoutsComponentState,
pageLayoutId,
);
@@ -54,11 +54,11 @@ export const useDuplicatePageLayoutTab = (pageLayoutIdFromProps?: string) => {
const duplicateTab = useCallback(
(tabId: string): string => {
const pageLayoutDraft = store.get(pageLayoutDraftAtom);
const currentPageLayoutDraft = store.get(pageLayoutDraft);
const allTabLayouts = store.get(pageLayoutCurrentLayoutsAtom);
const allTabLayouts = store.get(pageLayoutCurrentLayouts);
const sourceTab = pageLayoutDraft.tabs.find((t) => t.id === tabId);
const sourceTab = currentPageLayoutDraft.tabs.find((t) => t.id === tabId);
if (!isDefined(sourceTab)) {
throw new Error(`Tab with id ${tabId} not found`);
@@ -79,7 +79,7 @@ export const useDuplicatePageLayoutTab = (pageLayoutIdFromProps?: string) => {
};
});
const sortedTabs = sortTabsByPosition(pageLayoutDraft.tabs);
const sortedTabs = sortTabsByPosition(currentPageLayoutDraft.tabs);
const sourceIndex = sortedTabs.findIndex((t) => t.id === tabId);
const newTabPosition = calculateNewPosition({
@@ -113,13 +113,13 @@ export const useDuplicatePageLayoutTab = (pageLayoutIdFromProps?: string) => {
})),
};
store.set(pageLayoutCurrentLayoutsAtom, {
store.set(pageLayoutCurrentLayouts, {
...allTabLayouts,
[newTabId]: newLayouts,
});
const prev = store.get(pageLayoutDraftAtom);
store.set(pageLayoutDraftAtom, {
const prev = store.get(pageLayoutDraft);
store.set(pageLayoutDraft, {
...prev,
tabs: [...prev.tabs, newTab],
});
@@ -141,8 +141,8 @@ export const useDuplicatePageLayoutTab = (pageLayoutIdFromProps?: string) => {
[
closeCommandMenu,
navigatePageLayoutCommandMenu,
pageLayoutCurrentLayoutsAtom,
pageLayoutDraftAtom,
pageLayoutCurrentLayouts,
pageLayoutDraft,
setActiveTabId,
setTabSettingsOpenTabId,
store,
@@ -40,7 +40,7 @@ export const useResetDraftPageLayoutToPersistedPageLayout = (
componentInstanceId,
);
const activeTabIdAtom = activeTabIdComponentState.atomFamily({
const activeTabId = activeTabIdComponentState.atomFamily({
instanceId: tabListComponentInstanceId,
});
@@ -59,14 +59,14 @@ export const useResetDraftPageLayoutToPersistedPageLayout = (
const pageLayoutPersisted = store.get(pageLayoutPersistedState);
if (isDefined(pageLayoutPersisted)) {
const currentActiveTabId = store.get(activeTabIdAtom);
const currentActiveTabId = store.get(activeTabId);
const persistedTabIds = pageLayoutPersisted.tabs.map((tab) => tab.id);
const isActiveTabInPersistedTabs =
currentActiveTabId && persistedTabIds.includes(currentActiveTabId);
if (!isActiveTabInPersistedTabs && pageLayoutPersisted.tabs.length > 0) {
store.set(activeTabIdAtom, pageLayoutPersisted.tabs[0].id);
store.set(activeTabId, pageLayoutPersisted.tabs[0].id);
}
store.set(pageLayoutDraftState, {
@@ -91,7 +91,7 @@ export const useResetDraftPageLayoutToPersistedPageLayout = (
pageLayoutCurrentLayoutsState,
fieldsWidgetGroupsDraftState,
fieldsWidgetGroupsPersistedState,
activeTabIdAtom,
activeTabId,
store,
]);
@@ -1,6 +1,5 @@
import { COMMAND_MENU_COMPONENT_INSTANCE_ID } from '@/command-menu/constants/CommandMenuComponentInstanceId';
import { isCommandMenuOpenedStateV2 } from '@/command-menu/states/isCommandMenuOpenedStateV2';
import { jotaiStore } from '@/ui/utilities/state/jotai/jotaiStore';
import { MAIN_CONTEXT_STORE_INSTANCE_ID } from '@/context-store/constants/MainContextStoreInstanceId';
import { contextStoreIsPageInEditModeComponentState } from '@/context-store/states/contextStoreIsPageInEditModeComponentState';
import { PageLayoutComponentInstanceContext } from '@/page-layout/states/contexts/PageLayoutComponentInstanceContext';
@@ -36,14 +35,9 @@ export const useSetIsPageLayoutInEditMode = (pageLayoutIdFromProps: string) => {
store.set(contextStoreIsFullTabWidgetInEditModeState, value);
jotaiStore.set(
currentPageLayoutIdState.atom,
value ? pageLayoutId : null,
);
store.set(currentPageLayoutIdState.atom, value ? pageLayoutId : null);
const isCommandMenuOpened = jotaiStore.get(
isCommandMenuOpenedStateV2.atom,
);
const isCommandMenuOpened = store.get(isCommandMenuOpenedStateV2.atom);
if (isCommandMenuOpened) {
store.set(