Skip to content

Commit

Permalink
added ability to set configuration while creating index
Browse files Browse the repository at this point in the history
  • Loading branch information
antonkorotkov committed Aug 21, 2021
1 parent d42e402 commit f469178
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/api/elasticsearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,9 @@ export default class API {
*
* @param {*} index
*/
async createIndex(index) {
async createIndex(index, settings = {}) {
try {
const response = await this.client.put(`/${index}`)
const response = await this.client.put(`/${index}`, settings)
return response.data
} catch (err) {
throw new ConnectionError(err)
Expand Down
43 changes: 34 additions & 9 deletions src/components/modal/CreateIndexDialog/CreateIndexDialog.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script>
import { useStoreon } from '@storeon/svelte'
import { onMount, getContext } from 'svelte'
import JSONEditor from 'jsoneditor'
import API from '../../../api/elasticsearch'
import {
Expand All @@ -17,8 +18,11 @@
export let onCancel = () => {}
let indexName = ''
let isLoading = false
let indexName = '',
isLoading = false,
canCreate = true,
settingsEditor,
sEditor
let _indices =
$indices.data.map(
Expand All @@ -33,6 +37,25 @@
onMount(() => {
document.getElementById('index-name').focus()
if (settingsEditor) {
sEditor = new JSONEditor(
settingsEditor,
{
mode: 'code',
onChange: () => {
try {
sEditor.get()
canCreate = true
} catch (e) {
canCreate = false
}
},
},
{}
)
sEditor.aceEditor.setOptions({ maxLines: 32 })
}
})
const _onCancel = () => {
Expand All @@ -45,7 +68,7 @@
try {
const api = new API($connection)
const result = await api.createIndex(indexName)
const result = await api.createIndex(indexName, sEditor.get())
if (result.acknowledged) {
dispatch('notification/add', {
Expand Down Expand Up @@ -87,11 +110,13 @@
on:submit|preventDefault={create}
id="create-index-form"
>
<div class="fields">
<div class="sixteen wide field">
<label for="index-name">Index Name</label>
<input type="text" id="index-name" bind:value={indexName} />
</div>
<div class="field">
<label for="index-name">Index Name</label>
<input type="text" id="index-name" bind:value={indexName} />
</div>
<div class="field">
<label for="settings-editor">Index Configuration</label>
<div id="settings-editor" bind:this={settingsEditor} />
</div>
</form>
</div>
Expand All @@ -102,7 +127,7 @@
</div>
<button
class:inverted
disabled={!isIndexNameAllowed(indexName) || isLoading}
disabled={!isIndexNameAllowed(indexName) || isLoading || !canCreate}
type="submit"
class="ui positive right button"
class:loading={isLoading}
Expand Down

0 comments on commit f469178

Please sign in to comment.