From 8e34bc055d38b1adc84876b59b4f0b5c1ad8c92b Mon Sep 17 00:00:00 2001 From: Arman Date: Thu, 17 Nov 2022 17:28:25 +0100 Subject: [PATCH 001/112] feat: create inputId, add pattern, add char count --- src/lib/components/customId.svelte | 19 +------- src/lib/elements/forms/index.ts | 1 + src/lib/elements/forms/inputId.svelte | 69 +++++++++++++++++++++++++++ 3 files changed, 72 insertions(+), 17 deletions(-) create mode 100644 src/lib/elements/forms/inputId.svelte diff --git a/src/lib/components/customId.svelte b/src/lib/components/customId.svelte index 0596f9c70..9dd9fa0c4 100644 --- a/src/lib/components/customId.svelte +++ b/src/lib/components/customId.svelte @@ -1,7 +1,7 @@ + + +
+ + +
+ {value?.length ?? 0}/36 +
+
+
+
+
From b4c898be201a3c5e84dbfc6f87318bd7aade1d5e Mon Sep 17 00:00:00 2001 From: Arman Date: Thu, 17 Nov 2022 17:37:04 +0100 Subject: [PATCH 002/112] fix: remove unused variable --- src/lib/elements/forms/inputId.svelte | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/lib/elements/forms/inputId.svelte b/src/lib/elements/forms/inputId.svelte index 39ce8717a..cd2584469 100644 --- a/src/lib/elements/forms/inputId.svelte +++ b/src/lib/elements/forms/inputId.svelte @@ -5,7 +5,6 @@ export let value = ''; let element: HTMLInputElement; - let error: string; let icon = 'info'; const pattern = String.raw`/^[^._-][a-zA-Z0-9._-]*$/`; const autofocus = true; @@ -19,21 +18,13 @@ const handleInvalid = (event: Event) => { event.preventDefault(); - if (element.validity.valueMissing) { - error = 'This field is required'; - return; - } - if (element.validity.patternMismatch) { icon = 'exclamation'; return; } - - error = element.validationMessage; }; $: if (value) { - error = null; icon = 'info'; } From e05afbff928f8203fd3bbace577ce3448f914323 Mon Sep 17 00:00:00 2001 From: Arman Date: Wed, 23 Nov 2022 11:47:26 +0100 Subject: [PATCH 003/112] feat:update css --- package-lock.json | 28 +++++++++++++-------------- package.json | 4 ++-- src/lib/elements/forms/inputId.svelte | 9 ++++++--- 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/package-lock.json b/package-lock.json index 785ae480a..0a7d57f97 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,8 +10,8 @@ "dependencies": { "@analytics/google-analytics": "^1.0.5", "@aw-labs/appwrite-console": "^13.0.0", - "@aw-labs/icons": "0.0.0-77", - "@aw-labs/ui": "0.0.0-77", + "@aw-labs/icons": "0.0.0-78", + "@aw-labs/ui": "0.0.0-78", "@popperjs/core": "^2.11.6", "@sentry/svelte": "^7.19.0", "@sentry/tracing": "^7.19.0", @@ -154,14 +154,14 @@ } }, "node_modules/@aw-labs/icons": { - "version": "0.0.0-77", - "resolved": "https://registry.npmjs.org/@aw-labs/icons/-/icons-0.0.0-77.tgz", - "integrity": "sha512-z/gH6B//qShnlJbf1sxv0ltSbRvJha1El0pl4jACAWDD+orgh2hzBrv6YdgPi1AVBTacu2GWWTcyobItghbpgA==" + "version": "0.0.0-78", + "resolved": "https://registry.npmjs.org/@aw-labs/icons/-/icons-0.0.0-78.tgz", + "integrity": "sha512-M1yH0EUanjuHw1McVJfVKrkbHOoSd4PF8ZOYqMXOhSwuwk37MFR8jUapYb2NPu3WdfLTGI6H3N+HwaILePotCg==" }, "node_modules/@aw-labs/ui": { - "version": "0.0.0-77", - "resolved": "https://registry.npmjs.org/@aw-labs/ui/-/ui-0.0.0-77.tgz", - "integrity": "sha512-y/7cbPFcK+jUnarsn9X1arrIB69RVMPWMjjIiiaX7uSa0rq9ZN1agBZxfA63meyh23kdIK4K5CcJhatShMMsYg==", + "version": "0.0.0-78", + "resolved": "https://registry.npmjs.org/@aw-labs/ui/-/ui-0.0.0-78.tgz", + "integrity": "sha512-YjIqkwAqZLvjJ6MQBxTEbAuotXHL1E/LXwmHOH9/Tu6TvF5p8e83LlyHVG6d8rXwsmsGfUcXLJEvEcc8RMEOMQ==", "dependencies": { "@aw-labs/icons": "*", "normalize.css": "^8.0.1", @@ -7749,14 +7749,14 @@ } }, "@aw-labs/icons": { - "version": "0.0.0-77", - "resolved": "https://registry.npmjs.org/@aw-labs/icons/-/icons-0.0.0-77.tgz", - "integrity": "sha512-z/gH6B//qShnlJbf1sxv0ltSbRvJha1El0pl4jACAWDD+orgh2hzBrv6YdgPi1AVBTacu2GWWTcyobItghbpgA==" + "version": "0.0.0-78", + "resolved": "https://registry.npmjs.org/@aw-labs/icons/-/icons-0.0.0-78.tgz", + "integrity": "sha512-M1yH0EUanjuHw1McVJfVKrkbHOoSd4PF8ZOYqMXOhSwuwk37MFR8jUapYb2NPu3WdfLTGI6H3N+HwaILePotCg==" }, "@aw-labs/ui": { - "version": "0.0.0-77", - "resolved": "https://registry.npmjs.org/@aw-labs/ui/-/ui-0.0.0-77.tgz", - "integrity": "sha512-y/7cbPFcK+jUnarsn9X1arrIB69RVMPWMjjIiiaX7uSa0rq9ZN1agBZxfA63meyh23kdIK4K5CcJhatShMMsYg==", + "version": "0.0.0-78", + "resolved": "https://registry.npmjs.org/@aw-labs/ui/-/ui-0.0.0-78.tgz", + "integrity": "sha512-YjIqkwAqZLvjJ6MQBxTEbAuotXHL1E/LXwmHOH9/Tu6TvF5p8e83LlyHVG6d8rXwsmsGfUcXLJEvEcc8RMEOMQ==", "requires": { "@aw-labs/icons": "*", "normalize.css": "^8.0.1", diff --git a/package.json b/package.json index cbd2c487c..0a6855b61 100644 --- a/package.json +++ b/package.json @@ -22,8 +22,8 @@ "@analytics/google-analytics": "^1.0.5", "analytics": "^0.8.1", "@aw-labs/appwrite-console": "^13.0.0", - "@aw-labs/icons": "0.0.0-77", - "@aw-labs/ui": "0.0.0-77", + "@aw-labs/icons": "0.0.0-78", + "@aw-labs/ui": "0.0.0-78", "@popperjs/core": "^2.11.6", "@sentry/svelte": "^7.19.0", "@sentry/tracing": "^7.19.0", diff --git a/src/lib/elements/forms/inputId.svelte b/src/lib/elements/forms/inputId.svelte index cd2584469..6ab53c977 100644 --- a/src/lib/elements/forms/inputId.svelte +++ b/src/lib/elements/forms/inputId.svelte @@ -43,9 +43,12 @@ bind:this={element} on:invalid={handleInvalid} /> -
- {value?.length ?? 0}/36 -
+ + + {value?.length ?? 0} + + 36 +
From caccb3ee2e0dcb89514d6abb63676f8a2a779602 Mon Sep 17 00:00:00 2001 From: Arman Date: Wed, 23 Nov 2022 12:20:52 +0100 Subject: [PATCH 004/112] test: add tests --- tests/unit/elements/inputId.test.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 tests/unit/elements/inputId.test.ts diff --git a/tests/unit/elements/inputId.test.ts b/tests/unit/elements/inputId.test.ts new file mode 100644 index 000000000..aa4e4c795 --- /dev/null +++ b/tests/unit/elements/inputId.test.ts @@ -0,0 +1,22 @@ +import '@testing-library/jest-dom'; +import { render } from '@testing-library/svelte'; +import userEvent from '@testing-library/user-event'; +import { InputId } from '../../../src/lib/elements/forms'; + +test('shows id input', () => { + const { getByPlaceholderText } = render(InputId); + const input = getByPlaceholderText('Enter ID'); + + expect(input).toBeInTheDocument(); + expect(input).toHaveAttribute('type', 'text'); +}); + +test('state', async () => { + const { component, getByPlaceholderText } = render(InputId, { value: '' }); + const input = getByPlaceholderText('Enter ID'); + + console.log(component); + expect(component.value).toEqual(''); + await userEvent.type(input, 'lorem'); + expect(component.value).toEqual('lorem'); +}); From 2fd3a6dc48a591b7742f04b8c5792376e1ec9471 Mon Sep 17 00:00:00 2001 From: tglide <26071571+TGlide@users.noreply.github.com> Date: Mon, 12 Dec 2022 17:46:29 +0000 Subject: [PATCH 005/112] feat: empty arrays UI --- src/lib/elements/forms/inputTags.svelte | 3 +- src/lib/helpers/array.ts | 35 ++++++ .../createDocument.svelte | 5 +- .../document-[document]/attributeForm.svelte | 94 ++++++++++++++++ .../document-[document]/document.svelte | 105 +++--------------- .../wizard/step1.svelte | 84 +------------- .../collection-[collection]/wizard/store.ts | 23 +++- 7 files changed, 174 insertions(+), 175 deletions(-) create mode 100644 src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/document-[document]/attributeForm.svelte diff --git a/src/lib/elements/forms/inputTags.svelte b/src/lib/elements/forms/inputTags.svelte index 93d31f8ac..d9150dc6f 100644 --- a/src/lib/elements/forms/inputTags.svelte +++ b/src/lib/elements/forms/inputTags.svelte @@ -1,4 +1,5 @@ + +{#if attributes.length} +
    + {#each attributes as attribute} + {@const label = attribute.required ? `${attribute.key}*` : attribute.key} + {#if attribute.array} + {#if formValues[attribute.key].length === 0} +
    + {label} + +
    + {/if} + + {#each [...formValues[attribute.key].keys()] as index} +
  • +
    + +
    +
    + +
    +
  • + {/each} + + {#if formValues[attribute.key].length !== 0} + + {/if} + {:else} + + + + {/if} + {/each} + + {#if customId !== undefined} + {#if !showCustomId} +
    + (showCustomId = !showCustomId)}> + +
    + {:else} + + {/if} + {/if} +
+{/if} diff --git a/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/document-[document]/document.svelte b/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/document-[document]/document.svelte index 56f36a8bf..d18b264e9 100644 --- a/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/document-[document]/document.svelte +++ b/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/document-[document]/document.svelte @@ -11,27 +11,27 @@ import type { Models } from '@aw-labs/appwrite-console'; import { Dependencies } from '$lib/constants'; import { invalidate } from '$app/navigation'; - import Attribute from './attribute.svelte'; import { trackEvent } from '$lib/actions/analytics'; + import AttributeForm from './attributeForm.svelte'; let disableUpdate = true; let currentDoc: string; const databaseId = $page.params.database; const collectionId = $page.params.collection; const documentId = $page.params.document; + const work = writable( Object.keys($doc) - .filter( - (key) => - ![ - '$id', - '$collection', - '$collectionId', - '$databaseId', - '$createdAt', - '$updatedAt' - ].includes(key) - ) + .filter((key) => { + return ![ + '$id', + '$collection', + '$collectionId', + '$databaseId', + '$createdAt', + '$updatedAt' + ].includes(key); + }) .reduce((obj, key) => { obj[key] = $doc[key]; return obj; @@ -42,7 +42,7 @@ currentDoc = JSON.stringify($work); }); - $: if (currentDoc && $work) { + $: { if (currentDoc !== JSON.stringify($work)) { disableUpdate = false; } else { @@ -77,90 +77,13 @@ }); } } - - function addArrayItem(key: string) { - work.update((n) => { - if (!Array.isArray(n[key])) { - n[key] = []; - } - n[key].push(null); - - return n; - }); - } - - function removeArrayItem(key: string, index: number) { - work.update((n) => { - n[key].splice(index, 1); - - return n; - }); - } Update Data

Update document data based on the attributes created earlier.

-
- {#each $collection.attributes.filter((a) => a.status === 'available') as attribute} - {#if attribute.array} -
    - {#each [...$work[attribute.key].keys()] as index} -
  • -
    - -
    -
    - -
    -
  • - {:else} -
  • -
    - -
    -
    - -
    -
  • - {/each} -
- - - {:else} -
    - -
- {/if} - {/each} -
+
diff --git a/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/wizard/step1.svelte b/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/wizard/step1.svelte index e9da37025..1df88ae0c 100644 --- a/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/wizard/step1.svelte +++ b/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/wizard/step1.svelte @@ -1,28 +1,7 @@ @@ -31,61 +10,8 @@ Provide document data based on attributes you created earlier. - {#if $createDocument.attributes.length} - - {#each $createDocument.attributes as attribute} - {@const label = attribute.required ? `${attribute.key}*` : attribute.key} - {#if attribute.array} - {#each [...$createDocument.document[attribute.key].keys()] as index} -
  • -
    - -
    -
    - -
    -
  • - {/each} - - {:else} - - - - {/if} - {/each} - {#if !showCustomId} -
    - (showCustomId = !showCustomId)}> - -
    - {:else} - - {/if} -
    - {/if} + diff --git a/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/wizard/store.ts b/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/wizard/store.ts index eea107307..04cd8ed9f 100644 --- a/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/wizard/store.ts +++ b/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/wizard/store.ts @@ -1,14 +1,31 @@ import { writable } from 'svelte/store'; import type { Attributes } from '../store'; -export const createDocument = writable<{ +type CreateDocument = { id?: string; document: object; permissions: string[]; attributes: Attributes[]; -}>({ +}; + +const initialCreateDocument: CreateDocument = { id: null, document: {}, permissions: [], attributes: [] -}); +}; + +function createDocumentWritable() { + const store = writable({ ...initialCreateDocument }); + + const reset = () => { + store.set({ ...initialCreateDocument }); + }; + + return { + ...store, + reset + }; +} + +export const createDocument = createDocumentWritable(); From 7c784f78afef3dc9006109bd6c8c774070e151a1 Mon Sep 17 00:00:00 2001 From: tglide <26071571+TGlide@users.noreply.github.com> Date: Mon, 12 Dec 2022 17:49:26 +0000 Subject: [PATCH 006/112] chore: remove date on array jsdoc --- src/lib/helpers/array.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/lib/helpers/array.ts b/src/lib/helpers/array.ts index 47bddeb77..57468b22d 100644 --- a/src/lib/helpers/array.ts +++ b/src/lib/helpers/array.ts @@ -50,7 +50,6 @@ export function at(array: readonly T[] | [], index: number): T | undefined { /** * Get last item - * @date 12/12/2022 - 12:08:03 PM * * @export * @template T From f1b4205fe67d690ddee7627ba474029b07abcfd9 Mon Sep 17 00:00:00 2001 From: tglide <26071571+TGlide@users.noreply.github.com> Date: Mon, 12 Dec 2022 18:38:10 +0000 Subject: [PATCH 007/112] feat: add attribute types to input labels --- src/lib/elements/forms/inputCheckbox.svelte | 3 + src/lib/elements/forms/inputDateTime.svelte | 3 + src/lib/elements/forms/inputNumber.svelte | 3 + src/lib/elements/forms/inputSelect.svelte | 3 + src/lib/elements/forms/inputText.svelte | 7 +- src/lib/helpers/object.ts | 75 +++++++++++++++++++ src/lib/helpers/string.ts | 10 +++ .../document-[document]/attribute.svelte | 3 + .../document-[document]/attributeForm.svelte | 55 +++++++++----- .../attributes/boolean.svelte | 4 +- .../attributes/datetime.svelte | 9 ++- .../attributes/enum.svelte | 2 + .../attributes/integer.svelte | 2 + .../attributes/string.svelte | 2 + .../collection-[collection]/store.ts | 7 ++ tests/unit/helpers/object.test.ts | 74 ++++++++++++++++++ 16 files changed, 239 insertions(+), 23 deletions(-) create mode 100644 src/lib/helpers/object.ts create mode 100644 src/lib/helpers/string.ts create mode 100644 tests/unit/helpers/object.test.ts diff --git a/src/lib/elements/forms/inputCheckbox.svelte b/src/lib/elements/forms/inputCheckbox.svelte index cecc2a441..62de5ec3e 100644 --- a/src/lib/elements/forms/inputCheckbox.svelte +++ b/src/lib/elements/forms/inputCheckbox.svelte @@ -2,6 +2,7 @@ import { FormItem, Helper } from '.'; export let label: string; + export let optionalText: string | undefined = undefined; export let showLabel = true; export let id: string; export let value = false; @@ -27,6 +28,8 @@ + {optionalText} +
    + {optionalText} +
    + {optionalText} +
    + {optionalText} +
    (obj: T) { + return Object.entries(obj) as Array<[keyof T, T[keyof T]]>; +} + +type KeyTypesMap = Record | ((v: unknown) => boolean) | string>; +/** + * Checks if the given value is an object of type T, given a map of keys and + * their types/validators. + * + * @category Object + * + * @template T + * @param {unknown} object + * @param {KeyTypesMap} keyTypesMap + * @returns {value is T} + * + * @example + * ``` + * type ExampleType = { + * a: string; + * b: number; + * c: string | number; + * d: string[] + * e: { + * f: string; + * g: number; + * } + * } + * + * export const isExampleType = (value: unknown): value is ExampleType => { + * return isObjectType(value, { + * a: 'string', + * b: 'number', + * c: ['string', 'number'], + * d: (v) => Array.isArray(v) && v.every((v) => typeof v === 'string'), + * e: (v) => isObjectType(v, { + * f: 'string', + * g: 'number', + * }), + * }); + * }; + * ``` + */ +export const isObjectType = ( + object: unknown, + keyTypesMap: Partial> +): object is T => { + if (typeof object !== 'object' || object === null) { + return false; + } + + for (const [key, check] of objectEntries(keyTypesMap)) { + const value = (object as Record)[key]; + + if (typeof check === 'function') { + if (!check(value)) { + return false; + } + } else if (typeof check === 'string') { + if (typeof value !== check) { + return false; + } + } else if (!check.includes(typeof value)) { + return false; + } + } + + return true; +}; diff --git a/src/lib/helpers/string.ts b/src/lib/helpers/string.ts new file mode 100644 index 000000000..e67be0e07 --- /dev/null +++ b/src/lib/helpers/string.ts @@ -0,0 +1,10 @@ +/** + * Capitalizes the first letter of a string + * + * @export + * @param {string} str + * @returns {string} + */ +export function capitalize(str: string): string { + return str.charAt(0).toUpperCase() + str.slice(1); +} diff --git a/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/document-[document]/attribute.svelte b/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/document-[document]/attribute.svelte index 1a390b645..80c66eb4b 100644 --- a/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/document-[document]/attribute.svelte +++ b/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/document-[document]/attribute.svelte @@ -9,6 +9,7 @@ export let id: string; export let label: string; export let value: string | number | boolean; + export let optionalText: string | undefined = undefined; export let attribute: | Models.AttributeBoolean | Models.AttributeEmail @@ -43,6 +44,7 @@ {id} {label} {attribute} + {optionalText} bind:value /> {:else} {/if} {/if} diff --git a/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/document-[document]/attributeForm.svelte b/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/document-[document]/attributeForm.svelte index 7cb95c5ab..0cd78ae5d 100644 --- a/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/document-[document]/attributeForm.svelte +++ b/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/document-[document]/attributeForm.svelte @@ -3,7 +3,8 @@ import { FormList } from '$lib/elements/forms'; import Button from '$lib/elements/forms/button.svelte'; import Pill from '$lib/elements/pill.svelte'; - import type { Attributes } from '../store'; + import { capitalize } from '$lib/helpers/string'; + import { isAttributeEnum, type Attributes } from '../store'; import Attribute from './attribute.svelte'; export let attributes: Attributes[] = []; @@ -26,6 +27,11 @@ [key]: [...formValues[key], null] }; } + + function getAttributeType(attribute: Attributes) { + if (isAttributeEnum(attribute)) return 'Enum'; + return `${capitalize(attribute.type)}${attribute.array ? '[]' : ''}`; + } {#if attributes.length} @@ -35,7 +41,11 @@ {#if attribute.array} {#if formValues[attribute.key].length === 0}
    - {label} +
    + {label} + {getAttributeType(attribute)} +
    +
    {/if} - {#each [...formValues[attribute.key].keys()] as index} -
  • -
    - -
    -
    - -
    -
  • - {/each} - {#if formValues[attribute.key].length !== 0} +
      + {#each [...formValues[attribute.key].keys()] as index} +
    • +
      + +
      +
      + +
      +
    • + {/each} +
    - - + From 107a3e3150525b8b30cb1dc54466c0dd3e41db8d Mon Sep 17 00:00:00 2001 From: tglide <26071571+TGlide@users.noreply.github.com> Date: Wed, 14 Dec 2022 18:04:29 +0000 Subject: [PATCH 013/112] refactor: code organization --- src/lib/components/eventModal.svelte | 54 ++++++++++++++-------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/src/lib/components/eventModal.svelte b/src/lib/components/eventModal.svelte index 5c4cc8024..b91ba051c 100644 --- a/src/lib/components/eventModal.svelte +++ b/src/lib/components/eventModal.svelte @@ -154,6 +154,29 @@ } } + // Event string helpers + const serviceNames = services.map((s) => s.name); + const isService = (s: string) => serviceNames.includes(s); + + const resourceNames = services.flatMap((s) => s.resources.map((r) => r.name)); + const isResource = (s: string) => resourceNames.includes(s); + + const actionNames = [ + ...services.flatMap((s) => s.actions.map((a) => a.name)), + ...services.flatMap((s) => s.resources.flatMap((r) => r.actions.map((a) => a.name))) + ]; + const isAction = (s: string) => actionNames.includes(s); + + const attributeNames = [ + ...services.flatMap((s) => s.actions.flatMap((a) => a.attributes ?? [])), + ...services.flatMap((s) => + s.resources.flatMap((r) => r.actions.flatMap((a) => a.attributes ?? [])) + ) + ]; + const isAttribute = (s: string) => attributeNames.includes(s); + + const isField = (s: string) => isService(s) || isResource(s) || isAction(s) || isAttribute(s); + // State & Reactive Declarations let selected = { service: null as Service | null, @@ -173,25 +196,6 @@ attributes: selected.action?.attributes || [] }; - // Event string helpers - const serviceNames = services.map((s) => s.name); - const isService = (s: string) => serviceNames.includes(s); - const resourceNames = services.flatMap((s) => s.resources.map((r) => r.name)); - const isResource = (s: string) => resourceNames.includes(s); - const actionNames = [ - ...services.flatMap((s) => s.actions.map((a) => a.name)), - ...services.flatMap((s) => s.resources.flatMap((r) => r.actions.map((a) => a.name))) - ]; - const isAction = (s: string) => actionNames.includes(s); - const attributeNames = [ - ...services.flatMap((s) => s.actions.flatMap((a) => a.attributes ?? [])), - ...services.flatMap((s) => - s.resources.flatMap((r) => r.actions.flatMap((a) => a.attributes ?? [])) - ) - ]; - const isAttribute = (s: string) => attributeNames.includes(s); - const isField = (s: string) => isService(s) || isResource(s) || isAction(s) || isAttribute(s); - $: eventString = (function createEventString(): Array<{ value: string; description: string }> { let fields: string[] = []; @@ -221,6 +225,7 @@ } return fields.map((value, i, arr) => { + const prev = arr[i - 1]; let description = value; if (isService(value)) { @@ -229,15 +234,10 @@ description = 'resource'; } else if (isAction(value)) { description = 'action'; - } else if (isAttribute(value)) { + } else if (isAttribute(value) || isAction(prev)) { description = 'attribute'; - } else if (i > 0) { - const prev = arr[i - 1]; - if (isAction(prev)) { - description = 'attribute'; - } else if (isField(prev)) { - description = `ID of ${prev.slice(0, -1)}`; - } + } else if (isField(prev)) { + description = `ID of ${prev.slice(0, -1)}`; } return { value, description }; From df29f3e28f2b07d01e1a46674bb60f8197dee1a9 Mon Sep 17 00:00:00 2001 From: tglide <26071571+TGlide@users.noreply.github.com> Date: Wed, 14 Dec 2022 18:57:47 +0000 Subject: [PATCH 014/112] feat: custom input helper --- src/lib/components/eventModal.svelte | 79 +++++++++++++++++++++------- src/lib/helpers/array.ts | 34 ++++++++++++ 2 files changed, 94 insertions(+), 19 deletions(-) diff --git a/src/lib/components/eventModal.svelte b/src/lib/components/eventModal.svelte index b91ba051c..3686b8fad 100644 --- a/src/lib/components/eventModal.svelte +++ b/src/lib/components/eventModal.svelte @@ -3,7 +3,7 @@ import { Modal } from '$lib/components'; import { Pill } from '$lib/elements'; import { createEventDispatcher } from 'svelte'; - import { empty } from '$lib/helpers/array'; + import { at, empty, last } from '$lib/helpers/array'; import Copy from './copy.svelte'; // Props @@ -154,6 +154,56 @@ } } + function resetSelected() { + Object.keys(selected).forEach((key) => (selected[key] = null)); + } + + function toggleShowInput(e?: Event) { + e?.preventDefault(); + + showInput = !showInput; + if (showInput) return; + + helper = null; + + resetSelected(); + + for (const field of customInput.split('.')) { + if (isService(field)) { + selected.service = services.find((s) => s.name === field); + } else if (isResource(field)) { + const resource = selected.service?.resources.find((r) => r.name === field); + selected.resource = resource; + } else if (isAction(field)) { + const action = + selected.resource?.actions.find((a) => a.name === field) || + selected.service?.actions.find((a) => a.name === field); + selected.action = action; + } else if (isAttribute(field)) { + const attribute = selected.action?.attributes?.find((a) => a === field); + selected.attribute = attribute; + } + } + } + + function getHelperStr(input: string): string { + const fields = input.split('.'); + const secondToLastField = at(fields, -3); + const prevField = at(fields, -2); + const currField = last(fields); + + if (fields.length === 1) return 'service'; + if (isAttribute(currField) || isAction(prevField)) return 'attribute'; + if (isAction(currField)) return 'action'; + if (isResource(currField)) return 'resource'; + if (isService(currField)) return 'service'; + if (isService(prevField) || isResource(prevField)) return `ID of ${prevField}`; + if (isService(secondToLastField)) return 'resource or action'; + if (isResource(secondToLastField)) return 'action'; + + return ''; + } + // Event string helpers const serviceNames = services.map((s) => s.name); const isService = (s: string) => serviceNames.includes(s); @@ -246,16 +296,16 @@ $: inputValue = eventString.map((d) => d.value).join('.'); - $: if (!showInput) { - helper = null; - } - $: if (!show) { - Object.keys(selected).forEach((key) => (selected[key] = null)); + resetSelected(); helper = null; customInput = null; showInput = false; } + + $: if (showInput) { + helper = getHelperStr(customInput); + } @@ -331,23 +381,14 @@
    - -
    +

    {helper ?? ''}

    {:else}
    @@ -368,7 +409,7 @@ - + diff --git a/src/routes/console/project-[project]/functions/function-[function]/settings/+page.svelte b/src/routes/console/project-[project]/functions/function-[function]/settings/+page.svelte index 9313c97a0..ab6af3c11 100644 --- a/src/routes/console/project-[project]/functions/function-[function]/settings/+page.svelte +++ b/src/routes/console/project-[project]/functions/function-[function]/settings/+page.svelte @@ -50,6 +50,10 @@ const eventSet: Writable> = writable(new Set()); let showEvents = false; + let eventValue: string; + $: if (!showEvents) { + eventValue = undefined; + } let areEventsDisabled = true; onMount(async () => { @@ -271,7 +275,15 @@ } function handleEvent(event: CustomEvent) { - eventSet.set($eventSet.add(event.detail)); + if (eventValue) { + const newSet = new Set( + [...$eventSet].map((e) => (e === eventValue ? event.detail : e)) + ); + eventSet.set(newSet); + } else { + eventSet.set($eventSet.add(event.detail)); + } + eventValue = null; } $: if (permissions) { @@ -370,16 +382,27 @@ {event} - - + +
    + + +
    {/each} @@ -600,4 +623,4 @@ on:updated={handleVariableUpdated} /> {/if} - + From 6e8748095b44646ab90fa79030b29bd9bee74d91 Mon Sep 17 00:00:00 2001 From: tglide <26071571+TGlide@users.noreply.github.com> Date: Thu, 15 Dec 2022 13:46:01 +0000 Subject: [PATCH 019/112] refactor: move eventModal constants --- src/lib/components/eventModal.svelte | 138 +++++++-------------------- src/lib/constants.ts | 84 ++++++++++++++++ 2 files changed, 117 insertions(+), 105 deletions(-) diff --git a/src/lib/components/eventModal.svelte b/src/lib/components/eventModal.svelte index 46902b663..d4207ad9e 100644 --- a/src/lib/components/eventModal.svelte +++ b/src/lib/components/eventModal.svelte @@ -7,96 +7,19 @@ import Copy from './copy.svelte'; import { selectionStart } from '$lib/actions/selectionStart'; import { singular } from '$lib/helpers/string'; + import { + eventServices as services, + type EventAction, + type EventResource, + type EventService + } from '$lib/constants'; + import { tooltip } from '$lib/actions/tooltip'; // Props export let show = false; export let initialValue = ''; - // Types & Constants - type Service = { - name: string; - resources: Resource[]; - actions?: Action[]; - }; - - type Resource = { - name: string; - actions?: Action[]; - }; - - type Action = { - name: string; - attributes?: string[]; - }; - - const services: Array = [ - { - name: 'buckets', - resources: [ - { - name: 'files', - actions: [{ name: 'create' }, { name: 'update' }, { name: 'delete' }] - } - ], - actions: [{ name: 'create' }, { name: 'update' }, { name: 'delete' }] - }, - { - name: 'databases', - resources: [ - { - name: 'collections', - actions: [{ name: 'create' }, { name: 'update' }, { name: 'delete' }] - }, - { - name: 'documents', - actions: [{ name: 'create' }, { name: 'update' }, { name: 'delete' }] - } - ], - actions: [{ name: 'create' }, { name: 'update' }, { name: 'delete' }] - }, - { - name: 'functions', - resources: [ - { - name: 'deployments', - actions: [{ name: 'create' }, { name: 'update' }, { name: 'delete' }] - }, - { - name: 'executions', - actions: [{ name: 'create' }, { name: 'update' }, { name: 'delete' }] - } - ], - actions: [{ name: 'create' }, { name: 'update' }, { name: 'delete' }] - }, - { - name: 'teams', - resources: [ - { - name: 'memberships', - actions: [ - { name: 'create' }, - { name: 'update', attributes: ['status'] }, - { name: 'delete' } - ] - } - ], - actions: [{ name: 'create' }, { name: 'update' }, { name: 'delete' }] - }, - { - name: 'users', - resources: [ - { name: 'recovery', actions: [{ name: 'create' }, { name: 'delete' }] }, - { name: 'sessions', actions: [{ name: 'create' }, { name: 'delete' }] }, - { name: 'verifications', actions: [{ name: 'create' }, { name: 'delete' }] } - ], - actions: [ - { name: 'create' }, - { name: 'update', attributes: ['email', 'name', 'password', 'status', 'prefs'] }, - { name: 'delete' } - ] - } - ]; - + // Constants const serviceNames = services.map((s) => s.name); const resourceNames = services.flatMap((s) => s.resources.map((r) => r.name)); const actionNames = [ @@ -123,11 +46,11 @@ dispatch('created', inputValue); } - function select(field: 'service', value: Service); - function select(field: 'resource', value: Resource); - function select(field: 'action', value: Action); + function select(field: 'service', value: EventService); + function select(field: 'resource', value: EventResource); + function select(field: 'action', value: EventAction); function select(field: 'attribute', value: string); - function select(field: string, value: string | Service | Resource | Action) { + function select(field: string, value: string | EventService | EventResource | EventAction) { if (typeof value === 'string') { selected[field as 'attribute'] = selected[field] === value ? null : value; } else { @@ -220,6 +143,7 @@ if (isService(prevField) || isResource(prevField) || index === 1) { return `ID of ${singular(prevField)}`; } + // TODO: Find better name for 'resource or action' if (isService(secondToLastField) || index === 2) return 'resource or action'; if (isResource(secondToLastField)) return 'action'; @@ -249,9 +173,9 @@ // State & Reactive Declarations let selected = { - service: null as Service | null, - resource: null as Resource | null, - action: null as Action | null, + service: null as EventService | null, + resource: null as EventResource | null, + action: null as EventAction | null, attribute: null as string | null }; let helper: string = null; @@ -418,22 +342,26 @@ {/each}
    - - + + + {/key}

    {helper ?? ''}

    diff --git a/src/lib/constants.ts b/src/lib/constants.ts index 721c3db12..a27a1c21d 100644 --- a/src/lib/constants.ts +++ b/src/lib/constants.ts @@ -174,3 +174,87 @@ export const scopes: { category: 'Other' } ]; + +export type EventService = { + name: string; + resources: EventResource[]; + actions?: EventAction[]; +}; + +export type EventResource = { + name: string; + actions?: EventAction[]; +}; + +export type EventAction = { + name: string; + attributes?: string[]; +}; + +export const eventServices: Array = [ + { + name: 'buckets', + resources: [ + { + name: 'files', + actions: [{ name: 'create' }, { name: 'update' }, { name: 'delete' }] + } + ], + actions: [{ name: 'create' }, { name: 'update' }, { name: 'delete' }] + }, + { + name: 'databases', + resources: [ + { + name: 'collections', + actions: [{ name: 'create' }, { name: 'update' }, { name: 'delete' }] + }, + { + name: 'documents', + actions: [{ name: 'create' }, { name: 'update' }, { name: 'delete' }] + } + ], + actions: [{ name: 'create' }, { name: 'update' }, { name: 'delete' }] + }, + { + name: 'functions', + resources: [ + { + name: 'deployments', + actions: [{ name: 'create' }, { name: 'update' }, { name: 'delete' }] + }, + { + name: 'executions', + actions: [{ name: 'create' }, { name: 'update' }, { name: 'delete' }] + } + ], + actions: [{ name: 'create' }, { name: 'update' }, { name: 'delete' }] + }, + { + name: 'teams', + resources: [ + { + name: 'memberships', + actions: [ + { name: 'create' }, + { name: 'update', attributes: ['status'] }, + { name: 'delete' } + ] + } + ], + actions: [{ name: 'create' }, { name: 'update' }, { name: 'delete' }] + }, + { + name: 'users', + resources: [ + { name: 'recovery', actions: [{ name: 'create' }, { name: 'delete' }] }, + { name: 'sessions', actions: [{ name: 'create' }, { name: 'delete' }] }, + { name: 'verifications', actions: [{ name: 'create' }, { name: 'delete' }] } + ], + actions: [ + { name: 'create' }, + { name: 'update', attributes: ['email', 'name', 'password', 'status', 'prefs'] }, + { name: 'delete' } + ] + } +]; From 26690c7a847e96eebe600a1fd4bfbaa4fa8f6e50 Mon Sep 17 00:00:00 2001 From: tglide <26071571+TGlide@users.noreply.github.com> Date: Thu, 15 Dec 2022 18:35:25 +0000 Subject: [PATCH 020/112] refactor: document table improvements --- src/lib/actions/tooltip.ts | 11 ++++- src/lib/elements/forms/inputNumber.svelte | 2 +- .../[[page]]/+page.svelte | 48 ++++++++++++++++++- .../document-[document]/attributeForm.svelte | 2 +- 4 files changed, 58 insertions(+), 5 deletions(-) diff --git a/src/lib/actions/tooltip.ts b/src/lib/actions/tooltip.ts index 1636a14ec..b4dc14a5f 100644 --- a/src/lib/actions/tooltip.ts +++ b/src/lib/actions/tooltip.ts @@ -1,17 +1,24 @@ import type { Action } from 'svelte/action'; -import type { Props } from 'tippy.js'; +import type { Props as TippyProps } from 'tippy.js'; import tippy from 'tippy.js'; +type Props = TippyProps & { + disabled?: boolean; +}; + export const tooltip: Action> = (node, config) => { const instance = tippy(node, config); + if (config.disabled) instance.disable(); return { - update({ content }) { + update({ content, disabled }) { if (content !== instance.props.content) { instance.setProps({ content }); } + + disabled ? instance.disable() : instance.enable(); }, destroy() { instance.destroy(); diff --git a/src/lib/elements/forms/inputNumber.svelte b/src/lib/elements/forms/inputNumber.svelte index d10fe0b05..6a2650ef4 100644 --- a/src/lib/elements/forms/inputNumber.svelte +++ b/src/lib/elements/forms/inputNumber.svelte @@ -52,7 +52,7 @@ - + {optionalText}
    diff --git a/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/[[page]]/+page.svelte b/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/[[page]]/+page.svelte index 4aed513a9..a5416a323 100644 --- a/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/[[page]]/+page.svelte +++ b/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/[[page]]/+page.svelte @@ -19,6 +19,7 @@ import { page } from '$app/stores'; import { PAGE_LIMIT } from '$lib/constants'; import CreateAttribute from '../createAttribute.svelte'; + import { tooltip } from '$lib/actions/tooltip'; export let data: PageData; let showCreateAttribute = false; @@ -33,6 +34,44 @@ title: attribute.key })) ]; + + function formatArray(array: any[]) { + if (array.length === 0) return '[ ]'; + + let formattedFields: string[] = []; + for (const item of array) { + if (typeof item === 'string') { + formattedFields.push(`"${item}"`); + } else { + formattedFields.push(`${item}`); + } + } + + return `[${formattedFields.join(', ')}]`; + } + + function formatColumn(column: any) { + let formattedColumn: string; + + if (typeof column === 'string') { + formattedColumn = column; + } else if (Array.isArray(column)) { + formattedColumn = formatArray(column); + } else if (!column) { + formattedColumn = 'n/a'; + } else { + formattedColumn = `${column}`; + } + + return { + value: + formattedColumn.length > 20 + ? `${formattedColumn.slice(0, 20)}...` + : formattedColumn, + truncated: formattedColumn.length > 20, + whole: formattedColumn + }; + } @@ -70,8 +109,15 @@ {#each columns as column} + {@const formatted = formatColumn(document[column.key])} - {document[column.key] ?? 'n/a'} +
    + {formatted.value} +
    {/each} diff --git a/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/document-[document]/attributeForm.svelte b/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/document-[document]/attributeForm.svelte index 0cd78ae5d..80ca27509 100644 --- a/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/document-[document]/attributeForm.svelte +++ b/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/document-[document]/attributeForm.svelte @@ -60,10 +60,10 @@
    From df3544e1033022c1843d226f0f81120e32a25f0d Mon Sep 17 00:00:00 2001 From: tglide <26071571+TGlide@users.noreply.github.com> Date: Thu, 15 Dec 2022 19:19:52 +0000 Subject: [PATCH 021/112] refactor: separate updateEvents & use droplist for event options --- .../function-[function]/settings/+page.svelte | 154 ++---------------- .../settings/updateEvents.svelte | 144 ++++++++++++++++ 2 files changed, 160 insertions(+), 138 deletions(-) create mode 100644 src/routes/console/project-[project]/functions/function-[function]/settings/updateEvents.svelte diff --git a/src/routes/console/project-[project]/functions/function-[function]/settings/+page.svelte b/src/routes/console/project-[project]/functions/function-[function]/settings/+page.svelte index ab6af3c11..23dea10c9 100644 --- a/src/routes/console/project-[project]/functions/function-[function]/settings/+page.svelte +++ b/src/routes/console/project-[project]/functions/function-[function]/settings/+page.svelte @@ -1,37 +1,26 @@ @@ -370,60 +307,7 @@ -
    - - Update Events -

    Set the events that will trigger your function. Maximum 100 events allowed.

    - - {#if $eventSet.size} - - {#each Array.from($eventSet) as event} -
  • - - {event} - - -
    - - -
    -
    -
  • - {/each} -
    - -
    - -
    - {:else} - (showEvents = true)}>Add an event to get started - {/if} -
    - - - - -
    -
    +
    @@ -484,10 +368,6 @@ Download .env file -
    @@ -622,5 +502,3 @@ on:created={handleVariableCreated} on:updated={handleVariableUpdated} /> {/if} - - diff --git a/src/routes/console/project-[project]/functions/function-[function]/settings/updateEvents.svelte b/src/routes/console/project-[project]/functions/function-[function]/settings/updateEvents.svelte new file mode 100644 index 000000000..901b53c73 --- /dev/null +++ b/src/routes/console/project-[project]/functions/function-[function]/settings/updateEvents.svelte @@ -0,0 +1,144 @@ + + + + + Update Events +

    Set the events that will trigger your function. Maximum 100 events allowed.

    + + {#if $eventSet.size} + + {#each Array.from($eventSet) as event, i} +
  • + + {event} + + + + + + { + showDropdown[i] = false; + showEvents = true; + eventValue = event; + }}> + Edit + + { + $eventSet.delete(event); + eventSet.set($eventSet); + }}> + Delete + + + + +
  • + {/each} +
    + +
    + +
    + {:else} + (showEvents = true)}>Add an event to get started + {/if} +
    + + + + +
    + + + From bb2f10e84520fa0034801a1a68ea55d419780234 Mon Sep 17 00:00:00 2001 From: tglide <26071571+TGlide@users.noreply.github.com> Date: Thu, 15 Dec 2022 19:21:52 +0000 Subject: [PATCH 022/112] fix: event action naming convetions --- src/lib/components/eventModal.svelte | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/lib/components/eventModal.svelte b/src/lib/components/eventModal.svelte index d4207ad9e..9aadc6828 100644 --- a/src/lib/components/eventModal.svelte +++ b/src/lib/components/eventModal.svelte @@ -218,8 +218,6 @@ } if (selected.attribute) { fields.push(selected.attribute); - } else if (selected.action?.attributes) { - fields.push('*'); } } From 1a3959501bc3be1cdb63e9843d19529a5b3bcdea Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 10 Jan 2023 15:56:35 +0100 Subject: [PATCH 023/112] Merge branch 'main' of github.com:appwrite/console into feat-custom-id-pattern --- package-lock.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index 766f48f5c..8a793cced 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5399,9 +5399,9 @@ "dev": true }, "node_modules/json5": { - "version": "2.2.1", - "resolved": "https://registry.npmjs.org/json5/-/json5-2.2.1.tgz", - "integrity": "sha512-1hqLFMSrGHRHxav9q9gNjJ5EXznIxGVO09xQRrwplcS8qs28pZ8s8hupZAmqDwZUmVZ2Qb2jnyPOWcDH8m8dlA==", + "version": "2.2.3", + "resolved": "https://registry.npmjs.org/json5/-/json5-2.2.3.tgz", + "integrity": "sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==", "dev": true, "peer": true, "bin": { @@ -11827,9 +11827,9 @@ "dev": true }, "json5": { - "version": "2.2.1", - "resolved": "https://registry.npmjs.org/json5/-/json5-2.2.1.tgz", - "integrity": "sha512-1hqLFMSrGHRHxav9q9gNjJ5EXznIxGVO09xQRrwplcS8qs28pZ8s8hupZAmqDwZUmVZ2Qb2jnyPOWcDH8m8dlA==", + "version": "2.2.3", + "resolved": "https://registry.npmjs.org/json5/-/json5-2.2.3.tgz", + "integrity": "sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==", "dev": true, "peer": true }, From bf14907540e44ab69e84e80b8f5d892f9dbdb606 Mon Sep 17 00:00:00 2001 From: tglide <26071571+TGlide@users.noreply.github.com> Date: Mon, 23 Jan 2023 17:00:54 +0000 Subject: [PATCH 024/112] refactor: pr reviews --- src/lib/components/copy.svelte | 2 +- src/lib/components/eventModal.svelte | 12 ++++++------ tsconfig.json | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/lib/components/copy.svelte b/src/lib/components/copy.svelte index 7fd1cb18b..f1690ce8c 100644 --- a/src/lib/components/copy.svelte +++ b/src/lib/components/copy.svelte @@ -6,7 +6,7 @@ export let value: string; export let event: string = null; - export let appendTo: any | undefined = undefined; + export let appendTo: Parameters['1']['appendTo'] = undefined; let content = 'Click to copy'; diff --git a/src/lib/components/eventModal.svelte b/src/lib/components/eventModal.svelte index 9aadc6828..09d07e93c 100644 --- a/src/lib/components/eventModal.svelte +++ b/src/lib/components/eventModal.svelte @@ -54,7 +54,7 @@ if (typeof value === 'string') { selected[field as 'attribute'] = selected[field] === value ? null : value; } else { - selected[field as any] = (selected[field] as any)?.name === value.name ? null : value; + selected[field] = selected[field]?.name === value.name ? null : value; } customInput = null; @@ -121,8 +121,8 @@ } } - function toggleShowInput(e?: Event) { - e?.preventDefault(); + function toggleShowInput(e: Event) { + e.preventDefault(); showInput = !showInput; if (showInput) return; @@ -326,7 +326,7 @@ {:else}
    -
    +
    {#each eventString as route, i} {#key copyParent}
    {:else}
    -
    + +
    {#each eventString as route, i} Date: Wed, 1 Feb 2023 13:41:39 +0100 Subject: [PATCH 028/112] feat: execute redirection, create fixes, small fixes --- src/lib/layout/logs.svelte | 7 ++-- .../function-[function]/create.svelte | 37 +++++++++++++------ .../function-[function]/execute.svelte | 7 +++- 3 files changed, 35 insertions(+), 16 deletions(-) diff --git a/src/lib/layout/logs.svelte b/src/lib/layout/logs.svelte index ac6f8cfa3..39cd7b650 100644 --- a/src/lib/layout/logs.svelte +++ b/src/lib/layout/logs.svelte @@ -79,11 +79,10 @@
    Size: {size.value} {size.unit}
    -
    +
    {$log.data.status} -

    - {calculateTime($log.data.buildTime)} -

    + +
    diff --git a/src/routes/console/project-[project]/functions/function-[function]/create.svelte b/src/routes/console/project-[project]/functions/function-[function]/create.svelte index be7c21ddb..4d952eb97 100644 --- a/src/routes/console/project-[project]/functions/function-[function]/create.svelte +++ b/src/routes/console/project-[project]/functions/function-[function]/create.svelte @@ -26,6 +26,7 @@ let files: FileList; let lang = 'js'; let codeSnippets = {}; + let OS = 'unknown'; const functionId = $page.params.function; const dispatch = createEventDispatcher(); @@ -33,6 +34,7 @@ onMount(() => { lang = setLanguage($func.runtime); codeSnippets = setCodeSnippets(lang); + OS = navigator?.userAgentData?.platform || navigator?.platform || 'unknown'; }); function setLanguage(runtime: string) { @@ -107,6 +109,21 @@ }); } } + + function openCategory(category: string, index: number) { + switch (category) { + case 'CMD': + return OS.includes('Win'); + case 'PowerShell': + return OS.includes('Win'); + case 'Unix': + return ( + OS === 'unknown' || OS.includes('Linux') || OS.includes('Mac') || index === 0 + ); + default: + return index === 0; + } + } @@ -144,7 +161,7 @@

    {#each ['Unix', 'CMD', 'PowerShell'] as category, i} - + {category} {:else if mode === Mode.Github} -
    -
    - {#if $app.themeInUse === 'dark'} - github - {:else} - github - {/if} -
    -
    +
    + {#if $app.themeInUse === 'dark'} + github + {:else} + github + {/if} +

    Coming Soon!

    Creating deployments will be easier than ever with our upcoming Git Integration. - Just set up a repository and we’ll do the rest. + Just set up a repository and we'll do the rest.

    diff --git a/src/routes/console/project-[project]/functions/function-[function]/execute.svelte b/src/routes/console/project-[project]/functions/function-[function]/execute.svelte index 24f026f25..14f845a9a 100644 --- a/src/routes/console/project-[project]/functions/function-[function]/execute.svelte +++ b/src/routes/console/project-[project]/functions/function-[function]/execute.svelte @@ -1,5 +1,7 @@ {label}

    {/if}
    (hovering = false)}> -
    -
    -
    diff --git a/src/lib/layout/header.svelte b/src/lib/layout/header.svelte index 4f6ce4dc0..f83de1b19 100644 --- a/src/lib/layout/header.svelte +++ b/src/lib/layout/header.svelte @@ -93,7 +93,7 @@ Support -