Skip to content

Commit 81a6ad4

Browse files
BlankllCopilot
andauthored
fix: fix the manage tab not refreshing data when a new connection is selected (#195)
fix: Fix the manage tab not refreshing data when a new connection is selected - [x] Hidden switch state in the manage section not well saved Refs: #182 --------- Signed-off-by: seven <[email protected]> Co-authored-by: Copilot <[email protected]>
1 parent bffe301 commit 81a6ad4

File tree

4 files changed

+248
-208
lines changed

4 files changed

+248
-208
lines changed

src/components/tool-bar.vue

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66
:input-props="inputProps"
77
remote
88
filterable
9-
:default-value="activePanel?.connection?.name"
9+
:default-value="
10+
['ES_EDITOR', 'DYNAMO_EDITOR'].includes(props.type ?? '')
11+
? activePanel?.connection?.name
12+
: connection?.name
13+
"
1014
:loading="loadingRef.connection"
1115
@update:show="isOpen => handleOpen(isOpen, 'CONNECTION')"
1216
@update:value="value => handleUpdate(value, 'CONNECTION')"
@@ -114,6 +118,7 @@ const { loadDefaultSnippet, selectConnection } = tabStore;
114118
const { activePanel, activeElasticsearchIndexOption } = storeToRefs(tabStore);
115119
116120
const clusterManageStore = useClusterManageStore();
121+
const { setConnection, refreshStates } = clusterManageStore;
117122
const { connection, hideSystemIndices } = storeToRefs(clusterManageStore);
118123
119124
const loadingRef = ref({ connection: false, index: false });
@@ -128,10 +133,13 @@ const hideSystemIndicesRef = ref(true);
128133
129134
watch(
130135
() => props.type,
131-
newType => {
136+
async newType => {
132137
if (newType === 'ES_EDITOR') {
133138
hideSystemIndicesRef.value = activePanel?.value.hideSystemIndices ?? true;
134139
} else if (newType === 'MANAGE') {
140+
if (!connection.value && activePanel.value.connection) {
141+
setConnection(activePanel.value.connection);
142+
}
135143
hideSystemIndicesRef.value = hideSystemIndices.value;
136144
}
137145
},
@@ -198,9 +206,11 @@ const handleUpdate = async (value: string, type: 'CONNECTION' | 'INDEX') => {
198206
return;
199207
}
200208
try {
201-
['ES_EDITOR', 'DYNAMO_EDITOR'].includes(props.type ?? '')
202-
? await selectConnection(con)
203-
: (connection.value = con);
209+
if (['ES_EDITOR', 'DYNAMO_EDITOR'].includes(props.type ?? '')) {
210+
await selectConnection(con);
211+
} else {
212+
setConnection(con);
213+
}
204214
} catch (err) {
205215
const error = err as CustomError;
206216
message.error(`status: ${error.status}, details: ${error.details}`, {
@@ -237,12 +247,12 @@ const handleManageTabChange = (tabName: string) => {
237247
emits('switch-manage-tab', tabName);
238248
};
239249
240-
const handleHiddenChange = (value: boolean) => {
250+
const handleHiddenChange = async (value: boolean) => {
241251
if (props.type === 'ES_EDITOR' && activePanel.value) {
242252
activePanel.value.hideSystemIndices = value;
243253
}
244254
if (props.type === 'MANAGE' && connection.value) {
245-
hideSystemIndices.value = value;
255+
await refreshStates(value);
246256
}
247257
};
248258
</script>

src/store/clusterManageStore.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export const useClusterManageStore = defineStore('clusterManageStore', {
8686
hideSystemIndices: true,
8787
}),
8888
persist: {
89-
pick: ['showSystemIndices'],
89+
pick: ['hideSystemIndices'],
9090
storage: localStorage,
9191
},
9292
getters: {
@@ -120,6 +120,22 @@ export const useClusterManageStore = defineStore('clusterManageStore', {
120120
setConnection(connection: Connection) {
121121
this.connection = connection;
122122
},
123+
async refreshStates(hide?: boolean) {
124+
if (hide !== undefined && hide !== null) {
125+
this.hideSystemIndices = hide;
126+
}
127+
128+
try {
129+
await this.fetchCluster();
130+
await this.fetchIndices();
131+
await this.fetchAliases();
132+
await this.fetchNodes();
133+
await this.fetchShards();
134+
await this.fetchTemplates();
135+
} catch (err) {
136+
debug(`Error in refreshStates: ${err}`);
137+
}
138+
},
123139
async fetchCluster() {
124140
if (!this.connection) throw new Error(lang.global.t('connection.selectConnection'));
125141
if (this.connection.type === DatabaseType.ELASTICSEARCH) {

0 commit comments

Comments
 (0)