-
{{ t('index_templates.heading') }}
diff --git a/src/composables/components/indextemplates/IndexTemplates.ts b/src/composables/components/indextemplates/IndexTemplates.ts
new file mode 100644
index 00000000..16efbeee
--- /dev/null
+++ b/src/composables/components/indextemplates/IndexTemplates.ts
@@ -0,0 +1,73 @@
+import { useElasticsearchAdapter } from '../../CallElasticsearch.ts'
+import { ref, Ref } from 'vue'
+import { useConnectionStore } from '../../../store/connection.ts'
+
+export type GenericIndexTemplate = {
+ name: string,
+ order?: string,
+ version?: string,
+ priority?: string,
+ template?: string,
+ index_patterns?: string[],
+ indexPatterns?: string,
+ index_template?: {
+ index_patterns?: string[],
+ }
+}
+
+type IndexTemplates = {
+ index_templates?: Record,
+ component_templates?: Record
+} | Record
+
+export const useIndexTemplates = () => {
+ const { requestState, callElasticsearch } = useElasticsearchAdapter()
+ const data: Ref = ref(null)
+ const connectionStore = useConnectionStore()
+
+ const load = async () => {
+ if (!connectionStore.activeCluster) return
+ const majorVersion = parseInt(connectionStore.activeCluster.majorVersion)
+ const method = templateEndpoint(majorVersion)
+ if (!method) return
+
+ return callElasticsearch(method)
+ .then(body => (data.value = enrich(body)))
+ .catch(() => (data.value = null))
+ }
+
+ return {
+ data,
+ requestState,
+ load
+ }
+}
+
+const enrich = (data: IndexTemplates) => {
+ const templates = data.index_templates || data.component_templates || data
+ const results: GenericIndexTemplate[] = []
+ Object.entries(templates).map(([name, template]) => {
+ const indexPatterns = template.index_patterns?.join('') || template.index_template?.index_patterns?.join('') || template.component_template?.index_patterns?.join('') || template.template
+ results.push({
+ name,
+ indexPatterns,
+ ...template,
+ })
+ })
+ return results
+}
+
+const templateEndpoint = (majorVersion: number) => {
+ switch (majorVersion) {
+ case 5:
+ return 'templates'
+ case 6:
+ return 'templates'
+ case 7:
+ return 'templates'
+ case 8:
+ return 'indexTemplates'
+ default:
+ return null
+ }
+}
\ No newline at end of file
diff --git a/src/composables/components/indextemplates/IndexTemplatesTable.ts b/src/composables/components/indextemplates/IndexTemplatesTable.ts
index c1cdb369..25219764 100644
--- a/src/composables/components/indextemplates/IndexTemplatesTable.ts
+++ b/src/composables/components/indextemplates/IndexTemplatesTable.ts
@@ -1,45 +1,36 @@
import { useTranslation } from '../../i18n'
-import { computed, ref } from 'vue'
+import { computed } from 'vue'
import { genColumns } from '../../../helpers/tableColumns'
import { filterItems } from '../../../helpers/filters.ts'
-
-export type EsIndexTemplate = {
- name: string,
- index_patterns: string[],
- order: string,
- version: string,
-}
-
-export type EsIndexTemplates = Record
+import { GenericIndexTemplate } from './IndexTemplates.ts'
+import { useIndexTemplatesStore } from '../../../store/index_templates.ts'
+import { DEFAULT_HIDE_INDICES_REGEX } from '../../../consts.ts'
export type IndexTemplatesTableProps = {
- indexTemplates: EsIndexTemplates
+ indexTemplates: GenericIndexTemplate[]
}
export const useIndexTemplatesTable = (props: IndexTemplatesTableProps) => {
const t = useTranslation()
-
- const filter = ref('')
- const enrichedIndexTemplates = computed(() => {
- return Object.entries(props.indexTemplates).map(([name, template]) => {
- return Object.assign({}, { name }, { indexPatterns: template.index_patterns?.join('') }, template)
- })
- })
+ const indexTemplatesStore = useIndexTemplatesStore()
const filteredItems = computed(() => {
- return filterItems(enrichedIndexTemplates.value, filter.value, ['name', 'indexPatterns'])
+ let results = props.indexTemplates
+ if (results.length === 0) return []
+
+ if (!indexTemplatesStore.showHiddenIndices) {
+ results = results.filter((item: any) => !item.name.match(new RegExp(DEFAULT_HIDE_INDICES_REGEX)))
+ }
+ return filterItems(results, indexTemplatesStore.filter, ['name', 'indexPatterns'])
})
const columns = genColumns([
{ label: '' },
{ label: t('index_templates.index_templates_table.table.headers.name'), field: 'name', },
{ label: t('index_templates.index_templates_table.table.headers.index_patterns') },
- { label: t('index_templates.index_templates_table.table.headers.priority') },
- { label: t('index_templates.index_templates_table.table.headers.version') },
])
return {
- filter,
filteredItems,
columns
}
diff --git a/src/services/ElasticsearchAdapter.ts b/src/services/ElasticsearchAdapter.ts
index 7ebfa1de..526ed21c 100644
--- a/src/services/ElasticsearchAdapter.ts
+++ b/src/services/ElasticsearchAdapter.ts
@@ -72,10 +72,18 @@ export default class ElasticsearchAdapter {
return this.request(`_cat/indices/${query}`, 'GET', params)
}
- catIndexTemplates () {
+ templates () {
return this.request('_template', 'GET')
}
+ indexTemplates () {
+ return this.request('_index_template', 'GET')
+ }
+
+ componentTemplates () {
+ return this.request('_component_template', 'GET')
+ }
+
catShards (params: object, filter?: string) {
const query = filter ? `${filter}*` : ''
return this.request(`_cat/shards/${query}`, 'GET', params)
diff --git a/src/store/index_templates.ts b/src/store/index_templates.ts
new file mode 100644
index 00000000..e682e8ba
--- /dev/null
+++ b/src/store/index_templates.ts
@@ -0,0 +1,31 @@
+import { defineStore } from 'pinia'
+
+type IndexTemplatesState = {
+ filter: string,
+ showHiddenIndices: boolean,
+ stickyTableHeader: boolean,
+ pagination: any,
+}
+
+export const useIndexTemplatesStore = defineStore('indexTemplates', {
+ state: (): IndexTemplatesState => ({
+ filter: '',
+ showHiddenIndices: false,
+ stickyTableHeader: false,
+ pagination: {
+ sortBy: 'index',
+ descending: false,
+ rowsPerPage: 10
+ },
+ }),
+ persist: {
+ paths: [
+ 'filter',
+ 'showHiddenIndices',
+ 'stickyTableHeader',
+ 'pagination.sortBy',
+ 'pagination.descending',
+ 'pagination.rowsPerPage',
+ ]
+ }
+})
diff --git a/src/store/resize.ts b/src/store/resize.ts
index e780b3e1..795e6715 100644
--- a/src/store/resize.ts
+++ b/src/store/resize.ts
@@ -2,6 +2,7 @@ import { defineStore } from 'pinia'
type ResizeState = {
indicesTable: number,
+ indexTemplatesTable: number,
modalLoaderCodeViewer: number,
restForm: number,
searchQuery: number,
@@ -12,6 +13,7 @@ type ResizeState = {
export const useResizeStore = defineStore('resize', {
state: (): ResizeState => ({
indicesTable: 500,
+ indexTemplatesTable: 500,
modalLoaderCodeViewer: 600,
restForm: 400,
searchQuery: 400,