Skip to content

Commit 85fd1c4

Browse files
committed
feat: add unique ID to custom actions and update rendering in OverView component
1 parent a7c9380 commit 85fd1c4

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

frontend/src/stores/app.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
ignoredError,
1212
message,
1313
alert,
14+
sampleID,
1415
} from '@/utils'
1516
import {
1617
Download,
@@ -43,6 +44,7 @@ export const useAppStore = defineStore('app', () => {
4344

4445
/* Actions */
4546
interface CustomAction {
47+
id?: string
4648
component: string
4749
componentProps?: Recordable
4850
componentSlots?: Recordable
@@ -57,15 +59,18 @@ export const useAppStore = defineStore('app', () => {
5759
| string
5860
| number
5961
| boolean
60-
const customActions: { [key: string]: CustomAction[] } = {
62+
const customActions = ref<{ [key: string]: CustomAction[] }>({
6163
core_state: [],
62-
}
64+
})
6365
const addCustomActions = (target: string, actions: CustomAction | CustomAction[]) => {
64-
if (!customActions[target]) throw new Error('Target does not exist: ' + target)
66+
if (!customActions.value[target]) throw new Error('Target does not exist: ' + target)
6567
const _actions = Array.isArray(actions) ? actions : [actions]
66-
customActions[target].push(..._actions)
68+
_actions.forEach((action) => (action.id = sampleID()))
69+
customActions.value[target].push(..._actions)
6770
const remove = () => {
68-
customActions[target] = customActions[target].filter((a) => !_actions.includes(a))
71+
customActions.value[target] = customActions.value[target].filter(
72+
(a) => !_actions.some((added) => added.id === a.id),
73+
)
6974
}
7075
return remove
7176
}

frontend/src/views/HomeView/components/OverView.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,8 @@ onUnmounted(() => {
163163
{{ t('home.overview.tunMode') }}
164164
</Switch>
165165
<component
166-
v-for="(action, index) in appStore.customActions.core_state"
167-
:key="index"
166+
v-for="action in appStore.customActions.core_state"
167+
:key="action.id"
168168
:is="action.component"
169169
v-bind="action.componentProps"
170170
class="ml-8"

0 commit comments

Comments
 (0)