feat(settings): Features tab + sidebar reorg with feature-flag gating
Reorganises the admin sidebar around what users actually do, and adds a
single Features page that gates which feature surfaces appear in the
nav. Shrinks the main sidebar from 11 items to 4-6 (depending on
feature flags) and groups configuration screens into a single Settings
home with six logical sections.
Why
---
The current sidebar mixes three concerns: workspaces (Dashboard, Events,
Archives), feature surfaces (Analytics, Users), and configuration
screens that get touched maybe once a month (Email Settings, Branding,
Event Types, Backup, CMS Pages). That's 11 items, half of them config.
Backend
-------
- New `feature_flags` table (key, value, updated_at, updated_by).
Migration 088 detects existing-vs-fresh installs from the events
table:
* Existing install (events>0) → all 9 flags TRUE so nothing
vanishes from an admin's UI on upgrade.
* Fresh install (events=0) → spec defaults: galleries,
reminderEmails, analytics, userManagement TRUE; calendar,
calendarBooking, quotes, bills, messaging FALSE.
- New `/api/admin/feature-flags` (GET/PUT) under `settings.view` and
`settings.edit`. Server enforces the same dependency rules the
frontend does (galleries always TRUE, quotes=false → bills=false,
calendar=false → calendarBooking=false). PUT writes one
`feature_flags_updated` activity log row with the diff.
Frontend
--------
- `FeatureFlagsContext` provides `useFeatureFlags()` (with staged/save/
reset/isDirty) and `useFeatureEnabled(key)`. Mounted inside
AdminLayout so flag fetches carry the auth cookie. Source of truth
is the server response; staged is a local copy that the Features tab
edits and the Save button PUTs.
- `RequireFeature` route guard for /admin/analytics and /admin/users —
redirects to /admin/dashboard when the corresponding flag is OFF.
- AdminSidebar dropped from 11 to 6 items. Removed: Email Settings,
Branding, Event Types, Backup, CMS Pages (now Settings tabs).
Feature-gated: Analytics, Users.
- Old top-level routes (/admin/email, /admin/branding, /admin/event-
types, /admin/backup, /admin/cms) kept as <Navigate> redirects to
/admin/settings?tab=<key> so existing bookmarks don't 404.
- SettingsPage rewritten with a 6-group inner-nav (General /
Content & Appearance / Communication / Privacy & Security /
Integrations / System) and 19 tabs. New Features tab is the
default landing tab. URL ?tab=<key> roundtrips with state — deep
links and the back button work.
- FeaturesTab renders 9 cards across 5 sections. Toggles enabled for
Analytics + User Management (the two flags that gate sidebar items
in this PR). All other toggles disabled with a "Not yet available"
lockedReason — the cards still render so admins see the roadmap, but
the flag has no UI effect until the surface ships in its own PR. The
galleries card is locked TRUE per spec (foundation, can't be off).
- Live SidebarPreview reflects unsaved staged changes — admins see
what their sidebar will look like before they save.
- New i18n keys across all 5 locales (en, de, nl, pt, ru) for the
Features tab copy, the new Settings group labels, and the lifted
tab titles.
Verified end-to-end
-------------------
- Migration on this dev DB (existing install, 977 events): all 9 flags
set to TRUE.
- Migration on simulated fresh install (events table emptied): spec
defaults applied (5 OFF, 4 ON).
- Backend round-trip: GET → PUT → audit-log entry written, dependency
rule enforced (bills forced false when quotes=false even when bills=
true requested).
- UI Playwright spec: sidebar dropped 5 items, old top-level routes
redirect, Features tab is default, Galleries+Calendar+Quotes+Bills+
Messaging+ReminderEmails toggles disabled, Analytics+Users toggles
enabled, toggling Analytics off + saving updates the sidebar +
redirects /admin/analytics to /admin/dashboard.
- Smoke 13/13 still green; no regressions on existing flows.
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
import React, { useMemo } from 'react';
|
||||
import clsx from 'clsx';
|
||||
import {
|
||||
LayoutDashboard,
|
||||
Calendar,
|
||||
Archive,
|
||||
BarChart3,
|
||||
Settings,
|
||||
Users,
|
||||
} from 'lucide-react';
|
||||
import type { LucideIcon } from 'lucide-react';
|
||||
import { Card } from '../../../components/common';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import type { FeatureFlags } from '../../../contexts/FeatureFlagsContext';
|
||||
|
||||
interface PreviewItem {
|
||||
key: string;
|
||||
label: string;
|
||||
icon: LucideIcon;
|
||||
featureDriven: boolean;
|
||||
}
|
||||
|
||||
interface SidebarPreviewProps {
|
||||
staged: FeatureFlags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the live shape of the main admin sidebar based on the user's
|
||||
* staged (unsaved) feature flags. Items in green (primary tint) are
|
||||
* controlled by toggles above; greyscale items are unconditional.
|
||||
*/
|
||||
export const SidebarPreview: React.FC<SidebarPreviewProps> = ({ staged }) => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const items = useMemo<PreviewItem[]>(() => {
|
||||
const all: Array<PreviewItem & { gate?: keyof FeatureFlags }> = [
|
||||
{ key: 'dashboard', label: t('navigation.dashboard'), icon: LayoutDashboard, featureDriven: false },
|
||||
{ key: 'events', label: t('navigation.events'), icon: Calendar, featureDriven: false },
|
||||
{ key: 'archives', label: t('navigation.archives'), icon: Archive, featureDriven: false },
|
||||
{ key: 'analytics', label: t('admin.analytics', 'Analytics'), icon: BarChart3, featureDriven: true, gate: 'analytics' },
|
||||
{ key: 'settings', label: t('navigation.settings'), icon: Settings, featureDriven: false },
|
||||
{ key: 'users', label: t('navigation.users'), icon: Users, featureDriven: true, gate: 'userManagement' },
|
||||
];
|
||||
return all.filter((it) => !it.gate || staged[it.gate]);
|
||||
}, [staged, t]);
|
||||
|
||||
return (
|
||||
<Card padding="md">
|
||||
<div className="flex items-center justify-between mb-3">
|
||||
<h3 className="text-sm font-semibold text-neutral-900 dark:text-neutral-100">
|
||||
{t('settings.features.preview.title', 'Sidebar preview')}
|
||||
</h3>
|
||||
<span className="text-xs text-neutral-500 dark:text-neutral-400">
|
||||
{t('settings.features.preview.note', 'Reflects unsaved changes')}
|
||||
</span>
|
||||
</div>
|
||||
<ul className="flex flex-wrap gap-2">
|
||||
{items.map((item) => (
|
||||
<li
|
||||
key={item.key}
|
||||
className={clsx(
|
||||
'inline-flex items-center gap-2 px-2.5 py-1.5 rounded-md text-xs font-medium border',
|
||||
item.featureDriven
|
||||
? 'border-primary-200 bg-primary-50 text-primary-800 dark:border-primary-800 dark:bg-primary-900/30 dark:text-primary-200'
|
||||
: 'border-neutral-200 bg-neutral-50 text-neutral-700 dark:border-neutral-700 dark:bg-neutral-800 dark:text-neutral-300',
|
||||
)}
|
||||
>
|
||||
<item.icon className="w-3.5 h-3.5" />
|
||||
{item.label}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
<p className="mt-3 text-xs text-neutral-500 dark:text-neutral-400">
|
||||
{t(
|
||||
'settings.features.preview.legend',
|
||||
'Green tinted items are controlled by toggles above.',
|
||||
)}
|
||||
</p>
|
||||
</Card>
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user