Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

🐛 fix(sidebar): migrate every former default bottom group (#23739)

AmAzing-dc82da24e5bb
diff --git a/src/store/global/selectors/systemStatus.test.ts b/src/store/global/selectors/systemStatus.test.ts
index a34b6e438c5..aac4d2fc8cb 100644
--- a/src/store/global/selectors/systemStatus.test.ts
+++ b/src/store/global/selectors/systemStatus.test.ts
@@ -15,6 +15,7 @@ import {
reorderSidebarItems,
routeOverlayWrites,
setSidebarSectionHidden,
+ SIDEBAR_ACCORDION_KEYS,
SIDEBAR_SPACER_ID,
systemStatusSelectors,
} from './systemStatus';
@@ -348,14 +349,14 @@ describe('systemStatusSelectors', () => {
'goals',
'project',
'dashboard',
+ 'resource',
+ 'image',
+ 'community',
'favorites',
'recents',
'agent',
'channels',
SIDEBAR_SPACER_ID,
- 'image',
- 'community',
- 'resource',
]);
});
@@ -395,6 +396,52 @@ describe('systemStatusSelectors', () => {
]);
});
+ it.each([
+ ['April', ['pages', 'recents', 'agent', 'community', 'resource', 'memory']],
+ [
+ 'June',
+ [
+ 'tasks',
+ 'pages',
+ 'recents',
+ 'agent',
+ SIDEBAR_SPACER_ID,
+ 'image',
+ 'community',
+ 'resource',
+ 'memory',
+ ],
+ ],
+ [
+ 'August',
+ [
+ 'tasks',
+ 'resource',
+ 'recents',
+ 'private',
+ 'agent',
+ SIDEBAR_SPACER_ID,
+ 'image',
+ 'community',
+ 'pages',
+ 'memory',
+ ],
+ ],
+ ])('should move every link of the former %s default above the sections', (_, stored) => {
+ const items = systemStatusSelectors.sidebarItems(null)(
+ merge(initialState, { status: { sidebarItems: stored } }),
+ );
+ const firstSection = items.findIndex((key) => SIDEBAR_ACCORDION_KEYS.has(key));
+
+ expect(items.slice(items.indexOf(SIDEBAR_SPACER_ID) + 1)).toEqual([]);
+ // They land in default order, below the links that lead the list.
+ expect(items.indexOf('tasks')).toBeLessThan(items.indexOf('resource'));
+ expect(items.indexOf('project')).toBeLessThan(items.indexOf('image'));
+ expect(items.indexOf('resource')).toBeLessThan(items.indexOf('image'));
+ expect(items.indexOf('image')).toBeLessThan(items.indexOf('community'));
+ expect(items.indexOf('community')).toBeLessThan(firstSection);
+ });
+
it('should keep Generation and Plugins pinned at the bottom once saved that way', () => {
// A layout saved after the move no longer lists `memory`.
const stored = ['tasks', 'recents', 'agent', SIDEBAR_SPACER_ID, 'image', 'community'];
@@ -406,12 +453,12 @@ describe('systemStatusSelectors', () => {
});
it('should leave a hand-arranged bottom group in place and only drop Memory', () => {
- const stored = ['recents', 'agent', SIDEBAR_SPACER_ID, 'resource', 'image', 'memory'];
+ const stored = ['recents', 'agent', SIDEBAR_SPACER_ID, 'tasks', 'image', 'memory'];
const items = systemStatusSelectors.sidebarItems(null)(
merge(initialState, { status: { sidebarItems: stored } }),
);
const spacerIdx = items.indexOf(SIDEBAR_SPACER_ID);
- expect(items.slice(spacerIdx + 1)).toEqual(['resource', 'image']);
+ expect(items.slice(spacerIdx + 1)).toEqual(['tasks', 'image']);
expect(items).not.toContain('memory');
});
diff --git a/src/store/global/selectors/systemStatus.ts b/src/store/global/selectors/systemStatus.ts
index f79c7bb95b2..b0215a9b031 100644
--- a/src/store/global/selectors/systemStatus.ts
+++ b/src/store/global/selectors/systemStatus.ts
@@ -315,6 +315,8 @@ export const normalizeLegacyExpandedKeys = (keys: string[]): string[] => {
const FORMER_BOTTOM_LINKS = new Set(['image', 'community']);
/** Memory left the sidebar for Settings; only layouts saved before that still list it. */
const RETIRED_MEMORY_KEY = 'memory';
+/** Everything earlier defaults kept below the spacer, besides Memory. `pages` is retired. */
+const FORMER_DEFAULT_BOTTOM_KEYS = new Set(['community', 'image', 'pages', 'resource']);
const arraysEqual = (a: string[], b: string[]): boolean => {
if (a === b) return true;
@@ -345,22 +347,20 @@ const normalizeSpacerPosition = (order: string[]): string[] => {
return [...withoutSpacer.slice(0, insertAt), SIDEBAR_SPACER_ID, ...withoutSpacer.slice(insertAt)];
};
-// Generation and Plugins moved above the accordion. A layout saved before that
-// still lists `memory`, which no saved layout contains afterwards, so the move
-// runs once per layout and never undoes a later choice to pin them at the bottom.
-// A bottom group holding anything else was arranged by hand and stays.
-const migrateFormerBottomLinks = (order: string[]): string[] => {
+// Generation, Plugins and Docs moved above the accordion. A layout saved before
+// that still lists `memory`, which no saved layout contains afterwards, so the
+// move runs once per layout and never undoes a later choice to keep them below.
+// A bottom group holding anything else was arranged by hand and stays. The links
+// are only dropped here: the backfill puts them back in their default order.
+const dropFormerDefaultBottom = (order: string[]): string[] => {
if (!order.includes(RETIRED_MEMORY_KEY)) return order;
const without = order.filter((k) => k !== RETIRED_MEMORY_KEY);
const spacerIndex = without.indexOf(SIDEBAR_SPACER_ID);
const bottom = without.slice(spacerIndex + 1);
- if (bottom.length === 0 || !bottom.every((k) => FORMER_BOTTOM_LINKS.has(k))) return without;
-
- const top = without.slice(0, spacerIndex + 1);
- const accordionStart = top.findIndex((k) => SIDEBAR_ACCORDION_KEYS.has(k));
- const insertAt = accordionStart === -1 ? spacerIndex : accordionStart;
- return [...top.slice(0, insertAt), ...bottom, ...top.slice(insertAt)];
+ return bottom.length > 0 && bottom.every((k) => FORMER_DEFAULT_BOTTOM_KEYS.has(k))
+ ? without.slice(0, spacerIndex + 1)
+ : without;
};
// Projects used to be an accordion listing every project; it is now a single
@@ -407,10 +407,10 @@ const withChannelsAfterAgent = (order: string[]): string[] => {
const withAllKnownKeys = (order: string[]): string[] => {
const nextOrder = withChannelsAfterAgent(liftProjectOutOfAccordion(order));
- const present = new Set(nextOrder);
+ const withSpacer = dropFormerDefaultBottom(normalizeSpacerPosition(nextOrder));
+ const present = new Set(withSpacer);
const missing = DEFAULT_SIDEBAR_ITEMS.filter((k) => k !== SIDEBAR_SPACER_ID && !present.has(k));
- const withSpacer = migrateFormerBottomLinks(normalizeSpacerPosition(nextOrder));
if (missing.length === 0) return withSpacer;
const spacerIdx = withSpacer.indexOf(SIDEBAR_SPACER_ID);