From ccb28783a2e8035cf378328bab0b9d31a1bdc0d0 Mon Sep 17 00:00:00 2001 From: Jan Prochazka Date: Thu, 22 Aug 2024 11:48:34 +0200 Subject: [PATCH] new collection refactor --- packages/web/public/global.css | 18 +----- .../web/src/appobj/DatabaseAppObject.svelte | 12 +--- packages/web/src/commands/stdCommands.ts | 19 +------ packages/web/src/forms/FormArgument.svelte | 25 ++++++++- packages/web/src/forms/FormStringList.svelte | 55 +++++++++++++++++++ .../web/src/modals/NewCollectionModal.svelte | 34 ++++++++++-- 6 files changed, 110 insertions(+), 53 deletions(-) create mode 100644 packages/web/src/forms/FormStringList.svelte diff --git a/packages/web/public/global.css b/packages/web/public/global.css index aa785ed6..f4f427d8 100644 --- a/packages/web/public/global.css +++ b/packages/web/public/global.css @@ -96,7 +96,7 @@ body { max-width: 16.6666%; } -.largeFormMarker input[type='text'] { +.largeFormMarker input[type='text'], .largeFormMarker input[type='number'], .largeFormMarker input[type='password'], .largeFormMarker textarea { width: 100%; padding: 10px 10px; font-size: 14px; @@ -105,13 +105,6 @@ body { border: 1px solid var(--theme-border); } -.largeFormMarker input[type='password'] { - width: 100%; - padding: 10px 10px; - font-size: 14px; - box-sizing: border-box; - border-radius: 4px; -} .largeFormMarker select { width: 100%; @@ -121,15 +114,6 @@ body { border-radius: 4px; } -.largeFormMarker textarea { - width: 100%; - padding: 10px 10px; - font-size: 14px; - box-sizing: border-box; - border-radius: 4px; - border: 1px solid var(--theme-border); -} - body *::-webkit-scrollbar { height: 0.8em; width: 0.8em; diff --git a/packages/web/src/appobj/DatabaseAppObject.svelte b/packages/web/src/appobj/DatabaseAppObject.svelte index d5516f51..b5cb878c 100644 --- a/packages/web/src/appobj/DatabaseAppObject.svelte +++ b/packages/web/src/appobj/DatabaseAppObject.svelte @@ -93,17 +93,7 @@ const handleNewCollection = () => { showModal(NewCollectionModal, { driver, - onConfirm: async values => { - runOperationOnDatabase( - { conid: connection._id, database: name }, - { - type: 'createCollection', - collection: values, - } - ); - - // saveScriptToDatabase({ conid: connection._id, database: name }, `db.createCollection('${newCollection}')`); - }, + dbid: { conid: connection._id, database: name }, }); }; diff --git a/packages/web/src/commands/stdCommands.ts b/packages/web/src/commands/stdCommands.ts index f48684c6..32240988 100644 --- a/packages/web/src/commands/stdCommands.ts +++ b/packages/web/src/commands/stdCommands.ts @@ -294,24 +294,7 @@ registerCommand({ showModal(NewCollectionModal, { driver, - onConfirm: async values => { - // await apiCall('database-connections/run-script', { ...dbid, sql: `db.createCollection('${newCollection}')` }); - const resp = await apiCall('database-connections/run-operation', { - ...dbid, - operation: { - type: 'createCollection', - collection: values, - }, - }); - - const { errorMessage } = resp || {}; - if (errorMessage) { - showModal(ErrorMessageModal, { title: 'Error when executing operation', message: errorMessage }); - } else { - showSnackbarSuccess('Saved to database'); - apiCall('database-connections/sync-model', dbid); - } - }, + dbid, }); }, }); diff --git a/packages/web/src/forms/FormArgument.svelte b/packages/web/src/forms/FormArgument.svelte index 1be37420..ea1bd923 100644 --- a/packages/web/src/forms/FormArgument.svelte +++ b/packages/web/src/forms/FormArgument.svelte @@ -4,6 +4,7 @@ import FormCheckboxField from './FormCheckboxField.svelte'; import FormSelectField from './FormSelectField.svelte'; import FormTextField from './FormTextField.svelte'; + import FormStringList from './FormStringList.svelte'; export let arg; export let namePrefix; @@ -12,9 +13,29 @@ {#if arg.type == 'text'} - + +{:else if arg.type == 'stringlist'} + {:else if arg.type == 'number'} - + {:else if arg.type == 'checkbox'} {:else if arg.type == 'select'} diff --git a/packages/web/src/forms/FormStringList.svelte b/packages/web/src/forms/FormStringList.svelte new file mode 100644 index 00000000..65087271 --- /dev/null +++ b/packages/web/src/forms/FormStringList.svelte @@ -0,0 +1,55 @@ + + + + {#each stringList as value, index} +
+ { + const newValues = stringList.map((v, i) => (i === index ? e.target['value'] : v)); + setFieldValue(name, newValues); + }} + /> + + { + setFieldValue(name, [...stringList.slice(0, index), ...stringList.slice(index + 1)]); + }} + > + + +
+ {/each} + + { + setFieldValue(name, [...stringList, '']); + }} + /> +
+ + \ No newline at end of file diff --git a/packages/web/src/modals/NewCollectionModal.svelte b/packages/web/src/modals/NewCollectionModal.svelte index 4f48026b..17c117d3 100644 --- a/packages/web/src/modals/NewCollectionModal.svelte +++ b/packages/web/src/modals/NewCollectionModal.svelte @@ -5,15 +5,39 @@ import FormProvider from '../forms/FormProvider.svelte'; import FormSubmit from '../forms/FormSubmit.svelte'; import FormTextField from '../forms/FormTextField.svelte'; + import { apiCall } from '../utility/api'; + import { showSnackbarSuccess } from '../utility/snackbar'; + import ErrorMessageModal from './ErrorMessageModal.svelte'; import ModalBase from './ModalBase.svelte'; - import { closeCurrentModal } from './modalTools'; + import { closeCurrentModal, showModal } from './modalTools'; - export let onConfirm; export let driver; + export let dbid; + + let isSaving = false; const handleSubmit = async values => { - closeCurrentModal(); - onConfirm(values); + isSaving = true; + try { + const resp = await apiCall('database-connections/run-operation', { + ...dbid, + operation: { + type: 'createCollection', + collection: values, + }, + }); + + const { errorMessage } = resp || {}; + if (errorMessage) { + showModal(ErrorMessageModal, { title: 'Error when executing operation', message: errorMessage }); + } else { + showSnackbarSuccess('Saved to database'); + apiCall('database-connections/sync-model', dbid); + closeCurrentModal(); + } + } finally { + isSaving = false; + } }; @@ -26,7 +50,7 @@ - handleSubmit(e.detail)} /> + handleSubmit(e.detail)} disabled={isSaving} />