fix(plugins): show a trip page that replaces a core tab while that tab's addon is off

A trip-page plugin that replaces Lists, Costs, Documents or Collab is a stand-in
for the core tab, so its own tab stays on the trip whatever that addon is set to.
This commit is contained in:
Maurice
2026-11-23 14:53:34 +01:00
parent 9d4e52ddfc
commit fd10ce2876
4 changed files with 6 additions and 43 deletions
+2 -16
View File
@@ -1,7 +1,7 @@
// FE-UTIL-TRIPADDONS-001 to FE-UTIL-TRIPADDONS-003
// FE-UTIL-TRIPADDONS-001 to FE-UTIL-TRIPADDONS-002
import type { TripAddon } from '@trek/shared';
import { describe, expect, it } from 'vitest';
import { pluginPageShown, tripAddonEnabled } from './tripAddons';
import { tripAddonEnabled } from './tripAddons';
const addon = (id: string, enabled: boolean): TripAddon => ({
id,
@@ -25,17 +25,3 @@ describe('tripAddonEnabled', () => {
expect(tripAddonEnabled([], 'packing', false)).toBe(false);
});
});
describe('pluginPageShown', () => {
it('FE-UTIL-TRIPADDONS-003: a page that replaces core tabs shows while one of their addons is on', () => {
const on = (ids: string[]) => (id: string) => ids.includes(id);
expect(pluginPageShown(undefined, on([]))).toBe(true);
expect(pluginPageShown([], on([]))).toBe(true);
expect(pluginPageShown(['finanzplan'], on(['budget']))).toBe(true);
expect(pluginPageShown(['finanzplan'], on(['packing']))).toBe(false);
expect(pluginPageShown(['finanzplan', 'listen'], on(['packing']))).toBe(true);
expect(pluginPageShown(['dateien', 'collab'], on([]))).toBe(false);
// A tab no addon owns does not hide the page.
expect(pluginPageShown(['plan'], on([]))).toBe(true);
});
});
-22
View File
@@ -17,25 +17,3 @@ export function tripAddonEnabled(
const own = tripAddons?.find((addon) => addon.id === addonId);
return own ? own.enabled : instanceEnabled;
}
/** The trip addon a core trip tab belongs to; a plugin page that replaces the tab follows it. */
const TRIP_TAB_ADDON: Readonly<Record<string, string>> = {
listen: 'packing',
finanzplan: 'budget',
dateien: 'documents',
collab: 'collab',
};
/**
* Whether a plugin's trip page shows on a trip. A page that replaces core tabs
* stands in for them, so it shows while the addon of at least one of those tabs
* is on for the trip; a page that replaces none (or only tabs no addon owns)
* always shows.
*/
export function pluginPageShown(
replaces: readonly string[] | undefined,
addonOn: (addonId: string) => boolean
): boolean {
const owned = (replaces ?? []).flatMap((tab) => (TRIP_TAB_ADDON[tab] ? [TRIP_TAB_ADDON[tab]] : []));
return owned.length === 0 || owned.some(addonOn);
}