mirror of
https://github.com/appwrite/console.git
synced 2026-11-18 20:47:21 +00:00
Merge remote-tracking branch 'origin/main' into feat-SER-204-New-Archive-projects-ui-change
This commit is contained in:
commit
fce7e92b13
58 files changed
+1408
-633
No files matched your search
@@ -10,7 +10,6 @@ test('upgrade - free tier', async ({ page }) => {
|
||||
await page.getByRole('link', { name: 'Upgrade', exact: true }).click();
|
||||
await page.waitForURL(/\/organization-[^/]+\/change-plan/);
|
||||
await page.locator('input[value="tier-1"]').click();
|
||||
await page.getByRole('button', { name: 'add' }).first().click();
|
||||
|
||||
await enterCreditCard(page);
|
||||
|
||||
|
||||
@@ -7,12 +7,15 @@ type Metadata = {
|
||||
};
|
||||
|
||||
export async function enterCreditCard(page: Page) {
|
||||
const dialog = page.locator('.modal').filter({
|
||||
hasText: 'add payment method'
|
||||
});
|
||||
await dialog.waitFor({
|
||||
state: 'visible'
|
||||
});
|
||||
// click the `add` button inside correct view layer
|
||||
await page
|
||||
.locator('#no-payments-card-stack')
|
||||
.getByRole('button', { name: 'add' })
|
||||
.first()
|
||||
.click();
|
||||
|
||||
const dialog = page.locator('.modal').filter({ hasText: 'add payment method' });
|
||||
await dialog.waitFor({ state: 'visible' });
|
||||
await page.getByPlaceholder('cardholder').fill('Test User');
|
||||
const stripe = page.locator('[title="Secure payment input frame"]').nth(0).contentFrame();
|
||||
await stripe.locator('id=Field-numberInput').fill('4242424242424242');
|
||||
@@ -35,7 +38,6 @@ export async function createProProject(page: Page): Promise<Metadata> {
|
||||
await page.getByRole('radio', { name: /^Pro\b/ }).check();
|
||||
// `create organization` because there's already free created on start!
|
||||
await page.getByRole('button', { name: 'create organization' }).click();
|
||||
await page.getByRole('button', { name: 'add' }).first().click();
|
||||
await enterCreditCard(page);
|
||||
// skip members
|
||||
await page.getByRole('button', { name: 'create organization' }).click();
|
||||
|
||||
+1
-1
@@ -54,7 +54,7 @@
|
||||
"@melt-ui/svelte": "^0.86.5",
|
||||
"@playwright/test": "^1.51.1",
|
||||
"@sveltejs/adapter-static": "^3.0.8",
|
||||
"@sveltejs/kit": "^2.20.2",
|
||||
"@sveltejs/kit": "^2.36.2",
|
||||
"@sveltejs/vite-plugin-svelte": "^5.0.3",
|
||||
"@testing-library/dom": "^10.4.0",
|
||||
"@testing-library/jest-dom": "^6.6.3",
|
||||
|
||||
Generated
+36
-24
@@ -34,7 +34,7 @@ importers:
|
||||
version: 2.11.8
|
||||
'@sentry/sveltekit':
|
||||
specifier: ^8.38.0
|
||||
version: 8.55.0(@opentelemetry/api@1.9.0)(@opentelemetry/context-async-hooks@1.30.1(@opentelemetry/api@1.9.0))(@opentelemetry/core@1.30.1(@opentelemetry/api@1.9.0))(@opentelemetry/instrumentation@0.57.2(@opentelemetry/api@1.9.0))(@opentelemetry/sdk-trace-base@1.30.1(@opentelemetry/api@1.9.0))(@opentelemetry/semantic-conventions@1.30.0)(@sveltejs/kit@2.20.2(@sveltejs/vite-plugin-svelte@5.0.3(svelte@5.25.3)(vite@7.0.6(@types/node@22.13.14)(sass@1.86.0)))(svelte@5.25.3)(vite@7.0.6(@types/node@22.13.14)(sass@1.86.0)))(svelte@5.25.3)(vite@7.0.6(@types/node@22.13.14)(sass@1.86.0))
|
||||
version: 8.55.0(@opentelemetry/api@1.9.0)(@opentelemetry/context-async-hooks@1.30.1(@opentelemetry/api@1.9.0))(@opentelemetry/core@1.30.1(@opentelemetry/api@1.9.0))(@opentelemetry/instrumentation@0.57.2(@opentelemetry/api@1.9.0))(@opentelemetry/sdk-trace-base@1.30.1(@opentelemetry/api@1.9.0))(@opentelemetry/semantic-conventions@1.30.0)(@sveltejs/kit@2.36.3(@opentelemetry/api@1.9.0)(@sveltejs/vite-plugin-svelte@5.0.3(svelte@5.25.3)(vite@7.0.6(@types/node@22.13.14)(sass@1.86.0)))(svelte@5.25.3)(vite@7.0.6(@types/node@22.13.14)(sass@1.86.0)))(svelte@5.25.3)(vite@7.0.6(@types/node@22.13.14)(sass@1.86.0))
|
||||
'@stripe/stripe-js':
|
||||
specifier: ^3.5.0
|
||||
version: 3.5.0
|
||||
@@ -101,10 +101,10 @@ importers:
|
||||
version: 1.51.1
|
||||
'@sveltejs/adapter-static':
|
||||
specifier: ^3.0.8
|
||||
version: 3.0.8(@sveltejs/kit@2.20.2(@sveltejs/vite-plugin-svelte@5.0.3(svelte@5.25.3)(vite@7.0.6(@types/node@22.13.14)(sass@1.86.0)))(svelte@5.25.3)(vite@7.0.6(@types/node@22.13.14)(sass@1.86.0)))
|
||||
version: 3.0.8(@sveltejs/kit@2.36.3(@opentelemetry/api@1.9.0)(@sveltejs/vite-plugin-svelte@5.0.3(svelte@5.25.3)(vite@7.0.6(@types/node@22.13.14)(sass@1.86.0)))(svelte@5.25.3)(vite@7.0.6(@types/node@22.13.14)(sass@1.86.0)))
|
||||
'@sveltejs/kit':
|
||||
specifier: ^2.20.2
|
||||
version: 2.20.2(@sveltejs/vite-plugin-svelte@5.0.3(svelte@5.25.3)(vite@7.0.6(@types/node@22.13.14)(sass@1.86.0)))(svelte@5.25.3)(vite@7.0.6(@types/node@22.13.14)(sass@1.86.0))
|
||||
specifier: ^2.36.2
|
||||
version: 2.36.3(@opentelemetry/api@1.9.0)(@sveltejs/vite-plugin-svelte@5.0.3(svelte@5.25.3)(vite@7.0.6(@types/node@22.13.14)(sass@1.86.0)))(svelte@5.25.3)(vite@7.0.6(@types/node@22.13.14)(sass@1.86.0))
|
||||
'@sveltejs/vite-plugin-svelte':
|
||||
specifier: ^5.0.3
|
||||
version: 5.0.3(svelte@5.25.3)(vite@7.0.6(@types/node@22.13.14)(sass@1.86.0))
|
||||
@@ -1247,6 +1247,9 @@ packages:
|
||||
'@shikijs/vscode-textmate@10.0.2':
|
||||
resolution: {integrity: sha512-83yeghZ2xxin3Nj8z1NMd/NCuca+gsYXswywDy5bHvwlWL8tpTQmzGeUuHd9FC3E/SBEMvzJRwWEOz5gGes9Qg==}
|
||||
|
||||
'@standard-schema/spec@1.0.0':
|
||||
resolution: {integrity: sha512-m2bOd0f2RT9k8QJx1JN85cZYyH1RqFBdlwtkSlf4tBDYLCiiZnv1fIIwacK6cqwXavOydf0NPToMQgpKq+dVlA==}
|
||||
|
||||
'@stripe/stripe-js@3.5.0':
|
||||
resolution: {integrity: sha512-pKS3wZnJoL1iTyGBXAvCwduNNeghJHY6QSRSNNvpYnrrQrLZ6Owsazjyynu0e0ObRgks0i7Rv+pe2M7/MBTZpQ==}
|
||||
engines: {node: '>=12.16'}
|
||||
@@ -1261,14 +1264,18 @@ packages:
|
||||
peerDependencies:
|
||||
'@sveltejs/kit': ^2.0.0
|
||||
|
||||
'@sveltejs/kit@2.20.2':
|
||||
resolution: {integrity: sha512-Dv8TOAZC9vyfcAB9TMsvUEJsRbklRTeNfcYBPaeH6KnABJ99i3CvCB2eNx8fiiliIqe+9GIchBg4RodRH5p1BQ==}
|
||||
'@sveltejs/kit@2.36.3':
|
||||
resolution: {integrity: sha512-MVzwZz1GFznEQbL3f0i2v9AIc3lZH01izQj6XfIrthmZAwOzyXJCgXbLRss8vk//HfYsE4w6Tz+ukbf3rScPNQ==}
|
||||
engines: {node: '>=18.13'}
|
||||
hasBin: true
|
||||
peerDependencies:
|
||||
'@sveltejs/vite-plugin-svelte': ^3.0.0 || ^4.0.0-next.1 || ^5.0.0
|
||||
'@opentelemetry/api': ^1.0.0
|
||||
'@sveltejs/vite-plugin-svelte': ^3.0.0 || ^4.0.0-next.1 || ^5.0.0 || ^6.0.0-next.0
|
||||
svelte: ^4.0.0 || ^5.0.0-next.0
|
||||
vite: ^5.0.3 || ^6.0.0
|
||||
vite: ^5.0.3 || ^6.0.0 || ^7.0.0-beta.0
|
||||
peerDependenciesMeta:
|
||||
'@opentelemetry/api':
|
||||
optional: true
|
||||
|
||||
'@sveltejs/vite-plugin-svelte-inspector@4.0.1':
|
||||
resolution: {integrity: sha512-J/Nmb2Q2y7mck2hyCX4ckVHcR5tu2J+MtBEQqpDrrgELZ2uvraQcK/ioCV61AqkdXFgriksOKIceDcQmqnGhVw==}
|
||||
@@ -2009,8 +2016,8 @@ packages:
|
||||
engines: {node: '>=0.10'}
|
||||
hasBin: true
|
||||
|
||||
devalue@5.1.1:
|
||||
resolution: {integrity: sha512-maua5KUiapvEwiEAe+XnlZ3Rh0GD+qI1J/nb9vrJc3muPXvcF/8gXYTWF76+5DAqHyDUtOIImEuo0YKE9mshVw==}
|
||||
devalue@5.3.2:
|
||||
resolution: {integrity: sha512-UDsjUbpQn9kvm68slnrs+mfxwFkIflOhkanmyabZ8zOYk8SMEIbJ3TK+88g70hSIeytu4y18f0z/hYHMTrXIWw==}
|
||||
|
||||
devlop@1.1.0:
|
||||
resolution: {integrity: sha512-RWmIqhcFf1lRYBvNmr7qTNuyCt/7/ns2jbpp1+PalgE/rDQcBT0fioSMUpJ93irlUhC5hrg4cYqe6U+0ImW0rA==}
|
||||
@@ -2393,9 +2400,6 @@ packages:
|
||||
import-in-the-middle@1.13.1:
|
||||
resolution: {integrity: sha512-k2V9wNm9B+ysuelDTHjI9d5KPc4l8zAZTGqj+pcynvWkypZd857ryzN8jNC7Pg2YZXNMJcHRPpaDyCBbNyVRpA==}
|
||||
|
||||
import-meta-resolve@4.1.0:
|
||||
resolution: {integrity: sha512-I6fiaX09Xivtk+THaMfAwnA3MVA5Big1WHF1Dfx9hFuvNIWpXnorlkzhcQf6ehrqQiiZECRt1poOAkPmer3ruw==}
|
||||
|
||||
imurmurhash@0.1.4:
|
||||
resolution: {integrity: sha512-JmXMZ6wuvDmLiHEml9ykzqO6lwFbof0GG4IkcGaENdCRDDmMVnny7s5HsIgHCbaq0w2MyPhDqkhTUgS2LU2PHA==}
|
||||
engines: {node: '>=0.8.19'}
|
||||
@@ -4667,14 +4671,14 @@ snapshots:
|
||||
magic-string: 0.30.7
|
||||
svelte: 5.25.3
|
||||
|
||||
'@sentry/sveltekit@8.55.0(@opentelemetry/api@1.9.0)(@opentelemetry/context-async-hooks@1.30.1(@opentelemetry/api@1.9.0))(@opentelemetry/core@1.30.1(@opentelemetry/api@1.9.0))(@opentelemetry/instrumentation@0.57.2(@opentelemetry/api@1.9.0))(@opentelemetry/sdk-trace-base@1.30.1(@opentelemetry/api@1.9.0))(@opentelemetry/semantic-conventions@1.30.0)(@sveltejs/kit@2.20.2(@sveltejs/vite-plugin-svelte@5.0.3(svelte@5.25.3)(vite@7.0.6(@types/node@22.13.14)(sass@1.86.0)))(svelte@5.25.3)(vite@7.0.6(@types/node@22.13.14)(sass@1.86.0)))(svelte@5.25.3)(vite@7.0.6(@types/node@22.13.14)(sass@1.86.0))':
|
||||
'@sentry/sveltekit@8.55.0(@opentelemetry/api@1.9.0)(@opentelemetry/context-async-hooks@1.30.1(@opentelemetry/api@1.9.0))(@opentelemetry/core@1.30.1(@opentelemetry/api@1.9.0))(@opentelemetry/instrumentation@0.57.2(@opentelemetry/api@1.9.0))(@opentelemetry/sdk-trace-base@1.30.1(@opentelemetry/api@1.9.0))(@opentelemetry/semantic-conventions@1.30.0)(@sveltejs/kit@2.36.3(@opentelemetry/api@1.9.0)(@sveltejs/vite-plugin-svelte@5.0.3(svelte@5.25.3)(vite@7.0.6(@types/node@22.13.14)(sass@1.86.0)))(svelte@5.25.3)(vite@7.0.6(@types/node@22.13.14)(sass@1.86.0)))(svelte@5.25.3)(vite@7.0.6(@types/node@22.13.14)(sass@1.86.0))':
|
||||
dependencies:
|
||||
'@sentry/core': 8.55.0
|
||||
'@sentry/node': 8.55.0
|
||||
'@sentry/opentelemetry': 8.55.0(@opentelemetry/api@1.9.0)(@opentelemetry/context-async-hooks@1.30.1(@opentelemetry/api@1.9.0))(@opentelemetry/core@1.30.1(@opentelemetry/api@1.9.0))(@opentelemetry/instrumentation@0.57.2(@opentelemetry/api@1.9.0))(@opentelemetry/sdk-trace-base@1.30.1(@opentelemetry/api@1.9.0))(@opentelemetry/semantic-conventions@1.30.0)
|
||||
'@sentry/svelte': 8.55.0(svelte@5.25.3)
|
||||
'@sentry/vite-plugin': 2.22.6
|
||||
'@sveltejs/kit': 2.20.2(@sveltejs/vite-plugin-svelte@5.0.3(svelte@5.25.3)(vite@7.0.6(@types/node@22.13.14)(sass@1.86.0)))(svelte@5.25.3)(vite@7.0.6(@types/node@22.13.14)(sass@1.86.0))
|
||||
'@sveltejs/kit': 2.36.3(@opentelemetry/api@1.9.0)(@sveltejs/vite-plugin-svelte@5.0.3(svelte@5.25.3)(vite@7.0.6(@types/node@22.13.14)(sass@1.86.0)))(svelte@5.25.3)(vite@7.0.6(@types/node@22.13.14)(sass@1.86.0))
|
||||
magic-string: 0.30.7
|
||||
magicast: 0.2.8
|
||||
sorcery: 1.0.0
|
||||
@@ -4734,32 +4738,42 @@ snapshots:
|
||||
|
||||
'@shikijs/vscode-textmate@10.0.2': {}
|
||||
|
||||
'@standard-schema/spec@1.0.0': {}
|
||||
|
||||
'@stripe/stripe-js@3.5.0': {}
|
||||
|
||||
'@sveltejs/acorn-typescript@1.0.5(acorn@8.14.1)':
|
||||
dependencies:
|
||||
acorn: 8.14.1
|
||||
|
||||
'@sveltejs/adapter-static@3.0.8(@sveltejs/kit@2.20.2(@sveltejs/vite-plugin-svelte@5.0.3(svelte@5.25.3)(vite@7.0.6(@types/node@22.13.14)(sass@1.86.0)))(svelte@5.25.3)(vite@7.0.6(@types/node@22.13.14)(sass@1.86.0)))':
|
||||
'@sveltejs/acorn-typescript@1.0.5(acorn@8.15.0)':
|
||||
dependencies:
|
||||
'@sveltejs/kit': 2.20.2(@sveltejs/vite-plugin-svelte@5.0.3(svelte@5.25.3)(vite@7.0.6(@types/node@22.13.14)(sass@1.86.0)))(svelte@5.25.3)(vite@7.0.6(@types/node@22.13.14)(sass@1.86.0))
|
||||
acorn: 8.15.0
|
||||
|
||||
'@sveltejs/kit@2.20.2(@sveltejs/vite-plugin-svelte@5.0.3(svelte@5.25.3)(vite@7.0.6(@types/node@22.13.14)(sass@1.86.0)))(svelte@5.25.3)(vite@7.0.6(@types/node@22.13.14)(sass@1.86.0))':
|
||||
'@sveltejs/adapter-static@3.0.8(@sveltejs/kit@2.36.3(@opentelemetry/api@1.9.0)(@sveltejs/vite-plugin-svelte@5.0.3(svelte@5.25.3)(vite@7.0.6(@types/node@22.13.14)(sass@1.86.0)))(svelte@5.25.3)(vite@7.0.6(@types/node@22.13.14)(sass@1.86.0)))':
|
||||
dependencies:
|
||||
'@sveltejs/kit': 2.36.3(@opentelemetry/api@1.9.0)(@sveltejs/vite-plugin-svelte@5.0.3(svelte@5.25.3)(vite@7.0.6(@types/node@22.13.14)(sass@1.86.0)))(svelte@5.25.3)(vite@7.0.6(@types/node@22.13.14)(sass@1.86.0))
|
||||
|
||||
'@sveltejs/kit@2.36.3(@opentelemetry/api@1.9.0)(@sveltejs/vite-plugin-svelte@5.0.3(svelte@5.25.3)(vite@7.0.6(@types/node@22.13.14)(sass@1.86.0)))(svelte@5.25.3)(vite@7.0.6(@types/node@22.13.14)(sass@1.86.0))':
|
||||
dependencies:
|
||||
'@standard-schema/spec': 1.0.0
|
||||
'@sveltejs/acorn-typescript': 1.0.5(acorn@8.15.0)
|
||||
'@sveltejs/vite-plugin-svelte': 5.0.3(svelte@5.25.3)(vite@7.0.6(@types/node@22.13.14)(sass@1.86.0))
|
||||
'@types/cookie': 0.6.0
|
||||
acorn: 8.15.0
|
||||
cookie: 0.6.0
|
||||
devalue: 5.1.1
|
||||
devalue: 5.3.2
|
||||
esm-env: 1.2.2
|
||||
import-meta-resolve: 4.1.0
|
||||
kleur: 4.1.5
|
||||
magic-string: 0.30.17
|
||||
magic-string: 0.30.18
|
||||
mrmime: 2.0.1
|
||||
sade: 1.8.1
|
||||
set-cookie-parser: 2.7.1
|
||||
sirv: 3.0.1
|
||||
svelte: 5.25.3
|
||||
vite: 7.0.6(@types/node@22.13.14)(sass@1.86.0)
|
||||
optionalDependencies:
|
||||
'@opentelemetry/api': 1.9.0
|
||||
|
||||
'@sveltejs/vite-plugin-svelte-inspector@4.0.1(@sveltejs/vite-plugin-svelte@5.0.3(svelte@5.25.3)(vite@7.0.6(@types/node@22.13.14)(sass@1.86.0)))(svelte@5.25.3)(vite@7.0.6(@types/node@22.13.14)(sass@1.86.0))':
|
||||
dependencies:
|
||||
@@ -5641,7 +5655,7 @@ snapshots:
|
||||
detect-libc@1.0.3:
|
||||
optional: true
|
||||
|
||||
devalue@5.1.1: {}
|
||||
devalue@5.3.2: {}
|
||||
|
||||
devlop@1.1.0:
|
||||
dependencies:
|
||||
@@ -6069,8 +6083,6 @@ snapshots:
|
||||
cjs-module-lexer: 1.4.3
|
||||
module-details-from-path: 1.0.3
|
||||
|
||||
import-meta-resolve@4.1.0: {}
|
||||
|
||||
imurmurhash@0.1.4: {}
|
||||
|
||||
indent-string@4.0.0: {}
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
<script lang="ts">
|
||||
import { base } from '$app/paths';
|
||||
import { goto } from '$app/navigation';
|
||||
import { Button } from '$lib/elements/forms';
|
||||
import { HeaderAlert } from '$lib/layout';
|
||||
import { Typography } from '@appwrite.io/pink-svelte';
|
||||
import { hideNotification, shouldShowNotification } from '$lib/helpers/notifications';
|
||||
import { user } from '$lib/stores/user';
|
||||
import { wizard } from '$lib/stores/wizard';
|
||||
import { page } from '$app/state';
|
||||
|
||||
const { emailBannerClosed, onEmailBannerClose } = $props<{
|
||||
emailBannerClosed: boolean;
|
||||
onEmailBannerClose: (closed: boolean) => void;
|
||||
}>();
|
||||
|
||||
const isOnOnboarding = $derived(page.url?.pathname?.includes('/console/onboarding'));
|
||||
|
||||
const hasUser = $derived(!!$user);
|
||||
const needsEmailVerification = $derived(hasUser && !$user.emailVerification);
|
||||
const shouldShowNotificationBanner = $derived.by(() =>
|
||||
shouldShowNotification('email-verification-banner')
|
||||
);
|
||||
const wizardNotActive = $derived(!$wizard.show && !$wizard.cover);
|
||||
const bannerNotClosed = $derived(!emailBannerClosed);
|
||||
const notOnOnboarding = $derived(!isOnOnboarding);
|
||||
|
||||
const shouldShowEmailBanner = $derived(
|
||||
hasUser &&
|
||||
needsEmailVerification &&
|
||||
shouldShowNotificationBanner &&
|
||||
wizardNotActive &&
|
||||
bannerNotClosed &&
|
||||
notOnOnboarding
|
||||
);
|
||||
|
||||
function navigateToAccount() {
|
||||
goto(`${base}/account`);
|
||||
}
|
||||
|
||||
function handleDismiss() {
|
||||
onEmailBannerClose(true);
|
||||
hideNotification('email-verification-banner', { coolOffPeriod: 24 * 365 * 100 });
|
||||
}
|
||||
</script>
|
||||
|
||||
{#if shouldShowEmailBanner}
|
||||
<HeaderAlert
|
||||
type="warning"
|
||||
title="Your email address needs to be verified"
|
||||
dismissible
|
||||
on:dismiss={handleDismiss}>
|
||||
<svelte:fragment>
|
||||
To avoid losing access to your projects, make sure <Typography.Text
|
||||
variant="m-500"
|
||||
style="display:inline">{$user.email}</Typography.Text> is valid and up to date. Email
|
||||
verification will be required soon.
|
||||
</svelte:fragment>
|
||||
<svelte:fragment slot="buttons">
|
||||
<Button secondary size="s" on:click={navigateToAccount}>Update email address</Button>
|
||||
</svelte:fragment>
|
||||
</HeaderAlert>
|
||||
{/if}
|
||||
@@ -78,7 +78,7 @@
|
||||
</Layout.Stack>
|
||||
{:else}
|
||||
<Card.Base variant="secondary" radius="s" padding="xs">
|
||||
<Layout.Stack direction="row">
|
||||
<Layout.Stack direction="row" id="no-payments-card-stack">
|
||||
<Layout.Stack direction="row" gap="xxs" alignItems="center">
|
||||
<Icon
|
||||
icon={IconExclamationCircle}
|
||||
|
||||
@@ -21,6 +21,5 @@
|
||||
{#if ccImage}
|
||||
<img alt={brand} src={ccImage} {width} {height} style:border-radius="2.5px" />
|
||||
{:else}
|
||||
<!-- fallback: unionpay image not in Avatars API -->
|
||||
<Icon icon={IconCreditCard} color="--fgcolor-neutral-tertiary" />
|
||||
{/if}
|
||||
@@ -11,6 +11,7 @@
|
||||
import { menuOpen } from '$lib/components/menu/store';
|
||||
|
||||
export let time: string | null = null;
|
||||
export let showDatetime: boolean = false;
|
||||
export let canShowPopover: boolean = true;
|
||||
export let placement: ComponentProps<Popover>['placement'] = 'bottom';
|
||||
|
||||
@@ -85,7 +86,7 @@
|
||||
}
|
||||
}}
|
||||
on:mouseleave={() => hidePopover(hide)}>
|
||||
<slot>{capitalize(timeFromNow(time))}</slot>
|
||||
<slot>{showDatetime ? toLocaleDateTime(time) : capitalize(timeFromNow(time))}</slot>
|
||||
</button>
|
||||
|
||||
<div
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
ValidOperators
|
||||
} from './store';
|
||||
import { createEventDispatcher } from 'svelte';
|
||||
import { Icon, Layout, Popover } from '@appwrite.io/pink-svelte';
|
||||
import { Badge, Icon, Layout, Popover } from '@appwrite.io/pink-svelte';
|
||||
import { IconFilter, IconFilterLine } from '@appwrite.io/pink-icons-svelte';
|
||||
import { Click, Submit, trackEvent } from '$lib/actions/analytics';
|
||||
|
||||
@@ -44,12 +44,12 @@
|
||||
let showFiltersDesktop = false;
|
||||
let showFiltersMobile = false;
|
||||
|
||||
let applied = $tags.length;
|
||||
$: filtersAppliedCount = $tags.length;
|
||||
|
||||
beforeNavigate(() => {
|
||||
applied = $tags.length;
|
||||
showFiltersDesktop = false;
|
||||
showFiltersMobile = false;
|
||||
filtersAppliedCount = $tags.length;
|
||||
});
|
||||
|
||||
function clearAll() {
|
||||
@@ -87,7 +87,7 @@
|
||||
applied: number;
|
||||
}>
|
||||
) {
|
||||
applied = e.detail.applied;
|
||||
filtersAppliedCount = e.detail.applied;
|
||||
if (singleCondition) {
|
||||
showFiltersDesktop = false;
|
||||
showFiltersMobile = false;
|
||||
@@ -132,13 +132,20 @@
|
||||
trackEvent(Click.FilterApplyClick, { source: analyticsSource });
|
||||
}}
|
||||
{disabled}>
|
||||
<Icon icon={IconFilterLine} slot="start" size={onlyIcon ? 'm' : 's'} />
|
||||
{#if !onlyIcon}
|
||||
<Icon icon={IconFilterLine} slot="start" size={onlyIcon ? 'm' : 's'} />
|
||||
Filters
|
||||
{#if applied > 0}
|
||||
<span class="inline-tag">
|
||||
{applied}
|
||||
</span>
|
||||
{#if filtersAppliedCount > 0}
|
||||
<Badge size="xs" variant="secondary" content={filtersAppliedCount.toString()} />
|
||||
{/if}
|
||||
{:else}
|
||||
<Icon
|
||||
icon={IconFilterLine}
|
||||
size={onlyIcon ? 'm' : 's'}
|
||||
color="--fgcolor-neutral-tertiary" />
|
||||
|
||||
{#if filtersAppliedCount > 0}
|
||||
<Badge content={filtersAppliedCount.toString()} size="xs" variant="secondary" />
|
||||
{/if}
|
||||
{/if}
|
||||
</Button>
|
||||
@@ -160,7 +167,7 @@
|
||||
{columns}
|
||||
{singleCondition}
|
||||
on:apply={afterApply}
|
||||
on:clear={() => (applied = 0)} />
|
||||
on:clear={() => (filtersAppliedCount = 0)} />
|
||||
{/if}
|
||||
<div
|
||||
class="u-flex u-cross-center u-margin-block-start-16"
|
||||
@@ -180,7 +187,7 @@
|
||||
{:else}
|
||||
<Button
|
||||
size="s"
|
||||
disabled={applied === 0}
|
||||
disabled={filtersAppliedCount === 0}
|
||||
text
|
||||
on:click={clearAll}>
|
||||
Clear all
|
||||
@@ -202,10 +209,8 @@
|
||||
<Button size="s" secondary on:click={toggleMobileModal} {fullWidthMobile}>
|
||||
<Icon icon={IconFilter} slot="start" size="s" />
|
||||
Filters
|
||||
{#if applied > 0}
|
||||
<span class="inline-tag">
|
||||
{applied}
|
||||
</span>
|
||||
{#if filtersAppliedCount > 0}
|
||||
<Badge content={filtersAppliedCount.toString()} size="xs" variant="secondary" />
|
||||
{/if}
|
||||
</Button>
|
||||
</slot>
|
||||
@@ -223,7 +228,7 @@
|
||||
bind:arrayValues
|
||||
{singleCondition}
|
||||
on:apply={afterApply}
|
||||
on:clear={() => (applied = 0)} />
|
||||
on:clear={() => (filtersAppliedCount = 0)} />
|
||||
{/if}
|
||||
<svelte:fragment slot="footer">
|
||||
<div
|
||||
|
||||
@@ -85,4 +85,5 @@ export { default as ViewToggle } from './viewToggle.svelte';
|
||||
export { default as RegionEndpoint } from './regionEndpoint.svelte';
|
||||
export { default as ExpirationInput } from './expirationInput.svelte';
|
||||
export { default as EstimatedCard } from './estimatedCard.svelte';
|
||||
export { default as EmailVerificationBanner } from './alerts/emailVerificationBanner.svelte';
|
||||
export { default as SortButton, type SortDirection } from './sortButton.svelte';
|
||||
@@ -1,19 +1,29 @@
|
||||
<script lang="ts">
|
||||
import { page } from '$app/state';
|
||||
import { goto } from '$app/navigation';
|
||||
import { onDestroy } from 'svelte';
|
||||
import { goto } from '$app/navigation';
|
||||
import { trackEvent } from '$lib/actions/analytics';
|
||||
import { Icon, Input } from '@appwrite.io/pink-svelte';
|
||||
import { IconSearch, IconX } from '@appwrite.io/pink-icons-svelte';
|
||||
import { debounce as createDebounce } from '$lib/helpers/debounce.js';
|
||||
|
||||
export let placeholder = '';
|
||||
export let debounce = 250;
|
||||
export let required = false;
|
||||
export let disabled = false;
|
||||
export let autofocus = false;
|
||||
interface Props {
|
||||
placeholder?: string;
|
||||
debounce?: number;
|
||||
required?: boolean;
|
||||
disabled?: boolean;
|
||||
autofocus?: boolean;
|
||||
}
|
||||
|
||||
let inputValue = page.url.searchParams.get('search') ?? '';
|
||||
let {
|
||||
placeholder = '',
|
||||
debounce = 250,
|
||||
required = false,
|
||||
disabled = false,
|
||||
autofocus = false
|
||||
}: Props = $props();
|
||||
|
||||
let inputValue = $state(page.url.searchParams.get('search') ?? '');
|
||||
|
||||
const runSearch = createDebounce((value: string) => {
|
||||
const trimmed = value.trim();
|
||||
@@ -36,15 +46,21 @@
|
||||
goto(url, { keepFocus: true });
|
||||
}, debounce);
|
||||
|
||||
$: runSearch(inputValue);
|
||||
|
||||
function clearInput() {
|
||||
export function clearInput() {
|
||||
inputValue = '';
|
||||
}
|
||||
|
||||
onDestroy(() => {
|
||||
runSearch.cancel?.();
|
||||
});
|
||||
|
||||
$effect(() => {
|
||||
const urlSearch = page.url.searchParams.get('search') ?? '';
|
||||
|
||||
if (urlSearch !== inputValue) {
|
||||
runSearch(inputValue);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<div style:max-width="360px" style:width="100%">
|
||||
|
||||
@@ -34,13 +34,14 @@
|
||||
import { showSupportModal } from '$routes/(console)/wizard/support/store';
|
||||
import MobileSupportModal from '$routes/(console)/wizard/support/mobileSupportModal.svelte';
|
||||
import MobileFeedbackModal from '$routes/(console)/wizard/feedback/mobileFeedbackModal.svelte';
|
||||
import { getSidebarState, updateSidebarState } from '$lib/helpers/sidebar';
|
||||
import { getSidebarState, isInDatabasesRoute, updateSidebarState } from '$lib/helpers/sidebar';
|
||||
import { isTabletViewport, isSmallViewport } from '$lib/stores/viewport';
|
||||
import { Click, trackEvent } from '$lib/actions/analytics';
|
||||
import { bannerSpacing } from '$lib/layout/headerAlert.svelte';
|
||||
|
||||
import type { HTMLAttributes } from 'svelte/elements';
|
||||
import type { Models } from '@appwrite.io/console';
|
||||
import { noWidthTransition } from '$lib/stores/sidebar';
|
||||
|
||||
type $$Props = HTMLAttributes<HTMLElement> & {
|
||||
state?: 'closed' | 'open' | 'icons';
|
||||
@@ -72,8 +73,6 @@
|
||||
}
|
||||
}
|
||||
|
||||
$: state = $isTabletViewport ? 'closed' : getSidebarState($page);
|
||||
|
||||
const projectOptions = [
|
||||
{ name: 'Auth', icon: IconUserGroup, slug: 'auth', category: 'build' },
|
||||
{ name: 'Databases', icon: IconDatabase, slug: 'databases', category: 'build' },
|
||||
@@ -92,17 +91,26 @@
|
||||
const isSelected = (service: string): boolean => {
|
||||
return $page.route.id?.includes(service);
|
||||
};
|
||||
|
||||
$: state = $isTabletViewport
|
||||
? 'closed'
|
||||
: // example: manual resize
|
||||
isInDatabasesRoute($page.route)
|
||||
? 'icons'
|
||||
: getSidebarState();
|
||||
</script>
|
||||
|
||||
<div
|
||||
class="sidebar"
|
||||
class:only-mobile-tablet={!project}
|
||||
class:no-transitions={$noWidthTransition}
|
||||
style:--overlay-on-neutral={$app.themeInUse === 'dark'
|
||||
? 'var(--neutral-750)'
|
||||
: 'var(--neutral-100)'}>
|
||||
<Sidebar.Base
|
||||
{...$$props}
|
||||
bind:state
|
||||
on:resize={(event) => updateSidebarState($page, event.detail)}
|
||||
on:resize={(event) => updateSidebarState(event.detail)}
|
||||
resizable>
|
||||
<div slot="top">
|
||||
<div class="only-mobile-tablet top">
|
||||
@@ -356,16 +364,24 @@
|
||||
</Sidebar.Base>
|
||||
</div>
|
||||
|
||||
{#if subNavigation}
|
||||
<div
|
||||
class="sub-navigation"
|
||||
class:icons={state === 'icons'}
|
||||
style:--banner-spacing={$bannerSpacing ? $bannerSpacing : undefined}>
|
||||
<svelte:component this={subNavigation} />
|
||||
</div>
|
||||
{/if}
|
||||
<div style:--banner-spacing={$bannerSpacing ? $bannerSpacing : undefined}>
|
||||
{#if subNavigation}
|
||||
<div
|
||||
class="sub-navigation"
|
||||
class:icons={state === 'icons'}
|
||||
class:no-transitions={$noWidthTransition}>
|
||||
<svelte:component this={subNavigation} />
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<style lang="scss">
|
||||
.sidebar {
|
||||
&.no-transitions :global(nav) {
|
||||
transition: none !important;
|
||||
}
|
||||
}
|
||||
|
||||
.middle-container {
|
||||
flex: 1;
|
||||
overflow-y: visible;
|
||||
@@ -624,13 +640,17 @@
|
||||
background-color: var(--bgcolor-neutral-primary, #fff);
|
||||
z-index: 14;
|
||||
position: fixed;
|
||||
top: 48px;
|
||||
top: var(--banner-spacing, 48px);
|
||||
transition: width 0.2s linear;
|
||||
|
||||
&.icons {
|
||||
width: 266px;
|
||||
transition: width 0.3s linear;
|
||||
|
||||
&.no-transitions {
|
||||
transition: none !important;
|
||||
}
|
||||
|
||||
& :global(nav) {
|
||||
margin-top: var(--banner-spacing);
|
||||
}
|
||||
|
||||
@@ -18,8 +18,9 @@
|
||||
|
||||
let error: string;
|
||||
|
||||
function coerceToNumber(event: Event & { currentTarget: EventTarget & HTMLInputElement }) {
|
||||
const raw = event.currentTarget?.value ?? '';
|
||||
function coerceToNumber(event: CustomEvent) {
|
||||
const raw = event.detail ?? '';
|
||||
|
||||
if (raw === '') {
|
||||
value = nullable ? null : (undefined as unknown as number);
|
||||
return;
|
||||
@@ -74,7 +75,6 @@
|
||||
helper={error || helper}
|
||||
state={error ? 'error' : 'default'}
|
||||
on:invalid={handleInvalid}
|
||||
on:input={coerceToNumber}
|
||||
on:change={coerceToNumber}>
|
||||
<svelte:fragment slot="info">
|
||||
<slot name="info" slot="info" />
|
||||
|
||||
@@ -102,3 +102,11 @@ export function total(set: Array<number>): number {
|
||||
if (!set) return 0;
|
||||
return set.reduce((prev, curr) => prev + curr, 0);
|
||||
}
|
||||
|
||||
export function chunks<T>(array: T[], size: number = 10): T[][] {
|
||||
const output: T[][] = [];
|
||||
for (let i = 0; i < array.length; i += size) {
|
||||
output.push(array.slice(i, i + size));
|
||||
}
|
||||
return output;
|
||||
}
|
||||
+17
-17
@@ -2,6 +2,7 @@ import { faker } from '@faker-js/faker';
|
||||
import type { Columns } from '$routes/(console)/project-[region]-[project]/databases/database-[database]/table-[table]/store';
|
||||
import { ID, type Models } from '@appwrite.io/console';
|
||||
import { sdk } from '$lib/stores/sdk';
|
||||
import { isWithinSafeRange } from '$lib/helpers/numbers';
|
||||
|
||||
export async function generateColumns(
|
||||
project: Models.Project,
|
||||
@@ -148,6 +149,14 @@ function generateSingleValue(column: Columns): string | number | boolean | null
|
||||
case 'url': {
|
||||
return faker.internet.url();
|
||||
}
|
||||
|
||||
case 'enum': {
|
||||
const enumAttr = column as Models.ColumnEnum;
|
||||
if (enumAttr.elements?.length > 0) {
|
||||
return faker.helpers.arrayElement(enumAttr.elements);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return '';
|
||||
} else {
|
||||
@@ -159,19 +168,18 @@ function generateSingleValue(column: Columns): string | number | boolean | null
|
||||
|
||||
case 'integer': {
|
||||
const intAttr = column as Models.ColumnInteger;
|
||||
const min = intAttr.min ?? 0;
|
||||
const max = intAttr.max ?? 10000;
|
||||
const min = !isWithinSafeRange(intAttr.min) ? 0 : intAttr.min;
|
||||
const max = !isWithinSafeRange(intAttr.max) ? 100 : intAttr.max;
|
||||
return faker.number.int({ min, max });
|
||||
}
|
||||
|
||||
case 'float': {
|
||||
case 'double': {
|
||||
const floatAttr = column as Models.ColumnFloat;
|
||||
const min = floatAttr.min ?? 0;
|
||||
const max = floatAttr.max ?? 1000000;
|
||||
const precision = 2;
|
||||
return parseFloat(
|
||||
faker.number.float({ min, max, fractionDigits: precision }).toFixed(precision)
|
||||
);
|
||||
const min = !isWithinSafeRange(floatAttr.min) ? 0 : floatAttr.min;
|
||||
const max = !isWithinSafeRange(floatAttr.max) ? 100 : floatAttr.max;
|
||||
const precision = 4;
|
||||
|
||||
return faker.number.float({ min, max, fractionDigits: precision });
|
||||
}
|
||||
|
||||
case 'boolean': {
|
||||
@@ -182,14 +190,6 @@ function generateSingleValue(column: Columns): string | number | boolean | null
|
||||
return faker.date.recent({ days: 365 }).toISOString();
|
||||
}
|
||||
|
||||
case 'enum': {
|
||||
const enumAttr = column as Models.ColumnEnum;
|
||||
if (enumAttr.elements && enumAttr.elements.length > 0) {
|
||||
return faker.helpers.arrayElement(enumAttr.elements);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
default: {
|
||||
return faker.lorem.word();
|
||||
}
|
||||
|
||||
@@ -32,3 +32,7 @@ export function formatCurrency(number: number, locale = 'en-US', currency = 'USD
|
||||
});
|
||||
return formatter.format(number);
|
||||
}
|
||||
|
||||
export function isWithinSafeRange(val: number) {
|
||||
return Math.abs(val) < Number.MAX_SAFE_INTEGER;
|
||||
}
|
||||
@@ -1,18 +1,15 @@
|
||||
import { get } from 'svelte/store';
|
||||
import { user } from '$lib/stores/user';
|
||||
import { sdk } from '$lib/stores/sdk';
|
||||
import type { Page } from '@sveltejs/kit';
|
||||
|
||||
const userPreferences = () => get(user)?.prefs;
|
||||
|
||||
// for spreadsheet, closed with icons
|
||||
const isInDatabasesRoute = (page: Page) => {
|
||||
return page.route.id?.includes('databases/database-[database]');
|
||||
export const isInDatabasesRoute = (route: { id?: string }) => {
|
||||
return route.id?.includes('databases/database-[database]');
|
||||
};
|
||||
|
||||
export function updateSidebarState(page: Page, state: 'closed' | 'open' | 'icons') {
|
||||
if (isInDatabasesRoute(page)) return;
|
||||
|
||||
export function updateSidebarState(state: 'closed' | 'open' | 'icons') {
|
||||
if (state === 'open' || state === 'icons') {
|
||||
const currentPrefs = userPreferences();
|
||||
|
||||
@@ -25,9 +22,7 @@ export function updateSidebarState(page: Page, state: 'closed' | 'open' | 'icons
|
||||
}
|
||||
}
|
||||
|
||||
export function getSidebarState(page: Page): 'open' | 'icons' {
|
||||
if (isInDatabasesRoute(page)) return 'icons';
|
||||
|
||||
export function getSidebarState(): 'open' | 'icons' {
|
||||
const currentPrefs = userPreferences();
|
||||
if (currentPrefs && currentPrefs.sidebarState) {
|
||||
if (currentPrefs.sidebarState === 'open' || currentPrefs.sidebarState === 'icons') {
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 1.2 MiB |
Binary file not shown.
|
Before Width: | Height: | Size: 1.0 MiB |
Binary file not shown.
|
After Width: | Height: | Size: 744 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 285 KiB |
@@ -7,11 +7,24 @@
|
||||
<script lang="ts">
|
||||
import { onDestroy, onMount } from 'svelte';
|
||||
import { isTabletViewport } from '$lib/stores/viewport';
|
||||
import { createEventDispatcher } from 'svelte';
|
||||
import { Button } from '$lib/elements/forms';
|
||||
import { Icon } from '@appwrite.io/pink-svelte';
|
||||
import { IconX } from '@appwrite.io/pink-icons-svelte';
|
||||
import { afterNavigate } from '$app/navigation';
|
||||
|
||||
export let title: string;
|
||||
export let type: 'info' | 'success' | 'warning' | 'error' | 'default' = 'info';
|
||||
export let dismissible = false;
|
||||
|
||||
/**
|
||||
* This is needed because when the
|
||||
* slot's height gets changed, sometimes the update doesn't come through!
|
||||
*/
|
||||
let resizeObserver: ResizeObserver;
|
||||
|
||||
let container: HTMLElement | null = null;
|
||||
const dispatch = createEventDispatcher();
|
||||
|
||||
function setNavigationHeight() {
|
||||
const alertHeight = container ? container.getBoundingClientRect().height : 0;
|
||||
@@ -19,16 +32,23 @@
|
||||
const sidebar: HTMLElement = document.querySelector('main > div > nav');
|
||||
const contentSection: HTMLElement = document.querySelector('main > div > section');
|
||||
|
||||
if (alertHeight) {
|
||||
// for sidebar and sub-navigation!
|
||||
bannerSpacing.set(`${alertHeight}px`);
|
||||
} else {
|
||||
bannerSpacing.set(undefined);
|
||||
}
|
||||
|
||||
if (header) {
|
||||
header.style.top = `${alertHeight}px`;
|
||||
}
|
||||
|
||||
if (sidebar) {
|
||||
sidebar.style.top = `${alertHeight + ($isTabletViewport ? 0 : header.getBoundingClientRect().height)}px`;
|
||||
sidebar.style.height = `calc(100vh - (${alertHeight + ($isTabletViewport ? 0 : header.getBoundingClientRect().height)}px))`;
|
||||
const headerHeight = header?.getBoundingClientRect().height ?? 0;
|
||||
const topOffset = alertHeight + ($isTabletViewport ? 0 : headerHeight);
|
||||
|
||||
// for sidebar and sub-navigation!
|
||||
bannerSpacing.set(`${alertHeight}px`);
|
||||
sidebar.style.top = `${topOffset}px`;
|
||||
sidebar.style.height = `calc(100vh - ${topOffset}px)`;
|
||||
}
|
||||
|
||||
if (contentSection) {
|
||||
@@ -37,16 +57,24 @@
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
setNavigationHeight();
|
||||
if (container) {
|
||||
resizeObserver = new ResizeObserver(setNavigationHeight);
|
||||
resizeObserver.observe(container);
|
||||
}
|
||||
});
|
||||
|
||||
onDestroy(() => {
|
||||
container = null;
|
||||
setNavigationHeight();
|
||||
});
|
||||
</script>
|
||||
|
||||
<svelte:window on:resize={setNavigationHeight} />
|
||||
// remove observer!
|
||||
if (resizeObserver) {
|
||||
resizeObserver.disconnect();
|
||||
}
|
||||
});
|
||||
|
||||
afterNavigate(() => setNavigationHeight());
|
||||
</script>
|
||||
|
||||
<section
|
||||
bind:this={container}
|
||||
@@ -75,9 +103,14 @@
|
||||
<slot />
|
||||
</p>
|
||||
</div>
|
||||
{#if $$slots.buttons}
|
||||
{#if $$slots.buttons || dismissible}
|
||||
<div class="alert-buttons u-flex u-gap-16 u-cross-child-center">
|
||||
<slot name="buttons" />
|
||||
{#if dismissible}
|
||||
<Button text icon size="s" on:click={() => dispatch('dismiss')}>
|
||||
<Icon icon={IconX} slot="start" size="s" />
|
||||
</Button>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
+106
-76
@@ -1,9 +1,9 @@
|
||||
<script lang="ts">
|
||||
import { beforeNavigate } from '$app/navigation';
|
||||
import { afterNavigate, beforeNavigate } from '$app/navigation';
|
||||
import { Navbar, Sidebar } from '$lib/components';
|
||||
import { isNewWizardStatusOpen, wizard } from '$lib/stores/wizard';
|
||||
import { activeHeaderAlert } from '$routes/(console)/store';
|
||||
import { setContext } from 'svelte';
|
||||
import { onMount, setContext } from 'svelte';
|
||||
import { writable } from 'svelte/store';
|
||||
import { showSubNavigation } from '$lib/stores/layout';
|
||||
import { organization, organizationList } from '$lib/stores/organization';
|
||||
@@ -13,19 +13,109 @@
|
||||
import { isCloud } from '$lib/system';
|
||||
import SideNavigation from '$lib/layout/navigation.svelte';
|
||||
import { hasOnboardingDismissed } from '$lib/helpers/onboarding';
|
||||
import { isSidebarOpen } from '$lib/stores/sidebar';
|
||||
import { isSidebarOpen, noWidthTransition } from '$lib/stores/sidebar';
|
||||
import { BillingPlan } from '$lib/constants';
|
||||
import { page } from '$app/stores';
|
||||
import type { Models } from '@appwrite.io/console';
|
||||
import { getSidebarState, isInDatabasesRoute, updateSidebarState } from '$lib/helpers/sidebar';
|
||||
|
||||
export let showHeader = true;
|
||||
export let showFooter = true;
|
||||
export let showSideNavigation = false;
|
||||
export let selectedProject: Models.Project = null;
|
||||
|
||||
// variables
|
||||
let yOnMenuOpen: number;
|
||||
let showAccountMenu = false;
|
||||
let showContentTransition = false;
|
||||
let timeoutId: ReturnType<typeof setTimeout>;
|
||||
let state: undefined | 'open' | 'closed' | 'icons' = 'closed';
|
||||
|
||||
const isNarrow = setContext('isNarrow', writable(false));
|
||||
const bodyStyle = writable({ position: 'static', top: '' });
|
||||
const hasSubNavigation = setContext('hasSubNavigation', writable(false));
|
||||
|
||||
onMount(() => (state = getSidebarState()));
|
||||
|
||||
// user defined functions
|
||||
function style(node: HTMLElement, { position, top }) {
|
||||
node.style.position = position;
|
||||
node.style.top = top;
|
||||
|
||||
return {
|
||||
update: ({ position, top }) => {
|
||||
node.style.position = position;
|
||||
node.style.top = top;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function getProgressCard() {
|
||||
if (selectedProject && !hasOnboardingDismissed(selectedProject.$id, $user)) {
|
||||
const { platforms, pingCount } = selectedProject;
|
||||
let percentage = 33;
|
||||
|
||||
if (platforms.length > 0 && pingCount === 0) {
|
||||
percentage = 66;
|
||||
} else if (pingCount > 0) {
|
||||
percentage = 100;
|
||||
}
|
||||
|
||||
return {
|
||||
title: 'Get started',
|
||||
percentage
|
||||
};
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function handleResize() {
|
||||
$isSidebarOpen = false;
|
||||
showAccountMenu = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancel navigation when wizard is open and triggered by popstate
|
||||
*/
|
||||
beforeNavigate((navigation) => {
|
||||
if (navigation.willUnload) return;
|
||||
if (!($wizard.show || $wizard.cover)) return;
|
||||
if (navigation.type === 'popstate') {
|
||||
navigation.cancel();
|
||||
}
|
||||
if (navigation.type !== 'leave') {
|
||||
wizard.hide();
|
||||
}
|
||||
|
||||
if (!isInDatabasesRoute(navigation.from.route)) {
|
||||
updateSidebarState(state);
|
||||
} else if (isInDatabasesRoute(navigation.to.route)) {
|
||||
$noWidthTransition = true;
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Maintain the sidebar state after a navigation!
|
||||
*
|
||||
* This needs to be handled like this because
|
||||
* the setup around the sidebar is very tightly configured with 2 states sync.
|
||||
*/
|
||||
afterNavigate((navigation) => {
|
||||
const isEnteringDatabase = isInDatabasesRoute(navigation.to.route);
|
||||
const isLeavingDatabase =
|
||||
isInDatabasesRoute(navigation.from.route) && !isInDatabasesRoute(navigation.to.route);
|
||||
|
||||
if (isEnteringDatabase) {
|
||||
state = 'icons';
|
||||
} else if (isLeavingDatabase) {
|
||||
state = getSidebarState();
|
||||
$noWidthTransition = false;
|
||||
}
|
||||
});
|
||||
|
||||
// subscriptions
|
||||
isNewWizardStatusOpen.subscribe((value) => (showHeader = !value));
|
||||
|
||||
page.subscribe(({ url }) => {
|
||||
$showSubNavigation = url.searchParams.get('openNavbar') === 'true';
|
||||
@@ -40,50 +130,9 @@
|
||||
}
|
||||
});
|
||||
|
||||
const bodyStyle = writable({ position: 'static', top: '' });
|
||||
|
||||
function style(node, { position, top }) {
|
||||
node.style.position = position;
|
||||
node.style.top = top;
|
||||
|
||||
return {
|
||||
update: ({ position, top }) => {
|
||||
node.style.position = position;
|
||||
node.style.top = top;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
$: {
|
||||
if ($isSidebarOpen) {
|
||||
yOnMenuOpen = window.scrollY;
|
||||
bodyStyle.set({ position: 'fixed', top: `-${window.scrollY}px` });
|
||||
} else if (!$isSidebarOpen) {
|
||||
bodyStyle.set({ position: 'static', top: '' });
|
||||
requestAnimationFrame(() => {
|
||||
window.scrollTo(0, yOnMenuOpen);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancel navigation when wizard is open and triggered by popstate
|
||||
*/
|
||||
beforeNavigate((n) => {
|
||||
if (n.willUnload) return;
|
||||
if (!($wizard.show || $wizard.cover)) return;
|
||||
if (n.type === 'popstate') {
|
||||
n.cancel();
|
||||
}
|
||||
if (n.type !== 'leave') {
|
||||
wizard.hide();
|
||||
}
|
||||
});
|
||||
|
||||
const isNarrow = setContext('isNarrow', writable(false));
|
||||
const hasSubNavigation = setContext('hasSubNavigation', writable(false));
|
||||
|
||||
// reactive blocks
|
||||
$: sideSize = $hasSubNavigation ? ($isNarrow ? '17rem' : '25rem') : '12.5rem';
|
||||
|
||||
$: navbarProps = {
|
||||
logo: {
|
||||
src: 'https://appwrite.io/images/logos/logo.svg',
|
||||
@@ -112,40 +161,21 @@
|
||||
currentProject: selectedProject
|
||||
};
|
||||
|
||||
let showAccountMenu = false;
|
||||
$: subNavigation = $page.data.subNavigation;
|
||||
let state: undefined | 'open' | 'closed' | 'icons' = 'closed';
|
||||
$: state = $isSidebarOpen ? 'open' : 'closed';
|
||||
|
||||
let isProjectPage;
|
||||
$: subNavigation = $page.data.subNavigation;
|
||||
|
||||
$: isProjectPage = $page.route?.id?.includes('project-');
|
||||
|
||||
function handleResize() {
|
||||
$isSidebarOpen = false;
|
||||
showAccountMenu = false;
|
||||
}
|
||||
|
||||
const progressCard = function getProgressCard() {
|
||||
if (selectedProject && !hasOnboardingDismissed(selectedProject.$id, $user)) {
|
||||
const { platforms, pingCount } = selectedProject;
|
||||
let percentage = 33;
|
||||
|
||||
if (platforms.length > 0 && pingCount === 0) {
|
||||
percentage = 66;
|
||||
} else if (pingCount > 0) {
|
||||
percentage = 100;
|
||||
}
|
||||
|
||||
return {
|
||||
title: 'Get started',
|
||||
percentage
|
||||
};
|
||||
$: {
|
||||
if ($isSidebarOpen) {
|
||||
yOnMenuOpen = window.scrollY;
|
||||
bodyStyle.set({ position: 'fixed', top: `-${window.scrollY}px` });
|
||||
} else if (!$isSidebarOpen) {
|
||||
bodyStyle.set({ position: 'static', top: '' });
|
||||
requestAnimationFrame(() => window.scrollTo(0, yOnMenuOpen));
|
||||
}
|
||||
|
||||
return undefined;
|
||||
};
|
||||
|
||||
isNewWizardStatusOpen.subscribe((value) => (showHeader = !value));
|
||||
}
|
||||
</script>
|
||||
|
||||
<svelte:window on:resize={handleResize} />
|
||||
@@ -170,7 +200,7 @@
|
||||
{#if !$isNewWizardStatusOpen}
|
||||
<Sidebar
|
||||
project={selectedProject}
|
||||
progressCard={progressCard()}
|
||||
progressCard={getProgressCard()}
|
||||
avatar={navbarProps.avatar}
|
||||
bind:subNavigation
|
||||
bind:sideBarIsOpen={$isSidebarOpen}
|
||||
|
||||
@@ -59,6 +59,13 @@ async function updateConsolePreferences(store: ConsolePreferencesStore): Promise
|
||||
await sdk.forConsole.account.updatePrefs({ prefs: currentPreferences });
|
||||
}
|
||||
|
||||
function safePrefsKey(widthPreferences: TeamPreferences['widths'], from: string, to: string) {
|
||||
if (widthPreferences?.[from]) {
|
||||
widthPreferences[to] = widthPreferences[from];
|
||||
delete widthPreferences[from];
|
||||
}
|
||||
}
|
||||
|
||||
function createPreferences() {
|
||||
const { subscribe, set, update } = writable<ConsolePreferencesStore>({});
|
||||
let preferences: ConsolePreferencesStore = {};
|
||||
@@ -218,7 +225,7 @@ function createPreferences() {
|
||||
loadTeamPrefs: loadTeamPreferences,
|
||||
|
||||
getDisplayNames: (tableId: string) => {
|
||||
return teamPreferences?.displayNames?.[tableId];
|
||||
return teamPreferences?.displayNames?.[tableId] ?? ['$id'];
|
||||
},
|
||||
|
||||
setDisplayNames: async (
|
||||
@@ -242,16 +249,12 @@ function createPreferences() {
|
||||
return teamPreferences?.columnOrder?.[tableId] ?? [];
|
||||
},
|
||||
|
||||
async saveColumnOrder(
|
||||
orgId: string,
|
||||
collectionId: string,
|
||||
columnIds: TeamPreferences['order']
|
||||
) {
|
||||
async saveColumnOrder(orgId: string, tableId: string, columnIds: TeamPreferences['order']) {
|
||||
if (!teamPreferences.columnOrder) {
|
||||
teamPreferences.columnOrder = {};
|
||||
}
|
||||
|
||||
teamPreferences.columnOrder[collectionId] = columnIds;
|
||||
teamPreferences.columnOrder[tableId] = columnIds;
|
||||
|
||||
await sdk.forConsole.teams.updatePrefs({
|
||||
teamId: orgId,
|
||||
@@ -259,24 +262,27 @@ function createPreferences() {
|
||||
});
|
||||
},
|
||||
|
||||
getColumnWidths(collectionId: string): TeamPreferences['widths'] {
|
||||
return teamPreferences?.columnWidths?.[collectionId] ?? {};
|
||||
getColumnWidths(tableId: string): TeamPreferences['widths'] {
|
||||
const columnWidths = teamPreferences?.columnWidths?.[tableId] ?? {};
|
||||
safePrefsKey(columnWidths, '$uid', '$id');
|
||||
return columnWidths;
|
||||
},
|
||||
|
||||
async saveColumnWidths(
|
||||
orgId: string,
|
||||
collectionId: string,
|
||||
width: TeamPreferences['widths']
|
||||
) {
|
||||
async saveColumnWidths(orgId: string, tableId: string, width: TeamPreferences['widths']) {
|
||||
if (!teamPreferences.columnWidths) {
|
||||
teamPreferences.columnWidths = {};
|
||||
}
|
||||
|
||||
teamPreferences.columnWidths[collectionId] = {
|
||||
...teamPreferences.columnWidths[collectionId],
|
||||
teamPreferences.columnWidths[tableId] = {
|
||||
...teamPreferences.columnWidths[tableId],
|
||||
...width
|
||||
};
|
||||
|
||||
// older version could still have the problematic key!
|
||||
for (const tableWidths of Object.values(teamPreferences.columnWidths)) {
|
||||
safePrefsKey(tableWidths, '$id', '$uid');
|
||||
}
|
||||
|
||||
await sdk.forConsole.teams.updatePrefs({
|
||||
teamId: orgId,
|
||||
prefs: teamPreferences
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { writable } from 'svelte/store';
|
||||
|
||||
export const isSidebarOpen = writable(false);
|
||||
|
||||
export const noWidthTransition = writable(false);
|
||||
@@ -2,10 +2,26 @@ import { redirect } from '@sveltejs/kit';
|
||||
import { base } from '$app/paths';
|
||||
import type { LayoutLoad } from './$types';
|
||||
|
||||
export const load: LayoutLoad = async ({ parent }) => {
|
||||
export const load: LayoutLoad = async ({ parent, url }) => {
|
||||
const { account } = await parent();
|
||||
|
||||
if (!account) {
|
||||
redirect(303, base);
|
||||
const projectId = url.searchParams.get('projectId');
|
||||
const repositoryId = url.searchParams.get('repositoryId');
|
||||
const installationId = url.searchParams.get('installationId');
|
||||
const providerPullRequestId = url.searchParams.get('providerPullRequestId');
|
||||
|
||||
if (!installationId || !repositoryId || !providerPullRequestId) {
|
||||
redirect(303, `${base}`);
|
||||
}
|
||||
|
||||
if (!account) {
|
||||
redirect(303, `${base}`);
|
||||
}
|
||||
|
||||
return {
|
||||
projectId,
|
||||
repositoryId,
|
||||
installationId,
|
||||
providerPullRequestId
|
||||
};
|
||||
};
|
||||
@@ -1,5 +1,4 @@
|
||||
<script lang="ts">
|
||||
import { page } from '$app/state';
|
||||
import { app } from '$lib/stores/app';
|
||||
import AppwriteLogoDark from '$lib/images/appwrite-logo-dark.svg';
|
||||
import AppwriteLogoLight from '$lib/images/appwrite-logo-light.svg';
|
||||
@@ -7,6 +6,8 @@
|
||||
import { onMount } from 'svelte';
|
||||
import { getApiEndpoint } from '$lib/stores/sdk';
|
||||
|
||||
export let data;
|
||||
|
||||
const endpoint = getApiEndpoint();
|
||||
const client = new Client();
|
||||
const vcs = new Vcs(client);
|
||||
@@ -15,17 +16,16 @@
|
||||
let repositoryId: string;
|
||||
let providerPullRequestId: string;
|
||||
|
||||
let loading = false;
|
||||
let error = '';
|
||||
let success = '';
|
||||
let loading = false;
|
||||
|
||||
onMount(async () => {
|
||||
const projectId = page.url.searchParams.get('projectId');
|
||||
client.setEndpoint(endpoint).setProject(projectId).setMode('admin');
|
||||
repositoryId = data.repositoryId;
|
||||
installationId = data.installationId;
|
||||
providerPullRequestId = data.providerPullRequestId;
|
||||
|
||||
installationId = page.url.searchParams.get('installationId');
|
||||
repositoryId = page.url.searchParams.get('repositoryId');
|
||||
providerPullRequestId = page.url.searchParams.get('providerPullRequestId') + '';
|
||||
client.setEndpoint(endpoint).setProject(data.projectId).setMode('admin');
|
||||
});
|
||||
|
||||
async function approveDeployment() {
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
import { BillingPlan, INTERVAL } from '$lib/constants';
|
||||
import Footer from '$lib/layout/footer.svelte';
|
||||
import Shell from '$lib/layout/shell.svelte';
|
||||
|
||||
import { app } from '$lib/stores/app';
|
||||
import { database, checkForDatabaseBackupPolicies } from '$lib/stores/database';
|
||||
import { newOrgModal, organization, type Organization } from '$lib/stores/organization';
|
||||
@@ -39,11 +40,12 @@
|
||||
import MobileSupportModal from './wizard/support/mobileSupportModal.svelte';
|
||||
import { showSupportModal } from './wizard/support/store';
|
||||
import { activeHeaderAlert, consoleVariables } from './store';
|
||||
|
||||
import { base } from '$app/paths';
|
||||
import { headerAlert } from '$lib/stores/headerAlert';
|
||||
import { UsageRates } from '$lib/components/billing';
|
||||
import { base } from '$app/paths';
|
||||
import { canSeeProjects } from '$lib/stores/roles';
|
||||
import { BottomModalAlert } from '$lib/components';
|
||||
import { BottomModalAlert, EmailVerificationBanner } from '$lib/components';
|
||||
import {
|
||||
IconAnnotation,
|
||||
IconBookOpen,
|
||||
@@ -57,6 +59,7 @@
|
||||
import type { LayoutData } from './$types';
|
||||
|
||||
export let data: LayoutData;
|
||||
let emailBannerClosed = false;
|
||||
|
||||
function kebabToSentenceCase(str: string) {
|
||||
return str
|
||||
@@ -331,7 +334,7 @@
|
||||
|
||||
<CommandCenter />
|
||||
<Shell
|
||||
showSideNavigation={page.url.pathname !== '/console' &&
|
||||
showSideNavigation={page.url.pathname !== '/' &&
|
||||
!page?.params.organization &&
|
||||
!page.url.pathname.includes('/console/account') &&
|
||||
!page.url.pathname.includes('/console/card') &&
|
||||
@@ -344,6 +347,10 @@
|
||||
<Footer slot="footer" />
|
||||
</Shell>
|
||||
|
||||
<EmailVerificationBanner
|
||||
{emailBannerClosed}
|
||||
onEmailBannerClose={(closed) => (emailBannerClosed = closed)} />
|
||||
|
||||
{#if $wizard.show && $wizard.component}
|
||||
<svelte:component this={$wizard.component} {...$wizard.props} />
|
||||
{:else if $wizard.cover}
|
||||
|
||||
@@ -123,7 +123,7 @@
|
||||
}
|
||||
|
||||
async function handleSubmit() {
|
||||
if (!couponForm.checkValidity()) return;
|
||||
if (couponForm && !couponForm.checkValidity()) return;
|
||||
isSubmitting.set(true);
|
||||
try {
|
||||
let org: Organization | OrganizationError;
|
||||
@@ -392,7 +392,7 @@
|
||||
<Button
|
||||
fullWidthMobile
|
||||
on:click={() => {
|
||||
if (formComponent.checkValidity() && couponForm.checkValidity()) {
|
||||
if (formComponent.checkValidity() && (!couponForm || couponForm.checkValidity())) {
|
||||
handleSubmit();
|
||||
}
|
||||
}}
|
||||
|
||||
@@ -5,8 +5,8 @@ import TablesApiLight from '$lib/images/promos/tables-api-light.png';
|
||||
import TablesApiDark from '$lib/images/promos/tables-api-dark.png';
|
||||
import TimestampOverridesDark from '$lib/images/promos/timestamp-overrides-dark.png';
|
||||
import TimestampOverridesLight from '$lib/images/promos/timestamp-overrides-light.png';
|
||||
import AppwriteGeneralAvailabiltyLight from '$lib/images/promos/appwrite-general-availability-light.png';
|
||||
import AppwriteGeneralAvailabiltyDark from '$lib/images/promos/appwrite-general-availability-dark.png';
|
||||
import OptInRelationDark from '$lib/images/promos/opt-relation-dark.png';
|
||||
import OptInRelationLight from '$lib/images/promos/opt-relation-light.png';
|
||||
|
||||
const listOfPromotions: BottomModalAlertItem[] = [];
|
||||
|
||||
@@ -53,27 +53,27 @@ if (isCloud) {
|
||||
show: true
|
||||
};
|
||||
|
||||
const appwriteGeneralAvailabiltyPromo: BottomModalAlertItem = {
|
||||
id: 'modal:appwrite_general_availability_announcement',
|
||||
const optInRelationPromo: BottomModalAlertItem = {
|
||||
id: 'modal:opt_in_relation_announcement',
|
||||
src: {
|
||||
dark: AppwriteGeneralAvailabiltyDark,
|
||||
light: AppwriteGeneralAvailabiltyLight
|
||||
dark: OptInRelationDark,
|
||||
light: OptInRelationLight
|
||||
},
|
||||
title: 'Now Generally Available',
|
||||
message: 'After 26 months of Appwrite Cloud, we are ready to remove the beta tag.',
|
||||
title: 'Introducing Opt-in relationship loading',
|
||||
message:
|
||||
'Gain full control over which related rows to fetch and drastically reduce payload sizes.',
|
||||
plan: 'free',
|
||||
importance: 8,
|
||||
scope: 'everywhere',
|
||||
scope: 'project',
|
||||
cta: {
|
||||
text: 'Learn more',
|
||||
link: () => 'https://apwr.dev/ygTXfxA',
|
||||
text: 'Read announcement',
|
||||
link: () => 'https://appwrite.io/blog/post/announcing-opt-in-relationship-loading',
|
||||
external: true,
|
||||
hideOnClick: true
|
||||
},
|
||||
show: true
|
||||
};
|
||||
|
||||
listOfPromotions.push(tablesApiPromo, timestampOverridesPromo, appwriteGeneralAvailabiltyPromo);
|
||||
listOfPromotions.push(optInRelationPromo, tablesApiPromo, timestampOverridesPromo);
|
||||
}
|
||||
|
||||
export function addBottomModalAlerts() {
|
||||
|
||||
@@ -9,23 +9,19 @@
|
||||
import { registerCommands } from '$lib/commandCenter';
|
||||
import {
|
||||
CardContainer,
|
||||
DropList,
|
||||
DropListItem,
|
||||
Empty,
|
||||
EmptySearch,
|
||||
GridItem1,
|
||||
PaginationWithLimit
|
||||
PaginationWithLimit,
|
||||
SearchQuery
|
||||
} from '$lib/components';
|
||||
import { goto } from '$app/navigation';
|
||||
import { Submit, trackError, trackEvent, Click } from '$lib/actions/analytics';
|
||||
import { sdk } from '$lib/stores/sdk';
|
||||
import { loading } from '$routes/store';
|
||||
import { ID, Region, type Models } from '@appwrite.io/console';
|
||||
import { openImportWizard } from '../project-[region]-[project]/settings/migrations/(import)';
|
||||
import { trackEvent, Click } from '$lib/actions/analytics';
|
||||
import { type Models } from '@appwrite.io/console';
|
||||
import { billingProjectsLimitDate, readOnly, upgradeURL } from '$lib/stores/billing';
|
||||
import { onMount, type ComponentType } from 'svelte';
|
||||
import { canWriteProjects } from '$lib/stores/roles';
|
||||
import { checkPricingRefAndRedirect } from '$lib/helpers/pricingRedirect';
|
||||
import { Badge, Icon, Typography, Alert, Tag, Tooltip } from '@appwrite.io/pink-svelte';
|
||||
import { Alert, Badge, Icon, Layout, Tag, Tooltip, Typography } from '@appwrite.io/pink-svelte';
|
||||
import { isSmallViewport } from '$lib/stores/viewport';
|
||||
import {
|
||||
IconAndroid,
|
||||
@@ -46,9 +42,11 @@
|
||||
export let data;
|
||||
|
||||
let showCreate = false;
|
||||
let showCreateProjectCloud = false;
|
||||
let addOrganization = false;
|
||||
let showSelectProject = false;
|
||||
let showCreateProjectCloud = false;
|
||||
|
||||
let searchQuery: SearchQuery;
|
||||
|
||||
function filterPlatforms(platforms: { name: string; icon: string }[]) {
|
||||
return platforms.filter(
|
||||
@@ -94,28 +92,6 @@
|
||||
}
|
||||
]);
|
||||
|
||||
let showDropdown = false;
|
||||
|
||||
const importProject = async () => {
|
||||
try {
|
||||
loading.set(true);
|
||||
const project = await sdk.forConsole.projects.create({
|
||||
projectId: ID.unique(),
|
||||
name: `Imported project ${new Date().toISOString()}`,
|
||||
teamId: page.params.organization,
|
||||
region: Region.Fra
|
||||
});
|
||||
trackEvent(Submit.ProjectCreate, {
|
||||
teamId: page.params.organization
|
||||
});
|
||||
await goto(`${base}/project-${project.region}-${project.$id}/settings/migrations`);
|
||||
openImportWizard();
|
||||
loading.set(false);
|
||||
} catch (e) {
|
||||
trackError(e, Submit.ProjectCreate);
|
||||
}
|
||||
};
|
||||
|
||||
onMount(async () => checkPricingRefAndRedirect(page.url.searchParams));
|
||||
|
||||
function findRegion(project: Models.Project) {
|
||||
@@ -145,6 +121,9 @@
|
||||
Array.isArray(selectedProjects) && selectedProjects.length > 0
|
||||
? data.projects.projects.filter((project) => selectedProjects.includes(project.$id))
|
||||
: data.projects.projects;
|
||||
function clearSearch() {
|
||||
searchQuery?.clearInput();
|
||||
}
|
||||
</script>
|
||||
|
||||
<SelectProjectCloud
|
||||
@@ -153,29 +132,19 @@
|
||||
selectedProjects={data.organization.projects || []} />
|
||||
|
||||
<Container>
|
||||
<div class="u-flex u-gap-12 common-section u-main-space-between">
|
||||
<Typography.Title>Projects</Typography.Title>
|
||||
<Layout.Stack direction="row" justifyContent="space-between" class="common-section">
|
||||
<SearchQuery bind:this={searchQuery} placeholder="Search by name or ID" />
|
||||
|
||||
<DropList bind:show={showDropdown} placement="bottom-end">
|
||||
{#if $canWriteProjects}
|
||||
<Button
|
||||
on:click={handleCreateProject}
|
||||
event="create_project"
|
||||
disabled={$readOnly && !GRACE_PERIOD_OVERRIDE}>
|
||||
<Icon icon={IconPlus} slot="start" size="s" />
|
||||
Create project
|
||||
</Button>
|
||||
{/if}
|
||||
<svelte:fragment slot="list">
|
||||
<DropListItem on:click={() => (showCreate = true)}>Empty project</DropListItem>
|
||||
<DropListItem on:click={importProject}>
|
||||
<div class="u-flex u-gap-8 u-cross-center">
|
||||
Import project <span class="tag eyebrow-heading-3">Experimental</span>
|
||||
</div>
|
||||
</DropListItem>
|
||||
</svelte:fragment>
|
||||
</DropList>
|
||||
</div>
|
||||
{#if $canWriteProjects}
|
||||
<Button
|
||||
on:click={handleCreateProject}
|
||||
event="create_project"
|
||||
disabled={$readOnly && !GRACE_PERIOD_OVERRIDE}>
|
||||
<Icon icon={IconPlus} slot="start" size="s" />
|
||||
Create project
|
||||
</Button>
|
||||
{/if}
|
||||
</Layout.Stack>
|
||||
|
||||
{#if isCloud && $currentPlan?.projects && $currentPlan?.projects > 0 && data.organization.projects.length > 0 && $canWriteProjects && (projectsToArchive.length > 0 || data.projects.total > $currentPlan.projects)}
|
||||
<Alert.Inline
|
||||
@@ -284,7 +253,11 @@
|
||||
<p>Create a new project</p>
|
||||
</svelte:fragment>
|
||||
</CardContainer>
|
||||
{:else if data.projects.total === 0}
|
||||
{:else if data.search}
|
||||
<EmptySearch target="projects" hidePagination>
|
||||
<Button size="s" secondary on:click={clearSearch}>Clear search</Button>
|
||||
</EmptySearch>
|
||||
{:else}
|
||||
<Empty
|
||||
single
|
||||
allowCreate={$canWriteProjects}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Query } from '@appwrite.io/console';
|
||||
import { sdk } from '$lib/stores/sdk';
|
||||
import { getLimit, getPage, pageToOffset } from '$lib/helpers/load';
|
||||
import { getLimit, getPage, getSearch, pageToOffset } from '$lib/helpers/load';
|
||||
import { CARD_LIMIT, Dependencies } from '$lib/constants';
|
||||
import type { PageLoad } from './$types';
|
||||
import { redirect } from '@sveltejs/kit';
|
||||
@@ -16,6 +16,7 @@ export const load: PageLoad = async ({ params, url, route, depends, parent }) =>
|
||||
const page = getPage(url);
|
||||
const limit = getLimit(url, route, CARD_LIMIT);
|
||||
const offset = pageToOffset(page, limit);
|
||||
const search = getSearch(url);
|
||||
|
||||
const projects = await sdk.forConsole.projects.list({
|
||||
queries: [
|
||||
@@ -23,7 +24,8 @@ export const load: PageLoad = async ({ params, url, route, depends, parent }) =>
|
||||
Query.equal('teamId', params.organization),
|
||||
Query.limit(limit),
|
||||
Query.orderDesc('')
|
||||
]
|
||||
],
|
||||
search: search || undefined
|
||||
});
|
||||
|
||||
// set `default` if no region!
|
||||
@@ -34,6 +36,7 @@ export const load: PageLoad = async ({ params, url, route, depends, parent }) =>
|
||||
return {
|
||||
offset,
|
||||
limit,
|
||||
projects
|
||||
projects,
|
||||
search
|
||||
};
|
||||
};
|
||||
@@ -189,11 +189,10 @@
|
||||
}
|
||||
}
|
||||
|
||||
trackDowngradeFeedback();
|
||||
|
||||
await invalidate(Dependencies.ORGANIZATION);
|
||||
await Promise.all([trackDowngradeFeedback(), invalidate(Dependencies.ORGANIZATION)]);
|
||||
|
||||
await goto(previousPage);
|
||||
|
||||
addNotification({
|
||||
type: 'success',
|
||||
message: `${$organization.name} plan has been successfully updated.`
|
||||
|
||||
+3
@@ -19,6 +19,7 @@
|
||||
import { IconPlus } from '@appwrite.io/pink-icons-svelte';
|
||||
import { currentPlan } from '$lib/stores/organization';
|
||||
import { isCloud } from '$lib/system';
|
||||
import { noWidthTransition } from '$lib/stores/sidebar';
|
||||
|
||||
const project = page.params.project;
|
||||
const databaseId = page.params.database;
|
||||
@@ -141,6 +142,8 @@
|
||||
$registerSearchers(tablesSearcher);
|
||||
|
||||
$: $updateCommandGroupRanks({ tables: 10 });
|
||||
|
||||
$noWidthTransition = true;
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
|
||||
+37
-13
@@ -2,32 +2,56 @@ import { base } from '$app/paths';
|
||||
import type { PageLoad } from './$types';
|
||||
import { redirect } from '@sveltejs/kit';
|
||||
import { AppwriteException } from '@appwrite.io/console';
|
||||
import { databaseRowSheetOptions } from '../table-[table]/store';
|
||||
|
||||
const LEGACY_ROUTE_MAPPINGS = [
|
||||
const ROUTE_MAPPINGS: {
|
||||
pattern: RegExp;
|
||||
replacement?: string;
|
||||
sheet?: boolean;
|
||||
}[] = [
|
||||
// collection page redirect to table
|
||||
{ pattern: /^collection-([^/]+)/, replacement: 'table-$1' },
|
||||
|
||||
// document detail page redirect to their parent table
|
||||
{ pattern: /^document-([^/]+)/, replacement: 'table-$1' },
|
||||
// attribute detail redirect to table columns
|
||||
{ pattern: /^attribute-([^/]+)/, replacement: 'table-$1/columns' },
|
||||
{ pattern: /^document-([^/]+)/, sheet: true },
|
||||
|
||||
// attributes list page redirect to table columns
|
||||
{ pattern: /^attributes$/, replacement: 'columns' }
|
||||
{ pattern: /^attributes$/, replacement: 'columns' },
|
||||
|
||||
// New format routes,
|
||||
{ pattern: /^row-([^/]+)/, sheet: true }
|
||||
] as const;
|
||||
|
||||
function isLegacyRoute(segments: string[]): boolean {
|
||||
return segments.some((segment) =>
|
||||
LEGACY_ROUTE_MAPPINGS.some((mapping) => mapping.pattern.test(segment))
|
||||
ROUTE_MAPPINGS.some((mapping) => mapping.pattern.test(segment))
|
||||
);
|
||||
}
|
||||
|
||||
function rewriteLegacySegments(segments: string[]): string[] {
|
||||
return segments.map((segment) => {
|
||||
for (const mapping of LEGACY_ROUTE_MAPPINGS) {
|
||||
if (mapping.pattern.test(segment)) {
|
||||
return segment.replace(mapping.pattern, mapping.replacement);
|
||||
return segments
|
||||
.map((segment) => {
|
||||
for (const mapping of ROUTE_MAPPINGS) {
|
||||
if (mapping.pattern.test(segment)) {
|
||||
if (mapping.sheet) {
|
||||
const match = segment.match(mapping.pattern);
|
||||
if (match && match[1]) {
|
||||
databaseRowSheetOptions.update((options) => ({
|
||||
...options,
|
||||
rowId: match[1],
|
||||
title: 'Update row'
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
return !mapping.replacement
|
||||
? null
|
||||
: segment.replace(mapping.pattern, mapping.replacement);
|
||||
}
|
||||
}
|
||||
}
|
||||
return segment;
|
||||
});
|
||||
return segment;
|
||||
})
|
||||
.filter(Boolean);
|
||||
}
|
||||
|
||||
export const load: PageLoad = async ({ params, url }) => {
|
||||
|
||||
+43
-8
@@ -60,6 +60,8 @@
|
||||
import CreateIndex from './indexes/createIndex.svelte';
|
||||
import { hash } from '$lib/helpers/string';
|
||||
import { preferences } from '$lib/stores/preferences';
|
||||
import { buildRowUrl, isRelationship } from './rows/store';
|
||||
import { chunks } from '$lib/helpers/array';
|
||||
|
||||
let editRow: EditRow;
|
||||
let editRelatedRow: EditRelatedRow;
|
||||
@@ -249,7 +251,10 @@
|
||||
$randomDataModalState.show = false;
|
||||
|
||||
let columns = $table.columns;
|
||||
if (!columns.length) {
|
||||
const hasAnyRelationships = columns.some((column) => isRelationship(column));
|
||||
const filteredColumns = columns.filter((col) => col.type !== 'relationship');
|
||||
|
||||
if (!filteredColumns.length) {
|
||||
try {
|
||||
columns = await generateColumns($project, page.params.database, page.params.table);
|
||||
|
||||
@@ -272,12 +277,32 @@
|
||||
const { rows, ids } = generateFakeRecords(columns, $randomDataModalState.value);
|
||||
|
||||
rowIds = ids;
|
||||
const tablesSDK = sdk.forProject(page.params.region, page.params.project).tablesDB;
|
||||
|
||||
await sdk.forProject(page.params.region, page.params.project).tablesDB.createRows({
|
||||
databaseId: page.params.database,
|
||||
tableId: page.params.table,
|
||||
rows
|
||||
});
|
||||
if (hasAnyRelationships) {
|
||||
for (const batch of chunks(rows)) {
|
||||
try {
|
||||
await Promise.all(
|
||||
batch.map((row) =>
|
||||
tablesSDK.createRow({
|
||||
databaseId: page.params.database,
|
||||
tableId: page.params.table,
|
||||
rowId: row.$id,
|
||||
data: row
|
||||
})
|
||||
)
|
||||
);
|
||||
} catch (error) {
|
||||
// ignore, its sample data.
|
||||
}
|
||||
}
|
||||
} else {
|
||||
await tablesSDK.createRows({
|
||||
databaseId: page.params.database,
|
||||
tableId: page.params.table,
|
||||
rows
|
||||
});
|
||||
}
|
||||
|
||||
addNotification({
|
||||
type: 'success',
|
||||
@@ -313,6 +338,7 @@
|
||||
<SideSheet
|
||||
closeOnBlur
|
||||
title={$showCreateColumnSheet.title}
|
||||
titleBadge={selectedOption === 'Relationship' ? 'Experimental' : undefined}
|
||||
bind:show={$showCreateColumnSheet.show}
|
||||
submit={{
|
||||
text: 'Create',
|
||||
@@ -357,8 +383,17 @@
|
||||
text: 'Update',
|
||||
disabled: editRow?.isDisabled(),
|
||||
onClick: async () => await editRow?.update()
|
||||
}}
|
||||
topAction={{
|
||||
mode: 'copy-tag',
|
||||
text: 'Row URL',
|
||||
show: !!($databaseRowSheetOptions.rowId ?? $databaseRowSheetOptions.row?.$id),
|
||||
value: buildRowUrl($databaseRowSheetOptions.rowId ?? $databaseRowSheetOptions.row?.$id)
|
||||
}}>
|
||||
<EditRow bind:row={$databaseRowSheetOptions.row} bind:this={editRow} />
|
||||
<EditRow
|
||||
bind:this={editRow}
|
||||
bind:row={$databaseRowSheetOptions.row}
|
||||
bind:rowId={$databaseRowSheetOptions.rowId} />
|
||||
</SideSheet>
|
||||
|
||||
<SideSheet
|
||||
@@ -372,7 +407,7 @@
|
||||
}}>
|
||||
<EditRelatedRow
|
||||
bind:this={editRelatedRow}
|
||||
rowId={$databaseRelatedRowSheetOptions.rowId}
|
||||
rows={$databaseRelatedRowSheetOptions.rows}
|
||||
tableId={$databaseRelatedRowSheetOptions.tableId} />
|
||||
</SideSheet>
|
||||
|
||||
|
||||
+1
-1
@@ -58,7 +58,7 @@
|
||||
key: '$id',
|
||||
type: 'string',
|
||||
required: true,
|
||||
name: 'ID',
|
||||
name: '$id',
|
||||
selectable: false,
|
||||
system: true
|
||||
} as Models.ColumnString & {
|
||||
|
||||
+8
-3
@@ -11,6 +11,7 @@
|
||||
import Confirm from '$lib/components/confirm.svelte';
|
||||
import { Layout } from '@appwrite.io/pink-svelte';
|
||||
import { Dependencies } from '$lib/constants';
|
||||
import type { Models } from '@appwrite.io/console';
|
||||
|
||||
let {
|
||||
showDelete = $bindable(false),
|
||||
@@ -70,6 +71,10 @@
|
||||
trackError(e, Submit.ColumnDelete);
|
||||
}
|
||||
}
|
||||
|
||||
function getAsRelationship(column: string | Columns): Models.ColumnRelationship {
|
||||
return column as Models.ColumnRelationship;
|
||||
}
|
||||
</script>
|
||||
|
||||
<Confirm
|
||||
@@ -93,7 +98,7 @@
|
||||
|
||||
{#if requiresTwoWayConfirm}
|
||||
<!-- not allowed on multi selections, safe to assume that this isn't a string! -->
|
||||
{@const attribute = selectedColumn[0]}
|
||||
{@const column = getAsRelationship(selectedColumns[0])}
|
||||
<Layout.Stack direction="column" gap="xl">
|
||||
<p>
|
||||
This is a two way relationship and the corresponding relationship will also be
|
||||
@@ -102,8 +107,8 @@
|
||||
<p><b>This action is irreversible.</b></p>
|
||||
<ul>
|
||||
<InputChoice id="delete" label="Delete" showLabel={false} bind:value={checked}>
|
||||
Delete relationship between <b data-private>{attribute.key}</b> to
|
||||
<b data-private>{attribute.twoWayKey}</b>
|
||||
Delete relationship between <b data-private>{column.key}</b> to
|
||||
<b data-private>{column.twoWayKey}</b>
|
||||
</InputChoice>
|
||||
</ul>
|
||||
</Layout.Stack>
|
||||
|
||||
+20
-4
@@ -19,6 +19,8 @@
|
||||
expandTabs
|
||||
} from '../store';
|
||||
import SpreadsheetContainer from './spreadsheet.svelte';
|
||||
import { onDestroy, onMount } from 'svelte';
|
||||
import { debounce } from '$lib/helpers/debounce';
|
||||
|
||||
type Mode = 'rows' | 'rows-filtered' | 'indexes';
|
||||
|
||||
@@ -47,7 +49,9 @@
|
||||
|
||||
let spreadsheetContainer: HTMLElement;
|
||||
let headerElement: HTMLElement | null = null;
|
||||
let dynamicOverlayHeight = $state('70.5vh');
|
||||
|
||||
let resizeObserver: ResizeObserver;
|
||||
let dynamicOverlayHeight = $state('60.5vh');
|
||||
|
||||
const baseColProps = { draggable: false, resizable: false };
|
||||
|
||||
@@ -70,7 +74,21 @@
|
||||
}
|
||||
};
|
||||
|
||||
updateOverlayHeight();
|
||||
// the first render is in a pretty quick succession, delay helps!
|
||||
const debouncedUpdateOverlayHeight = debounce(() => updateOverlayHeight(), 250);
|
||||
|
||||
onMount(async () => {
|
||||
if (spreadsheetContainer) {
|
||||
resizeObserver = new ResizeObserver(debouncedUpdateOverlayHeight);
|
||||
resizeObserver.observe(spreadsheetContainer);
|
||||
}
|
||||
});
|
||||
|
||||
onDestroy(() => {
|
||||
if (resizeObserver) {
|
||||
resizeObserver.disconnect();
|
||||
}
|
||||
});
|
||||
|
||||
const getCustomColumns = (): Column[] =>
|
||||
customColumns.map((col: Column) => ({
|
||||
@@ -141,8 +159,6 @@
|
||||
const emptyCells = $derived(($isSmallViewport ? 14 : 17) + (!$expandTabs ? 2 : 0));
|
||||
</script>
|
||||
|
||||
<svelte:window on:resize={updateOverlayHeight} />
|
||||
|
||||
<div
|
||||
class="databases-spreadsheet spreadsheet-container-outer"
|
||||
data-mode={mode}
|
||||
|
||||
+38
-2
@@ -1,7 +1,8 @@
|
||||
<script lang="ts">
|
||||
import type { Snippet } from 'svelte';
|
||||
import { Button, Form } from '$lib/elements/forms';
|
||||
import { Divider, Layout, Sheet, Typography } from '@appwrite.io/pink-svelte';
|
||||
import { Badge, Divider, Layout, Sheet, Tag, Typography } from '@appwrite.io/pink-svelte';
|
||||
import { Copy } from '$lib/components';
|
||||
|
||||
let {
|
||||
show = $bindable(false),
|
||||
@@ -9,11 +10,23 @@
|
||||
closeOnBlur = false,
|
||||
submit,
|
||||
children = null,
|
||||
footer = null
|
||||
footer = null,
|
||||
titleBadge = null,
|
||||
topAction = null
|
||||
}: {
|
||||
show: boolean;
|
||||
title: string;
|
||||
titleBadge?: string;
|
||||
closeOnBlur?: boolean;
|
||||
topAction?:
|
||||
| {
|
||||
text: string;
|
||||
value: string;
|
||||
show?: boolean;
|
||||
mode?: 'copy-tag' | 'plaintext';
|
||||
onClick?: () => string | Promise<string>;
|
||||
}
|
||||
| undefined;
|
||||
submit?:
|
||||
| {
|
||||
text: string;
|
||||
@@ -24,6 +37,8 @@
|
||||
children?: Snippet;
|
||||
footer?: Snippet | null;
|
||||
} = $props();
|
||||
|
||||
let copyText = $state(undefined);
|
||||
</script>
|
||||
|
||||
<div class="sheet-container">
|
||||
@@ -32,6 +47,27 @@
|
||||
<Layout.Stack direction="row" justifyContent="space-between" alignItems="center">
|
||||
<Layout.Stack direction="row" gap="m" alignItems="center">
|
||||
<Typography.Text variant="m-400">{title}</Typography.Text>
|
||||
{#if titleBadge}
|
||||
<Badge variant="secondary" content={titleBadge} size="s" />
|
||||
{/if}
|
||||
|
||||
{#if topAction && topAction.text && topAction.show}
|
||||
{#if topAction.mode === 'copy-tag'}
|
||||
<Copy value={topAction.value} {copyText}>
|
||||
<Tag size="xs" variant="code">
|
||||
{topAction.text}
|
||||
</Tag>
|
||||
</Copy>
|
||||
{:else}
|
||||
<Button
|
||||
extraCompact
|
||||
text
|
||||
size="xs"
|
||||
on:click={topAction.onClick ?? undefined}>
|
||||
{topAction.text}
|
||||
</Button>
|
||||
{/if}
|
||||
{/if}
|
||||
</Layout.Stack>
|
||||
</Layout.Stack>
|
||||
</div>
|
||||
|
||||
+5
-1
@@ -16,7 +16,11 @@
|
||||
<Layout.Stack>
|
||||
{#each columns as column}
|
||||
{@const label = column.key}
|
||||
<ColumnItem {column} bind:formValues {label} />
|
||||
<ColumnItem
|
||||
{label}
|
||||
{column}
|
||||
{formValues}
|
||||
onUpdateFormValues={(values) => (formValues = values)} />
|
||||
{/each}
|
||||
|
||||
{#if customId !== undefined}
|
||||
|
||||
+26
-13
@@ -5,33 +5,44 @@
|
||||
import { IconPlus } from '@appwrite.io/pink-icons-svelte';
|
||||
import Column from './column.svelte';
|
||||
import type { Columns } from '../../store';
|
||||
import { writable } from 'svelte/store';
|
||||
|
||||
let {
|
||||
column,
|
||||
formValues = $bindable({}),
|
||||
label,
|
||||
editing = false,
|
||||
fromSpreadsheet = false
|
||||
fromSpreadsheet = false,
|
||||
onUpdateFormValues = null
|
||||
}: {
|
||||
column: Columns;
|
||||
formValues: object;
|
||||
label: string;
|
||||
editing?: boolean;
|
||||
fromSpreadsheet?: boolean;
|
||||
onUpdateFormValues?: (formValues: object) => void;
|
||||
} = $props();
|
||||
|
||||
let formStore = writable(formValues);
|
||||
|
||||
function removeArrayItem(key: string, index: number) {
|
||||
formValues = {
|
||||
...formValues,
|
||||
[key]: formValues[key].filter((_, i) => i !== index)
|
||||
const next = {
|
||||
...$formStore,
|
||||
[key]: $formStore[key].filter((_, i) => i !== index)
|
||||
};
|
||||
|
||||
formStore.set(next);
|
||||
onUpdateFormValues?.(next);
|
||||
}
|
||||
|
||||
function addArrayItem(key: string) {
|
||||
formValues = {
|
||||
...formValues,
|
||||
[key]: [...formValues[key], null]
|
||||
const next = {
|
||||
...$formStore,
|
||||
[key]: [...($formStore[key] ?? []), null]
|
||||
};
|
||||
|
||||
formStore.set(next);
|
||||
onUpdateFormValues?.(next);
|
||||
}
|
||||
|
||||
function getColumnType(column: Columns) {
|
||||
@@ -52,10 +63,12 @@
|
||||
}
|
||||
return `${capitalize(column.type)}${column.array ? '[]' : ''}`;
|
||||
}
|
||||
|
||||
formStore.subscribe((values) => onUpdateFormValues?.(values));
|
||||
</script>
|
||||
|
||||
{#if column.array}
|
||||
{#if formValues[column.key]?.length === 0}
|
||||
{#if $formStore[column.key]?.length === 0}
|
||||
{#if fromSpreadsheet}
|
||||
<Column
|
||||
array
|
||||
@@ -65,7 +78,7 @@
|
||||
id={column.key}
|
||||
limited={fromSpreadsheet}
|
||||
optionalText={getColumnType(column)}
|
||||
bind:value={formValues[column.key]}
|
||||
bind:value={$formStore[column.key]}
|
||||
on:click />
|
||||
{:else}
|
||||
<Layout.Stack direction="row" alignContent="space-between">
|
||||
@@ -90,11 +103,11 @@
|
||||
id={column.key}
|
||||
limited={fromSpreadsheet}
|
||||
optionalText={getColumnType(column)}
|
||||
bind:value={formValues[column.key]}
|
||||
bind:value={$formStore[column.key]}
|
||||
on:click />
|
||||
{:else}
|
||||
<Layout.Stack>
|
||||
{#each [...(formValues[column.key]?.keys() ?? [])] as index}
|
||||
{#each [...($formStore[column.key]?.keys() ?? [])] as index}
|
||||
<Layout.Stack direction="row" alignItems="flex-end" gap="xs">
|
||||
<Column
|
||||
{column}
|
||||
@@ -102,7 +115,7 @@
|
||||
id={`${column.key}-${index}`}
|
||||
optionalText={index === 0 ? getColumnType(column) : undefined}
|
||||
label={index === 0 ? label : ''}
|
||||
bind:value={formValues[column.key][index]} />
|
||||
bind:value={$formStore[column.key][index]} />
|
||||
<Button text icon on:click={() => removeArrayItem(column.key, index)}>
|
||||
<span class="icon-x" aria-hidden="true"></span>
|
||||
</Button>
|
||||
@@ -124,6 +137,6 @@
|
||||
id={column.key}
|
||||
limited={fromSpreadsheet}
|
||||
optionalText={getColumnType(column)}
|
||||
bind:value={formValues[column.key]}
|
||||
bind:value={$formStore[column.key]}
|
||||
on:click />
|
||||
{/if}
|
||||
+14
-34
@@ -14,39 +14,19 @@
|
||||
optionalText = undefined;
|
||||
}
|
||||
|
||||
const onChange = (event: CustomEvent) => {
|
||||
if (limited) {
|
||||
value = event.detail as boolean;
|
||||
}
|
||||
};
|
||||
$: options = [
|
||||
!column.required && { label: 'NULL', value: null },
|
||||
{ label: limited ? 'true' : 'True', value: true },
|
||||
{ label: limited ? 'false' : 'False', value: false }
|
||||
].filter(Boolean);
|
||||
</script>
|
||||
|
||||
{#if limited}
|
||||
<InputSelect
|
||||
{id}
|
||||
{label}
|
||||
{value}
|
||||
{optionalText}
|
||||
autofocus={limited}
|
||||
placeholder="Select a value"
|
||||
required={column.required}
|
||||
options={[
|
||||
{ label: 'True', value: true },
|
||||
{ label: 'False', value: false }
|
||||
].filter(Boolean)}
|
||||
on:change={onChange} />
|
||||
{:else}
|
||||
<InputSelect
|
||||
{id}
|
||||
{label}
|
||||
bind:value
|
||||
{optionalText}
|
||||
autofocus={limited}
|
||||
placeholder="Select a value"
|
||||
required={column.required}
|
||||
options={[
|
||||
!column.required && { label: 'NULL', value: null },
|
||||
{ label: 'True', value: true },
|
||||
{ label: 'False', value: false }
|
||||
].filter(Boolean)} />
|
||||
{/if}
|
||||
<InputSelect
|
||||
{id}
|
||||
{label}
|
||||
bind:value
|
||||
{options}
|
||||
{optionalText}
|
||||
autofocus={limited}
|
||||
placeholder="Select a value"
|
||||
required={column.required} />
|
||||
+6
@@ -1,6 +1,7 @@
|
||||
<script lang="ts">
|
||||
import { InputNumber } from '$lib/elements/forms';
|
||||
import type { Models } from '@appwrite.io/console';
|
||||
import { isWithinSafeRange } from '$lib/helpers/numbers';
|
||||
|
||||
export let id: string;
|
||||
export let label: string;
|
||||
@@ -13,6 +14,11 @@
|
||||
$: if (limited) {
|
||||
label = undefined;
|
||||
}
|
||||
|
||||
$: if (limited) {
|
||||
column.min = isWithinSafeRange(column.min) ? column.min : Number.MIN_SAFE_INTEGER;
|
||||
column.max = isWithinSafeRange(column.max) ? column.max : Number.MAX_SAFE_INTEGER;
|
||||
}
|
||||
</script>
|
||||
|
||||
<InputNumber
|
||||
|
||||
+118
-59
@@ -4,11 +4,20 @@
|
||||
import { preferences } from '$lib/stores/preferences';
|
||||
import { sdk } from '$lib/stores/sdk';
|
||||
import { Query, type Models } from '@appwrite.io/console';
|
||||
import { onMount } from 'svelte';
|
||||
import { type ComponentType, onMount } from 'svelte';
|
||||
import { isRelationshipToMany } from '../../store';
|
||||
import { IconPlus, IconX } from '@appwrite.io/pink-icons-svelte';
|
||||
import { Icon, Layout, Typography } from '@appwrite.io/pink-svelte';
|
||||
|
||||
type SelectOption = {
|
||||
label: string;
|
||||
value: string | null;
|
||||
data?: string[];
|
||||
disabled?: boolean;
|
||||
badge?: string;
|
||||
leadingIcon?: ComponentType;
|
||||
};
|
||||
|
||||
export let id: string;
|
||||
export let label: string;
|
||||
export let limited: boolean = false;
|
||||
@@ -25,6 +34,7 @@
|
||||
let showInput = false;
|
||||
let singleRel: string;
|
||||
let search: string = null;
|
||||
let loadingRelationships = false;
|
||||
|
||||
let newItemValue: string = '';
|
||||
let relatedList: string[] = [];
|
||||
@@ -33,27 +43,23 @@
|
||||
let offset = 0;
|
||||
|
||||
onMount(async () => {
|
||||
if (value && typeof value === 'object') {
|
||||
row = value as Models.Row;
|
||||
singleRel = row?.$id;
|
||||
}
|
||||
|
||||
if (value && isRelationshipToMany(column)) {
|
||||
// TODO: test this
|
||||
relatedList = (value as string[]).slice();
|
||||
}
|
||||
|
||||
if (editing && row?.[column.key]) {
|
||||
if (row[column.key]?.length) {
|
||||
relatedList =
|
||||
row[column.key]?.map((d: Record<string, unknown>) => {
|
||||
return d?.$id;
|
||||
}) ?? [];
|
||||
if (isRelationshipToMany(column)) {
|
||||
if (Array.isArray(value)) {
|
||||
relatedList = value.map((item: object | string) => {
|
||||
return typeof item === 'string' ? item : item['$id'];
|
||||
});
|
||||
}
|
||||
} else {
|
||||
if (value && typeof value === 'object') {
|
||||
row = value as Models.Row;
|
||||
singleRel = row?.$id;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
async function getRows(search: string = null) {
|
||||
loadingRelationships = true;
|
||||
|
||||
// already includes the `$id`, dw!
|
||||
const displayNames = preferences.getDisplayNames(column.relatedTable);
|
||||
|
||||
@@ -61,11 +67,17 @@
|
||||
? [Query.select(displayNames), Query.startsWith('$id', search), Query.orderDesc('')]
|
||||
: [Query.select(displayNames)];
|
||||
|
||||
return await sdk.forProject(page.params.region, page.params.project).tablesDB.listRows({
|
||||
databaseId,
|
||||
tableId: column.relatedTable,
|
||||
queries
|
||||
});
|
||||
const rows = await sdk
|
||||
.forProject(page.params.region, page.params.project)
|
||||
.tablesDB.listRows({
|
||||
databaseId,
|
||||
tableId: column.relatedTable,
|
||||
queries
|
||||
});
|
||||
|
||||
loadingRelationships = false;
|
||||
|
||||
return rows;
|
||||
}
|
||||
|
||||
function getAvailableOptions(excludeIndex?: number) {
|
||||
@@ -107,6 +119,58 @@
|
||||
showInput = false;
|
||||
}
|
||||
|
||||
function generateOptions(
|
||||
loading: boolean,
|
||||
rows: Models.Row[] | undefined,
|
||||
column: Models.ColumnRelationship,
|
||||
editing: boolean
|
||||
): SelectOption[] {
|
||||
if (loading) {
|
||||
return [{ label: 'Loading...', value: null, disabled: true }];
|
||||
}
|
||||
|
||||
let baseOptions: SelectOption[] =
|
||||
rows?.map((row) => {
|
||||
const names = preferences
|
||||
.getDisplayNames(column?.relatedTable)
|
||||
.filter((name) => name !== '$id');
|
||||
|
||||
const values = names
|
||||
.map((name) => row?.[name])
|
||||
.filter((value) => value != null && typeof value === 'string' && value !== '');
|
||||
|
||||
const displayValues = !editing
|
||||
? values
|
||||
: values.map((value) => (value.length > 5 ? value.slice(0, 5) + '...' : value));
|
||||
|
||||
let label: string;
|
||||
if (!values.length) {
|
||||
label = row.$id;
|
||||
} else {
|
||||
label = `${row.$id} (${displayValues.join(' | ')})`;
|
||||
}
|
||||
|
||||
return {
|
||||
label,
|
||||
value: row.$id,
|
||||
data: names.map((name) => row?.[name])
|
||||
};
|
||||
}) ?? [];
|
||||
|
||||
if (!isRelationshipToMany(column) && baseOptions.length && value && limited) {
|
||||
baseOptions = [
|
||||
{
|
||||
value: null,
|
||||
badge: 'Unlink',
|
||||
label: 'Remove relationship'
|
||||
},
|
||||
...baseOptions
|
||||
];
|
||||
}
|
||||
|
||||
return baseOptions;
|
||||
}
|
||||
|
||||
// Reactive statements
|
||||
$: getRows(search).then((res) => (rowList = res));
|
||||
|
||||
@@ -119,34 +183,7 @@
|
||||
|
||||
$: totalCount = relatedList?.length ?? 0;
|
||||
|
||||
$: options =
|
||||
rowList?.rows?.map((row) => {
|
||||
const names = preferences
|
||||
.getDisplayNames(column?.relatedTable)
|
||||
.filter((name) => name !== '$id');
|
||||
|
||||
const values = names
|
||||
.map((name) => row?.[name])
|
||||
// always supposed to be a string but just being a bit safe here
|
||||
.filter((value) => value != null && typeof value === 'string' && value !== '');
|
||||
|
||||
const displayValues = !editing
|
||||
? values
|
||||
: // on non edit routes like create, there's enough space!
|
||||
values.map((value) => (value.length > 5 ? value.slice(0, 5) + '...' : value));
|
||||
|
||||
const label = !values.length
|
||||
? row.$id
|
||||
: // values are in `$id (a | b)` format
|
||||
// previously used to have a `$id a | b`.
|
||||
`${row.$id} (${displayValues.join(' | ')})`;
|
||||
|
||||
return {
|
||||
label,
|
||||
value: row.$id,
|
||||
data: names.map((name) => row?.[name])
|
||||
};
|
||||
}) ?? [];
|
||||
$: options = generateOptions(loadingRelationships, rowList?.rows, column, editing);
|
||||
|
||||
$: hasItems = totalCount > 0;
|
||||
|
||||
@@ -286,13 +323,35 @@
|
||||
</Layout.Stack>
|
||||
</Layout.Stack>
|
||||
{:else}
|
||||
<InputSelect
|
||||
{id}
|
||||
{options}
|
||||
autofocus={limited}
|
||||
bind:value={singleRel}
|
||||
required={column.required}
|
||||
label={limited ? undefined : label}
|
||||
placeholder={`Select ${column.key}`}
|
||||
on:change={() => (value = rowList.rows.find((row) => row.$id === singleRel))} />
|
||||
<Layout.Stack direction="row" alignItems="center" gap="s">
|
||||
<InputSelect
|
||||
{id}
|
||||
{options}
|
||||
autofocus={limited}
|
||||
bind:value={singleRel}
|
||||
required={column.required}
|
||||
label={limited ? undefined : label}
|
||||
placeholder={`Select ${column.key}`}
|
||||
on:change={() => {
|
||||
if (singleRel === null) {
|
||||
value = null;
|
||||
} else {
|
||||
value = rowList.rows.find((row) => row.$id === singleRel);
|
||||
}
|
||||
}} />
|
||||
|
||||
{#if !limited && singleRel}
|
||||
<div style:padding-block-start="2.25rem">
|
||||
<Button
|
||||
icon
|
||||
extraCompact
|
||||
on:click={() => {
|
||||
value = null;
|
||||
singleRel = null;
|
||||
}}>
|
||||
<Icon icon={IconX} size="s" />
|
||||
</Button>
|
||||
</div>
|
||||
{/if}
|
||||
</Layout.Stack>
|
||||
{/if}
|
||||
+40
-12
@@ -7,13 +7,21 @@
|
||||
import { writable } from 'svelte/store';
|
||||
import ColumnForm from './columns/columnForm.svelte';
|
||||
import { Permissions } from '$lib/components/permissions';
|
||||
import type { Columns } from '../store';
|
||||
import { type Columns } from '../store';
|
||||
import { ID, type Models } from '@appwrite.io/console';
|
||||
import { Alert, Layout, Typography, Selector } from '@appwrite.io/pink-svelte';
|
||||
import SideSheet from '../layout/sidesheet.svelte';
|
||||
import { invalidate } from '$app/navigation';
|
||||
import { Dependencies } from '$lib/constants';
|
||||
import { tick } from 'svelte';
|
||||
import { isRelationship, isRelationshipToMany } from './store';
|
||||
|
||||
type CreateRow = {
|
||||
id?: string;
|
||||
row: object;
|
||||
permissions: string[];
|
||||
columns: Columns[];
|
||||
};
|
||||
|
||||
let {
|
||||
table,
|
||||
@@ -25,16 +33,15 @@
|
||||
existingData: Models.Row | null;
|
||||
} = $props();
|
||||
|
||||
let createMore = $state(false);
|
||||
let isSubmitting = $state(false);
|
||||
let columnFormWrapper: HTMLDivElement | null = $state(null);
|
||||
let createMore = $state(false);
|
||||
|
||||
type CreateRow = {
|
||||
id?: string;
|
||||
row: object;
|
||||
permissions: string[];
|
||||
columns: Columns[];
|
||||
};
|
||||
let createRow = writable<CreateRow>(computeInitialCreateRow());
|
||||
|
||||
function resetCreateRow(): void {
|
||||
createRow.set(computeInitialCreateRow());
|
||||
}
|
||||
|
||||
function computeInitialCreateRow(): CreateRow {
|
||||
const availableColumns = table.columns.filter((a) => a.status === 'available');
|
||||
@@ -55,15 +62,36 @@
|
||||
};
|
||||
}
|
||||
|
||||
function resetCreateRow(): void {
|
||||
createRow.set(computeInitialCreateRow());
|
||||
}
|
||||
// for one to *, we need the IDs,
|
||||
// for many to *, we need the full row object.
|
||||
function prepareRowPayload(createRowObject: CreateRow): object {
|
||||
const { row, columns } = createRowObject;
|
||||
|
||||
let createRow = writable<CreateRow>(computeInitialCreateRow());
|
||||
const payload = structuredClone(row);
|
||||
|
||||
for (const column of columns) {
|
||||
if (isRelationship(column) && !isRelationshipToMany(column)) {
|
||||
const key = column.key;
|
||||
const value = payload[key];
|
||||
|
||||
if (value && typeof value === 'object') {
|
||||
if (Array.isArray(value)) {
|
||||
payload[key] = value.map((item) => item?.$id).filter(Boolean);
|
||||
} else {
|
||||
payload[key] = (value as { $id: string })['$id'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return payload;
|
||||
}
|
||||
|
||||
async function create(): Promise<boolean> {
|
||||
isSubmitting = true;
|
||||
|
||||
$createRow.row = prepareRowPayload($createRow);
|
||||
|
||||
try {
|
||||
await sdk.forProject(page.params.region, page.params.project).tablesDB.createRow({
|
||||
databaseId: page.params.database,
|
||||
|
||||
+58
-7
@@ -10,19 +10,23 @@
|
||||
import { invalidate } from '$app/navigation';
|
||||
import { table, type Columns, PROHIBITED_ROW_KEYS } from '../store';
|
||||
import ColumnItem from './columns/columnItem.svelte';
|
||||
import { isRelationship, isRelationshipToMany } from './store';
|
||||
import { Layout } from '@appwrite.io/pink-svelte';
|
||||
import { buildWildcardColumnsQuery, isRelationship, isRelationshipToMany } from './store';
|
||||
import { Layout, Skeleton } from '@appwrite.io/pink-svelte';
|
||||
import { deepClone } from '$lib/helpers/object';
|
||||
|
||||
const tableId = page.params.table;
|
||||
const databaseId = page.params.database;
|
||||
|
||||
let {
|
||||
row = $bindable()
|
||||
row = $bindable(),
|
||||
rowId = $bindable(null)
|
||||
}: {
|
||||
row: Models.Row;
|
||||
row?: Models.Row | null;
|
||||
rowId?: string | null;
|
||||
} = $props();
|
||||
|
||||
let loading = $state(false);
|
||||
|
||||
let work = $state<Writable<Models.Row> | null>(null);
|
||||
let columnFormWrapper = $state<HTMLElement | null>(null);
|
||||
|
||||
@@ -39,10 +43,42 @@
|
||||
return writable(deepClone(result as Models.Row));
|
||||
}
|
||||
|
||||
async function loadRowFromId() {
|
||||
if (!rowId) return;
|
||||
loading = true;
|
||||
|
||||
try {
|
||||
row = await sdk.forProject(page.params.region, page.params.project).tablesDB.getRow({
|
||||
databaseId,
|
||||
tableId,
|
||||
rowId,
|
||||
queries: buildWildcardColumnsQuery($table)
|
||||
});
|
||||
} catch (error) {
|
||||
addNotification({
|
||||
message: `Failed to load row: ${error.message}`,
|
||||
type: 'error'
|
||||
});
|
||||
|
||||
row = null;
|
||||
} finally {
|
||||
rowId = null;
|
||||
loading = false;
|
||||
}
|
||||
}
|
||||
|
||||
$effect(() => {
|
||||
if (!row && rowId) {
|
||||
loadRowFromId();
|
||||
}
|
||||
});
|
||||
|
||||
$effect(() => {
|
||||
if (row) {
|
||||
work = initWork();
|
||||
focusFirstInput();
|
||||
} else {
|
||||
work = null;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -81,6 +117,8 @@
|
||||
}
|
||||
|
||||
export async function update() {
|
||||
if (!row || !work) return;
|
||||
|
||||
try {
|
||||
await sdk.forProject(page.params.region, page.params.project).tablesDB.updateRow({
|
||||
databaseId,
|
||||
@@ -106,7 +144,7 @@
|
||||
}
|
||||
|
||||
export function isDisabled(): boolean {
|
||||
if (!work || !$table?.columns?.length) return true;
|
||||
if (!work || !row || !$table?.columns?.length) return true;
|
||||
|
||||
return $table.columns.every((column) => compareColumns(column, $work, row));
|
||||
}
|
||||
@@ -118,14 +156,27 @@
|
||||
|
||||
firstInput?.focus({ preventScroll: true });
|
||||
}
|
||||
|
||||
function updateRowData(values: object) {
|
||||
work.set(values as Models.Row);
|
||||
}
|
||||
</script>
|
||||
|
||||
{#if $table.columns?.length && work}
|
||||
{#if loading}
|
||||
<div style:margin-block="" style:margin-inline-end="2.25rem">
|
||||
<Skeleton variant="line" height={40} width="auto" />
|
||||
</div>
|
||||
{:else if $table.columns?.length && work}
|
||||
<div bind:this={columnFormWrapper}>
|
||||
<Layout.Stack direction="column" gap="l">
|
||||
{#each $table.columns as column}
|
||||
{@const label = column.key}
|
||||
<ColumnItem {column} bind:formValues={$work} {label} editing />
|
||||
<ColumnItem
|
||||
{column}
|
||||
{label}
|
||||
editing
|
||||
formValues={$work}
|
||||
onUpdateFormValues={updateRowData} />
|
||||
{/each}
|
||||
</Layout.Stack>
|
||||
</div>
|
||||
|
||||
+259
-58
@@ -4,63 +4,158 @@
|
||||
import { page } from '$app/state';
|
||||
import { sdk } from '$lib/stores/sdk';
|
||||
import { addNotification } from '$lib/stores/notifications';
|
||||
import { type Writable, writable } from 'svelte/store';
|
||||
import { type Models } from '@appwrite.io/console';
|
||||
import { get, type Writable, writable } from 'svelte/store';
|
||||
import { type Models, Query } from '@appwrite.io/console';
|
||||
import { Dependencies } from '$lib/constants';
|
||||
import { invalidate } from '$app/navigation';
|
||||
import { type Columns, PROHIBITED_ROW_KEYS } from '../store';
|
||||
import ColumnItem from './columns/columnItem.svelte';
|
||||
import { buildWildcardColumnsQuery, isRelationship, isRelationshipToMany } from './store';
|
||||
import { Layout, Skeleton } from '@appwrite.io/pink-svelte';
|
||||
import { Divider, Layout, Skeleton, Typography } from '@appwrite.io/pink-svelte';
|
||||
import { deepClone } from '$lib/helpers/object';
|
||||
|
||||
const databaseId = page.params.database;
|
||||
|
||||
let {
|
||||
rowId,
|
||||
rows,
|
||||
tableId
|
||||
}: {
|
||||
rowId: string;
|
||||
rows: string | Models.Row[];
|
||||
tableId: string;
|
||||
} = $props();
|
||||
|
||||
let loading = $state(false);
|
||||
let fetchedRow = $state<Models.Row | null>(null);
|
||||
let fetchedRows = $state<Models.Row[]>([]);
|
||||
let relatedTable = $state<Models.Table | null>(null);
|
||||
|
||||
let work = $state<Writable<Models.Row> | null>(null);
|
||||
let disabledState = $state(calculateAndCompareDisabledState());
|
||||
|
||||
let workData = $state<Map<string, Writable<Models.Row>>>(new Map());
|
||||
let columnFormWrapper = $state<HTMLElement | null>(null);
|
||||
|
||||
function isSingleStore() {
|
||||
return typeof rows === 'string';
|
||||
}
|
||||
|
||||
async function loadRelatedRow() {
|
||||
loading = true;
|
||||
|
||||
try {
|
||||
relatedTable =
|
||||
page.data.tables?.[tableId] ??
|
||||
(await sdk.forProject(page.params.region, page.params.project).tablesDB.getTable({
|
||||
databaseId,
|
||||
tableId: tableId
|
||||
}));
|
||||
if (isSingleStore()) {
|
||||
relatedTable =
|
||||
page.data.tables?.[tableId] ??
|
||||
(await sdk
|
||||
.forProject(page.params.region, page.params.project)
|
||||
.tablesDB.getTable({
|
||||
databaseId,
|
||||
tableId: tableId
|
||||
}));
|
||||
|
||||
fetchedRow = await sdk
|
||||
.forProject(page.params.region, page.params.project)
|
||||
.tablesDB.getRow({
|
||||
databaseId,
|
||||
tableId: tableId,
|
||||
rowId: rowId,
|
||||
queries: buildWildcardColumnsQuery(relatedTable)
|
||||
const fetchedRow = await sdk
|
||||
.forProject(page.params.region, page.params.project)
|
||||
.tablesDB.getRow({
|
||||
databaseId,
|
||||
tableId: tableId,
|
||||
rowId: rows as string,
|
||||
queries: buildWildcardColumnsQuery(relatedTable)
|
||||
});
|
||||
|
||||
fetchedRows = [fetchedRow];
|
||||
} else {
|
||||
let fetchedTables = [];
|
||||
const processedRows = [];
|
||||
const existingRows = rows as Models.Row[];
|
||||
|
||||
const firstTableId = existingRows[0].$tableId;
|
||||
|
||||
const uniqueTableIds = [...new Set(existingRows.map((row) => row.$tableId))];
|
||||
const missingTableIds = uniqueTableIds.filter((tableId) => {
|
||||
return !page.data.tables?.find((table: Models.Table) => table.$id === tableId);
|
||||
});
|
||||
|
||||
const filteredKeys = Object.keys(fetchedRow).filter((key) => {
|
||||
return !PROHIBITED_ROW_KEYS.includes(key);
|
||||
if (missingTableIds.length > 0) {
|
||||
const tablesResponse = await sdk
|
||||
.forProject(page.params.region, page.params.project)
|
||||
.tablesDB.listTables({
|
||||
databaseId,
|
||||
queries: [
|
||||
Query.equal('$id', missingTableIds),
|
||||
Query.limit(missingTableIds.length)
|
||||
]
|
||||
});
|
||||
fetchedTables = tablesResponse.tables;
|
||||
}
|
||||
|
||||
const allTables = [...(page.data.tables || []), ...fetchedTables];
|
||||
relatedTable = allTables.find((table) => table.$id === firstTableId) || null;
|
||||
|
||||
let rowsMissingData = [];
|
||||
|
||||
for (const row of existingRows) {
|
||||
const rowTable = allTables.find((table) => table.$id === row.$tableId);
|
||||
|
||||
const hasAllColumns = rowTable.columns.every(
|
||||
(column: Columns) => column.key in row
|
||||
);
|
||||
|
||||
if (!hasAllColumns) {
|
||||
rowsMissingData.push({ row, rowTable });
|
||||
} else {
|
||||
processedRows.push(row);
|
||||
}
|
||||
}
|
||||
|
||||
if (rowsMissingData.length > 0) {
|
||||
const rowsByTable = new Map();
|
||||
|
||||
for (const { row, rowTable } of rowsMissingData) {
|
||||
if (!rowsByTable.has(row.$tableId)) {
|
||||
rowsByTable.set(row.$tableId, { rows: [], rowTable });
|
||||
}
|
||||
|
||||
rowsByTable.get(row.$tableId).rows.push(row);
|
||||
}
|
||||
|
||||
const fetchPromises = Array.from(rowsByTable.entries()).map(
|
||||
async ([tableId, { rows, rowTable }]) => {
|
||||
const rowIds: string[] = rows.map((row: Models.Row) => row.$id);
|
||||
const response = await sdk
|
||||
.forProject(page.params.region, page.params.project)
|
||||
.tablesDB.listRows({
|
||||
databaseId,
|
||||
tableId,
|
||||
queries: [
|
||||
Query.equal('$id', rowIds),
|
||||
Query.limit(rowIds.length),
|
||||
...buildWildcardColumnsQuery(rowTable)
|
||||
]
|
||||
});
|
||||
return response.rows;
|
||||
}
|
||||
);
|
||||
|
||||
const allCompleteRows = await Promise.all(fetchPromises);
|
||||
processedRows.push(...allCompleteRows.flat());
|
||||
}
|
||||
|
||||
fetchedRows = processedRows;
|
||||
}
|
||||
|
||||
const newWorkData = new Map();
|
||||
fetchedRows.forEach((row) => {
|
||||
const filteredKeys = Object.keys(row).filter((key) => {
|
||||
return !PROHIBITED_ROW_KEYS.includes(key);
|
||||
});
|
||||
|
||||
const workingData = filteredKeys.reduce((obj, key) => {
|
||||
obj[key] = row[key];
|
||||
return obj;
|
||||
}, {});
|
||||
|
||||
newWorkData.set(row.$id, writable(deepClone(workingData as Models.Row)));
|
||||
});
|
||||
|
||||
const workingData = filteredKeys.reduce((obj, key) => {
|
||||
obj[key] = fetchedRow[key];
|
||||
return obj;
|
||||
}, {});
|
||||
|
||||
work = writable(deepClone(workingData as Models.Row));
|
||||
workData = newWorkData;
|
||||
} catch (error) {
|
||||
addNotification({
|
||||
message: error.message,
|
||||
@@ -72,14 +167,6 @@
|
||||
}
|
||||
}
|
||||
|
||||
$effect(() => {
|
||||
if (rowId && tableId) {
|
||||
loadRelatedRow().then(() => {
|
||||
focusFirstInput();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
function compareColumns(column: Columns, $work: Models.Row, originalRow: Models.Row) {
|
||||
if (!column) {
|
||||
return false;
|
||||
@@ -94,6 +181,10 @@
|
||||
|
||||
if (isRelationship(column)) {
|
||||
if (isRelationshipToMany(column as Models.ColumnRelationship)) {
|
||||
if (!Array.isArray(workColumn) || !Array.isArray(currentColumn)) {
|
||||
return workColumn === currentColumn;
|
||||
}
|
||||
|
||||
const workIds = workColumn.map((doc: string | Record<string, unknown>) =>
|
||||
typeof doc === 'string' ? doc : doc.$id
|
||||
);
|
||||
@@ -114,22 +205,77 @@
|
||||
return workColumn === currentColumn;
|
||||
}
|
||||
|
||||
export async function update() {
|
||||
try {
|
||||
await sdk.forProject(page.params.region, page.params.project).tablesDB.updateRow({
|
||||
databaseId,
|
||||
tableId: relatedTable.$id,
|
||||
rowId: fetchedRow.$id,
|
||||
data: $work,
|
||||
permissions: $work.$permissions
|
||||
function calculateAndCompareDisabledState() {
|
||||
if (!relatedTable?.columns?.length || !fetchedRows.length) return true;
|
||||
|
||||
if (isSingleStore()) {
|
||||
const rowId = fetchedRows[0].$id;
|
||||
|
||||
const row = fetchedRows.find((r) => r.$id === rowId);
|
||||
const work = workData.get(rowId);
|
||||
if (!row || !work) return true;
|
||||
|
||||
const workValue = get(work);
|
||||
return relatedTable.columns.every((column) => compareColumns(column, workValue, row));
|
||||
} else {
|
||||
return fetchedRows.every((row) => {
|
||||
const work = workData.get(row.$id);
|
||||
if (!work) return true;
|
||||
|
||||
const workValue = get(work);
|
||||
|
||||
return relatedTable.columns.every((column) =>
|
||||
compareColumns(column, workValue, row)
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export async function update(rowId?: string) {
|
||||
try {
|
||||
if (rowId) {
|
||||
const work = workData.get(rowId);
|
||||
|
||||
const workValue = get(work);
|
||||
await sdk.forProject(page.params.region, page.params.project).tablesDB.updateRow({
|
||||
databaseId,
|
||||
tableId: relatedTable.$id,
|
||||
rowId: rowId,
|
||||
data: workValue,
|
||||
permissions: workValue.$permissions
|
||||
});
|
||||
|
||||
addNotification({
|
||||
message: 'Related row has been updated',
|
||||
type: 'success'
|
||||
});
|
||||
} else {
|
||||
const updatePromises = fetchedRows.map(async (row) => {
|
||||
const work = workData.get(row.$id);
|
||||
if (!work) return;
|
||||
|
||||
const workValue = get(work);
|
||||
return sdk
|
||||
.forProject(page.params.region, page.params.project)
|
||||
.tablesDB.updateRow({
|
||||
databaseId,
|
||||
tableId: relatedTable.$id,
|
||||
rowId: row.$id,
|
||||
data: workValue,
|
||||
permissions: workValue.$permissions
|
||||
});
|
||||
});
|
||||
|
||||
await Promise.all(updatePromises);
|
||||
|
||||
addNotification({
|
||||
message: 'Related row has been updated',
|
||||
type: 'success'
|
||||
});
|
||||
}
|
||||
|
||||
invalidate(Dependencies.ROW);
|
||||
trackEvent(Submit.RowUpdate);
|
||||
addNotification({
|
||||
message: 'Related row has been updated',
|
||||
type: 'success'
|
||||
});
|
||||
} catch (error) {
|
||||
addNotification({
|
||||
message: error.message,
|
||||
@@ -140,9 +286,7 @@
|
||||
}
|
||||
|
||||
export function isDisabled(): boolean {
|
||||
if (!work || !relatedTable?.columns?.length || !fetchedRow) return true;
|
||||
|
||||
return relatedTable.columns.every((column) => compareColumns(column, $work, fetchedRow));
|
||||
return disabledState;
|
||||
}
|
||||
|
||||
function focusFirstInput() {
|
||||
@@ -152,19 +296,76 @@
|
||||
|
||||
firstInput?.focus({ preventScroll: true });
|
||||
}
|
||||
|
||||
function getStore(id: string) {
|
||||
const rowInstance = workData.get(id);
|
||||
return get(rowInstance);
|
||||
}
|
||||
|
||||
function handleFormUpdate(rowId: string) {
|
||||
return (updatedFormValues: object) => {
|
||||
const workStore = workData.get(rowId);
|
||||
if (workStore) {
|
||||
workStore.set(updatedFormValues as Models.Row);
|
||||
disabledState = calculateAndCompareDisabledState();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
$effect(() => {
|
||||
if (rows && tableId) {
|
||||
loadRelatedRow().then(() => {
|
||||
focusFirstInput();
|
||||
});
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
{#if loading}
|
||||
<div style:margin-block="" style:margin-inline-end="2.25rem">
|
||||
<Skeleton variant="line" height={40} width="auto" />
|
||||
</div>
|
||||
{:else if relatedTable?.columns?.length && work}
|
||||
{:else if relatedTable?.columns?.length && fetchedRows.length}
|
||||
<div bind:this={columnFormWrapper}>
|
||||
<Layout.Stack direction="column" gap="l">
|
||||
{#each relatedTable.columns as column}
|
||||
{@const label = column.key}
|
||||
<ColumnItem {column} bind:formValues={$work} {label} editing />
|
||||
{/each}
|
||||
</Layout.Stack>
|
||||
{#if fetchedRows.length === 1}
|
||||
{@const workStore = getStore(fetchedRows[0].$id)}
|
||||
{#if workStore}
|
||||
<Layout.Stack direction="column" gap="l">
|
||||
{#each relatedTable.columns as column}
|
||||
{@const label = column.key}
|
||||
<ColumnItem
|
||||
{column}
|
||||
{label}
|
||||
editing
|
||||
formValues={workStore}
|
||||
onUpdateFormValues={handleFormUpdate(fetchedRows[0].$id)} />
|
||||
{/each}
|
||||
</Layout.Stack>
|
||||
{/if}
|
||||
{:else}
|
||||
<Layout.Stack direction="column" gap="m" class="column-item-stack">
|
||||
<Typography.Text variant="l-400">{relatedTable.name}</Typography.Text>
|
||||
<Layout.Stack direction="column" gap="l" class="column-item-stack">
|
||||
{#each fetchedRows as row, index (row.$id)}
|
||||
{@const workStore = getStore(row.$id)}
|
||||
{#if workStore}
|
||||
{#each relatedTable.columns as column}
|
||||
{@const label = column.key}
|
||||
<ColumnItem
|
||||
{column}
|
||||
{label}
|
||||
editing
|
||||
formValues={workStore}
|
||||
onUpdateFormValues={handleFormUpdate(row.$id)} />
|
||||
{/each}
|
||||
{/if}
|
||||
|
||||
{#if index < fetchedRows.length - 1}
|
||||
<Divider />
|
||||
{/if}
|
||||
{/each}
|
||||
</Layout.Stack>
|
||||
</Layout.Stack>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
+5
@@ -1,3 +1,4 @@
|
||||
import { page } from '$app/state';
|
||||
import type { Columns } from '../store';
|
||||
import { type Models, Query } from '@appwrite.io/console';
|
||||
|
||||
@@ -33,3 +34,7 @@ export function buildWildcardColumnsQuery(table: Models.Table | null = null): st
|
||||
Query.select(['*'])
|
||||
];
|
||||
}
|
||||
|
||||
export function buildRowUrl(rowId: string) {
|
||||
return `${page.url}/row-${rowId}`;
|
||||
}
|
||||
+27
-16
@@ -14,6 +14,7 @@
|
||||
| 'duplicate-row'
|
||||
| 'permissions'
|
||||
| 'activity'
|
||||
| 'copy-url'
|
||||
| 'copy-json'
|
||||
// | 'copy-snippet'
|
||||
| 'delete';
|
||||
@@ -29,6 +30,7 @@
|
||||
IconClipboardCopy,
|
||||
IconDuplicate,
|
||||
IconKey,
|
||||
IconLink,
|
||||
IconPencil,
|
||||
IconSortAscending,
|
||||
IconSortDescending,
|
||||
@@ -67,6 +69,7 @@
|
||||
{ label: 'Manage permissions', icon: IconKey, action: 'permissions' },
|
||||
{ label: 'View activity', icon: IconChartBar, action: 'activity' },
|
||||
{ divider: true },
|
||||
{ label: 'Copy URL', icon: IconLink, action: 'copy-url' },
|
||||
{ label: 'Copy as JSON', icon: IconClipboardCopy, action: 'copy-json' },
|
||||
{ divider: true },
|
||||
{ label: 'Delete', icon: IconTrash, action: 'delete', danger: true }
|
||||
@@ -156,21 +159,29 @@
|
||||
<!-- hacky, i know! -->
|
||||
<span bind:this={htmlSpanElement}> </span>
|
||||
|
||||
<ActionMenu.Root width="180px">
|
||||
{#each menuItems as item, index (index)}
|
||||
{#if item.divider}
|
||||
<div style:padding-block="0.25rem">
|
||||
<Divider />
|
||||
</div>
|
||||
{:else if shouldShow(item)}
|
||||
<ActionMenu.Item.Button
|
||||
leadingIcon={item.icon}
|
||||
status={item.danger ? 'danger' : undefined}
|
||||
on:click={() => item.action && handleSelect(item.action, hide)}>
|
||||
{item.label}
|
||||
</ActionMenu.Item.Button>
|
||||
{/if}
|
||||
{/each}
|
||||
</ActionMenu.Root>
|
||||
<div class="action-menu-root">
|
||||
<ActionMenu.Root width="180px">
|
||||
{#each menuItems as item, index (index)}
|
||||
{#if item.divider}
|
||||
<div style:padding-block="0.5rem" style:margin-inline="-1rem;">
|
||||
<Divider />
|
||||
</div>
|
||||
{:else if shouldShow(item)}
|
||||
<ActionMenu.Item.Button
|
||||
leadingIcon={item.icon}
|
||||
status={item.danger ? 'danger' : undefined}
|
||||
on:click={() => item.action && handleSelect(item.action, hide)}>
|
||||
{item.label}
|
||||
</ActionMenu.Item.Button>
|
||||
{/if}
|
||||
{/each}
|
||||
</ActionMenu.Root>
|
||||
</div>
|
||||
</svelte:fragment>
|
||||
</Popover>
|
||||
|
||||
<style>
|
||||
.action-menu-root :global(:first-child) {
|
||||
overflow: visible;
|
||||
}
|
||||
</style>
|
||||
+100
-33
@@ -11,7 +11,13 @@
|
||||
import { type Models, Query } from '@appwrite.io/console';
|
||||
import { type ComponentType, onDestroy, onMount } from 'svelte';
|
||||
import type { PageData } from './$types';
|
||||
import { isRelationship, isRelationshipToMany, isString } from './rows/store';
|
||||
import {
|
||||
buildRowUrl,
|
||||
buildWildcardColumnsQuery,
|
||||
isRelationship,
|
||||
isRelationshipToMany,
|
||||
isString
|
||||
} from './rows/store';
|
||||
import {
|
||||
columns,
|
||||
table,
|
||||
@@ -79,7 +85,8 @@
|
||||
import { pageToOffset } from '$lib/helpers/load';
|
||||
import { debounce } from '$lib/helpers/debounce';
|
||||
import { hash } from '$lib/helpers/string';
|
||||
import { abbreviateNumber } from '$lib/helpers/numbers';
|
||||
import { formatNumberWithCommas } from '$lib/helpers/numbers';
|
||||
import { chunks } from '$lib/helpers/array';
|
||||
|
||||
export let data: PageData;
|
||||
export let showRowCreateSheet: {
|
||||
@@ -131,6 +138,11 @@
|
||||
paginatedRows.clear();
|
||||
paginatedRows.setPage(1, data.rows.rows);
|
||||
}
|
||||
|
||||
// rowId exists, we have someone from old url format!
|
||||
if ($databaseRowSheetOptions && $databaseRowSheetOptions.rowId) {
|
||||
setTimeout(() => ($databaseRowSheetOptions.show = true), 250);
|
||||
}
|
||||
});
|
||||
|
||||
onDestroy(() => ($showCreateColumnSheet.show = false));
|
||||
@@ -140,7 +152,7 @@
|
||||
|
||||
const baseColumns = $table.columns.map((col) => ({
|
||||
id: col.key,
|
||||
title: col.array ? `${col.key} []` : col.key,
|
||||
title: col.key,
|
||||
type: col.type as ColumnType,
|
||||
hide: !!selectedColumnsToHide?.includes(col.key),
|
||||
array: col?.array,
|
||||
@@ -337,6 +349,8 @@
|
||||
|
||||
async function handleDelete() {
|
||||
showDelete = false;
|
||||
let hadErrors = false;
|
||||
|
||||
try {
|
||||
if (selectedRowForDelete) {
|
||||
await sdk.forProject(page.params.region, page.params.project).tablesDB.deleteRow({
|
||||
@@ -346,31 +360,61 @@
|
||||
});
|
||||
} else {
|
||||
if (selectedRows.length) {
|
||||
const batches: string[][] = [];
|
||||
for (let i = 0; i < selectedRows.length; i += 100) {
|
||||
batches.push(selectedRows.slice(i, i + 100));
|
||||
}
|
||||
|
||||
await Promise.all(
|
||||
batches.map((batch) =>
|
||||
sdk
|
||||
.forProject(page.params.region, page.params.project)
|
||||
.tablesDB.deleteRows({
|
||||
databaseId,
|
||||
tableId,
|
||||
queries: [Query.equal('$id', batch)]
|
||||
})
|
||||
)
|
||||
const hasAnyRelationships = $table.columns.some((column) =>
|
||||
isRelationship(column)
|
||||
);
|
||||
|
||||
const tablesSDK = sdk.forProject(
|
||||
page.params.region,
|
||||
page.params.project
|
||||
).tablesDB;
|
||||
|
||||
if (hasAnyRelationships) {
|
||||
for (const batch of chunks(selectedRows)) {
|
||||
try {
|
||||
await Promise.all(
|
||||
batch.map((rowId) =>
|
||||
tablesSDK.deleteRow({
|
||||
databaseId,
|
||||
tableId,
|
||||
rowId
|
||||
})
|
||||
)
|
||||
);
|
||||
} catch (e) {
|
||||
hadErrors = true;
|
||||
// ignore but keep proceeding!
|
||||
}
|
||||
}
|
||||
|
||||
if (hadErrors) {
|
||||
addNotification({
|
||||
type: 'error',
|
||||
message: 'Some rows could not be deleted'
|
||||
});
|
||||
}
|
||||
} else {
|
||||
for (const batch of chunks(selectedRows, 100)) {
|
||||
await tablesSDK.deleteRows({
|
||||
databaseId,
|
||||
tableId,
|
||||
queries: [Query.equal('$id', batch)]
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
await invalidate(Dependencies.ROWS);
|
||||
trackEvent(Submit.RowDelete);
|
||||
addNotification({
|
||||
type: 'success',
|
||||
message: `${selectedRows.length ? selectedRows.length : 1} row${selectedRows.length > 1 ? 's' : ''} deleted`
|
||||
});
|
||||
|
||||
if (!hadErrors) {
|
||||
// error is already shown above!
|
||||
addNotification({
|
||||
type: 'success',
|
||||
message: `${selectedRows.length ? selectedRows.length : 1} row${selectedRows.length > 1 ? 's' : ''} deleted`
|
||||
});
|
||||
}
|
||||
|
||||
spreadsheetRenderKey.set(
|
||||
hash([
|
||||
@@ -487,6 +531,21 @@
|
||||
$rowPermissionSheet.show = true;
|
||||
}
|
||||
|
||||
if (action === 'copy-url') {
|
||||
try {
|
||||
await copy(buildRowUrl(row.$id));
|
||||
addNotification({
|
||||
type: 'success',
|
||||
message: 'Row url copied'
|
||||
});
|
||||
} catch (e) {
|
||||
addNotification({
|
||||
type: 'error',
|
||||
message: e.message
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (action === 'copy-json') {
|
||||
const stringified = JSON.stringify(row, null, 2);
|
||||
try {
|
||||
@@ -569,7 +628,8 @@
|
||||
queries: [
|
||||
getCorrectOrderQuery(),
|
||||
Query.limit(SPREADSHEET_PAGE_LIMIT),
|
||||
Query.offset(pageToOffset(pageNumber, SPREADSHEET_PAGE_LIMIT))
|
||||
Query.offset(pageToOffset(pageNumber, SPREADSHEET_PAGE_LIMIT)),
|
||||
...buildWildcardColumnsQuery($table)
|
||||
]
|
||||
});
|
||||
|
||||
@@ -595,7 +655,8 @@
|
||||
queries: [
|
||||
getCorrectOrderQuery(),
|
||||
Query.limit(SPREADSHEET_PAGE_LIMIT),
|
||||
Query.offset(pageToOffset(targetPageNum, SPREADSHEET_PAGE_LIMIT))
|
||||
Query.offset(pageToOffset(targetPageNum, SPREADSHEET_PAGE_LIMIT)),
|
||||
...buildWildcardColumnsQuery($table)
|
||||
]
|
||||
});
|
||||
|
||||
@@ -680,7 +741,6 @@
|
||||
on:columnsResize={(resize) => saveColumnsWidth(resize.detail)}
|
||||
bind:currentPage
|
||||
nextPageTriggerOffset={2}
|
||||
paginationBufferSpace={35}
|
||||
jumpToPageNumber={jumpToPageReactive}
|
||||
loadingMore={$paginatedRowsLoading}
|
||||
itemsPerPage={SPREADSHEET_PAGE_LIMIT}
|
||||
@@ -729,8 +789,14 @@
|
||||
gap="xs"
|
||||
direction="row"
|
||||
alignItems="center"
|
||||
alignContent="center">
|
||||
{column.title}
|
||||
alignContent="center"
|
||||
style="min-width: 0;">
|
||||
<Typography.Text truncate>
|
||||
{column.title}
|
||||
</Typography.Text>
|
||||
|
||||
<!-- array indicator -->
|
||||
{#if column.array}[]{/if}
|
||||
|
||||
<SortButton
|
||||
onSort={sort}
|
||||
@@ -778,6 +844,7 @@
|
||||
>{row.$id}</Id>
|
||||
{:else if columnId === '$createdAt' || columnId === '$updatedAt'}
|
||||
<DualTimeView
|
||||
showDatetime
|
||||
time={row[columnId]}
|
||||
canShowPopover={canShowDatetimePopover} />
|
||||
{:else if columnId === 'actions'}
|
||||
@@ -813,11 +880,11 @@
|
||||
<Link.Button
|
||||
variant="muted"
|
||||
on:click={() => {
|
||||
$databaseRelatedRowSheetOptions.show = true;
|
||||
$databaseRelatedRowSheetOptions.tableId =
|
||||
columnId;
|
||||
$databaseRelatedRowSheetOptions.rowId =
|
||||
row[columnId]?.['$tableId'];
|
||||
$databaseRelatedRowSheetOptions.rows =
|
||||
row[columnId]?.['$id'];
|
||||
$databaseRelatedRowSheetOptions.show = true;
|
||||
}}>
|
||||
{displayValue}
|
||||
</Link.Button>
|
||||
@@ -838,9 +905,9 @@
|
||||
badge={itemsNum ?? 0}
|
||||
on:click={() => {
|
||||
$databaseRelatedRowSheetOptions.show = true;
|
||||
$databaseRelatedRowSheetOptions.rows =
|
||||
row[columnId];
|
||||
$databaseRelatedRowSheetOptions.tableId = columnId;
|
||||
$databaseRelatedRowSheetOptions.rowId =
|
||||
row[columnId]?.['$id'];
|
||||
}}>
|
||||
Items
|
||||
</Button.Button>
|
||||
@@ -922,7 +989,7 @@
|
||||
<span style:white-space="nowrap">
|
||||
{selectedRows.length
|
||||
? `${selectedRows.length} row${selectedRows.length === 1 ? '' : 's'} selected`
|
||||
: `${abbreviateNumber($rows.total)} row${$rows.total === 1 ? '' : 's'}`}
|
||||
: `${formatNumberWithCommas($rows.total)} row${$rows.total === 1 ? '' : 's'}`}
|
||||
</span>
|
||||
</Typography.Text>
|
||||
|
||||
|
||||
+6
-3
@@ -57,22 +57,24 @@ export const databaseColumnSheetOptions = writable<DatabaseSheetOptions>({
|
||||
export const databaseRowSheetOptions = writable<
|
||||
DatabaseSheetOptions & {
|
||||
row: Models.Row;
|
||||
rowId?: string;
|
||||
}
|
||||
>({
|
||||
title: null,
|
||||
show: false,
|
||||
row: null
|
||||
row: null,
|
||||
rowId: null // for loading from a given id
|
||||
});
|
||||
|
||||
export const databaseRelatedRowSheetOptions = writable<
|
||||
DatabaseSheetOptions & {
|
||||
rowId: string;
|
||||
rows: string | Models.Row[];
|
||||
tableId: string;
|
||||
}
|
||||
>({
|
||||
title: 'Update related row',
|
||||
show: false,
|
||||
rowId: null,
|
||||
rows: null,
|
||||
tableId: null
|
||||
});
|
||||
|
||||
@@ -177,6 +179,7 @@ export const paginatedRows = createSparsePagedDataStore<Models.DefaultRow>(SPREA
|
||||
|
||||
export const PROHIBITED_ROW_KEYS = [
|
||||
'$id',
|
||||
'$sequence',
|
||||
'$collection',
|
||||
'$tableId',
|
||||
'$databaseId',
|
||||
|
||||
+1
-1
@@ -72,7 +72,7 @@
|
||||
detectingRuntime = true;
|
||||
|
||||
const detections = (await sdk
|
||||
.forProject(page.params.regionn, page.params.project)
|
||||
.forProject(page.params.region, page.params.project)
|
||||
.vcs.createRepositoryDetection({
|
||||
installationId: data.installation.$id,
|
||||
providerRepositoryId: page.params.repository,
|
||||
|
||||
+2
-1
@@ -74,7 +74,8 @@
|
||||
{ label: 'PUT', value: ExecutionMethod.PUT },
|
||||
{ label: 'PATCH', value: ExecutionMethod.PATCH },
|
||||
{ label: 'DELETE', value: ExecutionMethod.DELETE },
|
||||
{ label: 'OPTIONS', value: ExecutionMethod.OPTIONS }
|
||||
{ label: 'OPTIONS', value: ExecutionMethod.OPTIONS },
|
||||
{ label: 'HEAD', value: ExecutionMethod.HEAD }
|
||||
];
|
||||
|
||||
let formComponent: Form;
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@
|
||||
export const promptDeleteProvider = (id: string) => {
|
||||
showDelete.set(true);
|
||||
goto(
|
||||
`${base}/project-${page.params.region}-${page.params.$id}/messaging/providers/provider-${id}`
|
||||
`${base}/project-${page.params.region}-${page.params.project}/messaging/providers/provider-${id}`
|
||||
);
|
||||
};
|
||||
</script>
|
||||
|
||||
+5
-2
@@ -16,6 +16,7 @@
|
||||
import { symmetricDifference } from '$lib/helpers/array';
|
||||
import Scopes from '../api-keys/scopes.svelte';
|
||||
import { InteractiveText, Layout, Typography } from '@appwrite.io/pink-svelte';
|
||||
import { getEffectiveScopes } from '../api-keys/scopes.svelte';
|
||||
|
||||
export let key: Models.DevKey | Models.Key;
|
||||
export let keyType: 'api' | 'dev' = 'api';
|
||||
@@ -162,6 +163,8 @@
|
||||
{#if isApiKey}
|
||||
<Form onSubmit={updateScopes}>
|
||||
{@const apiKey = asApiKey(key)}
|
||||
{@const apiKeyCorrectScopes = getEffectiveScopes(apiKey.scopes)}
|
||||
{@const currentEffective = scopes ? getEffectiveScopes(scopes) : null}
|
||||
<CardGrid>
|
||||
<svelte:fragment slot="title">Scopes</svelte:fragment>
|
||||
You can choose which permission scope to grant your application. It is a best practice
|
||||
@@ -176,8 +179,8 @@
|
||||
<Button
|
||||
submit
|
||||
disabled={scopes &&
|
||||
apiKey?.scopes &&
|
||||
!symmetricDifference(scopes, apiKey.scopes).length}>Update</Button>
|
||||
!symmetricDifference(currentEffective, apiKeyCorrectScopes).length}
|
||||
>Update</Button>
|
||||
</svelte:fragment>
|
||||
</CardGrid>
|
||||
</Form>
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
import { Badge, FloatingActionBar, Layout, Table } from '@appwrite.io/pink-svelte';
|
||||
import DeleteBatch from './deleteBatch.svelte';
|
||||
import { capitalize } from '$lib/helpers/string';
|
||||
import { getEffectiveScopes } from '../api-keys/scopes.svelte';
|
||||
|
||||
export let keyType: 'api' | 'dev' = 'api';
|
||||
export let keys: Models.KeyList | Models.DevKeyList;
|
||||
@@ -22,8 +23,9 @@
|
||||
const label = isApiKey ? 'API' : 'dev';
|
||||
const slug = isApiKey ? 'api-keys' : 'dev-keys';
|
||||
|
||||
function asApiKey(key: Models.Key | Models.DevKey) {
|
||||
return key as Models.Key;
|
||||
function getApiKeyScopeCount(key: Models.Key | Models.DevKey) {
|
||||
const apiKey = key as Models.Key;
|
||||
return getEffectiveScopes(apiKey.scopes).length;
|
||||
}
|
||||
|
||||
function getExpiryDetails(key: Models.Key | Models.DevKey): {
|
||||
@@ -85,7 +87,7 @@
|
||||
</Table.Cell>
|
||||
{#if isApiKey}
|
||||
<Table.Cell {root}>
|
||||
{asApiKey(key).scopes.length} Scopes
|
||||
{getApiKeyScopeCount(key)} Scopes
|
||||
</Table.Cell>
|
||||
{/if}
|
||||
</Table.Row.Link>
|
||||
|
||||
@@ -1,3 +1,30 @@
|
||||
<script lang="ts" context="module">
|
||||
const compatPairs = [
|
||||
{ newer: 'tables.', legacy: 'collections.' },
|
||||
{ newer: 'columns.', legacy: 'attributes.' },
|
||||
{ newer: 'rows.', legacy: 'documents.' }
|
||||
] as const;
|
||||
|
||||
export function getEffectiveScopes(scopes: string[]): string[] {
|
||||
const effectiveScopes = new Set<string>();
|
||||
|
||||
for (const scope of scopes) {
|
||||
let effectiveScope = scope;
|
||||
|
||||
for (const pair of compatPairs) {
|
||||
if (scope.startsWith(pair.legacy)) {
|
||||
effectiveScope = scope.replace(pair.legacy, pair.newer);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
effectiveScopes.add(effectiveScope);
|
||||
}
|
||||
|
||||
return Array.from(effectiveScopes);
|
||||
}
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
import { Button } from '$lib/elements/forms';
|
||||
import { scopes as allScopes } from '$lib/constants';
|
||||
@@ -7,37 +34,14 @@
|
||||
|
||||
export let scopes: string[];
|
||||
|
||||
const newScopes = ['tables.', 'columns.', 'rows.'];
|
||||
const legacyScopes = ['attributes.', 'collections.', 'documents.'];
|
||||
const compatPairs = [
|
||||
{ newer: 'tables.', legacy: 'collections.' },
|
||||
{ newer: 'columns.', legacy: 'attributes.' },
|
||||
{ newer: 'rows.', legacy: 'documents.' }
|
||||
] as const;
|
||||
|
||||
const isCreateMode = scopes.length === 0;
|
||||
const scopeCatalog = new Set(allScopes.map((s) => s.scope));
|
||||
|
||||
const hasLegacyScopes = !isCreateMode
|
||||
? scopes.some((scope) => legacyScopes.some((prefix) => scope?.startsWith(prefix)))
|
||||
: false;
|
||||
|
||||
const filteredScopes = allScopes.filter((scope) => {
|
||||
const val = scope.scope;
|
||||
|
||||
if (!val) return false;
|
||||
|
||||
if (isCreateMode) {
|
||||
return !legacyScopes.some((prefix) => val.startsWith(prefix));
|
||||
}
|
||||
|
||||
if (hasLegacyScopes) {
|
||||
// In edit mode, if legacy scopes exist, exclude new ones
|
||||
return !newScopes.some((prefix) => val.startsWith(prefix));
|
||||
} else {
|
||||
// In edit mode, if new scopes exist, exclude new ones
|
||||
return !legacyScopes.some((prefix) => val.startsWith(prefix));
|
||||
}
|
||||
const legacyPrefixes = ['collections.', 'attributes.', 'documents.'];
|
||||
return !legacyPrefixes.some((prefix) => val.startsWith(prefix));
|
||||
});
|
||||
|
||||
enum Category {
|
||||
@@ -62,13 +66,18 @@
|
||||
|
||||
let mounted = false;
|
||||
|
||||
onMount(() => {
|
||||
const computedScopes = syncScopes(scopes);
|
||||
if (symmetricDifference(scopes, computedScopes).length) {
|
||||
scopes = computedScopes;
|
||||
}
|
||||
const activeScopes = filteredScopes.reduce((prev, next) => {
|
||||
prev[next.scope] = false;
|
||||
return prev;
|
||||
}, {});
|
||||
|
||||
scopes.forEach((scope) => (activeScopes[scope] = true));
|
||||
onMount(() => {
|
||||
scopes.forEach((scope) => {
|
||||
const newerScope = toNewerScope(scope);
|
||||
if (newerScope in activeScopes) {
|
||||
activeScopes[newerScope] = true;
|
||||
}
|
||||
});
|
||||
|
||||
mounted = true;
|
||||
});
|
||||
@@ -85,14 +94,43 @@
|
||||
}
|
||||
}
|
||||
|
||||
function toNewerScope(scope: string): string {
|
||||
for (const pair of compatPairs) {
|
||||
if (scope.startsWith(pair.legacy)) {
|
||||
return scope.replace(pair.legacy, pair.newer);
|
||||
}
|
||||
}
|
||||
return scope;
|
||||
}
|
||||
|
||||
function getAllScopeVariants(scope: string): string[] {
|
||||
const variants = new Set([scope]);
|
||||
|
||||
for (const pair of compatPairs) {
|
||||
if (scope.startsWith(pair.newer)) {
|
||||
variants.add(scope.replace(pair.newer, pair.legacy));
|
||||
} else if (scope.startsWith(pair.legacy)) {
|
||||
variants.add(scope.replace(pair.legacy, pair.newer));
|
||||
}
|
||||
}
|
||||
|
||||
return Array.from(variants);
|
||||
}
|
||||
|
||||
function categoryState(category: string, s: string[]): boolean | 'indeterminate' {
|
||||
const scopesByCategory = filteredScopes.filter((n) => n.category === category);
|
||||
const filtered = scopesByCategory.filter((n) => s.includes(n.scope));
|
||||
if (filtered.length === 0) {
|
||||
|
||||
const activeInCategory = scopesByCategory.filter((scopeItem) => {
|
||||
const newerScope = scopeItem.scope;
|
||||
return s.some((scope) => toNewerScope(scope) === newerScope);
|
||||
});
|
||||
|
||||
if (activeInCategory.length === 0) {
|
||||
return false;
|
||||
} else if (filtered.length === scopesByCategory.length) {
|
||||
} else if (activeInCategory.length === scopesByCategory.length) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return 'indeterminate';
|
||||
}
|
||||
|
||||
@@ -105,41 +143,29 @@
|
||||
});
|
||||
}
|
||||
|
||||
function syncScopes(list: string[]): string[] {
|
||||
const out = new Set(list);
|
||||
const pairs = compatPairs.map((pair) =>
|
||||
hasLegacyScopes
|
||||
? ([pair.legacy, pair.newer] as const)
|
||||
: ([pair.newer, pair.legacy] as const)
|
||||
);
|
||||
function generateSyncedScopes(activeScopesObj: Record<string, boolean>): string[] {
|
||||
const result = new Set<string>();
|
||||
|
||||
for (const scope of list) {
|
||||
for (const [from, to] of pairs) {
|
||||
if (scope.startsWith(from)) {
|
||||
const counterpart = scope.replace(from, to);
|
||||
if (scopeCatalog.has(counterpart)) out.add(counterpart);
|
||||
}
|
||||
Object.entries(activeScopesObj).forEach(([scope, isActive]) => {
|
||||
if (isActive) {
|
||||
const variants = getAllScopeVariants(scope);
|
||||
variants.forEach((variant) => {
|
||||
if (scopeCatalog.has(variant)) {
|
||||
result.add(variant);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
return Array.from(out);
|
||||
});
|
||||
|
||||
return Array.from(result);
|
||||
}
|
||||
|
||||
const activeScopes = filteredScopes.reduce((prev, next) => {
|
||||
prev[next.scope] = false;
|
||||
|
||||
return prev;
|
||||
}, {});
|
||||
|
||||
$: {
|
||||
if (mounted) {
|
||||
const newScopeSet = filteredScopes
|
||||
.filter((scope) => activeScopes[scope.scope])
|
||||
.map(({ scope }) => scope);
|
||||
const newScopes = generateSyncedScopes(activeScopes);
|
||||
|
||||
const updatedScopes = hasLegacyScopes ? newScopeSet : syncScopes(newScopeSet);
|
||||
|
||||
if (symmetricDifference(scopes, updatedScopes).length) {
|
||||
scopes = updatedScopes;
|
||||
if (symmetricDifference(scopes, newScopes).length) {
|
||||
scopes = newScopes;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -160,7 +186,9 @@
|
||||
{@const checked = categoryState(category, scopes)}
|
||||
{@const isLastItem = index === categories.length - 1}
|
||||
{@const scopesLength = filteredScopes.filter(
|
||||
(n) => n.category === category && scopes.includes(n.scope)
|
||||
(n) =>
|
||||
n.category === category &&
|
||||
scopes.some((scope) => toNewerScope(scope) === n.scope)
|
||||
).length}
|
||||
<Accordion
|
||||
selectable
|
||||
|
||||
Reference in new issue
Block a user