Skip to content

Commit

Permalink
updating aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
antonkorotkov committed Jul 5, 2020
1 parent 89cbd28 commit 0c6a368
Show file tree
Hide file tree
Showing 5 changed files with 180 additions and 3 deletions.
2 changes: 1 addition & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function createWindow() {
backgroundColor: '#000',
webPreferences: {
nodeIntegration: true,
devTools: false,
devTools: true,
},
})

Expand Down
15 changes: 15 additions & 0 deletions src/api/elasticsearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,21 @@ export default class API {
throw new ConnectionError(err)
}
}

/**
*
* @param {*} index
* @param {*} alias
* @param {*} data
*/
async updateIndexAlias(index, alias, data) {
try {
const response = await this.client.put(`/${index}/_alias/${alias}`, data)
return response.data
} catch (err) {
throw new ConnectionError(err)
}
}
}

class ConnectionError extends Error {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
} else {
dispatch('notification/add', {
type: 'error',
message: `Something went wrong while creating the index`,
message: `Something went wrong while creating the alias`,
})
}
} catch (e) {
Expand Down Expand Up @@ -123,6 +123,7 @@
</div>
</div>
<div class="field">
<label for="filter-editor">Filter</label>
<div id="filter-editor" bind:this={filterEditor} />
</div>
</form>
Expand Down
152 changes: 152 additions & 0 deletions src/components/modal/EditAliasDialog/EditAliasDialog.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
<script>
export let aliases = {}
export let alias = {}
import { useStoreon } from '@storeon/svelte'
import JSONEditor from 'jsoneditor'
import { getContext, onMount, onDestroy } from 'svelte'
import get from 'lodash/get'
import API from '../../../api/elasticsearch'
const { dispatch, connection, index } = useStoreon('connection', 'index')
export let onCancel = () => {}
export let onOkay = () => {}
let indexRouting = '',
searchRouting = '',
isWriteIndex = false,
canSave = true,
filterEditor,
fEditor,
isLoading = false
const { close } = getContext('modal-window')
const _onCancel = () => {
onCancel()
close()
}
const _onOkay = () => {
onOkay(value)
close()
}
const save = async () => {
isLoading = true
try {
const api = new API($connection)
const result = await api.updateIndexAlias($index.selected, alias, {
filter: fEditor.get(),
is_write_index: isWriteIndex,
index_routing: indexRouting,
search_routing: searchRouting,
})
if (result.acknowledged) {
dispatch('notification/add', {
type: 'success',
message: `Alias ${alias} has been updated`,
})
dispatch('elasticsearch/index/fetch')
close()
} else {
dispatch('notification/add', {
type: 'error',
message: `Something went wrong while updating the alias`,
})
}
} catch (e) {
dispatch('notification/add', {
type: 'error',
message: e.message,
})
}
isLoading = false
}
onMount(() => {
const { filter, index_routing, search_routing, is_write_index } = get(
aliases,
alias,
{}
)
indexRouting = index_routing
searchRouting = search_routing
isWriteIndex = is_write_index
if (filterEditor) {
fEditor = new JSONEditor(
filterEditor,
{
mode: 'code',
onChange: () => {
try {
fEditor.get()
canSave = true
} catch (e) {
canSave = false
}
},
},
filter
)
}
})
onDestroy(() => {
if (fEditor) {
fEditor.destroy()
}
})
</script>

<div class="header">Update New Alias</div>

<div class="content">
<form class="ui form" on:submit|preventDefault={save} id="alias-form">
<div class="field">
<label for="index-routing">Index Routing</label>
<input type="text" id="index-routing" bind:value={indexRouting} />
</div>
<div class="field">
<label for="search-routing">Search Routing</label>
<input type="text" id="search-routing" bind:value={searchRouting} />
</div>
<div class="field">
<div class="ui checkbox">
<input
id="is-write-index"
type="checkbox"
bind:checked={isWriteIndex} />
<label for="is-write-index">Is Write Index</label>
</div>
</div>
<div class="field">
<label for="filter-editor">Filter</label>
<div id="filter-editor" bind:this={filterEditor} />
</div>
</form>
</div>

<div class="actions">
<div
class="ui black deny right button"
disabled={isLoading}
on:click={_onCancel}>
Cancel
</div>
<button
type="submit"
class="ui positive right button"
class:loading={isLoading}
form="alias-form"
disabled={!canSave || isLoading}>
Update
</button>
</div>
11 changes: 10 additions & 1 deletion src/workspace/index/tabs/AliasTableCell.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
import { useStoreon } from '@storeon/svelte'
import { getContext } from 'svelte'
import get from 'lodash/get'
import ViewAliasFilterDialog from '../../../components/modal/ViewAliasFilterDialog/ViewAliasFilterDialog.svelte'
import EditAliasDialog from '../../../components/modal/EditAliasDialog/EditAliasDialog.svelte'
import API from '../../../api/elasticsearch'
const { open } = getContext('modal-window')
Expand Down Expand Up @@ -47,7 +49,14 @@
}
const onUpdateClick = () => {
console.log(cell)
open(EditAliasDialog, {
alias: cell,
aliases: get(
$index,
['info', $index.selected, $index.selected, 'aliases'],
{}
),
})
}
</script>

Expand Down

0 comments on commit 0c6a368

Please sign in to comment.