@@ -4,36 +4,13 @@ import {
4
4
ClusterIndex ,
5
5
ClusterNode ,
6
6
ClusterShard ,
7
+ ClusterTemplate ,
7
8
esApi ,
8
9
loadHttpClient ,
9
10
} from '../datasources' ;
10
11
import { lang } from '../lang' ;
11
12
import { Connection , DatabaseType } from './connectionStore.ts' ;
12
- import { CustomError , debug , optionalToNullableInt } from '../common' ;
13
-
14
- export enum TemplateType {
15
- INDEX_TEMPLATE = 'INDEX_TEMPLATE' ,
16
- COMPONENT_TEMPLATE = 'COMPONENT_TEMPLATE' ,
17
- }
18
-
19
- type ComponentTemplate = {
20
- name : string ;
21
- type : TemplateType ;
22
- version : number | null ;
23
- alias_count : number | null ;
24
- mapping_count : number | null ;
25
- settings_count : number | null ;
26
- metadata_count : number | null ;
27
- included_in : Array < string > ;
28
- } ;
29
- type IndexTemplate = {
30
- name : string ;
31
- type : TemplateType ;
32
- index_patterns : Array < string > ;
33
- order : number | null ;
34
- version : number | null ;
35
- composed_of : Array < string > ;
36
- } ;
13
+ import { CustomError , debug } from '../common' ;
37
14
38
15
export type RawClusterStats = {
39
16
cluster_name : string ;
@@ -63,8 +40,6 @@ export type RawClusterStats = {
63
40
} ;
64
41
} ;
65
42
66
- export type ClusterTemplate = ComponentTemplate | IndexTemplate ;
67
-
68
43
export const useClusterManageStore = defineStore ( 'clusterManageStore' , {
69
44
state : ( ) : {
70
45
connection : Connection | undefined ;
@@ -201,45 +176,11 @@ export const useClusterManageStore = defineStore('clusterManageStore', {
201
176
async fetchTemplates ( ) {
202
177
if ( ! this . connection ) throw new Error ( lang . global . t ( 'connection.selectConnection' ) ) ;
203
178
if ( this . connection . type === DatabaseType . ELASTICSEARCH ) {
204
- const client = loadHttpClient ( this . connection ) ;
205
- const fetchIndexTemplates = async ( ) => {
206
- const data = ( await client . get ( '/_cat/templates' , 'format=json' ) ) as Array < {
207
- [ key : string ] : string ;
208
- } > ;
209
- return data . map ( ( template : { [ key : string ] : string } ) => ( {
210
- name : template . name ,
211
- type : TemplateType . INDEX_TEMPLATE ,
212
- order : optionalToNullableInt ( template . order ) ,
213
- version : optionalToNullableInt ( template . version ) ,
214
- index_patterns : template . index_patterns . slice ( 1 , - 1 ) . split ( ',' ) . filter ( Boolean ) ,
215
- composed_of : template . composed_of . slice ( 1 , - 1 ) . split ( ',' ) . filter ( Boolean ) ,
216
- } ) ) ;
217
- } ;
218
- const fetchComponentTemplates = async ( ) => {
219
- const data = ( await client . get ( '/_component_template' , 'format=json' ) ) as {
220
- component_templates : Array < {
221
- [ key : string ] : string ;
222
- } > ;
223
- } ;
224
-
225
- return data ?. component_templates . map ( ( template : { [ key : string ] : string } ) => ( {
226
- name : template . name ,
227
- type : TemplateType . COMPONENT_TEMPLATE ,
228
- version : optionalToNullableInt ( template . version ) ,
229
- alias_count : optionalToNullableInt ( template . alias_count ) ,
230
- mapping_count : optionalToNullableInt ( template . mapping_count ) ,
231
- settings_count : optionalToNullableInt ( template . settings_count ) ,
232
- metadata_count : optionalToNullableInt ( template . metadata_count ) ,
233
- included_in : template . included_in ?. slice ( 1 , - 1 ) . split ( ',' ) . filter ( Boolean ) ,
234
- } ) ) ;
235
- } ;
179
+ const templates = await esApi . catTemplates ( this . connection ) ;
236
180
237
- const [ indexTemplates , componentTemplates ] = await Promise . all ( [
238
- fetchIndexTemplates ( ) ,
239
- fetchComponentTemplates ( ) ,
240
- ] ) ;
241
-
242
- this . templates = [ ...indexTemplates , ...componentTemplates ] ;
181
+ this . templates = templates . filter ( template =>
182
+ this . hideSystemIndices ? ! template . name . startsWith ( '.' ) : true ,
183
+ ) ;
243
184
} else {
244
185
this . templates = [ ] ;
245
186
}
0 commit comments