-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
89cbd28
commit 0c6a368
Showing
5 changed files
with
180 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
152 changes: 152 additions & 0 deletions
152
src/components/modal/EditAliasDialog/EditAliasDialog.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters