Skip to content

Commit

Permalink
Fix TS mis-calls on menu.
Browse files Browse the repository at this point in the history
  • Loading branch information
BusterNeece committed Jan 15, 2025
1 parent f3fd75e commit d2abf8d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
1 change: 1 addition & 0 deletions frontend/components/Stations/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export function useStationsMenu(): ReactiveMenu {
// Reuse this variable to avoid multiple calls.
const userCanManageMedia = userAllowedForStation(StationPermission.Media);

// @ts-expect-error This is proper, TS just messes it up
const menu: ReactiveMenu = reactive([
{
key: 'profile',
Expand Down
27 changes: 16 additions & 11 deletions frontend/functions/filterMenu.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,37 @@
import {cloneDeep, filter, get, map} from "lodash";
import {ComputedRef, Reactive} from "vue";
import {ComputedRef, Reactive, toRaw} from "vue";
import {Icon} from "../components/Common/icons";
import {RouteLocationRaw} from "vue-router";
import {RouteLocationAsPathGeneric, RouteLocationAsRelativeGeneric} from "vue-router";
import {reactiveComputed} from "@vueuse/core";

export type ReactiveMenu = Reactive<Array<MenuCategory>>;
export type ReactiveMenu = Reactive<MenuCategory[]>;

interface RouteBasedUrl {
name: string,
params?: Record<string, any>
}

export interface MenuSubCategory {
key: string,
label: ComputedRef<string>,
url?: RouteLocationRaw | string | null,
icon?: Icon | null,
visible?: boolean | null,
external?: boolean | null,
url?: string | RouteBasedUrl,
icon?: Icon,
visible?: boolean,
external?: boolean,
title?: string,
class?: string,
"class"?: string,
}

export interface MenuCategory extends MenuSubCategory {
items?: MenuSubCategory[] | null
items?: MenuSubCategory[]
}

export default function filterMenu(menuItems: ReactiveMenu): ReactiveMenu {
return reactiveComputed(
() => filter(
map(
cloneDeep(menuItems),
(menuRow: MenuCategory): MenuCategory | null => {
cloneDeep(toRaw(menuItems as unknown as MenuCategory[])),
(menuRow): MenuCategory | null => {
const itemIsVisible: boolean = get(menuRow, 'visible', true);
if (!itemIsVisible) {
return null;
Expand Down

0 comments on commit d2abf8d

Please sign in to comment.