diff --git a/frontend/src/actions.js b/frontend/src/actions.js index eca588a..e425351 100644 --- a/frontend/src/actions.js +++ b/frontend/src/actions.js @@ -1,13 +1,72 @@ -export function input(node, { json, autofocus } = { json: false, autofocus: false }) { +import { int32, int64, isInt, uint64 } from './utils'; + +export function input(node, { autofocus, type, onValid, onInvalid, mandatory } = { + autofocus: false, + type: '', + onValid: () => 0, + onInvalid: () => 0, + mandatory: false, +}) { + + const getMessage = () => { + const checkInteger = () => (isInt(node.value) ? false : 'Value must be an integer'); + const checkNumberBoundaries = boundaries => { + if (node.value < boundaries[0]) { + return `Input is too low for type ${type}`; + } + else if (node.value > boundaries[1]) { + return `Input is too high for type ${type}`; + } + else { + return true; + } + }; + + switch (type) { + case 'json': + try { + JSON.parse(node.value); + return false; + } + catch { + return 'Invalid JSON'; + } + + case 'int': // int32 + return checkInteger() || checkNumberBoundaries(int32); + + case 'long': // int64 + return checkInteger() || checkNumberBoundaries(int64); + + case 'uint64': + return checkInteger() || checkNumberBoundaries(uint64); + + case 'string': + if (mandatory && (node.value == '')) { + return 'This field cannot empty'; + } + return false; + + case 'double': + case 'decimal': + default: + return false; + } + }; + const handleInput = () => { - if (json) { - try { - JSON.parse(node.value); - node.classList.remove('invalid'); - } - catch { - node.classList.add('invalid'); - } + const invalid = getMessage(); + if (invalid) { + node.classList.add('invalid'); + node.setCustomValidity(invalid); + node.reportValidity(); + onInvalid?.(); + } + else { + node.classList.remove('invalid'); + node.setCustomValidity(''); + node.reportValidity(); + onValid?.(); } }; diff --git a/frontend/src/components/grid-items.svelte b/frontend/src/components/grid-items.svelte index b1a5b36..6786d7b 100644 --- a/frontend/src/components/grid-items.svelte +++ b/frontend/src/components/grid-items.svelte @@ -111,7 +111,7 @@ {#if item.children?.length} + + + {/each} +{/if} + + diff --git a/frontend/src/organisms/connection/collection/components/forminput.svelte b/frontend/src/organisms/connection/collection/components/forminput.svelte new file mode 100644 index 0000000..97517a6 --- /dev/null +++ b/frontend/src/organisms/connection/collection/components/forminput.svelte @@ -0,0 +1,76 @@ + + +
+ {#if type === 'string'} + + {:else if numericTypes.includes(type)} + + {:else if type === 'bool'} + + {:else if type === 'date'} + {@const isNotDate = !isDate(value)} + + + {/if} +
+ + diff --git a/frontend/src/organisms/connection/collection/indexes-detail.svelte b/frontend/src/organisms/connection/collection/components/indexdetail.svelte similarity index 94% rename from frontend/src/organisms/connection/collection/indexes-detail.svelte rename to frontend/src/organisms/connection/collection/components/indexdetail.svelte index 8f663cb..94d0ef9 100644 --- a/frontend/src/organisms/connection/collection/indexes-detail.svelte +++ b/frontend/src/organisms/connection/collection/components/indexdetail.svelte @@ -1,8 +1,8 @@ + + + removeView(e.detail)} + bind:selectedKey={activeViewKey} + /> + +
+ {#if $views[activeViewKey]} +
+ {#key activeViewKey} + + {/key} + +
+ + {#if $views[activeViewKey].type === 'list'} +
+ + +
+ {:else if $views[activeViewKey].type === 'table'} +
+ {#each $views[activeViewKey].columns as column, columnIndex} +
+ + + + + + + + + + + + +
+ {:else} +

No columns yet

+ {/each} +
+ + + {/if} + {/if} +
+
+ + diff --git a/frontend/src/organisms/connection/collection/find-viewconfig.svelte b/frontend/src/organisms/connection/collection/find-viewconfig.svelte deleted file mode 100644 index 1039468..0000000 --- a/frontend/src/organisms/connection/collection/find-viewconfig.svelte +++ /dev/null @@ -1,182 +0,0 @@ - - - - removeView(e.detail)} - bind:selectedKey={activeViewKey} - /> - -
- {#if $views[activeViewKey]} -
- {#key activeViewKey} - - {/key} - -
- - {#if $views[activeViewKey].type === 'list'} -
- - -
- {:else if $views[activeViewKey].type === 'table'} - {#each $views[activeViewKey].columns as column, columnIndex} -
- - - - - -
- {/each} - - - {/if} - {/if} -
-
- - diff --git a/frontend/src/organisms/connection/collection/find.svelte b/frontend/src/organisms/connection/collection/find.svelte index 4f7e43d..b251a4e 100644 --- a/frontend/src/organisms/connection/collection/find.svelte +++ b/frontend/src/organisms/connection/collection/find.svelte @@ -1,18 +1,18 @@ @@ -108,19 +106,19 @@