mirror of
https://dev.azure.com/hugendubel/ISA/_git/ISA-Frontend
synced 2025-12-31 09:37:15 +01:00
fix(tabs): fix tab activation issue
This commit is contained in:
@@ -79,21 +79,27 @@ export const TabService = signalStore(
|
|||||||
},
|
},
|
||||||
activateTab(id: number) {
|
activateTab(id: number) {
|
||||||
const tab = store.entityMap()[id];
|
const tab = store.entityMap()[id];
|
||||||
|
patchState(store, { activatedTabId: id });
|
||||||
|
|
||||||
if (!tab) {
|
if (!tab) {
|
||||||
store._logger.warn('Cannot activate non-existent tab', () => ({ tabId: id }));
|
store._logger.warn('Cannot activate non-existent tab', () => ({
|
||||||
|
tabId: id,
|
||||||
|
}));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const changes: Partial<Tab> = { activatedAt: Date.now() };
|
const changes: Partial<Tab> = { activatedAt: Date.now() };
|
||||||
patchState(store, updateEntity({ id, changes }));
|
patchState(store, updateEntity({ id, changes }));
|
||||||
patchState(store, { activatedTabId: id });
|
|
||||||
store._logger.debug('Tab activated', () => ({ tabId: id }));
|
store._logger.debug('Tab activated', () => ({ tabId: id }));
|
||||||
},
|
},
|
||||||
patchTab(id: number, changes: z.infer<typeof PatchTabSchema>) {
|
patchTab(id: number, changes: z.infer<typeof PatchTabSchema>) {
|
||||||
const currentTab = store.entityMap()[id];
|
const currentTab = store.entityMap()[id];
|
||||||
|
|
||||||
if (!currentTab) {
|
if (!currentTab) {
|
||||||
store._logger.warn('Cannot patch non-existent tab', () => ({ tabId: id }));
|
store._logger.warn('Cannot patch non-existent tab', () => ({
|
||||||
|
tabId: id,
|
||||||
|
}));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,7 +122,10 @@ export const TabService = signalStore(
|
|||||||
const currentTab = store.entityMap()[id];
|
const currentTab = store.entityMap()[id];
|
||||||
|
|
||||||
if (!currentTab) {
|
if (!currentTab) {
|
||||||
store._logger.warn('Cannot patch metadata for non-existent tab', () => ({ tabId: id }));
|
store._logger.warn(
|
||||||
|
'Cannot patch metadata for non-existent tab',
|
||||||
|
() => ({ tabId: id }),
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,7 +153,10 @@ export const TabService = signalStore(
|
|||||||
const parsed: TabLocation = TabLocationSchema.parse(location);
|
const parsed: TabLocation = TabLocationSchema.parse(location);
|
||||||
const currentTab = store.entityMap()[id];
|
const currentTab = store.entityMap()[id];
|
||||||
if (!currentTab) {
|
if (!currentTab) {
|
||||||
store._logger.warn('Cannot navigate to location for non-existent tab', () => ({ tabId: id }));
|
store._logger.warn(
|
||||||
|
'Cannot navigate to location for non-existent tab',
|
||||||
|
() => ({ tabId: id }),
|
||||||
|
);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -229,7 +241,9 @@ export const TabService = signalStore(
|
|||||||
navigateBack(id: number) {
|
navigateBack(id: number) {
|
||||||
const currentTab = store.entityMap()[id];
|
const currentTab = store.entityMap()[id];
|
||||||
if (!currentTab) {
|
if (!currentTab) {
|
||||||
store._logger.warn('Cannot navigate back for non-existent tab', () => ({ tabId: id }));
|
store._logger.warn('Cannot navigate back for non-existent tab', () => ({
|
||||||
|
tabId: id,
|
||||||
|
}));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -243,7 +257,10 @@ export const TabService = signalStore(
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (validatedCurrent <= 0) {
|
if (validatedCurrent <= 0) {
|
||||||
store._logger.debug('Cannot navigate back - at beginning of history', () => ({ tabId: id }));
|
store._logger.debug(
|
||||||
|
'Cannot navigate back - at beginning of history',
|
||||||
|
() => ({ tabId: id }),
|
||||||
|
);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -269,7 +286,10 @@ export const TabService = signalStore(
|
|||||||
navigateForward(id: number) {
|
navigateForward(id: number) {
|
||||||
const currentTab = store.entityMap()[id];
|
const currentTab = store.entityMap()[id];
|
||||||
if (!currentTab) {
|
if (!currentTab) {
|
||||||
store._logger.warn('Cannot navigate forward for non-existent tab', () => ({ tabId: id }));
|
store._logger.warn(
|
||||||
|
'Cannot navigate forward for non-existent tab',
|
||||||
|
() => ({ tabId: id }),
|
||||||
|
);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -283,7 +303,10 @@ export const TabService = signalStore(
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (validatedCurrent >= currentLocation.locations.length - 1) {
|
if (validatedCurrent >= currentLocation.locations.length - 1) {
|
||||||
store._logger.debug('Cannot navigate forward - at end of history', () => ({ tabId: id }));
|
store._logger.debug(
|
||||||
|
'Cannot navigate forward - at end of history',
|
||||||
|
() => ({ tabId: id }),
|
||||||
|
);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -309,7 +332,10 @@ export const TabService = signalStore(
|
|||||||
clearLocationHistory(id: number) {
|
clearLocationHistory(id: number) {
|
||||||
const currentTab = store.entityMap()[id];
|
const currentTab = store.entityMap()[id];
|
||||||
if (!currentTab) {
|
if (!currentTab) {
|
||||||
store._logger.warn('Cannot clear location history for non-existent tab', () => ({ tabId: id }));
|
store._logger.warn(
|
||||||
|
'Cannot clear location history for non-existent tab',
|
||||||
|
() => ({ tabId: id }),
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -352,11 +378,14 @@ export const TabService = signalStore(
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (wasInvalid && store._config.enableIndexValidation) {
|
if (wasInvalid && store._config.enableIndexValidation) {
|
||||||
store._logger.warn('Invalid location index corrected in getCurrentLocation', () => ({
|
store._logger.warn(
|
||||||
tabId: id,
|
'Invalid location index corrected in getCurrentLocation',
|
||||||
invalidIndex: currentLocation.current,
|
() => ({
|
||||||
correctedIndex: validatedCurrent,
|
tabId: id,
|
||||||
}));
|
invalidIndex: currentLocation.current,
|
||||||
|
correctedIndex: validatedCurrent,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
// Correct the invalid index in store (SIDE EFFECT)
|
// Correct the invalid index in store (SIDE EFFECT)
|
||||||
const changes: Partial<Tab> = {
|
const changes: Partial<Tab> = {
|
||||||
@@ -380,7 +409,10 @@ export const TabService = signalStore(
|
|||||||
updateCurrentLocation(id: number, updates: Partial<TabLocation>) {
|
updateCurrentLocation(id: number, updates: Partial<TabLocation>) {
|
||||||
const currentTab = store.entityMap()[id];
|
const currentTab = store.entityMap()[id];
|
||||||
if (!currentTab) {
|
if (!currentTab) {
|
||||||
store._logger.warn('Cannot update current location for non-existent tab', () => ({ tabId: id }));
|
store._logger.warn(
|
||||||
|
'Cannot update current location for non-existent tab',
|
||||||
|
() => ({ tabId: id }),
|
||||||
|
);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -389,11 +421,14 @@ export const TabService = signalStore(
|
|||||||
currentLocation.current < 0 ||
|
currentLocation.current < 0 ||
|
||||||
currentLocation.current >= currentLocation.locations.length
|
currentLocation.current >= currentLocation.locations.length
|
||||||
) {
|
) {
|
||||||
store._logger.warn('Cannot update current location - invalid index', () => ({
|
store._logger.warn(
|
||||||
tabId: id,
|
'Cannot update current location - invalid index',
|
||||||
currentIndex: currentLocation.current,
|
() => ({
|
||||||
historyLength: currentLocation.locations.length,
|
tabId: id,
|
||||||
}));
|
currentIndex: currentLocation.current,
|
||||||
|
historyLength: currentLocation.locations.length,
|
||||||
|
}),
|
||||||
|
);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user