Skip to content

Commit 3caeb32

Browse files
convert panel view menu components to composition API + ts
1 parent 0a88098 commit 3caeb32

2 files changed

Lines changed: 100 additions & 124 deletions

File tree

client/src/components/Panels/Menus/PanelViewMenu.vue

Lines changed: 67 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,66 @@
1+
<script setup lang="ts">
2+
import { BDropdown, BDropdownDivider, BDropdownGroup } from "bootstrap-vue";
3+
import { computed } from "vue";
4+
5+
import type { Panel } from "@/stores/toolStore";
6+
7+
import PanelViewMenuItem from "./PanelViewMenuItem.vue";
8+
9+
const groupsDefinitions = [
10+
{ type: "ontology", title: "...by Ontology" },
11+
{ type: "activity", title: "...for Activity" },
12+
{ type: "publication", title: "...from Publication" },
13+
{ type: "training", title: "...for Training" },
14+
];
15+
16+
const props = defineProps<{
17+
panelViews: Record<string, Panel>;
18+
currentPanelView: string;
19+
storeLoading: boolean;
20+
}>();
21+
22+
const emit = defineEmits<{
23+
(e: "updatePanelView", panelViewId: string): void;
24+
}>();
25+
26+
const defaultPanelView = computed(() => props.panelViews["default"] || Object.values(props.panelViews)[0]);
27+
28+
const groupedPanelViews = computed(() => {
29+
const groups = [];
30+
for (const group of groupsDefinitions) {
31+
const viewType = group.type;
32+
const panelViews = panelViewsOfType(viewType);
33+
if (panelViews.length > 0) {
34+
groups.push({
35+
type: viewType,
36+
title: group.title,
37+
panelViews: panelViews,
38+
});
39+
}
40+
}
41+
return groups;
42+
});
43+
44+
const ungroupedPanelViews = computed(() => panelViewsOfType("generic"));
45+
46+
function panelViewsOfType(panelViewType: string) {
47+
const panelViews = [];
48+
for (const panelViewId in props.panelViews) {
49+
const panelView = props.panelViews[panelViewId];
50+
if (panelView?.view_type === panelViewType) {
51+
panelViews.push(panelView);
52+
}
53+
}
54+
return panelViews;
55+
}
56+
57+
function updatePanelView(panelView: Panel) {
58+
emit("updatePanelView", panelView.id);
59+
}
60+
</script>
61+
162
<template>
2-
<b-dropdown
63+
<BDropdown
364
v-b-tooltip.hover.top.noninteractive
465
right
566
block
@@ -16,10 +77,11 @@
1677
<slot name="panel-view-selector"></slot><span class="sr-only">View all tool panel configurations</span>
1778
</template>
1879
<PanelViewMenuItem
80+
v-if="defaultPanelView"
1981
:current-panel-view="currentPanelView"
2082
:panel-view="defaultPanelView"
2183
@onSelect="updatePanelView" />
22-
<b-dropdown-group v-for="group in groupedPanelViews" :id="group.type" :key="group.type">
84+
<BDropdownGroup v-for="group in groupedPanelViews" :id="group.type" :key="group.type">
2385
<template v-slot:header>
2486
<small class="font-weight-bold">{{ group.title }}</small>
2587
</template>
@@ -29,82 +91,17 @@
2991
:current-panel-view="currentPanelView"
3092
:panel-view="panelView"
3193
@onSelect="updatePanelView" />
32-
</b-dropdown-group>
33-
<b-dropdown-divider v-if="ungroupedPanelViews.length > 0" />
94+
</BDropdownGroup>
95+
<BDropdownDivider v-if="ungroupedPanelViews.length > 0" />
3496
<PanelViewMenuItem
3597
v-for="(panelView, key) in ungroupedPanelViews"
3698
:key="key"
3799
:current-panel-view="currentPanelView"
38100
:panel-view="panelView"
39101
@onSelect="updatePanelView" />
40-
</b-dropdown>
102+
</BDropdown>
41103
</template>
42104

43-
<script>
44-
import PanelViewMenuItem from "./PanelViewMenuItem";
45-
46-
const groupsDefinitions = [
47-
{ type: "ontology", title: "...by Ontology" },
48-
{ type: "activity", title: "...for Activity" },
49-
{ type: "publication", title: "...from Publication" },
50-
{ type: "training", title: "...for Training" },
51-
];
52-
53-
export default {
54-
components: { PanelViewMenuItem },
55-
props: {
56-
panelViews: {
57-
type: Object,
58-
},
59-
currentPanelView: {
60-
type: String,
61-
},
62-
storeLoading: {
63-
type: Boolean,
64-
default: false,
65-
},
66-
},
67-
computed: {
68-
defaultPanelView() {
69-
return this.panelViewsOfType("default")[0];
70-
},
71-
groupedPanelViews() {
72-
const groups = [];
73-
for (const group of groupsDefinitions) {
74-
const viewType = group.type;
75-
const panelViews = this.panelViewsOfType(viewType);
76-
if (panelViews.length > 0) {
77-
groups.push({
78-
type: viewType,
79-
title: group.title,
80-
panelViews: panelViews,
81-
});
82-
}
83-
}
84-
return groups;
85-
},
86-
ungroupedPanelViews() {
87-
return this.panelViewsOfType("generic");
88-
},
89-
},
90-
methods: {
91-
updatePanelView(panelView) {
92-
this.$emit("updatePanelView", panelView.id);
93-
},
94-
panelViewsOfType(panelViewType) {
95-
const panelViews = [];
96-
for (const panelViewId in this.panelViews) {
97-
const panelView = this.panelViews[panelViewId];
98-
if (panelView.view_type == panelViewType) {
99-
panelViews.push(panelView);
100-
}
101-
}
102-
return panelViews;
103-
},
104-
},
105-
};
106-
</script>
107-
108105
<style lang="scss">
109106
.tool-panel-dropdown .dropdown-menu {
110107
overflow: auto;
Lines changed: 33 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,40 @@
1-
<template>
2-
<BDropdownItem class="ml-1" :title="title" :data-panel-id="panelView.id" :active="isSelected" @click="onClick">
3-
<FontAwesomeIcon :icon="icon" data-description="panel view item icon" fixed-width />
4-
<span v-localize>{{ name }}</span>
5-
</BDropdownItem>
6-
</template>
7-
8-
<script>
1+
<script setup lang="ts">
92
import { faCheck, faEye } from "@fortawesome/free-solid-svg-icons";
103
import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";
114
import { BDropdownItem } from "bootstrap-vue";
5+
import { computed } from "vue";
6+
7+
import type { Panel } from "@/stores/toolStore";
128
139
import { types_to_icons } from "../utilities";
1410
15-
export default {
16-
components: {
17-
BDropdownItem,
18-
FontAwesomeIcon,
19-
},
20-
props: {
21-
currentPanelView: {
22-
type: String,
23-
required: true,
24-
},
25-
panelView: {
26-
type: Object,
27-
required: true,
28-
},
29-
},
30-
data() {
31-
return {
32-
faCheck,
33-
faEye,
34-
};
35-
},
36-
computed: {
37-
title() {
38-
return this.panelView.description;
39-
},
40-
icon() {
41-
const viewType = this.panelView.view_type;
42-
if (this.isSelected) {
43-
return this.faCheck;
44-
} else {
45-
return types_to_icons[viewType] || this.faEye;
46-
}
47-
},
48-
isSelected() {
49-
return this.currentPanelView == this.panelView.id;
50-
},
51-
name() {
52-
return this.panelView.name;
53-
},
54-
},
55-
methods: {
56-
onClick() {
57-
this.$emit("onSelect", this.panelView);
58-
},
59-
},
60-
};
11+
const props = defineProps<{
12+
currentPanelView: string;
13+
panelView: Panel;
14+
}>();
15+
16+
const emit = defineEmits<{
17+
(e: "onSelect", panelView: Panel): void;
18+
}>();
19+
20+
const icon = computed(() => {
21+
const viewType = props.panelView.view_type;
22+
if (props.currentPanelView === props.panelView.id) {
23+
return faCheck;
24+
} else {
25+
return types_to_icons[viewType] || faEye;
26+
}
27+
});
6128
</script>
29+
30+
<template>
31+
<BDropdownItem
32+
class="ml-1"
33+
:title="props.panelView.description"
34+
:data-panel-id="panelView.id"
35+
:active="props.currentPanelView === props.panelView.id"
36+
@click="emit('onSelect', props.panelView)">
37+
<FontAwesomeIcon :icon="icon" data-description="panel view item icon" fixed-width />
38+
<span v-localize>{{ props.panelView.name }}</span>
39+
</BDropdownItem>
40+
</template>

0 commit comments

Comments
 (0)