From 30c681b5357b03c88be3ee2437ecf1053baec8c4 Mon Sep 17 00:00:00 2001 From: seven Date: Sun, 13 Oct 2024 19:21:50 +0800 Subject: [PATCH] fix: bulk action with index (#116) fix: bulk action with index should pass index to the request url Refs: #114 --------- Signed-off-by: seven --- .github/workflows/release.yml | 1 + package-lock.json | 4 ++-- package.json | 2 +- src/common/requestUtil.ts | 11 +---------- src/datasources/fetchApi.ts | 2 +- src/store/connectionStore.ts | 26 +++++++++++++++++--------- src/views/editor/index.vue | 2 +- 7 files changed, 24 insertions(+), 24 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index eb5dfb7..3d0ba49 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -51,6 +51,7 @@ jobs: - name: install dependencies (ubuntu only) if: matrix.os == 'ubuntu-latest' run: | + echo "deb http://gb.archive.ubuntu.com/ubuntu jammy main" | sudo tee -a /etc/apt/sources.list sudo apt-get update sudo apt-get install -y libgtk-3-dev libwebkit2gtk-4.0-dev libappindicator3-dev librsvg2-dev patchelf pkg-config libssl-dev gcc-aarch64-linux-gnu - name: install frontend dependencies diff --git a/package-lock.json b/package-lock.json index 206c749..7055941 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "dockit", - "version": "0.4.6", + "version": "0.4.7", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "dockit", - "version": "0.4.6", + "version": "0.4.7", "license": "Apache-2.0", "dependencies": { "@tauri-apps/api": "^1.6.0", diff --git a/package.json b/package.json index 69b95f0..86f8212 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "dockit", "private": true, "type": "module", - "version": "0.4.6", + "version": "0.4.7", "description": "DocKit is a desktop client designed for NoSQL database, support Elasticsearch and OpenSearch across Mac, windows and Linux", "author": "geekfun ", "homepage": "ttps://dockit.geekfun.club", diff --git a/src/common/requestUtil.ts b/src/common/requestUtil.ts index f2a00c8..8382209 100644 --- a/src/common/requestUtil.ts +++ b/src/common/requestUtil.ts @@ -9,18 +9,9 @@ export const buildAuthHeader = (username: string | undefined, password: string | export const buildURL = ( host: string, port: number, - index: string | undefined, path: string | undefined, queryParameters?: string, ) => { const trimmedPath = path?.startsWith('/') ? path.slice(1) : path; - const pathWithIndex = - index && - !['_nodes', '_cluster', '_cat', '_bulk', '_aliases', '_analyze'].includes( - trimmedPath?.split('/')[0] ?? '', - ) - ? `${index}/${trimmedPath}` - : `${trimmedPath}`; - - return `${host}:${port}/${pathWithIndex}${queryParameters ? `?${queryParameters}` : ''}`; + return `${host}:${port}/${trimmedPath}${queryParameters ? `?${queryParameters}` : ''}`; }; diff --git a/src/datasources/fetchApi.ts b/src/datasources/fetchApi.ts index e02dcc8..b19de0f 100644 --- a/src/datasources/fetchApi.ts +++ b/src/datasources/fetchApi.ts @@ -43,7 +43,7 @@ const fetchWrapper = async ({ ssl: boolean; }) => { try { - const url = buildURL(host, port, undefined, path, queryParameters); + const url = buildURL(host, port, path, queryParameters); const { data, status, details } = await fetchRequest(url, { method, headers: { ...buildAuthHeader(username, password) }, diff --git a/src/store/connectionStore.ts b/src/store/connectionStore.ts index 458e383..66520a7 100644 --- a/src/store/connectionStore.ts +++ b/src/store/connectionStore.ts @@ -37,13 +37,21 @@ type Established = | (Connection & { indices: Array; activeIndex?: ConnectionIndex }) | null; -const buildPath = (index: string | undefined, path: string | undefined) => { - return index && - !['_nodes', '_cluster', '_cat', '_bulk', '_aliases', '_analyze'].includes( - path?.split('/')[0] ?? '', - ) - ? `/${index}/${path}` - : `/${path}`; +const buildPath = ( + index: string | undefined, + path: string | undefined, + established: Established, +) => { + const pathAction = path?.split('/')[0] ?? ''; + if (['_nodes', '_cluster', '_cat', '_aliases', '_analyze'].includes(pathAction)) { + return `/${path}`; + } + if (index && ['_search', '_msearch', '_bulk'].includes(pathAction)) { + return `/${index}/${path}`; + } + const indexName = index ?? established?.activeIndex?.index; + + return indexName ? `/${indexName}/${path}` : `/${path}`; }; export const useConnectionStore = defineStore('connectionStore', { @@ -158,7 +166,7 @@ export const useConnectionStore = defineStore('connectionStore', { } } catch (err) {} - const reqPath = buildPath(index, path); + const reqPath = buildPath(index, path, this.established); const dispatch: { [method: string]: () => Promise } = { POST: async () => client.post(reqPath, queryParameters, qdsl), @@ -177,7 +185,7 @@ export const useConnectionStore = defineStore('connectionStore', { password: undefined, }; const params = queryParams ? `${queryParams}&format=json` : 'format=json'; - const url = buildURL(host, port, index, path, params); + const url = buildURL(host, port, buildPath(index, path, this.established), params); const headers = { 'Content-Type': 'application/json', diff --git a/src/views/editor/index.vue b/src/views/editor/index.vue index d0603e5..848d2c9 100644 --- a/src/views/editor/index.vue +++ b/src/views/editor/index.vue @@ -148,7 +148,7 @@ const executeQueryAction = async (position: { column: number; lineNumber: number ...action, queryParams: action.queryParams ?? undefined, qdsl: transformQDSL(action), - index: action.index || established.value?.activeIndex?.index, + index: action.index, }); displayJsonEditor(JSON.stringify(data, null, ' '));