[core] added computation in EssentialExpansionLink

fixes #9
This commit is contained in:
groegert 2021-05-27 12:35:25 +02:00
parent 22f47bd34e
commit c38032085f
1 changed files with 8 additions and 13 deletions

View File

@ -1,11 +1,7 @@
yarn run v1.22.10
$ /mnt/data/home/thomas/devel/flaschengeist/flaschengeist-frontend/node_modules/.bin/prettier src/components/navigation/EssentialExpansionLink.vue
<template> <template>
<q-expansion-item <q-expansion-item v-if="isGranted(entry)" clickable :label="getTitle(entry)" :icon="entry.icon" expand-separator>
v-if="isGranted(entry)"
clickable
:label="getTitle(entry)"
:icon="entry.icon"
expand-separator
>
<q-list class="q-ml-lg"> <q-list class="q-ml-lg">
<div v-for="child in entry.children" :key="child.link"> <div v-for="child in entry.children" :key="child.link">
<q-item v-if="isGranted(child)" clickable :to="{ name: child.link }"> <q-item v-if="isGranted(child)" clickable :to="{ name: child.link }">
@ -27,9 +23,9 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import { defineComponent, PropType } from 'vue'; import { computed, defineComponent, PropType } from 'vue';
import { hasPermissions } from '@flaschengeist/api';
import { FG_Plugin } from '@flaschengeist/types'; import { FG_Plugin } from '@flaschengeist/types';
import { useMainStore } from 'app/api';
export default defineComponent({ export default defineComponent({
name: 'EssentialExpansionLink', name: 'EssentialExpansionLink',
@ -44,13 +40,11 @@ export default defineComponent({
addShortCut: (val: FG_Plugin.MenuLink) => val.link, addShortCut: (val: FG_Plugin.MenuLink) => val.link,
}, },
setup(props, { emit }) { setup(props, { emit }) {
const store = useMainStore();
function isGranted(val: FG_Plugin.MenuLink) { function isGranted(val: FG_Plugin.MenuLink) {
return !val.permissions || val.permissions.every((p) => store.permissions.includes(p)); return computed(() => hasPermissions(val.permissions || []));
} }
function getTitle(entry: FG_Plugin.MenuLink) { function getTitle(entry: FG_Plugin.MenuLink) {
return typeof entry.title === 'function' ? entry.title() : entry.title; return computed(() => (typeof entry.title === 'function' ? entry.title() : entry.title)).value;
} }
function addShortCut(val: FG_Plugin.MenuLink) { function addShortCut(val: FG_Plugin.MenuLink) {
@ -61,3 +55,4 @@ export default defineComponent({
}, },
}); });
</script> </script>
Done in 0.67s.