From 0669b48cb5bad9bad14348afabc6be539bb1787c Mon Sep 17 00:00:00 2001 From: Ryan Wang Date: Fri, 29 Jul 2022 17:58:14 +0800 Subject: [PATCH] feat: api supports field filtering (#591) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ryan Wang #### What type of PR is this? /kind feature /milestone 2.0 #### What this PR does / why we need it: 适配 https://github.com/halo-dev/halo/pull/2279 接口支持通过参数筛选数据。 #### Which issue(s) this PR fixes: None #### Screenshots: None #### Special notes for your reviewer: /hold until https://github.com/halo-dev/halo/pull/2279 merge #### Does this PR introduce a user-facing change? ```release-note None ``` --- package.json | 2 +- packages/shared/package.json | 2 +- pnpm-lock.yaml | 12 ++++---- src/modules/system/plugins/PluginDetail.vue | 25 +++++++--------- src/modules/system/plugins/PluginList.vue | 29 ++++++++++++++++-- src/modules/system/roles/RoleList.vue | 14 ++++----- .../system/roles/composables/use-role.ts | 30 +++++++++---------- 7 files changed, 64 insertions(+), 50 deletions(-) diff --git a/package.json b/package.json index 31d0264f..a48c6669 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ "@formkit/vue": "1.0.0-beta.9", "@halo-dev/admin-api": "^1.1.0", "@halo-dev/admin-shared": "workspace:*", - "@halo-dev/api-client": "^0.0.5", + "@halo-dev/api-client": "^0.0.6", "@halo-dev/components": "workspace:*", "@vueuse/components": "^8.9.4", "@vueuse/core": "^8.9.4", diff --git a/packages/shared/package.json b/packages/shared/package.json index 5857e169..b1ef3fb2 100644 --- a/packages/shared/package.json +++ b/packages/shared/package.json @@ -35,7 +35,7 @@ "homepage": "https://github.com/halo-dev/halo-admin/tree/next/shared/components#readme", "license": "MIT", "dependencies": { - "@halo-dev/api-client": "^0.0.5", + "@halo-dev/api-client": "^0.0.6", "@halo-dev/components": "workspace:*", "axios": "^0.27.2" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c097308f..1a1d8fe2 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -14,7 +14,7 @@ importers: '@formkit/vue': 1.0.0-beta.9 '@halo-dev/admin-api': ^1.1.0 '@halo-dev/admin-shared': workspace:* - '@halo-dev/api-client': ^0.0.5 + '@halo-dev/api-client': ^0.0.6 '@halo-dev/components': workspace:* '@rushstack/eslint-patch': ^1.1.4 '@tailwindcss/aspect-ratio': ^0.4.0 @@ -84,7 +84,7 @@ importers: '@formkit/vue': 1.0.0-beta.9_jly5jqkcc2zgnt3crhnp3znzv4 '@halo-dev/admin-api': 1.1.0 '@halo-dev/admin-shared': link:packages/shared - '@halo-dev/api-client': 0.0.5 + '@halo-dev/api-client': 0.0.6 '@halo-dev/components': link:packages/components '@vueuse/components': 8.9.4_vue@3.2.37 '@vueuse/core': 8.9.4_vue@3.2.37 @@ -176,12 +176,12 @@ importers: packages/shared: specifiers: - '@halo-dev/api-client': ^0.0.5 + '@halo-dev/api-client': ^0.0.6 '@halo-dev/components': workspace:* axios: ^0.27.2 vite-plugin-dts: ^1.3.1 dependencies: - '@halo-dev/api-client': 0.0.5 + '@halo-dev/api-client': 0.0.6 '@halo-dev/components': link:../components axios: 0.27.2 devDependencies: @@ -1873,8 +1873,8 @@ packages: - debug dev: false - /@halo-dev/api-client/0.0.5: - resolution: {integrity: sha512-UqT6svy1nEVGF1swZXJgvu9iy6gQhaJ/o8lY5736Q4BbW8pYrqQBEQYNv8ySRBQr762/Cy7wDFijAGlPod7tDw==} + /@halo-dev/api-client/0.0.6: + resolution: {integrity: sha512-JDWGlTq+pHVrZsmqDCXAowZQFcNL3M6+guL37yrKbhylUgIutYpCMU/d2Qogc+c43FzFBq84igP84T5XtuknjQ==} dev: false /@halo-dev/logger/1.1.0: diff --git a/src/modules/system/plugins/PluginDetail.vue b/src/modules/system/plugins/PluginDetail.vue index 7dc4fde2..1a76c0d9 100644 --- a/src/modules/system/plugins/PluginDetail.vue +++ b/src/modules/system/plugins/PluginDetail.vue @@ -1,7 +1,7 @@ diff --git a/src/modules/system/plugins/PluginList.vue b/src/modules/system/plugins/PluginList.vue index 987646d7..039a2fe3 100644 --- a/src/modules/system/plugins/PluginList.vue +++ b/src/modules/system/plugins/PluginList.vue @@ -12,23 +12,42 @@ import { } from "@halo-dev/components"; import PluginListItem from "./components/PluginListItem.vue"; import PluginInstallModal from "./components/PluginInstallModal.vue"; -import { onMounted, ref } from "vue"; +import { onMounted, ref, watch } from "vue"; import { apiClient } from "@halo-dev/admin-shared"; import type { Plugin } from "@halo-dev/api-client"; const plugins = ref([] as Plugin[]); const pluginInstall = ref(false); +const keyword = ref(""); const handleFetchPlugins = async () => { try { + const fieldSelector: Array = []; + + if (keyword.value) { + fieldSelector.push(`name=${keyword.value}`); + } + const { data } = - await apiClient.extension.plugin.listpluginHaloRunV1alpha1Plugin(); + await apiClient.extension.plugin.listpluginHaloRunV1alpha1Plugin( + 0, + 0, + [], + fieldSelector + ); plugins.value = data.items; } catch (e) { console.error("Fail to fetch plugins", e); } }; +watch( + () => keyword.value, + () => { + handleFetchPlugins(); + } +); + onMounted(handleFetchPlugins);
    -
  • +
  • diff --git a/src/modules/system/roles/composables/use-role.ts b/src/modules/system/roles/composables/use-role.ts index f7362eda..dba21bfc 100644 --- a/src/modules/system/roles/composables/use-role.ts +++ b/src/modules/system/roles/composables/use-role.ts @@ -59,21 +59,13 @@ export function useRoleForm() { } export function useRoleTemplateSelection() { - const rawRoles = ref([] as Role[]); + const roleTemplates = ref([] as Role[]); const selectedRoleTemplates = ref>(new Set()); - // Get all role templates based on the condition that `metadata.labels.[halo.run/role-template] === 'true'` - const roleTemplates = computed(() => { - return rawRoles.value.filter( - (role) => - role.metadata.labels?.[roleLabels.TEMPLATE] === "true" && - role.metadata.labels?.["halo.run/hidden"] !== "true" - ); - }); - /** - * Grouping role templates by module + * Grouping role templates by module
    * Example: + * ```json * { * "module": "Users Management", * "roles": [ @@ -151,6 +143,7 @@ export function useRoleTemplateSelection() { * } * ] * } + * ``` */ const roleTemplateGroups = computed(() => { const groups: RoleTemplateGroup[] = []; @@ -171,10 +164,16 @@ export function useRoleTemplateSelection() { return groups; }); + /** + * Get all role templates based on the condition that `metadata.labels.[halo.run/role-template] = 'true'` and `!halo.run/hidden` + */ const handleFetchRoles = async () => { try { - const { data } = await apiClient.extension.role.listv1alpha1Role(); - rawRoles.value = data.items; + const { data } = await apiClient.extension.role.listv1alpha1Role(0, 0, [ + `${roleLabels.TEMPLATE}=true`, + "!halo.run/hidden", + ]); + roleTemplates.value = data.items; } catch (e) { console.error(e); } @@ -185,7 +184,9 @@ export function useRoleTemplateSelection() { if (!checked) { return; } - const role = rawRoles.value.find((role) => role.metadata.name === value); + const role = roleTemplates.value.find( + (role) => role.metadata.name === value + ); const dependencies = role?.metadata.annotations?.[rbacAnnotations.DEPENDENCIES]; if (!dependencies) { @@ -200,7 +201,6 @@ export function useRoleTemplateSelection() { onMounted(handleFetchRoles); return { - rawRoles, selectedRoleTemplates, roleTemplates, roleTemplateGroups,