mirror of
https://github.com/appwrite/console.git
synced 2026-11-18 20:47:21 +00:00
Merge branch 'main' of https://github.com/appwrite/appwrite-console-poc into tests-2
This commit is contained in:
commit
97fb13524b
44 files changed
+578
-339
No files matched your search
@@ -1,18 +1,24 @@
|
||||
<script lang="ts">
|
||||
import Step from './step.svelte';
|
||||
|
||||
export let steps: { text: string; substeps?: { text: string }[] }[];
|
||||
export let currentStep = 0;
|
||||
export let currentSub = 0;
|
||||
export let steps: {
|
||||
text: string;
|
||||
substeps?: {
|
||||
text: string;
|
||||
}[];
|
||||
}[];
|
||||
export let currentStep = 1;
|
||||
export let currentSub = 1;
|
||||
</script>
|
||||
|
||||
<ol class="steps">
|
||||
{#if steps}
|
||||
{#each steps as step, index}
|
||||
{@const stepNumber = index + 1}
|
||||
<Step
|
||||
bind:currentSub
|
||||
current={currentStep === index}
|
||||
completed={index < currentStep}
|
||||
current={currentStep === stepNumber}
|
||||
completed={stepNumber < currentStep}
|
||||
{step} />
|
||||
{/each}
|
||||
{/if}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
<form class="form common-section" on:submit|preventDefault>
|
||||
<!-- svelte-ignore a11y-no-redundant-roles -->
|
||||
<form role="form" class="form common-section" on:submit|preventDefault>
|
||||
<slot />
|
||||
</form>
|
||||
@@ -7,5 +7,6 @@ export { default as Notification } from './notification.svelte';
|
||||
export { default as Notifications } from './notifications.svelte';
|
||||
export { default as Shell } from './shell.svelte';
|
||||
export { default as Wizard } from './wizard.svelte';
|
||||
export { default as WizardStep } from './wizardStep.svelte';
|
||||
export { default as Breadcrumbs } from './breadcrumbs.svelte';
|
||||
export { default as Unauthenticated } from './unauthenticated.svelte';
|
||||
@@ -16,6 +16,7 @@
|
||||
import { user } from '$lib/stores/user';
|
||||
import { goto } from '$app/navigation';
|
||||
import { browser } from '$app/environment';
|
||||
import { wizard } from '$lib/stores/wizard';
|
||||
|
||||
export let isOpen = false;
|
||||
export let showSideNavigation = false;
|
||||
@@ -105,7 +106,8 @@
|
||||
<main
|
||||
class:grid-with-side={showSideNavigation}
|
||||
class:grid={!showSideNavigation}
|
||||
class:is-open={isOpen}>
|
||||
class:is-open={isOpen}
|
||||
class:u-hide={$wizard.show}>
|
||||
<header class="main-header">
|
||||
<button
|
||||
class:u-hide={!showSideNavigation}
|
||||
|
||||
@@ -1,59 +1,93 @@
|
||||
<script context="module" lang="ts">
|
||||
export type WizardStepsType = Map<
|
||||
number,
|
||||
{
|
||||
label: string;
|
||||
component: typeof SvelteComponent;
|
||||
}
|
||||
>;
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
import { createEventDispatcher } from 'svelte';
|
||||
import { Steps } from '$lib/components';
|
||||
import { Button, Form } from '$lib/elements/forms';
|
||||
import { wizard } from '$lib/stores/wizard';
|
||||
import { createEventDispatcher, type SvelteComponent } from 'svelte';
|
||||
|
||||
export let show = false;
|
||||
export let title: string;
|
||||
export let steps: WizardStepsType;
|
||||
export let finalAction = 'Create';
|
||||
|
||||
const dispatch = createEventDispatcher();
|
||||
|
||||
const handleKeydown = (event: KeyboardEvent) => {
|
||||
let currentStep = 1;
|
||||
|
||||
function handleKeydown(event: KeyboardEvent) {
|
||||
if (event.key === 'Escape') {
|
||||
event.preventDefault();
|
||||
closeModal();
|
||||
wizard.hide();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
const closeModal = () => {
|
||||
show = false;
|
||||
dispatch('close');
|
||||
};
|
||||
function submit() {
|
||||
if (isLastStep) {
|
||||
dispatch('finish');
|
||||
} else {
|
||||
currentStep++;
|
||||
}
|
||||
}
|
||||
|
||||
$: sortedSteps = [...steps].sort(([a], [b]) => (a > b ? 1 : -1));
|
||||
$: isLastStep = currentStep === steps.size;
|
||||
</script>
|
||||
|
||||
<svelte:window on:keydown={handleKeydown} />
|
||||
|
||||
{#if show}
|
||||
<section class="wizard">
|
||||
<div class="wizard-header-strip" />
|
||||
<div class="wizard-start-bg" />
|
||||
<div class="wizard-end-bg" />
|
||||
<section class="wizard">
|
||||
<div class="wizard-header-strip" />
|
||||
<div class="wizard-start-bg" />
|
||||
<div class="wizard-end-bg" />
|
||||
|
||||
<header class="wizard-header">
|
||||
<div class="body-text-1">{title}</div>
|
||||
<header class="wizard-header">
|
||||
<div class="body-text-1">{title}</div>
|
||||
|
||||
<slot name="header" />
|
||||
<button class="x-button" aria-label="close wizard" on:click={closeModal}>
|
||||
<span class="icon-x" aria-hidden="true" />
|
||||
</button>
|
||||
</header>
|
||||
<slot name="header" />
|
||||
<button class="x-button" aria-label="close wizard" on:click={wizard.hide}>
|
||||
<span class="icon-x" aria-hidden="true" />
|
||||
</button>
|
||||
</header>
|
||||
|
||||
<aside class="wizard-side">
|
||||
<slot name="aside" />
|
||||
</aside>
|
||||
<div class="wizard-media">
|
||||
<slot name="media" />
|
||||
</div>
|
||||
<div class="wizard-main">
|
||||
<slot />
|
||||
</div>
|
||||
</section>
|
||||
{/if}
|
||||
|
||||
<style>
|
||||
.wizard {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
z-index: 100;
|
||||
}
|
||||
</style>
|
||||
<aside class="wizard-side">
|
||||
<Steps
|
||||
steps={sortedSteps.map(([, { label }]) => ({
|
||||
text: label
|
||||
}))}
|
||||
{currentStep} />
|
||||
</aside>
|
||||
<div class="wizard-media">
|
||||
<slot name="media" />
|
||||
</div>
|
||||
<div class="wizard-main">
|
||||
<Form on:submit={submit}>
|
||||
{#each sortedSteps as [step, { component }]}
|
||||
{#if currentStep === step}
|
||||
<svelte:component this={component} />
|
||||
{/if}
|
||||
{/each}
|
||||
<div class="form-footer">
|
||||
<div class="u-flex u-main-end u-gap-12">
|
||||
{#if currentStep === 1}
|
||||
<Button secondary on:click={wizard.hide}>Cancel</Button>
|
||||
<Button submit>Next</Button>
|
||||
{:else if isLastStep}
|
||||
<Button secondary on:click={() => currentStep--}>Back</Button>
|
||||
<Button submit>{finalAction}</Button>
|
||||
{:else}
|
||||
<Button secondary on:click={() => currentStep--}>Back</Button>
|
||||
<Button submit>Next</Button>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
</Form>
|
||||
</div>
|
||||
</section>
|
||||
@@ -0,0 +1,10 @@
|
||||
<header class="form-header">
|
||||
<h1 class="heading-level-6">
|
||||
<slot name="title" />
|
||||
</h1>
|
||||
<p>
|
||||
<slot name="subtitle" />
|
||||
</p>
|
||||
</header>
|
||||
|
||||
<slot />
|
||||
@@ -0,0 +1,7 @@
|
||||
<script lang="ts">
|
||||
import { wizard } from '$lib/stores/wizard';
|
||||
</script>
|
||||
|
||||
{#if $wizard.show && $wizard.component}
|
||||
<svelte:component this={$wizard.component} />
|
||||
{/if}
|
||||
@@ -0,0 +1,10 @@
|
||||
<script lang="ts">
|
||||
import WizardStep from '$lib/layout/wizardStep.svelte';
|
||||
</script>
|
||||
|
||||
<WizardStep>
|
||||
<svelte:fragment slot="title">step-1</svelte:fragment>
|
||||
<svelte:fragment slot="subtitle">sub-title-1</svelte:fragment>
|
||||
<input name="step-1-required" required data-testid="step-1-required" type="text" />
|
||||
<input name="step-1-optional" data-testid="step-1-optional" type="text" />
|
||||
</WizardStep>
|
||||
@@ -0,0 +1,10 @@
|
||||
<script lang="ts">
|
||||
import WizardStep from '$lib/layout/wizardStep.svelte';
|
||||
</script>
|
||||
|
||||
<WizardStep>
|
||||
<svelte:fragment slot="title">step-2</svelte:fragment>
|
||||
<svelte:fragment slot="subtitle">sub-title-2</svelte:fragment>
|
||||
<input data-testid="step-2-first" type="text" />
|
||||
<input data-testid="step-2-second" type="text" />
|
||||
</WizardStep>
|
||||
@@ -0,0 +1,24 @@
|
||||
<script lang="ts">
|
||||
import Wizard from '$lib/layout/wizard.svelte';
|
||||
import Step1 from './wizard.step1.test.svelte';
|
||||
import Step2 from './wizard.step2.test.svelte';
|
||||
import type { WizardStepsType } from '$lib/layout/wizard.svelte';
|
||||
import { wizard } from '$lib/stores/wizard';
|
||||
|
||||
const stepsComponents: WizardStepsType = new Map();
|
||||
|
||||
stepsComponents.set(1, {
|
||||
label: 'label-step-1',
|
||||
component: Step1
|
||||
});
|
||||
stepsComponents.set(2, {
|
||||
label: 'label-step-2',
|
||||
component: Step2
|
||||
});
|
||||
|
||||
function finish() {
|
||||
wizard.hide();
|
||||
}
|
||||
</script>
|
||||
|
||||
<Wizard title="wizard-title" steps={stepsComponents} on:finish={finish} />
|
||||
@@ -0,0 +1,34 @@
|
||||
import type { SvelteComponent } from 'svelte';
|
||||
import { writable } from 'svelte/store';
|
||||
|
||||
export type WizardStore = {
|
||||
show: boolean;
|
||||
component?: typeof SvelteComponent;
|
||||
};
|
||||
|
||||
function createWizardStore() {
|
||||
const { subscribe, update } = writable<WizardStore>({
|
||||
show: false,
|
||||
component: null
|
||||
});
|
||||
|
||||
return {
|
||||
subscribe,
|
||||
start: (component: typeof SvelteComponent) =>
|
||||
update((n) => {
|
||||
n.show = true;
|
||||
n.component = component;
|
||||
|
||||
return n;
|
||||
}),
|
||||
hide: () =>
|
||||
update((n) => {
|
||||
n.show = false;
|
||||
n.component = null;
|
||||
|
||||
return n;
|
||||
})
|
||||
};
|
||||
}
|
||||
|
||||
export const wizard = createWizardStore();
|
||||
@@ -13,6 +13,7 @@
|
||||
import { page } from '$app/stores';
|
||||
import { afterNavigate } from '$app/navigation';
|
||||
import { onMount } from 'svelte';
|
||||
import { wizard } from '$lib/stores/wizard';
|
||||
|
||||
updateLayout({
|
||||
title: $organization?.name ?? '',
|
||||
@@ -50,6 +51,10 @@
|
||||
<footer class="main-footer" />
|
||||
</Shell>
|
||||
|
||||
{#if $wizard.show && $wizard.component}
|
||||
<svelte:component this={$wizard.component} />
|
||||
{/if}
|
||||
|
||||
{#if $newOrgModal}
|
||||
<Create bind:show={$newOrgModal} closable={!!$organizationList?.total} />
|
||||
{/if}
|
||||
@@ -137,13 +137,6 @@
|
||||
|
||||
<svelte:fragment slot="aside">
|
||||
<FormList>
|
||||
<InputPassword
|
||||
id="newPassword"
|
||||
label="New password"
|
||||
placeholder="Enter password"
|
||||
autocomplete={false}
|
||||
showPasswordButton={true}
|
||||
bind:value={newPassword} />
|
||||
<InputPassword
|
||||
id="oldPassword"
|
||||
label="Old password"
|
||||
@@ -151,6 +144,13 @@
|
||||
autocomplete={false}
|
||||
showPasswordButton={true}
|
||||
bind:value={oldPassword} />
|
||||
<InputPassword
|
||||
id="newPassword"
|
||||
label="New password"
|
||||
placeholder="Enter password"
|
||||
autocomplete={false}
|
||||
showPasswordButton={true}
|
||||
bind:value={newPassword} />
|
||||
</FormList>
|
||||
</svelte:fragment>
|
||||
|
||||
|
||||
+5
-2
@@ -8,9 +8,10 @@
|
||||
|
||||
const databaseId = $page.params.database;
|
||||
const collectionId = $page.params.collection;
|
||||
|
||||
const path = `databases/database/${databaseId}/collection/${collectionId}`;
|
||||
|
||||
let loaded = false;
|
||||
|
||||
onMount(handle);
|
||||
afterNavigate(handle);
|
||||
|
||||
@@ -51,6 +52,8 @@
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
loaded = true;
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -58,6 +61,6 @@
|
||||
<title>Appwrite - {$collection?.name ?? 'Collection'}</title>
|
||||
</svelte:head>
|
||||
|
||||
{#if $collection}
|
||||
{#if $collection && loaded}
|
||||
<slot />
|
||||
{/if}
|
||||
+8
-8
@@ -14,10 +14,10 @@
|
||||
import { Container } from '$lib/layout';
|
||||
import { Button } from '$lib/elements/forms';
|
||||
import { base } from '$app/paths';
|
||||
import Create from './_create.svelte';
|
||||
import { wizard } from '$lib/stores/wizard';
|
||||
import Create from './createDocument.svelte';
|
||||
|
||||
let offset = 0;
|
||||
let showCreate = false;
|
||||
|
||||
const limit = 5;
|
||||
const projectId = $page.params.project;
|
||||
@@ -30,13 +30,17 @@
|
||||
title: attribute.key
|
||||
}))
|
||||
];
|
||||
|
||||
function openWizard() {
|
||||
wizard.start(Create);
|
||||
}
|
||||
</script>
|
||||
|
||||
<Container>
|
||||
<div class="u-flex u-gap-12 common-section u-main-space-between">
|
||||
<h2 class="heading-level-5">Documents</h2>
|
||||
|
||||
<Button on:click={() => (showCreate = true)}>
|
||||
<Button on:click={openWizard}>
|
||||
<span class="icon-plus" aria-hidden="true" />
|
||||
<span class="text">Create document</span>
|
||||
</Button>
|
||||
@@ -80,7 +84,7 @@
|
||||
<Empty dashed centered>
|
||||
<div class="u-flex u-flex-vertical u-cross-center">
|
||||
<div class="common-section">
|
||||
<Button secondary round on:click={() => (showCreate = true)}>
|
||||
<Button secondary round on:click={openWizard}>
|
||||
<span class="icon-plus" aria-hidden="true" />
|
||||
</Button>
|
||||
</div>
|
||||
@@ -94,7 +98,3 @@
|
||||
</Empty>
|
||||
{/if}
|
||||
</Container>
|
||||
|
||||
{#if showCreate}
|
||||
<Create bind:showCreate />
|
||||
{/if}
|
||||
-238
@@ -1,238 +0,0 @@
|
||||
<script lang="ts">
|
||||
import { Wizard } from '$lib/layout';
|
||||
import { Steps, Alert, InnerModal } from '$lib/components';
|
||||
import { Form, Button, InputTags, InputText } from '$lib/elements/forms';
|
||||
import { Pill } from '$lib/elements';
|
||||
import { attributeList } from './store';
|
||||
import { sdkForProject } from '$lib/stores/sdk';
|
||||
import { page } from '$app/stores';
|
||||
import { onMount } from 'svelte';
|
||||
import { addNotification } from '$lib/stores/notifications';
|
||||
import Attribute from './document/[document]/_attribute.svelte';
|
||||
|
||||
export let showCreate = false;
|
||||
|
||||
const databaseId = $page.params.database;
|
||||
const collectionId = $page.params.collection;
|
||||
|
||||
let newDocument = {};
|
||||
let read: string[];
|
||||
let write: string[];
|
||||
let id: string;
|
||||
let showCustomId = false;
|
||||
let steps = [{ text: 'Create data' }, { text: 'Set permissions' }];
|
||||
let currentStep = 0;
|
||||
let attributes = [];
|
||||
|
||||
onMount(async () => {
|
||||
await attributeList.load(databaseId, collectionId);
|
||||
initializeDocument();
|
||||
});
|
||||
|
||||
const initializeDocument = () => {
|
||||
attributes = $attributeList?.attributes?.filter((a) => a.status === 'available');
|
||||
$attributeList.attributes.forEach((attr) => {
|
||||
if (attr.array) {
|
||||
newDocument[attr.key] = [null];
|
||||
} else {
|
||||
newDocument[attr.key] = null;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const create = async () => {
|
||||
if (currentStep < steps.length - 1) {
|
||||
currentStep++;
|
||||
} else {
|
||||
try {
|
||||
await sdkForProject.databases.createDocument(
|
||||
databaseId,
|
||||
collectionId,
|
||||
id ?? 'unique()',
|
||||
newDocument,
|
||||
read,
|
||||
write
|
||||
);
|
||||
addNotification({
|
||||
message: 'Document has been created',
|
||||
type: 'success'
|
||||
});
|
||||
showCreate = false;
|
||||
} catch (error) {
|
||||
addNotification({
|
||||
message: error.message,
|
||||
type: 'error'
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
$: attributeList.load(databaseId, collectionId);
|
||||
|
||||
$: if (!showCreate) {
|
||||
initializeDocument();
|
||||
currentStep = 0;
|
||||
read = write = [];
|
||||
}
|
||||
</script>
|
||||
|
||||
<Wizard title="Create document" bind:show={showCreate}>
|
||||
<svelte:fragment slot="aside">
|
||||
<Steps {steps} bind:currentStep />
|
||||
</svelte:fragment>
|
||||
<Form on:submit={create}>
|
||||
{#if currentStep === 0}
|
||||
<header class="form-header">
|
||||
<h1 class="heading-level-6">Create document data</h1>
|
||||
<p>Provide document data based on attributes you created earlier.</p>
|
||||
</header>
|
||||
{#if attributes.length}
|
||||
<ul class="form-list">
|
||||
{#each attributes as attribute}
|
||||
{@const label = attribute.required ? `${attribute.key}*` : attribute.key}
|
||||
{#if attribute.array}
|
||||
{#each newDocument[attribute.key] as _v, index}
|
||||
<li class="form-item is-multiple">
|
||||
<div class="form-item-part u-stretch">
|
||||
<Attribute
|
||||
{attribute}
|
||||
id={`${attribute.key}-${index}`}
|
||||
label={index === 0 ? label : ''}
|
||||
bind:value={newDocument[attribute.key][index]} />
|
||||
</div>
|
||||
<div class="form-item-part u-cross-child-end">
|
||||
<Button
|
||||
text
|
||||
disabled={index === 0}
|
||||
on:click={() => {
|
||||
newDocument[attribute.key].splice(index, 1);
|
||||
newDocument = newDocument;
|
||||
}}>
|
||||
<span class="icon-x" aria-hidden="true" />
|
||||
</Button>
|
||||
</div>
|
||||
</li>
|
||||
{:else}
|
||||
<li class="form-item is-multiple">
|
||||
<div class="form-item-part u-stretch">
|
||||
<Attribute
|
||||
{attribute}
|
||||
id={`${attribute.key}-0`}
|
||||
{label}
|
||||
bind:value={newDocument[attribute.key][0]} />
|
||||
</div>
|
||||
<div class="form-item-part u-cross-child-end">
|
||||
<Button text disabled>
|
||||
<span class="icon-x" aria-hidden="true" />
|
||||
</Button>
|
||||
</div>
|
||||
</li>
|
||||
{/each}
|
||||
|
||||
<Button
|
||||
text
|
||||
disabled={newDocument[attribute.key][
|
||||
newDocument[attribute.key].length - 1
|
||||
] === null}
|
||||
on:click={() => {
|
||||
{
|
||||
newDocument[attribute.key].push(null);
|
||||
newDocument = newDocument;
|
||||
}
|
||||
}}>
|
||||
<span class="icon-plus" aria-hidden="true" />
|
||||
<span class="text"> Add item</span>
|
||||
</Button>
|
||||
{:else}
|
||||
<ul class="form-list">
|
||||
<Attribute
|
||||
{attribute}
|
||||
id={attribute.key}
|
||||
{label}
|
||||
bind:value={newDocument[attribute.key]} />
|
||||
</ul>
|
||||
{/if}
|
||||
{/each}
|
||||
{#if !showCustomId}
|
||||
<div>
|
||||
<Pill button on:click={() => (showCustomId = !showCustomId)}
|
||||
><span class="icon-pencil" aria-hidden="true" /><span class="text">
|
||||
Document ID
|
||||
</span></Pill>
|
||||
</div>
|
||||
{:else}
|
||||
<InnerModal bind:show={showCustomId}>
|
||||
<svelte:fragment slot="title">User ID</svelte:fragment>
|
||||
Enter a custom document ID. Leave blank for a randomly generated one.
|
||||
<svelte:fragment slot="content">
|
||||
<div class="form">
|
||||
<InputText
|
||||
id="id"
|
||||
label="Custom ID"
|
||||
showLabel={false}
|
||||
placeholder="Enter ID"
|
||||
autofocus={true}
|
||||
bind:value={id} />
|
||||
|
||||
<div class="u-flex u-gap-4 u-margin-block-start-8 u-small">
|
||||
<span
|
||||
class="icon-info u-cross-center u-margin-block-start-2 u-line-height-1 u-icon-small"
|
||||
aria-hidden="true" />
|
||||
<span class="text u-line-height-1-5"
|
||||
>Allowed characters: alphanumeric, hyphen, non-leading
|
||||
underscore, period</span>
|
||||
</div>
|
||||
</div>
|
||||
</svelte:fragment>
|
||||
</InnerModal>
|
||||
{/if}
|
||||
</ul>
|
||||
{/if}
|
||||
{:else if currentStep === 1}
|
||||
<header class="form-header">
|
||||
<h1 class="heading-level-6">Set Permissions</h1>
|
||||
<p>
|
||||
Assign read or write permissions at the <b> Collection Level</b> or
|
||||
<b> Document Level</b>. If collection Level permissions are assigned,
|
||||
permissions applied to individual documents are ignored.
|
||||
</p>
|
||||
</header>
|
||||
<Alert type="info">
|
||||
<svelte:fragment slot="title">
|
||||
You have Collection Level permissions enabled
|
||||
</svelte:fragment>
|
||||
<p>
|
||||
If you want to assign permissions specific to this document, you will need to
|
||||
update your Collection Settings to enable Document Level permissions.
|
||||
</p>
|
||||
</Alert>
|
||||
|
||||
<ul class="common-section">
|
||||
<InputTags
|
||||
id="read"
|
||||
label="Read Access"
|
||||
placeholder="User ID, Team ID, or Role"
|
||||
bind:tags={read} />
|
||||
<InputTags
|
||||
id="write"
|
||||
label="Write Access"
|
||||
placeholder="User ID, Team ID, or Role"
|
||||
bind:tags={write} />
|
||||
</ul>
|
||||
{/if}
|
||||
<div class="form-footer">
|
||||
<div class="u-flex u-main-end u-gap-12">
|
||||
{#if currentStep === 0}
|
||||
<Button secondary on:click={() => (showCreate = false)}>Cancel</Button>
|
||||
<Button submit>Next</Button>
|
||||
{:else if currentStep === steps.length - 1}
|
||||
<Button secondary on:click={() => currentStep--}>Back</Button>
|
||||
<Button submit>Create</Button>
|
||||
{:else}
|
||||
<Button secondary on:click={() => currentStep--}>Back</Button>
|
||||
<Button submit>Next</Button>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
</Form>
|
||||
</Wizard>
|
||||
+6
-6
@@ -14,10 +14,10 @@
|
||||
import type { Attributes } from '../store';
|
||||
import { Container } from '$lib/layout';
|
||||
import { Pill } from '$lib/elements';
|
||||
import Create from '../_createAttribute.svelte';
|
||||
import CreateIndex from '../_createIndex.svelte';
|
||||
import Delete from '../_deleteAttribute.svelte';
|
||||
import Overview from '../_overview.svelte';
|
||||
import Create from './createAttribute.svelte';
|
||||
import CreateIndex from '../indexes/createIndex.svelte';
|
||||
import Delete from './deleteAttribute.svelte';
|
||||
import Overview from './overview.svelte';
|
||||
|
||||
let offset = 0;
|
||||
const limit = 5;
|
||||
@@ -118,12 +118,12 @@
|
||||
<Empty dashed centered>
|
||||
<div class="u-flex u-flex-vertical u-cross-center">
|
||||
<div class="common-section">
|
||||
<Button secondary round on:click={() => console.log('showCreate = true')}>
|
||||
<Button secondary round on:click={() => (showCreate = true)}>
|
||||
<span class="icon-plus" aria-hidden="true" />
|
||||
</Button>
|
||||
</div>
|
||||
<div class="common-section">
|
||||
<p>Crate your first document to get started</p>
|
||||
<p>Crate your first attribute to get started</p>
|
||||
</div>
|
||||
<div class="common-section">
|
||||
<Button secondary href="#">Documentation</Button>
|
||||
|
||||
File renamed without changes.
+3
-3
@@ -1,9 +1,9 @@
|
||||
<script lang="ts">
|
||||
import { Modal } from '$lib/components';
|
||||
import { option, options } from './attributes/store';
|
||||
import { option, options } from './store';
|
||||
import { Button, InputText, Form, FormList, InputSelect } from '$lib/elements/forms';
|
||||
import { collection } from './store';
|
||||
import type { Attributes } from './store';
|
||||
import { collection } from '../store';
|
||||
import type { Attributes } from '../store';
|
||||
|
||||
export let showCreate = false;
|
||||
|
||||
+2
-2
@@ -5,8 +5,8 @@
|
||||
import { Modal } from '$lib/components';
|
||||
import { Button, Form } from '$lib/elements/forms';
|
||||
import { addNotification } from '$lib/stores/notifications';
|
||||
import { collection } from './store';
|
||||
import type { Attributes } from './store';
|
||||
import { collection } from '../store';
|
||||
import type { Attributes } from '../store';
|
||||
import { sdkForProject } from '$lib/stores/sdk';
|
||||
|
||||
export let showDelete = false;
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
+2
-2
@@ -1,8 +1,8 @@
|
||||
<script lang="ts">
|
||||
import { Modal } from '$lib/components';
|
||||
import { option, options } from './attributes/store';
|
||||
import { option, options } from './store';
|
||||
import { InputText, FormList } from '$lib/elements/forms';
|
||||
import type { Attributes } from './store';
|
||||
import type { Attributes } from '../store';
|
||||
|
||||
export let showOverview = false;
|
||||
export let selectedAttribute: Attributes;
|
||||
+8
-8
@@ -1,13 +1,13 @@
|
||||
import type { SvelteComponent } from 'svelte';
|
||||
import { writable } from 'svelte/store';
|
||||
import Boolean from './_boolean.svelte';
|
||||
import Email from './_email.svelte';
|
||||
import Enum from './_enum.svelte';
|
||||
import Float from './_float.svelte';
|
||||
import Integer from './_integer.svelte';
|
||||
import Ip from './_ip.svelte';
|
||||
import String from './_string.svelte';
|
||||
import Url from './_url.svelte';
|
||||
import Boolean from './boolean.svelte';
|
||||
import Email from './email.svelte';
|
||||
import Enum from './enum.svelte';
|
||||
import Float from './float.svelte';
|
||||
import Integer from './integer.svelte';
|
||||
import Ip from './ip.svelte';
|
||||
import String from './string.svelte';
|
||||
import Url from './url.svelte';
|
||||
|
||||
export type Option = {
|
||||
name: string;
|
||||
|
||||
File renamed without changes.
File renamed without changes.
+76
@@ -0,0 +1,76 @@
|
||||
<script lang="ts">
|
||||
import { Wizard } from '$lib/layout';
|
||||
import { attributeList, documentList } from './store';
|
||||
import { sdkForProject } from '$lib/stores/sdk';
|
||||
import { page } from '$app/stores';
|
||||
import { onDestroy, onMount } from 'svelte';
|
||||
import { addNotification } from '$lib/stores/notifications';
|
||||
import { wizard } from '$lib/stores/wizard';
|
||||
import Step1 from './wizard/step1.svelte';
|
||||
import Step2 from './wizard/step2.svelte';
|
||||
import { createDocument } from './wizard/store';
|
||||
import type { WizardStepsType } from '$lib/layout/wizard.svelte';
|
||||
|
||||
const databaseId = $page.params.database;
|
||||
const collectionId = $page.params.collection;
|
||||
|
||||
onMount(async () => {
|
||||
await attributeList.load(databaseId, collectionId);
|
||||
initializeDocument();
|
||||
});
|
||||
|
||||
const initializeDocument = () => {
|
||||
$createDocument.attributes = $attributeList?.attributes?.filter(
|
||||
(a) => a.status === 'available'
|
||||
);
|
||||
$attributeList.attributes.forEach((attr) => {
|
||||
if (attr.array) {
|
||||
$createDocument.document[attr.key] = [null];
|
||||
} else {
|
||||
$createDocument.document[attr.key] = null;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const create = async () => {
|
||||
try {
|
||||
await sdkForProject.databases.createDocument(
|
||||
databaseId,
|
||||
collectionId,
|
||||
$createDocument.id ?? 'unique()',
|
||||
$createDocument.document,
|
||||
$createDocument.read,
|
||||
$createDocument.write
|
||||
);
|
||||
addNotification({
|
||||
message: 'Document has been created',
|
||||
type: 'success'
|
||||
});
|
||||
documentList.load(databaseId, collectionId);
|
||||
wizard.hide();
|
||||
} catch (error) {
|
||||
addNotification({
|
||||
message: error.message,
|
||||
type: 'error'
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
onDestroy(() => {
|
||||
$createDocument.document = {};
|
||||
$createDocument.read = [];
|
||||
$createDocument.write = [];
|
||||
});
|
||||
|
||||
const stepsComponents: WizardStepsType = new Map();
|
||||
stepsComponents.set(1, {
|
||||
label: 'Create data',
|
||||
component: Step1
|
||||
});
|
||||
stepsComponents.set(2, {
|
||||
label: 'Set permissions',
|
||||
component: Step2
|
||||
});
|
||||
</script>
|
||||
|
||||
<Wizard title="Create document" steps={stepsComponents} on:finish={create} />
|
||||
+3
-3
@@ -15,9 +15,9 @@
|
||||
import { Container } from '$lib/layout';
|
||||
import { indexList, collection } from '../store';
|
||||
import { onMount } from 'svelte';
|
||||
import Delete from '../_deleteIndex.svelte';
|
||||
import Create from '../_createIndex.svelte';
|
||||
import Overview from '../_overviewIndex.svelte';
|
||||
import Delete from './deleteIndex.svelte';
|
||||
import Create from './createIndex.svelte';
|
||||
import Overview from './overviewIndex.svelte';
|
||||
import type { Models } from '@aw-labs/appwrite-console';
|
||||
|
||||
let showDropdown = [];
|
||||
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
<script lang="ts">
|
||||
import { Modal } from '$lib/components';
|
||||
import { Button, InputText, Form, FormList, InputSelect } from '$lib/elements/forms';
|
||||
import { collection } from './store';
|
||||
import type { Attributes } from './store';
|
||||
import { collection } from '../store';
|
||||
import type { Attributes } from '../store';
|
||||
import { onMount } from 'svelte';
|
||||
import { sdkForProject } from '$lib/stores/sdk';
|
||||
import { addNotification } from '$lib/stores/notifications';
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
import { Modal } from '$lib/components';
|
||||
import { Button, Form } from '$lib/elements/forms';
|
||||
import { addNotification } from '$lib/stores/notifications';
|
||||
import { collection } from './store';
|
||||
import { collection } from '../store';
|
||||
import { sdkForProject } from '$lib/stores/sdk';
|
||||
import type { Models } from '@aw-labs/appwrite-console';
|
||||
import { createEventDispatcher } from 'svelte';
|
||||
File renamed without changes.
File renamed without changes.
+1
-1
@@ -6,10 +6,10 @@
|
||||
import { toLocaleDateTime } from '$lib/helpers/date';
|
||||
import { sdkForProject } from '$lib/stores/sdk';
|
||||
import { addNotification } from '$lib/stores/notifications';
|
||||
import Delete from '../_delete.svelte';
|
||||
import { onMount } from 'svelte';
|
||||
import { page } from '$app/stores';
|
||||
import { difference } from '$lib/helpers/array';
|
||||
import Delete from './deleteCollection.svelte';
|
||||
|
||||
const databaseId = $page.params.database;
|
||||
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@
|
||||
import { Button, Form } from '$lib/elements/forms';
|
||||
import { addNotification } from '$lib/stores/notifications';
|
||||
import { sdkForProject } from '$lib/stores/sdk';
|
||||
import { collection } from './store';
|
||||
import { collection } from '../store';
|
||||
|
||||
export let showDelete = false;
|
||||
|
||||
+3
-3
@@ -66,9 +66,9 @@ export const documentList = cachedStore<
|
||||
load: (
|
||||
databaseId: string,
|
||||
collectionId: string,
|
||||
queries: [],
|
||||
limit: number,
|
||||
offset: number
|
||||
queries?: [],
|
||||
limit?: number,
|
||||
offset?: number
|
||||
) => Promise<void>;
|
||||
}
|
||||
>('documentList', function ({ set }) {
|
||||
|
||||
+120
@@ -0,0 +1,120 @@
|
||||
<script lang="ts">
|
||||
import { InnerModal } from '$lib/components';
|
||||
import { Pill } from '$lib/elements';
|
||||
import { Button, InputText } from '$lib/elements/forms';
|
||||
import { WizardStep } from '$lib/layout';
|
||||
import { createDocument } from './store';
|
||||
import Attribute from '../document/[document]/_attribute.svelte';
|
||||
|
||||
let showCustomId = false;
|
||||
</script>
|
||||
|
||||
<WizardStep>
|
||||
<svelte:fragment slot="title">Create document data</svelte:fragment>
|
||||
<svelte:fragment slot="subtitle">
|
||||
Provide document data based on attributes you created earlier.
|
||||
</svelte:fragment>
|
||||
|
||||
{#if $createDocument.attributes.length}
|
||||
<ul class="form-list">
|
||||
{#each $createDocument.attributes as attribute}
|
||||
{@const label = attribute.required ? `${attribute.key}*` : attribute.key}
|
||||
{#if attribute.array}
|
||||
{#each $createDocument.document[attribute.key] as _v, index}
|
||||
<li class="form-item is-multiple">
|
||||
<div class="form-item-part u-stretch">
|
||||
<Attribute
|
||||
{attribute}
|
||||
id={`${attribute.key}-${index}`}
|
||||
label={index === 0 ? label : ''}
|
||||
bind:value={$createDocument.document[attribute.key][index]} />
|
||||
</div>
|
||||
<div class="form-item-part u-cross-child-end">
|
||||
<Button
|
||||
text
|
||||
disabled={index === 0}
|
||||
on:click={() => {
|
||||
$createDocument.document[attribute.key].splice(index, 1);
|
||||
}}>
|
||||
<span class="icon-x" aria-hidden="true" />
|
||||
</Button>
|
||||
</div>
|
||||
</li>
|
||||
{:else}
|
||||
<li class="form-item is-multiple">
|
||||
<div class="form-item-part u-stretch">
|
||||
<Attribute
|
||||
{attribute}
|
||||
id={`${attribute.key}-0`}
|
||||
{label}
|
||||
bind:value={$createDocument.document[attribute.key][0]} />
|
||||
</div>
|
||||
<div class="form-item-part u-cross-child-end">
|
||||
<Button text disabled>
|
||||
<span class="icon-x" aria-hidden="true" />
|
||||
</Button>
|
||||
</div>
|
||||
</li>
|
||||
{/each}
|
||||
|
||||
<Button
|
||||
text
|
||||
disabled={$createDocument.document[attribute.key][
|
||||
$createDocument.document[attribute.key].length - 1
|
||||
] === null}
|
||||
on:click={() => {
|
||||
{
|
||||
$createDocument.document[attribute.key].push(null);
|
||||
}
|
||||
}}>
|
||||
<span class="icon-plus" aria-hidden="true" />
|
||||
<span class="text"> Add item</span>
|
||||
</Button>
|
||||
{:else}
|
||||
<ul class="form-list">
|
||||
<Attribute
|
||||
{attribute}
|
||||
id={attribute.key}
|
||||
{label}
|
||||
bind:value={$createDocument.document[attribute.key]} />
|
||||
</ul>
|
||||
{/if}
|
||||
{/each}
|
||||
{#if !showCustomId}
|
||||
<div>
|
||||
<Pill button on:click={() => (showCustomId = !showCustomId)}>
|
||||
<span class="icon-pencil" aria-hidden="true" /><span class="text">
|
||||
Document ID
|
||||
</span>
|
||||
</Pill>
|
||||
</div>
|
||||
{:else}
|
||||
<InnerModal bind:show={showCustomId}>
|
||||
<svelte:fragment slot="title">User ID</svelte:fragment>
|
||||
Enter a custom document ID. Leave blank for a randomly generated one.
|
||||
<svelte:fragment slot="content">
|
||||
<div class="form">
|
||||
<InputText
|
||||
id="id"
|
||||
label="Custom ID"
|
||||
showLabel={false}
|
||||
placeholder="Enter ID"
|
||||
autofocus={true}
|
||||
bind:value={$createDocument.id} />
|
||||
|
||||
<div class="u-flex u-gap-4 u-margin-block-start-8 u-small">
|
||||
<span
|
||||
class="icon-info u-cross-center u-margin-block-start-2 u-line-height-1 u-icon-small"
|
||||
aria-hidden="true" />
|
||||
<span class="text u-line-height-1-5">
|
||||
Allowed characters: alphanumeric, hyphen, non-leading
|
||||
underscore, period
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</svelte:fragment>
|
||||
</InnerModal>
|
||||
{/if}
|
||||
</ul>
|
||||
{/if}
|
||||
</WizardStep>
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
<script lang="ts">
|
||||
import { Alert } from '$lib/components';
|
||||
import { InputTags } from '$lib/elements/forms';
|
||||
import { WizardStep } from '$lib/layout';
|
||||
import { createDocument } from './store';
|
||||
</script>
|
||||
|
||||
<WizardStep>
|
||||
<svelte:fragment slot="title">Set Permissions</svelte:fragment>
|
||||
<svelte:fragment slot="subtitle">
|
||||
Assign read or write permissions at the <b> Collection Level</b> or
|
||||
<b> Document Level</b>. If collection Level permissions are assigned, permissions applied to
|
||||
individual documents are ignored.
|
||||
</svelte:fragment>
|
||||
<Alert type="info">
|
||||
<svelte:fragment slot="title">
|
||||
You have Collection Level permissions enabled
|
||||
</svelte:fragment>
|
||||
<p>
|
||||
If you want to assign permissions specific to this document, you will need to update
|
||||
your Collection Settings to enable Document Level permissions.
|
||||
</p>
|
||||
</Alert>
|
||||
|
||||
<ul class="common-section">
|
||||
<InputTags
|
||||
id="read"
|
||||
label="Read Access"
|
||||
placeholder="User ID, Team ID, or Role"
|
||||
bind:tags={$createDocument.read} />
|
||||
<InputTags
|
||||
id="write"
|
||||
label="Write Access"
|
||||
placeholder="User ID, Team ID, or Role"
|
||||
bind:tags={$createDocument.write} />
|
||||
</ul>
|
||||
</WizardStep>
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
import { writable } from 'svelte/store';
|
||||
import type { Attributes } from '../store';
|
||||
|
||||
export const createDocument = writable<{
|
||||
id?: string;
|
||||
document: object;
|
||||
read: string[];
|
||||
write: string[];
|
||||
attributes: Attributes[];
|
||||
}>({
|
||||
id: null,
|
||||
document: {},
|
||||
read: [],
|
||||
write: [],
|
||||
attributes: []
|
||||
});
|
||||
@@ -8,6 +8,8 @@
|
||||
const bucketId = $page.params.bucket;
|
||||
const path = `storage/bucket/${bucketId}`;
|
||||
|
||||
let loaded = false;
|
||||
|
||||
onMount(handle);
|
||||
afterNavigate(handle);
|
||||
|
||||
@@ -43,6 +45,7 @@
|
||||
}
|
||||
]
|
||||
});
|
||||
loaded = true;
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -50,6 +53,6 @@
|
||||
<title>Appwrite - Bucket</title>
|
||||
</svelte:head>
|
||||
|
||||
{#if $bucket}
|
||||
{#if $bucket && loaded}
|
||||
<slot />
|
||||
{/if}
|
||||
@@ -2,8 +2,6 @@ import '@testing-library/jest-dom';
|
||||
import { render } from '@testing-library/svelte';
|
||||
import { level, updateLayout } from '../../../src/lib/stores/layout';
|
||||
import { tick } from 'svelte';
|
||||
|
||||
/** @tsignore */
|
||||
import BreadcrumbsComponent from '../../../src/lib/layout/breadcrumbs.svelte';
|
||||
|
||||
test('shows relevant breadcrumbs', async () => {
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
import '@testing-library/jest-dom';
|
||||
import { render } from '@testing-library/svelte';
|
||||
import { wizard } from '../../../src/lib/stores/wizard';
|
||||
import { tick } from 'svelte';
|
||||
import WizardComponent from '../../../src/lib/mock/wizard.test.svelte';
|
||||
import WizardContainer from '../../../src/lib/mock/wizard.container.test.svelte';
|
||||
|
||||
test('shows wizard and hides it', async () => {
|
||||
const { queryByText } = render(WizardContainer);
|
||||
|
||||
/**
|
||||
* Wizard is hidden before started.
|
||||
*/
|
||||
expect(queryByText('wizard-title')).not.toBeInTheDocument();
|
||||
expect(queryByText('step-1')).not.toBeInTheDocument();
|
||||
expect(queryByText('sub-title-1')).not.toBeInTheDocument();
|
||||
expect(queryByText('step-2')).not.toBeInTheDocument();
|
||||
expect(queryByText('sub-title-2')).not.toBeInTheDocument();
|
||||
|
||||
wizard.start(WizardComponent);
|
||||
await tick();
|
||||
|
||||
/**
|
||||
* First step is shown, second is hidden.
|
||||
*/
|
||||
expect(queryByText('wizard-title')).toBeInTheDocument();
|
||||
expect(queryByText('step-1')).toBeInTheDocument();
|
||||
expect(queryByText('sub-title-1')).toBeInTheDocument();
|
||||
|
||||
expect(queryByText('step-2')).not.toBeInTheDocument();
|
||||
expect(queryByText('sub-title-2')).not.toBeInTheDocument();
|
||||
|
||||
wizard.hide();
|
||||
await tick();
|
||||
|
||||
/**
|
||||
* Wizard is hidden.
|
||||
*/
|
||||
expect(queryByText('wizard-title')).not.toBeInTheDocument();
|
||||
expect(queryByText('step-1')).not.toBeInTheDocument();
|
||||
expect(queryByText('sub-title-1')).not.toBeInTheDocument();
|
||||
expect(queryByText('step-2')).not.toBeInTheDocument();
|
||||
expect(queryByText('sub-title-2')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
test('shows next step with submit', async () => {
|
||||
const { getByTestId, getByRole, queryByText } = render(WizardContainer);
|
||||
|
||||
wizard.start(WizardComponent);
|
||||
await tick();
|
||||
|
||||
const form = getByRole('form') as HTMLFormElement;
|
||||
const step1 = queryByText('step-1');
|
||||
const step1Required = getByTestId('step-1-required');
|
||||
const step1Optional = getByTestId('step-1-optional');
|
||||
|
||||
expect(step1).toBeInTheDocument();
|
||||
expect(step1Required).toBeInTheDocument();
|
||||
expect(step1Optional).toBeInTheDocument();
|
||||
|
||||
form.submit();
|
||||
await tick();
|
||||
|
||||
expect(step1).not.toBeInTheDocument();
|
||||
|
||||
const step2 = queryByText('step-2');
|
||||
const step2First = getByTestId('step-2-first');
|
||||
const step2Second = getByTestId('step-2-second');
|
||||
|
||||
expect(step2).toBeInTheDocument();
|
||||
expect(step2First).toBeInTheDocument();
|
||||
expect(step2Second).toBeInTheDocument();
|
||||
|
||||
form.submit();
|
||||
await tick();
|
||||
|
||||
expect(form).not.toBeInTheDocument();
|
||||
expect(step1).not.toBeInTheDocument();
|
||||
expect(step2).not.toBeInTheDocument();
|
||||
});
|
||||
Reference in new issue
Block a user