From faaf9481a2a872fc68644bd7751661eefa4098d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C5=A1per=20Grom?= Date: Sun, 27 Sep 2026 13:29:55 +0100 Subject: [PATCH] refactor: convert the admin insights-projects and collections stores to setup stores (CM-1571) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refs linuxfoundation/lfx-cdp-insights-ops#271 Signed-off-by: Gašper Grom --- .../modules/collections/pinia/actions.ts | 14 ------ .../collections/pinia/collections.store.ts | 29 ++++++++++++ .../admin/modules/collections/pinia/index.ts | 12 +---- .../admin/modules/collections/pinia/state.ts | 11 ----- .../insights-projects/pinia/actions.ts | 35 -------------- .../modules/insights-projects/pinia/index.ts | 12 +---- .../pinia/insights-projects.store.ts | 47 +++++++++++++++++++ .../modules/insights-projects/pinia/state.ts | 11 ----- 8 files changed, 78 insertions(+), 93 deletions(-) delete mode 100644 frontend/src/modules/admin/modules/collections/pinia/actions.ts create mode 100644 frontend/src/modules/admin/modules/collections/pinia/collections.store.ts delete mode 100644 frontend/src/modules/admin/modules/collections/pinia/state.ts delete mode 100644 frontend/src/modules/admin/modules/insights-projects/pinia/actions.ts create mode 100644 frontend/src/modules/admin/modules/insights-projects/pinia/insights-projects.store.ts delete mode 100644 frontend/src/modules/admin/modules/insights-projects/pinia/state.ts diff --git a/frontend/src/modules/admin/modules/collections/pinia/actions.ts b/frontend/src/modules/admin/modules/collections/pinia/actions.ts deleted file mode 100644 index 823a48bbab..0000000000 --- a/frontend/src/modules/admin/modules/collections/pinia/actions.ts +++ /dev/null @@ -1,14 +0,0 @@ -import type { CollectionModel } from '../models/collection.model'; -import type { CollectionsState } from './state'; - -export default { - setCollections(this: CollectionsState, collections: CollectionModel[]) { - this.collections = collections; - }, - getCollection(this: CollectionsState, id: string) { - return this.collections.find((c) => c.id === id); - }, - getCollections(this: CollectionsState) { - return this.collections; - }, -}; diff --git a/frontend/src/modules/admin/modules/collections/pinia/collections.store.ts b/frontend/src/modules/admin/modules/collections/pinia/collections.store.ts new file mode 100644 index 0000000000..a922387110 --- /dev/null +++ b/frontend/src/modules/admin/modules/collections/pinia/collections.store.ts @@ -0,0 +1,29 @@ +// Copyright (c) 2026 The Linux Foundation and each contributor. +// SPDX-License-Identifier: MIT + +import { defineStore } from 'pinia'; +import { ref } from 'vue'; +import type { CollectionModel } from '../models/collection.model'; + +export const useCollectionsStore = defineStore('collections-store', () => { + const collections = ref([]); + + function setCollections(value: CollectionModel[]) { + collections.value = value; + } + + function getCollection(id: string) { + return collections.value.find((c) => c.id === id); + } + + function getCollections() { + return collections.value; + } + + return { + collections, + setCollections, + getCollection, + getCollections, + }; +}); diff --git a/frontend/src/modules/admin/modules/collections/pinia/index.ts b/frontend/src/modules/admin/modules/collections/pinia/index.ts index 7e08a211ea..4c5d2da3b5 100644 --- a/frontend/src/modules/admin/modules/collections/pinia/index.ts +++ b/frontend/src/modules/admin/modules/collections/pinia/index.ts @@ -1,11 +1 @@ -import { defineStore } from 'pinia'; -import state from './state'; -import actions from './actions'; - -export const useCollectionsStore = defineStore( - 'collections-store', - { - state, - actions, - }, -); +export * from './collections.store'; diff --git a/frontend/src/modules/admin/modules/collections/pinia/state.ts b/frontend/src/modules/admin/modules/collections/pinia/state.ts deleted file mode 100644 index c399959460..0000000000 --- a/frontend/src/modules/admin/modules/collections/pinia/state.ts +++ /dev/null @@ -1,11 +0,0 @@ -import type { CollectionModel } from '../models/collection.model'; - -export interface CollectionsState { - collections: CollectionModel[]; -} - -const state: CollectionsState = { - collections: [], -}; - -export default () => state; diff --git a/frontend/src/modules/admin/modules/insights-projects/pinia/actions.ts b/frontend/src/modules/admin/modules/insights-projects/pinia/actions.ts deleted file mode 100644 index e3d8bc334c..0000000000 --- a/frontend/src/modules/admin/modules/insights-projects/pinia/actions.ts +++ /dev/null @@ -1,35 +0,0 @@ -import type { InsightsProjectModel } from '../models/insights-project.model'; -import type { InsightsProjectsState } from './state'; - -export default { - setInsightsProjects( - this: InsightsProjectsState, - insightsProjects: InsightsProjectModel[], - ) { - this.insightsProjects = insightsProjects; - }, - getInsightsProject(this: InsightsProjectsState, id: string) { - return this.insightsProjects.find((c) => c.id === id); - }, - getInsightsProjects(this: InsightsProjectsState) { - return this.insightsProjects; - }, - updateInsightsProject( - this: InsightsProjectsState, - project: InsightsProjectModel, - ) { - const index = this.insightsProjects.findIndex((c) => c.id === project.id); - if (index !== -1) { - this.insightsProjects[index] = project; - } - }, - createInsightsProject( - this: InsightsProjectsState, - project: InsightsProjectModel, - ) { - this.insightsProjects.push(project); - }, - searchInsightsProjects(this: InsightsProjectsState, query: string) { - return this.insightsProjects.filter((c) => c.name.toLowerCase().includes(query.toLowerCase())); - }, -}; diff --git a/frontend/src/modules/admin/modules/insights-projects/pinia/index.ts b/frontend/src/modules/admin/modules/insights-projects/pinia/index.ts index d7e757ceb1..14beefc00b 100644 --- a/frontend/src/modules/admin/modules/insights-projects/pinia/index.ts +++ b/frontend/src/modules/admin/modules/insights-projects/pinia/index.ts @@ -1,11 +1 @@ -import { defineStore } from 'pinia'; -import state from './state'; -import actions from './actions'; - -export const useInsightsProjectsStore = defineStore( - 'insights-projects-store', - { - state, - actions, - }, -); +export * from './insights-projects.store'; diff --git a/frontend/src/modules/admin/modules/insights-projects/pinia/insights-projects.store.ts b/frontend/src/modules/admin/modules/insights-projects/pinia/insights-projects.store.ts new file mode 100644 index 0000000000..ca45bcbf04 --- /dev/null +++ b/frontend/src/modules/admin/modules/insights-projects/pinia/insights-projects.store.ts @@ -0,0 +1,47 @@ +// Copyright (c) 2026 The Linux Foundation and each contributor. +// SPDX-License-Identifier: MIT + +import { defineStore } from 'pinia'; +import { ref } from 'vue'; +import type { InsightsProjectModel } from '../models/insights-project.model'; + +export const useInsightsProjectsStore = defineStore('insights-projects-store', () => { + const insightsProjects = ref([]); + + function setInsightsProjects(projects: InsightsProjectModel[]) { + insightsProjects.value = projects; + } + + function getInsightsProject(id: string) { + return insightsProjects.value.find((c) => c.id === id); + } + + function getInsightsProjects() { + return insightsProjects.value; + } + + function updateInsightsProject(project: InsightsProjectModel) { + const index = insightsProjects.value.findIndex((c) => c.id === project.id); + if (index !== -1) { + insightsProjects.value[index] = project; + } + } + + function createInsightsProject(project: InsightsProjectModel) { + insightsProjects.value.push(project); + } + + function searchInsightsProjects(query: string) { + return insightsProjects.value.filter((c) => c.name.toLowerCase().includes(query.toLowerCase())); + } + + return { + insightsProjects, + setInsightsProjects, + getInsightsProject, + getInsightsProjects, + updateInsightsProject, + createInsightsProject, + searchInsightsProjects, + }; +}); diff --git a/frontend/src/modules/admin/modules/insights-projects/pinia/state.ts b/frontend/src/modules/admin/modules/insights-projects/pinia/state.ts deleted file mode 100644 index c4f100552d..0000000000 --- a/frontend/src/modules/admin/modules/insights-projects/pinia/state.ts +++ /dev/null @@ -1,11 +0,0 @@ -import type { InsightsProjectModel } from '../models/insights-project.model'; - -export interface InsightsProjectsState { - insightsProjects: InsightsProjectModel[]; -} - -const state: InsightsProjectsState = { - insightsProjects: [], -}; - -export default () => state;