From 8e2e304ec7d7cbeb8016a9545daa0e199fba40c7 Mon Sep 17 00:00:00 2001 From: jialin Date: Wed, 13 Mar 2024 21:10:53 +0800 Subject: [PATCH] chore: filter templates jump from catalog list --- .../projects/pages/detail.vue | 19 +++++++++- .../catalogs/components/list-view.vue | 10 +++++- .../hooks/filter-catalog-listener.ts | 35 +++++++++++++++++++ src/views/operation-hub/pages/main.vue | 24 ++++++++----- .../templates/components/table-list.vue | 26 +++++++++++++- 5 files changed, 102 insertions(+), 12 deletions(-) create mode 100644 src/views/operation-hub/hooks/filter-catalog-listener.ts diff --git a/src/views/application-management/projects/pages/detail.vue b/src/views/application-management/projects/pages/detail.vue index dac79f04..55c06cc5 100644 --- a/src/views/application-management/projects/pages/detail.vue +++ b/src/views/application-management/projects/pages/detail.vue @@ -134,7 +134,7 @@ import { Resources, Actions } from '@/permissions/config'; import { PROJECT } from '@/router/config'; import { ProjectTabs } from '@/views/config'; - import { ref, onMounted, reactive } from 'vue'; + import { ref, onMounted, onBeforeUnmount, reactive } from 'vue'; import _ from 'lodash'; import useTabActive, { TabPage } from '@/hooks/use-tab-active'; import useCallCommon from '@/hooks/use-call-common'; @@ -147,6 +147,11 @@ import TemplateList from '@/views/application-management/templates/pages/list.vue'; import CatalogList from '@/views/application-management/catalogs/pages/list.vue'; import WorkflowList from '@/views/application-management/workflows/pages/list.vue'; + import { + listenFilterCatalogAction, + removeFilterCatalogActionListener, + emitFilterTemplateAction + } from '@/views/operation-hub/hooks/filter-catalog-listener'; import { queryItemProject } from '../api'; import { projectDetailTabs } from '../config'; import userProjectBreadcrumbData from '../hooks/use-project-breadcrumb-data'; @@ -238,6 +243,13 @@ initActiveTab(); breadCrumbList.value = await initBreadValues([]); }; + listenFilterCatalogAction((data) => { + handleTabChange(ProjectTabs.TEMPLATES); + setTimeout(() => { + emitFilterTemplateAction(data); + }, 100); + }); + onMounted(() => { initBread(); projectStore.setEnterProjectDefault({ @@ -246,6 +258,11 @@ list: false }); }); + + onBeforeUnmount(() => { + removeFilterCatalogActionListener(); + }); + init(); diff --git a/src/views/operation-hub/catalogs/components/list-view.vue b/src/views/operation-hub/catalogs/components/list-view.vue index cdd60559..0c893335 100644 --- a/src/views/operation-hub/catalogs/components/list-view.vue +++ b/src/views/operation-hub/catalogs/components/list-view.vue @@ -8,6 +8,7 @@ :pagination="false" row-key="id" :row-selection="rowSelectionRef" + @cell-click="handleCellClick" @sorter-change="handleSortChange" @selection-change="handleSelectChange" > @@ -28,7 +29,7 @@ }" > @@ -154,6 +155,7 @@ import StatusLabel from '../../connectors/components/status-label.vue'; import { queryCatalogs, refreshCatalog, deleteCatalogs } from '../api'; import { actionList } from '../config'; + import { emitFilterCatalogAction } from '../../hooks/filter-catalog-listener'; const props = defineProps({ list: { @@ -214,6 +216,12 @@ : null; }); + const handleCellClick = (row, col) => { + if (col.dataIndex === 'name') { + emitFilterCatalogAction(row); + } + }; + const setActionList = (row) => { const list = _.filter(actionList, (item) => { return item.filterFun ? item.filterFun(row) : true; diff --git a/src/views/operation-hub/hooks/filter-catalog-listener.ts b/src/views/operation-hub/hooks/filter-catalog-listener.ts new file mode 100644 index 00000000..fcf01613 --- /dev/null +++ b/src/views/operation-hub/hooks/filter-catalog-listener.ts @@ -0,0 +1,35 @@ +import mitt, { Handler } from 'mitt'; + +const emitter = mitt(); + +const key = Symbol('FILTER_CATALOG_LIST_KEY'); + +const key2 = Symbol('FILTER_TEMPLATE_LIST_KEY'); + +// trigger the event +export function emitFilterCatalogAction(data: any) { + emitter.emit(key, data); +} + +export function listenFilterCatalogAction(handler: (data) => void) { + emitter.on(key, handler as Handler); +} + +export function removeFilterCatalogActionListener() { + emitter.off(key); +} + +// filter template +export function emitFilterTemplateAction(data: any) { + emitter.emit(key2, data); +} + +export function listenFilterTemplateAction(handler: (data) => void) { + emitter.on(key2, handler as Handler); +} + +export function removeFilterTemplateActionListener() { + emitter.off(key2); +} + +export default {}; diff --git a/src/views/operation-hub/pages/main.vue b/src/views/operation-hub/pages/main.vue index 787ef987..8bba049a 100644 --- a/src/views/operation-hub/pages/main.vue +++ b/src/views/operation-hub/pages/main.vue @@ -53,14 +53,6 @@ > - - @@ -69,7 +61,7 @@