diff --git a/src/graphql/http/index.ts b/src/graphql/http/index.ts index 400220ac..d9825404 100644 --- a/src/graphql/http/index.ts +++ b/src/graphql/http/index.ts @@ -15,12 +15,13 @@ * limitations under the License. */ import { httpQuery } from "../base"; +import { HttpURL } from "./url"; -export default async function fetchQuery({ method, json, url }: { method: string; json?: unknown; url: string }) { +export default async function fetchQuery({ method, json, path }: { method: string; json?: unknown; path: string }) { const response = await httpQuery({ method, json, - url, + url: (HttpURL as { [key: string]: string })[path], }); if (response.errors) { response.errors = response.errors.map((e: { message: string }) => e.message).join(" "); diff --git a/src/graphql/http/url.ts b/src/graphql/http/url.ts index 199995ff..764c9c27 100644 --- a/src/graphql/http/url.ts +++ b/src/graphql/http/url.ts @@ -14,8 +14,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -export const ClusterNodes = `/status/cluster/nodes`; -export const ConfigTTL = `/status/config/ttl`; - -export const DebuggingConfigDump = `/debugging/config/dump`; +export const HttpURL = { + ClusterNodes: `/status/cluster/nodes`, + ConfigTTL: `/status/config/ttl`, + DebuggingConfigDump: `/debugging/config/dump`, +}; diff --git a/src/store/modules/settings.ts b/src/store/modules/settings.ts index 85bd4f48..c8b9e3f5 100644 --- a/src/store/modules/settings.ts +++ b/src/store/modules/settings.ts @@ -21,28 +21,42 @@ import type { Cluster } from "@/types/settings"; interface SettingsState { loading: boolean; - nodes: Cluster[]; + clusterNodes: Cluster[]; } export const settingsStore = defineStore({ id: "settings", state: (): SettingsState => ({ - nodes: [], + clusterNodes: [], loading: false, }), actions: { - async getNodes() { + async getClusterNodes() { this.loading = true; const res = await fetchQuery({ method: "get", - url: "", + path: "ClusterNodes", }); this.loading = false; - if (res.errors) { - return res; - } - - return res.data; + return res.nodes; + }, + async getConfigTTL() { + this.loading = true; + const res = await fetchQuery({ + method: "get", + path: "ConfigTTL", + }); + this.loading = false; + return res; + }, + async getDebuggingConfigDump() { + this.loading = true; + const res = await fetchQuery({ + method: "get", + path: "DebuggingConfigDump", + }); + this.loading = false; + return res; }, }, });