Skip to content

Commit ef91691

Browse files
committed
feat(editor): surface unregistered and mysql synced menus
1 parent 10c3d16 commit ef91691

5 files changed

Lines changed: 34 additions & 3 deletions

File tree

resources/js/components/MenuSidebar.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,20 @@ export function MenuSidebar({ menus, activeKey, onOpen, onDelete }: MenuSidebarP
6161
);
6262
}
6363

64+
function describe(menu: MenuDescriptor): string {
65+
const notes = [`${menu.itemCount} entries`];
66+
67+
if (menu.source === 'mysql') {
68+
notes.push('synced from MySQL, edits go to the database');
69+
}
70+
71+
if (!menu.registered) {
72+
notes.push('not listed in settings.yml, the plugin does not load it');
73+
}
74+
75+
return `${menu.fileName} (${notes.join('; ')})`;
76+
}
77+
6478
function MenuRow({
6579
menu,
6680
active,
@@ -77,12 +91,14 @@ function MenuRow({
7791
<button
7892
type="button"
7993
onClick={() => onOpen(menu)}
80-
title={`${menu.fileName} (${menu.itemCount} entries)`}
94+
title={describe(menu)}
8195
className={`flex-1 truncate px-3 py-1 text-left text-sm ${
8296
active ? 'bg-slate-800 text-sky-300' : 'text-slate-300 hover:bg-slate-800/60'
8397
}`}
8498
>
8599
{menu.fileName}
100+
{menu.source === 'mysql' && <span className="ml-1 text-xs text-sky-500">sync</span>}
101+
{!menu.registered && <span className="ml-1 text-xs text-amber-500">unregistered</span>}
86102
</button>
87103
{onDelete !== null && (
88104
<button

resources/js/editor/__tests__/store.test.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,16 @@ import { activeTab, editorReducer, hasUnsavedWork, initialStore, isDirty, type E
33
import type { MenuDescriptor } from '../../types/editor';
44

55
function menu(fileName: string, platform = 'JAVA'): MenuDescriptor {
6-
return { fileName, menuName: fileName, platform, type: 'CHEST', openCommand: '', itemCount: 0 };
6+
return {
7+
fileName,
8+
menuName: fileName,
9+
platform,
10+
type: 'CHEST',
11+
openCommand: '',
12+
itemCount: 0,
13+
registered: true,
14+
source: 'disk',
15+
};
716
}
817

918
function withTabs(...fileNames: string[]): EditorStore {

resources/js/editor/demo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@ export async function fetchDemoMenu(menu: MenuDescriptor): Promise<string> {
3232
}
3333

3434
function descriptor(platform: string, fileName: string, menuName: string, type: string): MenuDescriptor {
35-
return { fileName, menuName, platform, type, openCommand: '', itemCount: 0 };
35+
return { fileName, menuName, platform, type, openCommand: '', itemCount: 0, registered: true, source: 'disk' };
3636
}

resources/js/editor/menus.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ export const SETTINGS_DESCRIPTOR: MenuDescriptor = {
5757
type: 'CONFIG',
5858
openCommand: '',
5959
itemCount: 0,
60+
registered: true,
61+
source: 'disk',
6062
};
6163

6264
/** Stable identity of an open tab. */

resources/js/types/editor.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ export interface MenuDescriptor {
3131
type: string;
3232
openCommand: string;
3333
itemCount: number;
34+
/** False when the file sits in the folder but is not listed in settings.yml, so the plugin never loads it. */
35+
registered: boolean;
36+
/** Where the content lives: a menu synced from MySQL is not edited on disk. */
37+
source: 'disk' | 'mysql';
3438
}
3539

3640
export interface MenuContent {

0 commit comments

Comments
 (0)