diff --git a/frontend/src/components/details.svelte b/frontend/src/components/details.svelte new file mode 100644 index 0000000..06ac7c1 --- /dev/null +++ b/frontend/src/components/details.svelte @@ -0,0 +1,67 @@ + + +
+ + + {title} + + {#if deletable} + + {/if} + + + +
+ + diff --git a/frontend/src/components/forminput.svelte b/frontend/src/components/forminput.svelte index 2203217..b2dd9fb 100644 --- a/frontend/src/components/forminput.svelte +++ b/frontend/src/components/forminput.svelte @@ -1,18 +1,21 @@
{#if type === 'string'} - + {:else if type === 'objectid'} {:else if numericInputTypes.includes(type)} - + {:else if type === 'bool'} - @@ -120,17 +129,13 @@ } .actions { - display: none; + display: flex; position: absolute; right: 5px; - top: 6px; + top: 5px; background-color: #fff; } .actions button:last-child { border-radius: 2px 6px 6px 2px; } - - .forminput:hover .actions { - display: flex; - } diff --git a/frontend/src/components/grid-items.svelte b/frontend/src/components/grid-items.svelte index d0ac33f..60af9cd 100644 --- a/frontend/src/components/grid-items.svelte +++ b/frontend/src/components/grid-items.svelte @@ -26,7 +26,7 @@ let _items = []; $: refresh(hideObjectIndicators, items); - $: inputsValid = Object.values(validity).every(v => !!v); + $: inputsValid = Object.values(validity).every(v => v !== false); function refresh(hideObjectIndicators, items) { _items = objectToArray(items).map(item => { diff --git a/frontend/src/components/grid.svelte b/frontend/src/components/grid.svelte index 00ce73f..71c53a1 100644 --- a/frontend/src/components/grid.svelte +++ b/frontend/src/components/grid.svelte @@ -1,7 +1,5 @@
@@ -73,14 +64,6 @@ on:trigger /> - - {#if canAddRows} - - - - {/if}
diff --git a/frontend/src/organisms/connection/collection/components/form.svelte b/frontend/src/organisms/connection/collection/components/form.svelte index 5e20194..69e0423 100644 --- a/frontend/src/organisms/connection/collection/components/form.svelte +++ b/frontend/src/organisms/connection/collection/components/form.svelte @@ -23,16 +23,18 @@ }; const keypathProxy = new Proxy(item, { - get: (item, key) => resolveKeypath(item, key), + get: resolveKeypath, set: (item, key, value) => { setValue(item, key, value); - return true; + // eslint-disable-next-line no-self-assign + value = value; + return item; }, }); {#if item && view} - {#each view?.columns?.filter(c => inputTypes.includes(c.inputType)) || [] as column} + {#each view?.columns?.filter(c => inputTypes.includes(c.inputType)) || [] as column, index} {/each} diff --git a/frontend/src/organisms/connection/collection/insert.svelte b/frontend/src/organisms/connection/collection/insert.svelte index 3914932..26b88bd 100644 --- a/frontend/src/organisms/connection/collection/insert.svelte +++ b/frontend/src/organisms/connection/collection/insert.svelte @@ -8,21 +8,33 @@ import ObjectViewer from '../../../components/objectviewer.svelte'; import Grid from '../../../components/grid.svelte'; import { inputTypes, randomString } from '../../../utils'; + import { EJSON } from 'bson'; + import Details from '../../../components/details.svelte'; export let collection; const dispatch = createEventDispatcher(); + const formValidity = {}; let json = ''; let newItems = []; let insertedIds; let objectViewerData = ''; let viewType = 'form'; - let formValid = false; + let allValid = false; $: viewsForCollection = views.forCollection(collection.hostKey, collection.dbKey, collection.key); $: oppositeViewType = viewType === 'table' ? 'form' : 'table'; + $: allValid = Object.values(formValidity).every(v => v !== false); - $: if (collection.viewKey !== 'list') { - json = JSON.stringify(newItems, undefined, 2); + $: { + if (collection.viewKey === 'list') { + try { + newItems = EJSON.parse(json, { relaxed: false }); + } + catch { /* ok */ } + } + else { + json = EJSON.stringify(newItems, undefined, 2, { relaxed: false }); + } } async function insert() { @@ -56,47 +68,69 @@ function addRow() { newItems = [ ...newItems, {} ]; } + + function deleteRow(index) { + newItems.splice(index, 1); + newItems = newItems; + }
- {#if collection.viewKey === 'list'} - - {:else if viewType === 'form'} -
- -
- {:else if viewType === 'table'} -
- inputTypes.includes(c.inputType)) - .map(c => ({ ...c, id: randomString(8), title: c.key })) || [] - } - showHeaders={true} - canAddRows={true} - canSelect={false} - canRemoveItems={true} - hideChildrenToggles={true} - on:addRow={addRow} - bind:inputsValid={formValid} - /> -
- {/if} +
+ {#if collection.viewKey === 'list'} + + {:else if viewType === 'form'} +
+ {#each newItems as item, index} +
deleteRow(index)} + > +
+ +
+
+ {/each} +
+ {:else if viewType === 'table'} +
+ inputTypes.includes(c.inputType)) + .map(c => ({ ...c, id: randomString(8), title: c.key })) || [] + } + showHeaders={true} + canSelect={false} + canRemoveItems={true} + hideChildrenToggles={true} + on:addRow={addRow} + bind:inputsValid={allValid} + /> +
+ {/if} +
+ {#if collection.viewKey !== 'list'} + + {/if} {#if insertedIds} Success! {insertedIds.length} document{insertedIds.length > 1 ? 's' : ''} inserted {/if} @@ -123,7 +157,7 @@ -
@@ -135,11 +169,14 @@