@bevel-software/platform-core-frontend 0.9.1 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/core/CoreAppShell.tsx +4 -0
- package/src/core/__tests__/AppChrome.test.tsx +3 -0
- package/src/modules/update-check/__tests__/UpdateBanner.test.tsx +126 -0
- package/src/modules/update-check/components/UpdateBanner.tsx +92 -0
- package/src/modules/update-check/services/update-check.api.ts +24 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bevel-software/platform-core-frontend",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "Open-source core UI of the Bevel platform (raw TS/TSX source): workspace explorer/viewer, branches & change requests, Library, secrets, tools, access control.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.ts",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"tailwind-merge": "^3.5.0",
|
|
42
42
|
"xlsx": "https://cdn.sheetjs.com/xlsx-0.20.3/xlsx-0.20.3.tgz",
|
|
43
43
|
"yaml": "^2.9.0",
|
|
44
|
-
"@bevel-software/platform-shared": "0.
|
|
44
|
+
"@bevel-software/platform-shared": "0.10.0"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@testing-library/jest-dom": "^6.9.1",
|
|
@@ -36,6 +36,7 @@ import {
|
|
|
36
36
|
import { MaintenanceOverlay } from '../modules/layout/components/MaintenanceOverlay';
|
|
37
37
|
import { AdminProvider } from '../modules/admin/state/admin.context';
|
|
38
38
|
import { RolesCorruptedBanner } from '../modules/admin/components/RolesCorruptedBanner';
|
|
39
|
+
import { UpdateBanner } from '../modules/update-check/components/UpdateBanner';
|
|
39
40
|
import { ConnectToolsPage } from '../modules/secrets-vault/components/ConnectToolsPage';
|
|
40
41
|
import { SettingsLayout } from '../modules/settings/components/SettingsLayout';
|
|
41
42
|
import { DeploymentPage } from '../modules/settings/components/DeploymentPage';
|
|
@@ -171,6 +172,9 @@ function AuthenticatedAppInner() {
|
|
|
171
172
|
const CORE_BANNERS: BannerDef[] = [
|
|
172
173
|
{ id: 'demo', order: 20, node: <DemoBanner /> },
|
|
173
174
|
{ id: 'roles-corrupted', order: 30, node: <RolesCorruptedBanner /> },
|
|
175
|
+
// Admins-only "a newer release exists" line — quiet, dismissible per
|
|
176
|
+
// version, below the louder condition banners above.
|
|
177
|
+
{ id: 'update-available', order: 35, node: <UpdateBanner /> },
|
|
174
178
|
];
|
|
175
179
|
|
|
176
180
|
// Core panes; merged (by `order`) with registry-contributed panes (the
|
|
@@ -19,6 +19,9 @@ vi.mock('../../modules/layout/components/DemoBanner', () => ({
|
|
|
19
19
|
vi.mock('../../modules/admin/components/RolesCorruptedBanner', () => ({
|
|
20
20
|
RolesCorruptedBanner: () => null,
|
|
21
21
|
}));
|
|
22
|
+
vi.mock('../../modules/update-check/components/UpdateBanner', () => ({
|
|
23
|
+
UpdateBanner: () => null,
|
|
24
|
+
}));
|
|
22
25
|
|
|
23
26
|
/**
|
|
24
27
|
* A stand-in app surface carrying the two gestures these tests need — the
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
+
import { render, screen, waitFor } from '@testing-library/react';
|
|
3
|
+
import userEvent from '@testing-library/user-event';
|
|
4
|
+
import { UpdateBanner } from '../components/UpdateBanner';
|
|
5
|
+
import { AdminContext, type AdminContextValue } from '../../admin/state/admin.context';
|
|
6
|
+
import { fetchUpdateCheck } from '../services/update-check.api';
|
|
7
|
+
|
|
8
|
+
vi.mock('../services/update-check.api', () => ({
|
|
9
|
+
fetchUpdateCheck: vi.fn(),
|
|
10
|
+
}));
|
|
11
|
+
|
|
12
|
+
// The banner keys its dismissal per signed-in account; the tests sign in a
|
|
13
|
+
// fixed admin (mixed-case, to pin the lowercased storage key).
|
|
14
|
+
vi.mock('../../auth/state/auth.context', () => ({
|
|
15
|
+
useAuth: () => ({ user: { email: 'Admin@Example.com' } }),
|
|
16
|
+
}));
|
|
17
|
+
|
|
18
|
+
const fetchUpdateCheckMock = vi.mocked(fetchUpdateCheck);
|
|
19
|
+
const DISMISSED_KEY = 'bevel.updateBanner.dismissedVersion.admin@example.com';
|
|
20
|
+
|
|
21
|
+
function adminContext(overrides: Partial<AdminContextValue> = {}): AdminContextValue {
|
|
22
|
+
return {
|
|
23
|
+
isAdmin: true,
|
|
24
|
+
isAdminLoading: false,
|
|
25
|
+
unreadCount: 0,
|
|
26
|
+
lastSeen: null,
|
|
27
|
+
markSeen: () => {},
|
|
28
|
+
refresh: () => {},
|
|
29
|
+
rolesConfigCorrupted: false,
|
|
30
|
+
rolesConfigErrors: [],
|
|
31
|
+
runRolesRecovery: async () => {},
|
|
32
|
+
...overrides,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function renderBanner(ctx: AdminContextValue) {
|
|
37
|
+
return render(
|
|
38
|
+
<AdminContext.Provider value={ctx}>
|
|
39
|
+
<UpdateBanner />
|
|
40
|
+
</AdminContext.Provider>,
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
beforeEach(() => {
|
|
45
|
+
fetchUpdateCheckMock.mockReset();
|
|
46
|
+
// test-setup clears localStorage between tests already.
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
describe('UpdateBanner', () => {
|
|
50
|
+
it('shows the quiet line with the release-notes link for an admin', async () => {
|
|
51
|
+
fetchUpdateCheckMock.mockResolvedValue({
|
|
52
|
+
updateAvailable: true,
|
|
53
|
+
current: '0.9.1',
|
|
54
|
+
latest: '0.10.0',
|
|
55
|
+
notesUrl: 'https://github.com/Bevel-Software/Hexis/releases/tag/v0.10.0',
|
|
56
|
+
});
|
|
57
|
+
renderBanner(adminContext());
|
|
58
|
+
await waitFor(() =>
|
|
59
|
+
expect(screen.getByText(/Hexis 0\.10\.0 is available/)).toBeInTheDocument(),
|
|
60
|
+
);
|
|
61
|
+
const link = screen.getByRole('link', { name: /see what's new/ });
|
|
62
|
+
expect(link).toHaveAttribute(
|
|
63
|
+
'href',
|
|
64
|
+
'https://github.com/Bevel-Software/Hexis/releases/tag/v0.10.0',
|
|
65
|
+
);
|
|
66
|
+
expect(link).toHaveAttribute('target', '_blank');
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('dismiss hides it, and the dismissal sticks per VERSION across mounts', async () => {
|
|
70
|
+
fetchUpdateCheckMock.mockResolvedValue({
|
|
71
|
+
updateAvailable: true,
|
|
72
|
+
current: '0.9.1',
|
|
73
|
+
latest: '0.10.0',
|
|
74
|
+
notesUrl: 'https://example.invalid/notes',
|
|
75
|
+
});
|
|
76
|
+
const { unmount } = renderBanner(adminContext());
|
|
77
|
+
await waitFor(() => expect(screen.getByRole('status')).toBeInTheDocument());
|
|
78
|
+
|
|
79
|
+
await userEvent.click(screen.getByRole('button', { name: 'Dismiss' }));
|
|
80
|
+
expect(screen.queryByRole('status')).not.toBeInTheDocument();
|
|
81
|
+
// Persisted under the ACCOUNT's key (lowercased): on a shared machine one
|
|
82
|
+
// admin's dismissal must not hide the line from the next admin.
|
|
83
|
+
expect(localStorage.getItem(DISMISSED_KEY)).toBe('0.10.0');
|
|
84
|
+
|
|
85
|
+
// A fresh mount (a reload) with the SAME version stays dismissed…
|
|
86
|
+
unmount();
|
|
87
|
+
renderBanner(adminContext());
|
|
88
|
+
await waitFor(() => expect(fetchUpdateCheckMock).toHaveBeenCalledTimes(2));
|
|
89
|
+
expect(screen.queryByRole('status')).not.toBeInTheDocument();
|
|
90
|
+
|
|
91
|
+
// …and a NEWER release resurfaces the banner.
|
|
92
|
+
fetchUpdateCheckMock.mockResolvedValue({
|
|
93
|
+
updateAvailable: true,
|
|
94
|
+
current: '0.9.1',
|
|
95
|
+
latest: '0.10.1',
|
|
96
|
+
notesUrl: 'https://example.invalid/notes',
|
|
97
|
+
});
|
|
98
|
+
renderBanner(adminContext());
|
|
99
|
+
await waitFor(() =>
|
|
100
|
+
expect(screen.getByText(/Hexis 0\.10\.1 is available/)).toBeInTheDocument(),
|
|
101
|
+
);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it('non-admins never fetch and never render', async () => {
|
|
105
|
+
renderBanner(adminContext({ isAdmin: false }));
|
|
106
|
+
// Give any stray effect a tick to fire before asserting it did not.
|
|
107
|
+
await Promise.resolve();
|
|
108
|
+
expect(fetchUpdateCheckMock).not.toHaveBeenCalled();
|
|
109
|
+
expect(screen.queryByRole('status')).not.toBeInTheDocument();
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it('waits out the admin verdict rather than fetching for everyone', async () => {
|
|
113
|
+
// isAdmin TRUE while still loading: only the loading guard can stop this
|
|
114
|
+
// fetch, so the test fails if that guard is ever removed.
|
|
115
|
+
renderBanner(adminContext({ isAdmin: true, isAdminLoading: true }));
|
|
116
|
+
await Promise.resolve();
|
|
117
|
+
expect(fetchUpdateCheckMock).not.toHaveBeenCalled();
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it('renders nothing while up to date', async () => {
|
|
121
|
+
fetchUpdateCheckMock.mockResolvedValue({ updateAvailable: false, current: '0.9.1' });
|
|
122
|
+
renderBanner(adminContext());
|
|
123
|
+
await waitFor(() => expect(fetchUpdateCheckMock).toHaveBeenCalled());
|
|
124
|
+
expect(screen.queryByRole('status')).not.toBeInTheDocument();
|
|
125
|
+
});
|
|
126
|
+
});
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
import { Sparkles, X } from 'lucide-react';
|
|
3
|
+
import { useAdmin } from '../../admin/state/admin.context';
|
|
4
|
+
import { useAuth } from '../../auth/state/auth.context';
|
|
5
|
+
import { fetchUpdateCheck, type UpdateCheckResult } from '../services/update-check.api';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The one quiet line admins see when a newer release is published:
|
|
9
|
+
* "Hexis 0.10.0 is available — see what's new". ADMINS ONLY — they are the
|
|
10
|
+
* people who can act on it, and nobody else fetches or renders anything.
|
|
11
|
+
*
|
|
12
|
+
* Checked ONCE per app load (no polling — the server caches the answer for
|
|
13
|
+
* hours anyway). Dismissing remembers the dismissed VERSION, so 0.10.0 stays
|
|
14
|
+
* dismissed until 0.10.1 appears — PER ACCOUNT, like the rest of the
|
|
15
|
+
* persisted admin state: on a shared machine one admin's dismissal must not
|
|
16
|
+
* hide the line from the next admin who signs in.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
function dismissedKey(email: string | null): string {
|
|
20
|
+
return `bevel.updateBanner.dismissedVersion.${(email ?? 'anonymous').toLowerCase()}`;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function UpdateBanner() {
|
|
24
|
+
const { isAdmin, isAdminLoading } = useAdmin();
|
|
25
|
+
const { user } = useAuth();
|
|
26
|
+
const storageKey = dismissedKey(user?.email ?? null);
|
|
27
|
+
const [info, setInfo] = useState<UpdateCheckResult | null>(null);
|
|
28
|
+
// Read at RENDER time, not captured in state: the signed-in email (and with
|
|
29
|
+
// it the storage key) can resolve after the first render, and a captured
|
|
30
|
+
// initial read would keep consulting the anonymous key. A state tick just
|
|
31
|
+
// forces the re-render after a dismissal writes.
|
|
32
|
+
const [, setDismissTick] = useState(0);
|
|
33
|
+
const dismissedVersion = localStorage.getItem(storageKey);
|
|
34
|
+
|
|
35
|
+
// Fires once, when the admin verdict settles positive. Non-admins never
|
|
36
|
+
// reach the fetch — the endpoint would 403 them anyway, and a guaranteed
|
|
37
|
+
// 403 per page load is console noise nobody needs.
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
if (isAdminLoading || !isAdmin) return;
|
|
40
|
+
let cancelled = false;
|
|
41
|
+
fetchUpdateCheck().then((result) => {
|
|
42
|
+
if (!cancelled) setInfo(result);
|
|
43
|
+
});
|
|
44
|
+
return () => {
|
|
45
|
+
cancelled = true;
|
|
46
|
+
};
|
|
47
|
+
}, [isAdmin, isAdminLoading]);
|
|
48
|
+
|
|
49
|
+
if (!isAdmin || !info?.updateAvailable || !info.latest) return null;
|
|
50
|
+
const latest = info.latest;
|
|
51
|
+
if (dismissedVersion === latest) return null;
|
|
52
|
+
|
|
53
|
+
const dismiss = () => {
|
|
54
|
+
localStorage.setItem(storageKey, latest);
|
|
55
|
+
setDismissTick((t) => t + 1);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
// A calm neutral, deliberately quieter than the demo/danger banners: an
|
|
59
|
+
// available update is information, not a condition.
|
|
60
|
+
return (
|
|
61
|
+
<div
|
|
62
|
+
role="status"
|
|
63
|
+
className="flex items-center gap-2 px-4 py-2 bg-sunken border-b border-line text-sm text-ink shrink-0"
|
|
64
|
+
>
|
|
65
|
+
<Sparkles size={16} className="shrink-0 text-ink-muted" />
|
|
66
|
+
<span className="flex-1">
|
|
67
|
+
Hexis {latest} is available
|
|
68
|
+
{info.notesUrl && (
|
|
69
|
+
<>
|
|
70
|
+
{' — '}
|
|
71
|
+
<a
|
|
72
|
+
href={info.notesUrl}
|
|
73
|
+
target="_blank"
|
|
74
|
+
rel="noreferrer"
|
|
75
|
+
className="text-accent hover:underline"
|
|
76
|
+
>
|
|
77
|
+
see what's new
|
|
78
|
+
</a>
|
|
79
|
+
</>
|
|
80
|
+
)}
|
|
81
|
+
</span>
|
|
82
|
+
<button
|
|
83
|
+
type="button"
|
|
84
|
+
onClick={dismiss}
|
|
85
|
+
aria-label="Dismiss"
|
|
86
|
+
className="shrink-0 p-1 rounded-sm text-ink-muted hover:text-ink hover:bg-hover"
|
|
87
|
+
>
|
|
88
|
+
<X size={14} />
|
|
89
|
+
</button>
|
|
90
|
+
</div>
|
|
91
|
+
);
|
|
92
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { authFetch } from '../../../lib/api';
|
|
2
|
+
|
|
3
|
+
/** Mirrors the backend shape in `update-check.service.ts`. */
|
|
4
|
+
export interface UpdateCheckResult {
|
|
5
|
+
updateAvailable: boolean;
|
|
6
|
+
current: string;
|
|
7
|
+
latest?: string;
|
|
8
|
+
notesUrl?: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Ask the server whether a newer release exists. Every failure — network,
|
|
13
|
+
* 403, a disabled check — is "no update": the banner is a courtesy, and a
|
|
14
|
+
* courtesy never renders an error state.
|
|
15
|
+
*/
|
|
16
|
+
export async function fetchUpdateCheck(): Promise<UpdateCheckResult> {
|
|
17
|
+
try {
|
|
18
|
+
const res = await authFetch('/api/update-check');
|
|
19
|
+
if (!res.ok) return { updateAvailable: false, current: '' };
|
|
20
|
+
return (await res.json()) as UpdateCheckResult;
|
|
21
|
+
} catch {
|
|
22
|
+
return { updateAvailable: false, current: '' };
|
|
23
|
+
}
|
|
24
|
+
}
|