Skip to content

Commit

Permalink
fix: auto refresh indices link #19 (#21)
Browse files Browse the repository at this point in the history
Signed-off-by: seven <[email protected]>
  • Loading branch information
Blankll authored Feb 6, 2024
1 parent 926c7f8 commit 80b26d8
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 10 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,5 @@ jobs:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
files: |
LICENSE
out/make/**/*.dmg
out/make/**/*.rpm
out/make/**/*.deb
out/make/**/*.Setup.exe
out/make/**/*.{dmg,rpm,deb,Setup.exe}
2 changes: 1 addition & 1 deletion src/electron/sourceFIleApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ const sourceFileApi: { [key: string]: (filePath: string, content: string) => unk

export const registerSourceFileApiListener = (ipcMain: Electron.IpcMain) => {
ipcMain.handle('sourceFileAPI', (_, { content, method }: SourceFileApiInput) =>
sourceFileApi[method.toLowerCase()]('./data/default.search', content),
sourceFileApi[method.toLowerCase()]('../../data/default.search', content),
);
};
15 changes: 13 additions & 2 deletions src/store/connectionStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,19 @@ export const useConnectionStore = defineStore('connectionStore', {
}));
this.established = { ...connection, indices };
},
async fetchIndices() {
if (!this.established) throw new Error('no connection established');
const client = loadHttpClient(this.established as Connection);
const data = await client.get('/_cat/indices', 'format=json');
this.established!.indices = data.map((index: { [key: string]: string }) => ({
...index,
docs: {
count: parseInt(index['docs.count'], 10),
deleted: parseInt(index['docs.deleted'], 10),
},
store: { size: index['store.size'] },
}));
},
selectIndex(indexName: string) {
this.established = {
...this.established,
Expand All @@ -119,8 +132,6 @@ export const useConnectionStore = defineStore('connectionStore', {
const reqPath = buildPath(index, path);
const body = qdsl ? JSON.parse(qdsl) : undefined;

// eslint-disable-next-line no-console
console.log('before req', { index, qdsl, method, path });
const dispatch: { [method: string]: () => Promise<unknown> } = {
POST: async () => client.post(reqPath, undefined, body),
PUT: async () => client.put(reqPath, undefined, body),
Expand Down
26 changes: 25 additions & 1 deletion src/views/connect/components/collection-selector.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,27 @@
<n-select
:options="options"
placeholder="No collection/index selected"
remote
filterable
:loading="loadingRef"
@update:value="handleUpdateValue"
@update:show="handleOpen"
/>
</div>
</template>

<script setup lang="ts">
import { storeToRefs } from 'pinia';
import { useConnectionStore } from '../../../store';
import { useLang } from '../../../lang';
const message = useMessage();
const lang = useLang();
const connectionStore = useConnectionStore();
const { establishedIndexNames } = storeToRefs(connectionStore);
const { establishedIndexNames, established } = storeToRefs(connectionStore);
const { fetchIndices } = connectionStore;
const loadingRef = ref(false);
// build options list
const options = computed(() =>
establishedIndexNames.value.map(name => ({ label: name, value: name })),
Expand All @@ -23,6 +32,21 @@ const options = computed(() =>
const handleUpdateValue = (value: string) => {
connectionStore.selectIndex(value);
};
const handleOpen = async (isOpen: boolean) => {
if (!isOpen) return;
if (!established.value) {
message.error(lang.t('editor.establishedRequired'), {
closable: true,
keepAliveOnHover: true,
duration: 3000,
});
return;
}
loadingRef.value = true;
await fetchIndices();
loadingRef.value = false;
};
</script>

<style lang="scss" scoped>
Expand Down
2 changes: 0 additions & 2 deletions src/views/editor/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,6 @@ const executeQueryAction = async (
return;
}
try {
// eslint-disable-next-line no-console
console.log(`execute ${JSON.stringify({ action })}`);
if (!established.value) {
message.error(lang.t('editor.establishedRequired'), {
closable: true,
Expand Down

0 comments on commit 80b26d8

Please sign in to comment.