Skip to content

Commit

Permalink
fix: bulk action with index (#116)
Browse files Browse the repository at this point in the history
fix: bulk action with index should pass index to the request url

Refs: #114

---------

Signed-off-by: seven <[email protected]>
  • Loading branch information
Blankll authored Oct 13, 2024
1 parent 7f9d7b0 commit 30c681b
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 24 deletions.
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>",
"homepage": "ttps://dockit.geekfun.club",
Expand Down
11 changes: 1 addition & 10 deletions src/common/requestUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}` : ''}`;
};
2 changes: 1 addition & 1 deletion src/datasources/fetchApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) },
Expand Down
26 changes: 17 additions & 9 deletions src/store/connectionStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,21 @@ type Established =
| (Connection & { indices: Array<ConnectionIndex>; 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', {
Expand Down Expand Up @@ -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<unknown> } = {
POST: async () => client.post(reqPath, queryParameters, qdsl),
Expand All @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion src/views/editor/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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, ' '));
Expand Down

0 comments on commit 30c681b

Please sign in to comment.