Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions src/frontend/shared/nav-rail-panel.story.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<template>
<Story title="Nav rail panel" group="shared">
<Variant title="Admin" :setup-app="loadAdmin">
<div class="min-h-screen bg-gray-50">
<Sidebar />
</div>
</Variant>

<Variant title="Editor" :setup-app="loadEditor">
<div class="min-h-screen bg-gray-50">
<Sidebar />
</div>
</Variant>
</Story>
</template>

<script setup lang="ts">
import Sidebar from './sidebar.vue';
import { adminUser, editorUser, sharedProps } from '../test/mocks';
import { useSharedStore } from '../store';
import type { AppUserInterface } from '../../types';
import type { StoryHandler } from './helpers';

const loadNav = (user: AppUserInterface): StoryHandler => {
return (): void => {
const shared = useSharedStore();
shared.setFromProps({ ...sharedProps, user });
shared.setSidebarOpen(true);
};
};

const loadAdmin = loadNav(adminUser);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice 👏

const loadEditor = loadNav(editorUser);
</script>

<docs lang="md">
# Nav rail panel

Sidebar navigation with role-based visibility.

## Subscription gating

Links controlled by `config.subscriptions` via `subscribed('feature')`: Streams, Stories, Pages, Resources, Invitations, Audience, Interface.

## Admin gating

Requires `isAdmin && subscribed(...)`:

- **Invitations**
- **Settings**

## Admin only

Requires `isAdmin`:

- **Team**

Compare the **Admin** and **Editor** variants: editors see content links but not Invitations, Settings, or Team.
</docs>
2 changes: 1 addition & 1 deletion src/frontend/shared/nav-rail-panel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
>

<a
v-if="subscribed('invitation')"
v-if="isAdmin && subscribed('invitation')"
:class="classList('invitation')"
:href="`/${locale}/invitation`"
>Invitations</a
Expand Down
13 changes: 13 additions & 0 deletions src/frontend/test/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type {
StorySpec,
InvitationItem,
UiConfig,
AppUserInterface,
} from '../../types.ts';
import { StoryHandler } from '../shared/helpers.js';
import { useSharedStore } from '../store/shared.js';
Expand Down Expand Up @@ -444,6 +445,18 @@ export const user = {
isAllowed: (locale: string) => locale === 'en',
};

export const adminUser: AppUserInterface = {
...user,
role: 'admin',
isAdmin: true,
};

export const editorUser: AppUserInterface = {
...user,
role: 'editor',
isAdmin: false,
};

export const stories = ['John', 'Acts'];

export const story: StorySpec = {
Expand Down
Loading