From dc5b12ee0dd9fb28cad67642bc22ea523311bf1f Mon Sep 17 00:00:00 2001 From: Romein van Buren Date: Sun, 29 Jan 2023 20:16:31 +0100 Subject: [PATCH] Form bugfixes --- frontend/src/actions.js | 2 +- .../connection/collection/components/form.svelte | 5 +++-- .../collection/components/viewconfig.svelte | 2 +- .../organisms/connection/collection/insert.svelte | 15 +++++++-------- frontend/src/organisms/connection/hosttree.svelte | 1 + frontend/src/organisms/connection/index.svelte | 2 -- 6 files changed, 13 insertions(+), 14 deletions(-) diff --git a/frontend/src/actions.js b/frontend/src/actions.js index e425351..3a9ba0c 100644 --- a/frontend/src/actions.js +++ b/frontend/src/actions.js @@ -42,7 +42,7 @@ export function input(node, { autofocus, type, onValid, onInvalid, mandatory } = return checkInteger() || checkNumberBoundaries(uint64); case 'string': - if (mandatory && (node.value == '')) { + if (mandatory && (!node.value)) { return 'This field cannot empty'; } return false; diff --git a/frontend/src/organisms/connection/collection/components/form.svelte b/frontend/src/organisms/connection/collection/components/form.svelte index f88f3f8..73cb13a 100644 --- a/frontend/src/organisms/connection/collection/components/form.svelte +++ b/frontend/src/organisms/connection/collection/components/form.svelte @@ -8,7 +8,7 @@ export let valid = false; const validity = {}; - $: valid = Object.values(validity).every(v => !!v); + $: valid = Object.values(validity).every(v => v !== false); const iconMap = { string: 'text', @@ -49,7 +49,7 @@
-
@@ -89,6 +89,7 @@ font-size: 10px; padding: 3px 5px; font-weight: 600; + line-height: 1; } .tag.invalid { background-color: rgba(255, 80, 80, 0.3); diff --git a/frontend/src/organisms/connection/collection/components/viewconfig.svelte b/frontend/src/organisms/connection/collection/components/viewconfig.svelte index e1e09c4..62a68c9 100644 --- a/frontend/src/organisms/connection/collection/components/viewconfig.svelte +++ b/frontend/src/organisms/connection/collection/components/viewconfig.svelte @@ -35,7 +35,7 @@ database: collection.dbKey, collection: collection.key, type: 'table', - columns: [ { key: '_id', showInTable: true, inputType: 'string' } ], + columns: [ { key: '_id', showInTable: true, inputType: 'objectid', mandatory: true } ], }; activeViewKey = newViewKey; } diff --git a/frontend/src/organisms/connection/collection/insert.svelte b/frontend/src/organisms/connection/collection/insert.svelte index 654c739..a97a871 100644 --- a/frontend/src/organisms/connection/collection/insert.svelte +++ b/frontend/src/organisms/connection/collection/insert.svelte @@ -19,15 +19,14 @@ $: viewsForCollection = views.forCollection(collection.hostKey, collection.dbKey, collection.key); $: oppositeViewType = viewType === 'table' ? 'form' : 'table'; + $: if (collection.viewKey !== 'list') { + json = JSON.stringify(newItems, undefined, 2); + } + async function insert() { - if (collection.viewKey === 'list') { - insertedIds = await InsertItems(collection.hostKey, collection.dbKey, collection.key, json); - } - else { - insertedIds = await InsertItems(collection.hostKey, collection.dbKey, collection.key, JSON.stringify(newItems)); - if (insertedIds) { - newItems = []; - } + insertedIds = await InsertItems(collection.hostKey, collection.dbKey, collection.key, json); + if ((collection.viewKey === 'list') && insertedIds) { + newItems = []; } } diff --git a/frontend/src/organisms/connection/hosttree.svelte b/frontend/src/organisms/connection/hosttree.svelte index c37c2e4..48db998 100644 --- a/frontend/src/organisms/connection/hosttree.svelte +++ b/frontend/src/organisms/connection/hosttree.svelte @@ -115,6 +115,7 @@ { label: 'Drop database…', fn: () => dropDatabase(dbKey) }, { separator: true }, { label: 'New database…', fn: () => dispatch('newDatabase') }, + { label: 'New collection…', fn: () => dispatch('newCollection') }, ], })), menu: [ diff --git a/frontend/src/organisms/connection/index.svelte b/frontend/src/organisms/connection/index.svelte index b24e4ff..e262529 100644 --- a/frontend/src/organisms/connection/index.svelte +++ b/frontend/src/organisms/connection/index.svelte @@ -48,7 +48,6 @@ busy.start(); $connections[activeHostKey].databases[newDb.name] = { collections: {} }; newDb = undefined; - await hostTree.reload(); busy.end(); } @@ -73,7 +72,6 @@ busy.start(); $connections[activeHostKey].databases[activeDbKey].collections[newColl.name] = {}; newColl = undefined; - await hostTree.reload(); busy.end(); }