Skip to content

Commit bffe301

Browse files
authored
feat: switch button to control show/hide system indices (#194)
feat: switch button to control show/hide system indices This pull request introduces several enhancements and fixes across multiple files, focusing on improving data handling, user interface functionality, and code maintainability. The most significant changes include adding a toggle for hiding/displaying system indices, improving shard and node data handling, and refactoring code to enhance type safety and error handling. ### UI Enhancements: * Added a switch to toggle hiding/displaying system indices in the `ES_EDITOR` and `MANAGE` views, along with the necessary logic to manage this state (`src/components/tool-bar.vue`). [[1]](diffhunk://#diff-41529f6c831b85b601d7be26f3a5b99e5e80914851b3e9f3bcac05527d28cc52R36-R50) [[2]](diffhunk://#diff-41529f6c831b85b601d7be26f3a5b99e5e80914851b3e9f3bcac05527d28cc52R126-R140) [[3]](diffhunk://#diff-41529f6c831b85b601d7be26f3a5b99e5e80914851b3e9f3bcac05527d28cc52L119-R151) [[4]](diffhunk://#diff-41529f6c831b85b601d7be26f3a5b99e5e80914851b3e9f3bcac05527d28cc52R239-R247) [[5]](diffhunk://#diff-41529f6c831b85b601d7be26f3a5b99e5e80914851b3e9f3bcac05527d28cc52R269-R276) * Updated shard and node displays to improve clarity and usability, including rendering shard counts and node data more robustly (`src/views/manage/components/index-manage.vue`, `src/views/manage/components/shared-manage.vue`). [[1]](diffhunk://#diff-98c3fe96f51a74a6d72e4ae6966bcde55c8a1ea6bb2d71687198c313e24e8d35L230-R238) [[2]](diffhunk://#diff-04635db97053bc7b92172426dce08928141a0dc84445f714d256ea86f052d704L99-R148) [[3]](diffhunk://#diff-04635db97053bc7b92172426dce08928141a0dc84445f714d256ea86f052d704L134-R161) ### Data Handling Improvements: * Improved shard data handling by grouping shards by index and node, and refactoring shard-related logic to use `ClusterShard` instead of `ShardState` for better type consistency (`src/views/manage/components/shared-manage.vue`). [[1]](diffhunk://#diff-04635db97053bc7b92172426dce08928141a0dc84445f714d256ea86f052d704L99-R148) [[2]](diffhunk://#diff-04635db97053bc7b92172426dce08928141a0dc84445f714d256ea86f052d704L157-R185) [[3]](diffhunk://#diff-04635db97053bc7b92172426dce08928141a0dc84445f714d256ea86f052d704L214-R250) * Enhanced node data retrieval by replacing a state-fetching function with direct access to the `nodes` store, simplifying the logic and reducing API calls (`src/views/manage/components/node-state.vue`). [[1]](diffhunk://#diff-63fa584de9981b286070aab6e579ae15669c1d50652bf2e562dbfb9d0aa4055dL109-R112) [[2]](diffhunk://#diff-63fa584de9981b286070aab6e579ae15669c1d50652bf2e562dbfb9d0aa4055dL124-R125) ### Code Refactoring: * Refactored type definitions and imports for better modularity and maintainability, moving shared types like `ClusterShard` and `NodeRoleEnum` to `datasources` and updating their usage across components (`src/views/manage/components/shared-manage.vue`, `src/views/manage/components/node-state.vue`). [[1]](diffhunk://#diff-98c3fe96f51a74a6d72e4ae6966bcde55c8a1ea6bb2d71687198c313e24e8d35R87) [[2]](diffhunk://#diff-63fa584de9981b286070aab6e579ae15669c1d50652bf2e562dbfb9d0aa4055dL77-R84) [[3]](diffhunk://#diff-04635db97053bc7b92172426dce08928141a0dc84445f714d256ea86f052d704R83-R90) * Added a new export for `esApi.ts` in `datasources/index.ts` to centralize Elasticsearch API utilities (`src/datasources/index.ts`). ### Bug Fixes: * Fixed an issue in `optionalToNullableInt` to return `null` for invalid numeric strings, preventing unexpected behavior (`src/common/valueConversion.ts`). * Added fallback logic for shard and segment size calculations to avoid runtime errors when data is missing or undefined (`src/views/manage/components/shared-manage.vue`). [[1]](diffhunk://#diff-04635db97053bc7b92172426dce08928141a0dc84445f714d256ea86f052d704L170-R216) [[2]](diffhunk://#diff-04635db97053bc7b92172426dce08928141a0dc84445f714d256ea86f052d704L214-R250) Refs: #182 --------- Signed-off-by: seven <[email protected]>
1 parent 7fdfee1 commit bffe301

File tree

9 files changed

+898
-821
lines changed

9 files changed

+898
-821
lines changed

src/common/valueConversion.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
export const optionalToNullableInt = (value: string | number | null | undefined) => {
22
if (value === null || value === undefined) return null;
3-
return parseInt(`${value}`, 10);
3+
4+
const parsed = parseInt(`${value}`, 10);
5+
return isNaN(parsed) ? null : parsed;
46
};

src/components/tool-bar.vue

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,21 @@
3333
<Search />
3434
</template>
3535
</n-select>
36+
<n-tooltip trigger="hover" v-if="['ES_EDITOR', 'MANAGE'].includes(props.type ?? '')">
37+
<template #trigger>
38+
<n-switch
39+
:round="false"
40+
v-model:value="hideSystemIndicesRef"
41+
class="action-index-switch"
42+
@update:value="handleHiddenChange"
43+
>
44+
<template #checked> Hidden</template>
45+
<template #unchecked>Display</template>
46+
</n-switch>
47+
</template>
48+
Hide/Display system indices
49+
</n-tooltip>
50+
3651
<n-tooltip v-if="props.type === 'ES_EDITOR'" trigger="hover">
3752
<template #trigger>
3853
<n-icon size="20" class="action-load-icon" @click="loadDefaultSnippet">
@@ -99,7 +114,7 @@ const { loadDefaultSnippet, selectConnection } = tabStore;
99114
const { activePanel, activeElasticsearchIndexOption } = storeToRefs(tabStore);
100115
101116
const clusterManageStore = useClusterManageStore();
102-
const { connection } = storeToRefs(clusterManageStore);
117+
const { connection, hideSystemIndices } = storeToRefs(clusterManageStore);
103118
104119
const loadingRef = ref({ connection: false, index: false });
105120
@@ -108,6 +123,21 @@ const selectionState = ref<{ connection: boolean; index: boolean }>({
108123
connection: false,
109124
index: false,
110125
});
126+
127+
const hideSystemIndicesRef = ref(true);
128+
129+
watch(
130+
() => props.type,
131+
newType => {
132+
if (newType === 'ES_EDITOR') {
133+
hideSystemIndicesRef.value = activePanel?.value.hideSystemIndices ?? true;
134+
} else if (newType === 'MANAGE') {
135+
hideSystemIndicesRef.value = hideSystemIndices.value;
136+
}
137+
},
138+
{ immediate: true },
139+
);
140+
111141
const options = computed(
112142
() =>
113143
({
@@ -116,9 +146,9 @@ const options = computed(
116146
({ name }) => !filterRef.value.connection || name.includes(filterRef.value.connection),
117147
)
118148
.map(({ name }) => ({ label: name, value: name })),
119-
index: activeElasticsearchIndexOption.value?.filter(
120-
index => !filterRef.value.index || index.value.includes(filterRef.value.index),
121-
),
149+
index: activeElasticsearchIndexOption.value
150+
?.filter(index => (hideSystemIndicesRef.value ? !index.value.startsWith('.') : true))
151+
.filter(index => !filterRef.value.index || index.value.includes(filterRef.value.index)),
122152
}) as Record<string, { label: string; value: string }[]>,
123153
);
124154
@@ -206,6 +236,15 @@ const handleSearch = async (input: string, type: 'CONNECTION' | 'INDEX') => {
206236
const handleManageTabChange = (tabName: string) => {
207237
emits('switch-manage-tab', tabName);
208238
};
239+
240+
const handleHiddenChange = (value: boolean) => {
241+
if (props.type === 'ES_EDITOR' && activePanel.value) {
242+
activePanel.value.hideSystemIndices = value;
243+
}
244+
if (props.type === 'MANAGE' && connection.value) {
245+
hideSystemIndices.value = value;
246+
}
247+
};
209248
</script>
210249

211250
<style lang="scss" scoped>
@@ -227,6 +266,14 @@ const handleManageTabChange = (tabName: string) => {
227266
line-height: 40px;
228267
}
229268
269+
.action-index-switch {
270+
cursor: pointer;
271+
padding: 0;
272+
margin-left: 10px;
273+
height: inherit;
274+
min-width: 80px;
275+
}
276+
230277
.manage-container {
231278
margin-right: 10px;
232279
}

0 commit comments

Comments
 (0)