Merge branch 'main' into relatonship-lazy-queries

This commit is contained in:
Darshan committed 2025-07-08 16:35:46 +05:30
commit 79141462a8
35 files changed
+417 -311

No files matched your search

+21 -4
View File
@@ -148,7 +148,12 @@
})}
clearOnCallback={false}
on:keydown={(e) => {
if (e.detail.key !== 'Escape') {
const showingExamples = !$isLoading && !answer;
if (e.detail.key === 'Enter' && $input.trim()) {
e.detail.cancel();
return;
}
if (e.detail.key !== 'Escape' && !showingExamples) {
e.detail.cancel();
}
}}
@@ -302,15 +307,27 @@
}
}
:global(.answer ul),
:global(.answer ol) {
gap: 1rem;
:global(.answer ul) {
padding-inline-start: 1rem;
list-style-type: disc;
display: grid;
gap: 1rem;
}
:global(.answer ol) {
padding-inline-start: 1.1rem;
list-style-type: decimal;
display: grid;
gap: 1rem;
}
:global(.answer a) {
text-decoration: underline;
}
:global(.answer a:hover) {
opacity: 0.8;
}
}
.experimental {
+59 -34
View File
@@ -3,7 +3,6 @@
import { hideNotification, shouldShowNotification } from '$lib/helpers/notifications';
import { app } from '$lib/stores/app';
import {
type BottomModalAlertAction,
type BottomModalAlertItem,
bottomModalAlertsConfig,
dismissBottomModalAlert,
@@ -20,18 +19,18 @@
import { goto } from '$app/navigation';
import { Typography } from '@appwrite.io/pink-svelte';
let currentIndex = 0;
let openModalOnMobile = false;
let currentIndex = $state(0);
let openModalOnMobile = $state(false);
function getPageScope(pathname: string) {
const isProjectPage = pathname.includes('project-[region]-[project]');
const isOrganizationPage = pathname.includes('organization-[organization]');
function getPageScope(route: string) {
const isProjectPage = route.includes('project-[region]-[project]');
const isOrganizationPage = route.includes('organization-[organization]');
return { isProjectPage, isOrganizationPage };
}
function filterModalAlerts(alerts: BottomModalAlertItem[], pathname: string) {
const { isProjectPage, isOrganizationPage } = getPageScope(pathname);
function filterModalAlerts(alerts: BottomModalAlertItem[], route: string) {
const { isProjectPage, isOrganizationPage } = getPageScope(route);
return alerts
.sort((a, b) => b.importance - a.importance)
@@ -51,19 +50,32 @@
});
}
$: filteredModalAlerts = filterModalAlerts($bottomModalAlertsConfig.alerts, page.route.id);
const bottomModalAlerts = $derived($bottomModalAlertsConfig.alerts);
$: currentModalAlert = filteredModalAlerts[currentIndex] as BottomModalAlertItem;
const filteredModalAlerts = $derived(filterModalAlerts(bottomModalAlerts, page.route.id));
$: hasOnlyPrimaryCta = typeof currentModalAlert?.learnMore === 'undefined';
const currentModalAlert = $derived(filteredModalAlerts[currentIndex] as BottomModalAlertItem);
function handleClose() {
filteredModalAlerts.forEach((alert) => {
const hasOnlyPrimaryCta = $derived(typeof currentModalAlert?.learnMore === 'undefined');
const isOnOnboarding = $derived(page.route.id.includes('(console)/onboarding'));
function handleClose(id: string | null = null) {
const alerts = !id
? filteredModalAlerts
: filteredModalAlerts.filter((alert) => alert.id === id);
alerts.forEach((alert) => {
const modalAlert = alert;
dismissBottomModalAlert(modalAlert.id);
hideNotification(modalAlert.id, { coolOffPeriod: 24 * 365 });
if (modalAlert.closed) modalAlert.closed();
});
// reset `currentIndex` if we removed the last item
if (currentIndex >= filteredModalAlerts.length - 1) {
currentIndex = Math.max(0, filteredModalAlerts.length - 2);
}
}
function showNext() {
@@ -114,8 +126,13 @@
}
// the button component cannot have both href and on:click!
function triggerWindowLink(alertAction: BottomModalAlertAction, event?: string) {
function triggerWindowLink(alert: BottomModalAlertItem, event?: string) {
const alertAction = alert.cta;
const shouldShowUpgrade = showUpgrade();
// for correct event tracking after removal
const currentModalId = currentModalAlert.id;
const url = shouldShowUpgrade
? $upgradeURL
: alertAction.link({
@@ -130,14 +147,12 @@
}
if (alertAction?.hideOnClick === true) {
// be careful of this one.
// once clicked, its gone!
handleClose();
handleClose(alert.id); // gone!
}
trackEvent(Click.PromoClick, {
promo: currentModalAlert.id,
type: shouldShowUpgrade ? 'upgrade' : (event ?? `cta_click_${currentModalAlert.id}`)
promo: currentModalId,
type: shouldShowUpgrade ? 'upgrade' : (event ?? `cta_click_${currentModalId}`)
});
}
@@ -156,12 +171,10 @@
}
}
onMount(() => {
addBottomModalAlerts();
});
onMount(addBottomModalAlerts);
</script>
{#if filteredModalAlerts.length > 0 && currentModalAlert && !page.url.pathname.includes('console/onboarding')}
{#if !isOnOnboarding && filteredModalAlerts.length > 0 && currentModalAlert}
{@const shouldShowUpgrade = showUpgrade()}
<div class="main-alert-wrapper is-not-mobile">
<div class="alert-container">
@@ -170,7 +183,7 @@
<button
aria-label="Close modal"
class="icon-inline-tag"
on:click={() => handleClose()}>
onclick={() => handleClose()}>
<svg
xmlns="http://www.w3.org/2000/svg"
width="20"
@@ -208,14 +221,19 @@
<button
aria-label="Previous"
class="icon-cheveron-left"
on:click={showPrevious}
style:cursor={currentIndex !== 0 ? 'pointer' : undefined}
onclick={showPrevious}
disabled={currentIndex === 0}
class:active={currentIndex > 0}></button>
<button
aria-label="Next"
class="icon-cheveron-right"
on:click={showNext}
onclick={showNext}
style:cursor={currentIndex !==
filteredModalAlerts.length - 1
? 'pointer'
: undefined}
disabled={currentIndex === filteredModalAlerts.length - 1}
class:active={currentIndex !==
filteredModalAlerts.length - 1}></button>
@@ -243,7 +261,7 @@
fullWidthMobile
secondary={!hasOnlyPrimaryCta}
class={`${hasOnlyPrimaryCta ? 'only-primary-cta' : ''}`}
on:click={() => triggerWindowLink(currentModalAlert.cta)}>
on:click={() => triggerWindowLink(currentModalAlert)}>
{currentModalAlert.cta.text}
</Button>
@@ -276,7 +294,7 @@
<button
aria-label="Close modal"
class="icon-inline-tag"
on:click={() => handleClose()}>
onclick={() => handleClose()}>
<svg
xmlns="http://www.w3.org/2000/svg"
width="20"
@@ -314,14 +332,21 @@
<button
aria-label="Previous"
class="icon-cheveron-left"
on:click={showPrevious}
style:cursor={currentIndex !== 0
? 'pointer'
: undefined}
onclick={showPrevious}
disabled={currentIndex === 0}
class:active={currentIndex > 0}></button>
<button
aria-label="Next"
class="icon-cheveron-right"
on:click={showNext}
onclick={showNext}
style:cursor={currentIndex !==
filteredModalAlerts.length - 1
? 'pointer'
: undefined}
disabled={currentIndex ===
filteredModalAlerts.length - 1}
class:active={currentIndex !==
@@ -352,7 +377,7 @@
fullWidthMobile
on:click={() => {
openModalOnMobile = false;
triggerWindowLink(currentModalAlert.cta);
triggerWindowLink(currentModalAlert);
}}>
{shouldShowUpgrade
? 'Upgrade plan'
@@ -382,13 +407,13 @@
{:else}
{@const mobileConfig = getMobileWindowConfig()}
<!-- we don't need keydown because we show this only on mobile -->
<!-- svelte-ignore a11y-click-events-have-key-events -->
<!-- svelte-ignore a11y_click_events_have_key_events -->
<div
tabindex="0"
role="button"
class:showing={!openModalOnMobile}
class="card notification-card u-width-full-line"
on:click={() => {
onclick={() => {
if (mobileConfig.cta) {
// navigate manually!
triggerMobileWindowLink();
@@ -401,7 +426,7 @@
<Typography.Text variant="m-500" color="--fgcolor-neutral-primary">
{currentModalAlert.title}
</Typography.Text>
<button on:click={hideAllModalAlerts} aria-label="Close">
<button onclick={hideAllModalAlerts} aria-label="Close">
<span class="icon-x"></span>
</button>
</div>
+17 -15
View File
@@ -20,6 +20,7 @@
let maxHeight = $state('none');
let containerRef = $state<HTMLElement>(null);
const collectionId = $derived(page.params.collection);
const calcMaxHeight = () => {
if (containerRef) {
@@ -32,10 +33,10 @@
};
const saveColumnPreferences = () => {
const shownColumns = $columns.filter((n) => n.hide !== true).map((n) => n.id);
const shownColumns = $columns.filter((n) => n.hide === true).map((n) => n.id);
if (isCustomCollection) {
preferences.setCustomCollectionColumns(page.params.collection, shownColumns);
preferences.setCustomCollectionColumns(collectionId, shownColumns);
} else {
preferences.setColumns(shownColumns);
}
@@ -43,24 +44,24 @@
onMount(() => {
if (isCustomCollection) {
const shownColumns = preferences.getCustomCollectionColumns(page.params.collection);
const shownColumns = preferences.getCustomCollectionColumns(collectionId);
columns.update((columns) => {
return columns.map((column) => {
column.hide = !shownColumns.includes(column.id);
columns.update((n) =>
n.map((column) => {
column.hide = shownColumns?.includes(column.id) ?? false;
return column;
});
});
})
);
} else {
const prefs = preferences.get(page.route);
if (prefs?.columns && prefs.columns.length > 0) {
columns.update((cols) => {
return cols.map((column) => {
column.hide = !prefs.columns.includes(column.id);
if (prefs?.columns) {
columns.update((n) =>
n.map((column) => {
column.hide = prefs.columns?.includes(column.id) ?? false;
return column;
});
});
})
);
}
}
@@ -79,7 +80,7 @@
columns.update((cols) =>
cols.map((col) => {
if (col.id === column.id) {
col.hide = !column.hide;
column.hide = !column.hide;
}
return col;
})
@@ -90,6 +91,7 @@
</script>
<svelte:window on:resize={calcMaxHeight} />
{#if $columns?.length}
<Popover let:toggle placement="bottom-end" padding="none">
{@render children(toggle, selectedColumnsNumber)}
+7 -5
View File
@@ -88,11 +88,13 @@
{@const exists = $groups.has(role)}
<Table.Row.Button {root} on:click={() => onSelection(role)} disabled={exists}>
<Table.Cell column="checkbox" {root}>
<Selector.Checkbox
size="s"
id={team.$id}
disabled={exists}
checked={exists || selected.has(role)} />
<div style:pointer-events="none">
<Selector.Checkbox
size="s"
id={team.$id}
disabled={exists}
checked={exists || selected.has(role)} />
</div>
</Table.Cell>
<Table.Cell column="team" {root}>
<Layout.Stack direction="row" alignItems="center" gap="s">
+7 -5
View File
@@ -90,11 +90,13 @@
{@const exists = $groups.has(role)}
<Table.Row.Button {root} on:click={() => onSelection(role)} disabled={exists}>
<Table.Cell column="checkbox" {root}>
<Selector.Checkbox
size="s"
id={user.$id}
disabled={exists}
checked={exists || selected.has(role)} />
<div style:pointer-events="none">
<Selector.Checkbox
size="s"
id={user.$id}
disabled={exists}
checked={exists || selected.has(role)} />
</div>
</Table.Cell>
<Table.Cell column="user" {root}>
<Layout.Stack direction="row" alignItems="center" gap="s">
+1 -1
View File
@@ -18,7 +18,7 @@ export enum Dependencies {
INVOICES = 'dependency:invoices',
ADDRESS = 'dependency:address',
UPGRADE_PLAN = 'dependency:upgrade_plan',
CREATE_ORGANIZATION = 'dependency:create_organization',
ORGANIZATIONS = 'dependency:organizations',
PAYMENT_METHODS = 'dependency:paymentMethods',
ORGANIZATION = 'dependency:organization',
MEMBERS = 'dependency:members',
Binary file not shown.

After

Width:  |  Height:  |  Size: 77 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB

+1
View File
@@ -287,6 +287,7 @@ export function checkForEnterpriseTrial(org: Organization) {
}
export function calculateEnterpriseTrial(org: Organization) {
if (!org || !org.billingNextInvoiceDate) return 0;
const endDate = new Date(org.billingNextInvoiceDate);
const startDate = new Date(org.billingCurrentInvoiceDate);
const today = new Date();
+1 -1
View File
@@ -176,7 +176,7 @@ function createPreferences() {
names: TeamPreferences['names']
) => {
let teamPrefs: Models.Preferences;
update((n) => {
await updateAndSync((n) => {
if (!n?.displayNames) {
n ??= {};
n.displayNames ??= {};
@@ -56,7 +56,7 @@
if (organization) {
org = await sdk.forConsole.billing.setBillingAddress(organization, response.$id);
trackEvent(Submit.OrganizationBillingAddressUpdate);
await invalidate(Dependencies.ORGANIZATION);
await invalidate(Dependencies.ORGANIZATIONS);
}
await invalidate(Dependencies.ADDRESS);
+25 -16
View File
@@ -1,10 +1,9 @@
import { isCloud } from '$lib/system';
import { isSameDay } from '$lib/helpers/date';
import {
type BottomModalAlertItem,
showBottomModalAlert,
setMobileSingleAlertLayout
} from '$lib/stores/bottom-alerts';
import { type BottomModalAlertItem, showBottomModalAlert } from '$lib/stores/bottom-alerts';
import BulkApiDark from '$lib/images/promos/bulk-api-dark.png';
import BulkApiLight from '$lib/images/promos/bulk-api-light.png';
import CSVImportDark from '$lib/images/promos/csv-import-placeholder-dark.png';
import CSVImportLight from '$lib/images/promos/csv-import-placeholder-light.png';
@@ -33,18 +32,28 @@ if (isCloud) {
show: true
};
listOfPromotions.push(csvImportPromo);
setMobileSingleAlertLayout({
title: csvImportPromo.title,
message: csvImportPromo.message,
enabled: true,
const bulkApiPromo: BottomModalAlertItem = {
id: 'modal:bulk_api_announcement',
src: {
dark: BulkApiDark,
light: BulkApiLight
},
title: 'Introducing Bulk API',
message:
'A new Appwrite Databases feature, explicitly designed to handle heavy write workloads.',
plan: 'free',
importance: 8,
scope: 'project',
cta: {
link: csvImportPromo.cta.link,
external: csvImportPromo.cta.external,
hideOnClick: csvImportPromo.cta.hideOnClick
}
});
text: 'Read announcement',
link: () => 'https://appwrite.io/blog/post/announcing-bulk-api',
external: true,
hideOnClick: true
},
show: true
};
listOfPromotions.push(bulkApiPromo, csvImportPromo);
}
export function addBottomModalAlerts() {
@@ -6,7 +6,7 @@ import type { Organization } from '$lib/stores/organization';
export const load: PageLoad = async ({ url, parent, depends }) => {
const { organizations } = await parent();
depends(Dependencies.CREATE_ORGANIZATION);
depends(Dependencies.ORGANIZATIONS);
const [coupon, paymentMethods] = await Promise.all([
getCoupon(url),
@@ -50,7 +50,7 @@
// fixes an edge case where
// the org is not available for some reason!
await invalidate(Dependencies.CREATE_ORGANIZATION);
await invalidate(Dependencies.ORGANIZATIONS);
}
isLoading = false;
}
@@ -1,6 +1,5 @@
<script lang="ts">
import { Container } from '$lib/layout';
import { organization } from '$lib/stores/organization';
import BudgetCap from './budgetCap.svelte';
import PlanSummary from './planSummary.svelte';
import BillingAddress from './billingAddress.svelte';
@@ -25,14 +24,15 @@
import type { PageData } from './$types';
export let data: PageData;
let organization = data.organization;
// why are these reactive?
$: defaultPaymentMethod = data?.paymentMethods?.paymentMethods?.find(
(method: PaymentMethodData) => method.$id === $organization?.paymentMethodId
(method: PaymentMethodData) => method.$id === organization?.paymentMethodId
);
$: backupPaymentMethod = data?.paymentMethods?.paymentMethods?.find(
(method: PaymentMethodData) => method.$id === $organization?.backupPaymentMethodId
(method: PaymentMethodData) => method.$id === organization?.backupPaymentMethodId
);
onMount(async () => {
@@ -52,10 +52,10 @@
);
await confirmPayment(
$organization.$id,
organization.$id,
invoice.clientSecret,
$organization.paymentMethodId,
`${base}/organization-${$organization.$id}/billing?type=validate-invoice&invoice=${invoice.$id}`
organization.paymentMethodId,
`${base}/organization-${organization.$id}/billing?type=validate-invoice&invoice=${invoice.$id}`
);
}
@@ -64,7 +64,7 @@
page.url.searchParams.get('type') === 'validate-invoice'
) {
const invoiceId = page.url.searchParams.get('invoice');
await sdk.forConsole.billing.updateInvoiceStatus($organization.$id, invoiceId);
await sdk.forConsole.billing.updateInvoiceStatus(organization.$id, invoiceId);
invalidate(Dependencies.INVOICES);
invalidate(Dependencies.ORGANIZATION);
}
@@ -84,7 +84,7 @@
}
if (page.url.searchParams.has('clientSecret')) {
const clientSecret = page.url.searchParams.get('clientSecret');
await confirmPayment($organization.$id, clientSecret, $organization.paymentMethodId);
await confirmPayment(organization.$id, clientSecret, organization.paymentMethodId);
}
});
</script>
@@ -93,7 +93,7 @@
{#if $failedInvoice}
{#if $failedInvoice?.lastError}
<Alert.Inline status="error">
The scheduled payment for {$organization.name} failed due to following error: {$failedInvoice.lastError}
The scheduled payment for {organization.name} failed due to following error: {$failedInvoice.lastError}
<svelte:fragment slot="actions">
<Button
text
@@ -106,7 +106,7 @@
{:else}
<Alert.Inline
status="error"
title={`The scheduled payment for ${$organization.name} failed`}>
title={`The scheduled payment for ${organization.name} failed`}>
To avoid service disruptions in organization's your projects, please verify your
payment details and update them if necessary.
</Alert.Inline>
@@ -115,29 +115,33 @@
{#if defaultPaymentMethod?.failed && !backupPaymentMethod}
<Alert.Inline
status="error"
title={`The default payment method for ${$organization.name} has expired`}>
title={`The default payment method for ${organization.name} has expired`}>
To avoid service disruptions in your organization's projects, please update your payment
details.
</Alert.Inline>
{/if}
{#if $organization?.billingPlanDowngrade}
{#if organization?.billingPlanDowngrade}
<Alert.Inline status="info">
Your organization has changed to {tierToPlan($organization?.billingPlanDowngrade).name} plan.
You will continue to have access to {tierToPlan($organization?.billingPlan).name} plan features
until your billing period ends on {toLocaleDate($organization.billingNextInvoiceDate)}.
Your organization has changed to {tierToPlan(organization?.billingPlanDowngrade).name} plan.
You will continue to have access to {tierToPlan(organization?.billingPlan).name} plan features
until your billing period ends on {toLocaleDate(organization.billingNextInvoiceDate)}.
</Alert.Inline>
{/if}
<Typography.Title>Billing</Typography.Title>
<PlanSummary
availableCredit={data?.availableCredit}
currentPlan={data?.aggregationBillingPlan}
currentPlan={data?.currentPlan}
currentAggregation={data?.billingAggregation}
currentInvoice={data?.billingInvoice} />
<PaymentHistory />
<PaymentMethods methods={data?.paymentMethods} />
<BillingAddress {data} />
<PaymentMethods organization={data?.organization} methods={data?.paymentMethods} />
<BillingAddress
organization={data?.organization}
billingAddress={data?.billingAddress}
locale={data?.locale}
countryList={data?.countryList} />
<TaxId />
<BudgetCap />
<BudgetCap organization={data?.organization} currentPlan={data?.currentPlan} />
<AvailableCredit areCreditsSupported={data.areCreditsSupported} />
</Container>
@@ -7,7 +7,7 @@ import type { PageLoad } from './$types';
import { isCloud } from '$lib/system';
export const load: PageLoad = async ({ parent, depends }) => {
const { organization, scopes, currentPlan, countryList, locale, plansInfo } = await parent();
const { organization, scopes, currentPlan, countryList, locale } = await parent();
if (!scopes.includes('billing.read')) {
return redirect(301, `/console/organization-${organization.$id}`);
@@ -64,10 +64,6 @@ export const load: PageLoad = async ({ parent, depends }) => {
areCreditsSupported ? sdk.forConsole.billing.getAvailableCredit(organization.$id) : null
]);
const aggregationBillingPlan = plansInfo.get(
billingAggregation?.plan ?? organization.billingPlan
);
// make number
const credits = availableCredit ? availableCredit.available : null;
@@ -75,7 +71,6 @@ export const load: PageLoad = async ({ parent, depends }) => {
paymentMethods,
addressList,
billingAddress,
aggregationBillingPlan,
availableCredit: credits,
billingAggregation,
billingInvoice,
@@ -7,7 +7,7 @@
import type { Address } from '$lib/sdk/billing';
import { addressList } from '$lib/stores/billing';
import { addNotification } from '$lib/stores/notifications';
import { organization } from '$lib/stores/organization';
import { type Organization } from '$lib/stores/organization';
import { sdk } from '$lib/stores/sdk';
import RemoveAddress from './removeAddress.svelte';
import { user } from '$lib/stores/user';
@@ -23,14 +23,11 @@
IconTrash
} from '@appwrite.io/pink-icons-svelte';
import type { Models } from '@appwrite.io/console';
import type { PageData } from './$types';
export let data: PageData;
const locale: Models.Locale = data.locale;
const countryList: Models.CountryList = data.countryList;
let billingAddress: Address = data?.billingAddress;
export let organization: Organization;
export let locale: Models.Locale;
export let countryList: Models.CountryList;
export let billingAddress: Address;
let showCreate = false;
let showEdit = false;
@@ -39,16 +36,16 @@
async function addAddress(addressId: string) {
try {
await sdk.forConsole.billing.setBillingAddress($organization.$id, addressId);
await sdk.forConsole.billing.setBillingAddress(organization.$id, addressId);
addNotification({
type: 'success',
message: `A new billing address has been added to ${$organization.name}`
message: `A new billing address has been added to ${organization.name}`
});
trackEvent(Submit.OrganizationBillingAddressUpdate);
invalidate(Dependencies.ADDRESS);
invalidate(Dependencies.ORGANIZATION);
invalidate(Dependencies.ORGANIZATIONS);
} catch (error) {
addNotification({
type: 'error',
@@ -63,7 +60,7 @@
<svelte:fragment slot="title">Billing address</svelte:fragment>
View or update your billing address. This address will be included in your invoices from Appwrite.
<svelte:fragment slot="aside">
{#if $organization?.billingAddressId && billingAddress}
{#if organization?.billingAddressId && billingAddress}
<Card.Base variant="secondary" padding="s">
<Layout.Stack direction="row" justifyContent="space-between">
<div>
@@ -140,7 +137,7 @@
</CardGrid>
{#if showCreate}
<AddressModal bind:show={showCreate} organization={$organization?.$id} {countryList} {locale} />
<AddressModal bind:show={showCreate} organization={organization?.$id} {countryList} {locale} />
{/if}
{#if showEdit}
<EditAddressModal
@@ -7,18 +7,20 @@
import { Button, Form } from '$lib/elements/forms';
import { symmetricDifference } from '$lib/helpers/array';
import { addNotification } from '$lib/stores/notifications';
import { currentPlan, organization } from '$lib/stores/organization';
import { type Organization } from '$lib/stores/organization';
import { sdk } from '$lib/stores/sdk';
import { onMount } from 'svelte';
import { Alert, Icon, Table } from '@appwrite.io/pink-svelte';
import { IconTrash } from '@appwrite.io/pink-icons-svelte';
import InputSelect from '$lib/elements/forms/inputSelect.svelte';
import type { Plan } from '$lib/sdk/billing';
export let organization: Organization;
export let currentPlan: Plan;
export let alertsEnabled = false;
let search: string;
let selectedAlert: number;
let alerts: number[] = [];
let alerts: number[] = organization?.budgetAlerts ?? [];
$: options = [
{ value: 25, label: '25%', disabled: false },
@@ -33,10 +35,6 @@
};
});
onMount(() => {
alerts = $organization?.budgetAlerts ?? [];
});
function addAlert() {
if (alerts.some((alert) => alert === selectedAlert)) {
return;
@@ -50,8 +48,8 @@
async function updateBudget() {
try {
await sdk.forConsole.billing.updateBudget(
$organization.$id,
$organization.billingBudget,
organization.$id,
organization.billingBudget,
alerts
);
@@ -60,7 +58,7 @@
addNotification({
type: 'success',
isHtml: true,
message: `<span> ${alerts.length === 0 ? 'Budget alerts removed from' : alerts.length > 1 ? `Budget alerts added to` : 'A budget alert has been added to'} <b>${$organization.name}</b> </span>`
message: `<span> ${alerts.length === 0 ? 'Budget alerts removed from' : alerts.length > 1 ? `Budget alerts added to` : 'A budget alert has been added to'} <b>${organization.name}</b> </span>`
});
trackEvent(Submit.BudgetAlertsUpdate, {
alerts
@@ -75,26 +73,26 @@
}
$: isButtonDisabled =
symmetricDifference(alerts, $organization.budgetAlerts).length === 0 || !alertsEnabled;
symmetricDifference(alerts, organization.budgetAlerts).length === 0 || !alertsEnabled;
</script>
<CardGrid>
<svelte:fragment slot="title">Billing alerts</svelte:fragment>
{#if !$currentPlan.budgeting}
{#if !currentPlan.budgeting}
Get notified by email when your organization meets a percentage of your budget cap. <b
>{tierToPlan($organization.billingPlan).name} organizations will receive one notification
>{tierToPlan(organization.billingPlan).name} organizations will receive one notification
at 75% resource usage.</b>
{:else}
Get notified by email when your organization meets or exceeds a percentage of your specified
billing alert(s).
{/if}
<svelte:fragment slot="aside">
{#if !$currentPlan.budgeting}
{#if !currentPlan.budgeting}
<Alert.Inline status="info" title="Billing alerts are a Pro plan feature">
Upgrade to a Pro plan to manage when you receive billing alerts for your
organization.
</Alert.Inline>
{:else if !$currentPlan.budgetCapEnabled}
{:else if !currentPlan.budgetCapEnabled}
<Alert.Inline status="info" title="Budget cap disabled">
Budget caps are not supported on your current plan. For more information, please
reach out to your customer success manager.
@@ -150,7 +148,7 @@
<svelte:fragment slot="actions">
<Form onSubmit={updateBudget}>
{#if $organization?.billingPlan === BillingPlan.FREE || $organization?.billingPlan === BillingPlan.GITHUB_EDUCATION}
{#if organization?.billingPlan === BillingPlan.FREE || organization?.billingPlan === BillingPlan.GITHUB_EDUCATION}
<Button
secondary
href={$upgradeURL}
@@ -6,31 +6,28 @@
import { Button, Form, InputNumber, InputSwitch } from '$lib/elements/forms';
import { showUsageRatesModal, upgradeURL } from '$lib/stores/billing';
import { addNotification } from '$lib/stores/notifications';
import { organization, currentPlan } from '$lib/stores/organization';
import { type Organization } from '$lib/stores/organization';
import { sdk } from '$lib/stores/sdk';
import { Alert, Link } from '@appwrite.io/pink-svelte';
import { onMount } from 'svelte';
import BudgetAlert from './budgetAlert.svelte';
import type { Plan } from '$lib/sdk/billing';
let capActive = false;
let budget: number;
onMount(() => {
budget = $organization?.billingBudget;
capActive = $organization?.billingBudget !== null;
});
export let currentPlan: Plan;
export let organization: Organization;
let capActive = organization?.billingBudget !== null;
let budget = organization.billingBudget;
async function updateBudget() {
try {
await sdk.forConsole.billing.updateBudget(
$organization.$id,
organization.$id,
budget,
$organization.budgetAlerts
organization.budgetAlerts
);
await invalidate(Dependencies.ORGANIZATION);
addNotification({
type: 'success',
message: `Budget cap enabled for ${$organization.name}`
message: `Budget cap enabled for ${organization.name}`
});
trackEvent(Submit.BudgetCapUpdate, {
budget: capActive ? budget : undefined
@@ -55,7 +52,7 @@
Restrict your resource usage by setting a budget cap. Cap usage is reset at the beginning of
each billing cycle.
<svelte:fragment slot="aside">
{#if !$currentPlan.budgeting}
{#if !currentPlan.budgeting}
<Alert.Inline status="info" title="Budget caps are a Pro plan feature">
Upgrade to a Pro plan to set a budget cap for your organization. For more
information on what you can do with a Pro plan,
@@ -64,7 +61,7 @@
target="_blank"
rel="noopener noreferrer">view our pricing guide.</Link.Anchor>
</Alert.Inline>
{:else if !$currentPlan.budgetCapEnabled}
{:else if !currentPlan.budgetCapEnabled}
<Alert.Inline status="info" title="Budget cap disabled">
Budget caps are not supported on your current plan. For more information, please
reach out to your customer success manager.
@@ -92,7 +89,7 @@
</svelte:fragment>
<svelte:fragment slot="actions">
{#if $organization?.billingPlan === BillingPlan.FREE}
{#if organization?.billingPlan === BillingPlan.FREE}
<Button
secondary
href={$upgradeURL}
@@ -105,10 +102,10 @@
>Upgrade to Pro
</Button>
{:else}
<Button disabled={$organization?.billingBudget === budget} submit>Update</Button>
<Button disabled={organization?.billingBudget === budget} submit>Update</Button>
{/if}
</svelte:fragment>
</CardGrid>
</Form>
<BudgetAlert alertsEnabled={capActive && budget > 0} />
<BudgetAlert {organization} {currentPlan} alertsEnabled={capActive && budget > 0} />
@@ -5,7 +5,7 @@
import { CardGrid, CreditCardBrandImage, CreditCardInfo } from '$lib/components';
import { BillingPlan, Dependencies } from '$lib/constants';
import { addNotification } from '$lib/stores/notifications';
import { organization } from '$lib/stores/organization';
import { type Organization } from '$lib/stores/organization';
import { Button } from '$lib/elements/forms';
import { hasStripePublicKey, isCloud } from '$lib/system';
import type { PaymentList, PaymentMethodData } from '$lib/sdk/billing';
@@ -34,6 +34,7 @@
IconTrash
} from '@appwrite.io/pink-icons-svelte';
export let organization: Organization;
export let methods: PaymentList;
let showPayment = false;
@@ -47,12 +48,12 @@
async function addPaymentMethod(paymentMethodId: string) {
try {
await sdk.forConsole.billing.setOrganizationPaymentMethod(
$organization.$id,
organization.$id,
paymentMethodId
);
addNotification({
type: 'success',
message: `A new payment method has been added to ${$organization.name}`
message: `A new payment method has been added to ${organization.name}`
});
trackEvent(Submit.OrganizationPaymentUpdate);
invalidate(Dependencies.ORGANIZATION);
@@ -68,12 +69,12 @@
async function addBackupPaymentMethod(paymentMethodId: string) {
try {
await sdk.forConsole.billing.setOrganizationPaymentMethodBackup(
$organization.$id,
organization.$id,
paymentMethodId
);
addNotification({
type: 'success',
message: `A new payment method has been added to ${$organization.name}`
message: `A new payment method has been added to ${organization.name}`
});
invalidate(Dependencies.ORGANIZATION);
} catch (error) {
@@ -85,15 +86,15 @@
}
}
$: if ($organization?.backupPaymentMethodId) {
$: if (organization?.backupPaymentMethodId) {
sdk.forConsole.billing
.getOrganizationPaymentMethod($organization.$id, $organization.backupPaymentMethodId)
.getOrganizationPaymentMethod(organization.$id, organization.backupPaymentMethodId)
.then((res) => (backupPaymentMethod = res));
}
$: if ($organization?.paymentMethodId) {
$: if (organization?.paymentMethodId) {
sdk.forConsole.billing
.getOrganizationPaymentMethod($organization.$id, $organization.paymentMethodId)
.getOrganizationPaymentMethod(organization.$id, organization.paymentMethodId)
.then((res) => (defaultPaymentMethod = res));
}
@@ -112,7 +113,7 @@
<svelte:fragment slot="title">Payment methods</svelte:fragment>
View or update your organization payment methods here.
<svelte:fragment slot="aside">
{#if $organization?.paymentMethodId}
{#if organization?.paymentMethodId}
<Table.Root
let:root
columns={[
@@ -168,7 +169,7 @@
</Popover>
</Table.Cell>
</Table.Row.Base>
{#if $organization?.backupPaymentMethodId}
{#if organization?.backupPaymentMethodId}
<Table.Row.Base {root}>
<CreditCardInfo {root} isBackup paymentMethod={backupPaymentMethod} />
<Table.Cell column="actions" {root}>
@@ -209,9 +210,9 @@
</Table.Row.Base>
{/if}
</Table.Root>
{#if !$organization?.backupPaymentMethodId}
{#if !organization?.backupPaymentMethodId}
{@const filteredPaymentMethods = methods.paymentMethods.filter(
(o) => !!o.last4 && o.$id !== $organization?.paymentMethodId
(o) => !!o.last4 && o.$id !== organization?.paymentMethodId
)}
<div>
<Popover let:toggle placement="bottom-start" padding="none">
@@ -264,7 +265,7 @@
{/if}
{:else}
{@const filteredPaymentMethods = methods.paymentMethods.filter(
(o) => !!o.last4 && o.$id !== $organization?.backupPaymentMethodId
(o) => !!o.last4 && o.$id !== organization?.backupPaymentMethodId
)}
<Card.Base>
<Layout.Stack justifyContent="center" alignItems="center" gap="m">
@@ -319,15 +320,15 @@
bind:show={showEdit} />
{/if}
{#if isCloud && hasStripePublicKey}
<ReplaceCard {methods} bind:show={showReplace} isBackup={isSelectedBackup} />
<ReplaceCard {organization} {methods} bind:show={showReplace} isBackup={isSelectedBackup} />
{/if}
{#if showDelete && isCloud && hasStripePublicKey}
{@const hasOtherMethod = isSelectedBackup
? !!$organization?.paymentMethodId
: !!$organization?.backupPaymentMethodId}
? !!organization?.paymentMethodId
: !!organization?.backupPaymentMethodId}
<DeleteOrgPayment
bind:showDelete
{hasOtherMethod}
isBackup={isSelectedBackup}
disabled={$organization?.billingPlan !== BillingPlan.FREE && !hasOtherMethod} />
disabled={organization?.billingPlan !== BillingPlan.FREE && !hasOtherMethod} />
{/if}
@@ -20,7 +20,7 @@
message: `The billing address has been removed from ${$organization.name}`
});
trackEvent(Submit.OrganizationBillingAddressDelete);
invalidate(Dependencies.ORGANIZATION);
invalidate(Dependencies.ORGANIZATIONS);
show = false;
} catch (e) {
error = e.message;
@@ -3,7 +3,7 @@
import { FakeModal } from '$lib/components';
import { Button } from '$lib/elements/forms';
import { sdk } from '$lib/stores/sdk';
import { organization } from '$lib/stores/organization';
import type { Organization } from '$lib/stores/organization';
import { Dependencies } from '$lib/constants';
import { submitStripeCard } from '$lib/stores/stripe';
import { onMount } from 'svelte';
@@ -12,6 +12,7 @@
import { Submit, trackError, trackEvent } from '$lib/actions/analytics';
import { PaymentBoxes } from '$lib/components/billing';
export let organization: Organization;
export let show = false;
export let isBackup = false;
export let methods: PaymentList;
@@ -21,12 +22,12 @@
let selectedPaymentMethodId: string;
onMount(async () => {
if (!$organization.paymentMethodId && !$organization.backupPaymentMethodId) {
if (!organization.paymentMethodId && !organization.backupPaymentMethodId) {
selectedPaymentMethodId = methods?.total ? methods.paymentMethods[0].$id : null;
} else {
selectedPaymentMethodId = isBackup
? $organization.backupPaymentMethodId
: $organization.paymentMethodId;
? organization.backupPaymentMethodId
: organization.paymentMethodId;
// If the selected payment method does not belong to the current user, select the first one.
if (
methods?.total &&
@@ -40,7 +41,7 @@
async function handleSubmit() {
try {
if (selectedPaymentMethodId === '$new') {
const method = await submitStripeCard(name, $organization.$id);
const method = await submitStripeCard(name, organization.$id);
selectedPaymentMethodId = method.$id;
}
isBackup
@@ -68,7 +69,7 @@
async function addPaymentMethod(paymentMethodId: string) {
try {
await sdk.forConsole.billing.setOrganizationPaymentMethod(
$organization.$id,
organization.$id,
paymentMethodId
);
} catch (e) {
@@ -79,7 +80,7 @@
async function addBackupPaymentMethod(paymentMethodId: string) {
try {
await sdk.forConsole.billing.setOrganizationPaymentMethodBackup(
$organization.$id,
organization.$id,
paymentMethodId
);
} catch (e) {
@@ -97,18 +98,18 @@
methods={filteredMethods}
bind:name
bind:group={selectedPaymentMethodId}
defaultMethod={$organization?.paymentMethodId}
backupMethod={$organization?.backupPaymentMethodId}
defaultMethod={organization?.paymentMethodId}
backupMethod={organization?.backupPaymentMethodId}
disabledCondition={isBackup
? $organization.paymentMethodId
: $organization.backupPaymentMethodId} />
? organization.paymentMethodId
: organization.backupPaymentMethodId} />
<svelte:fragment slot="footer">
<Button text on:click={() => (show = false)}>Cancel</Button>
<Button
secondary
submit
disabled={selectedPaymentMethodId ===
(isBackup ? $organization.backupPaymentMethodId : $organization.paymentMethodId)}>
(isBackup ? organization.backupPaymentMethodId : organization.paymentMethodId)}>
Save
</Button>
</svelte:fragment>
@@ -7,7 +7,13 @@
import { toLocaleDate } from '$lib/helpers/date';
import { isTabSelected } from '$lib/helpers/load';
import { Cover } from '$lib/layout';
import { daysLeftInTrial, getServiceLimit, plansInfo, readOnly } from '$lib/stores/billing';
import {
daysLeftInTrial,
getServiceLimit,
plansInfo,
readOnly,
tierToPlan
} from '$lib/stores/billing';
import { members, newMemberModal, type Organization } from '$lib/stores/organization';
import {
canSeeBilling,
@@ -114,14 +120,25 @@
{/if}
{#if $isOwner}
<Button
secondary
size="s"
on:click={() => newMemberModal.set(true)}
disabled={areMembersLimited}>
<Icon icon={IconPlus} size="s" slot="start" />
Invite
</Button>
<Tooltip disabled={!areMembersLimited} placement="bottom-end">
<div>
<Button
secondary
size="s"
on:click={() => newMemberModal.set(true)}
disabled={areMembersLimited}>
<Icon icon={IconPlus} size="s" slot="start" />
Invite
</Button>
</div>
<div slot="tooltip">
{organization?.billingPlan === BillingPlan.FREE
? 'Upgrade to add more members'
: `You've reached the members limit for the ${
tierToPlan(organization?.billingPlan)?.name
} plan`}
</div>
</Tooltip>
{/if}
</Layout.Stack>
</div>
@@ -31,8 +31,11 @@
Icon,
Typography,
Popover,
ActionMenu
ActionMenu,
Tooltip
} from '@appwrite.io/pink-svelte';
import { BillingPlan } from '$lib/constants';
import { tierToPlan } from '$lib/stores/billing';
export let data;
@@ -41,6 +44,13 @@
let showEdit = false;
let showDropdown = [];
// Calculate if button should be disabled and tooltip should show
$: memberCount = data.organizationMembers?.total ?? 0;
$: isFreeWithMembers = $organization?.billingPlan === BillingPlan.FREE && memberCount >= 1;
$: isButtonDisabled = isCloud
? isFreeWithMembers || !$currentPlan?.addons?.seats?.supported
: false;
const resend = async (member: Models.Membership) => {
try {
await sdk.forConsole.teams.createMembership(
@@ -70,14 +80,25 @@
<Container>
<Layout.Stack direction="row" justifyContent="space-between">
<Typography.Title>Members</Typography.Title>
<ConsoleButton
size="s"
event="create_user"
on:click={() => newMemberModal.set(true)}
disabled={isCloud ? !$currentPlan?.addons?.seats?.supported : false}>
<Icon size="s" icon={IconPlus} slot="start" />
<span class="text">Invite</span>
</ConsoleButton>
<Tooltip disabled={!isButtonDisabled} placement="bottom-end">
<div>
<ConsoleButton
size="s"
event="create_user"
on:click={() => newMemberModal.set(true)}
disabled={isButtonDisabled}>
<Icon size="s" icon={IconPlus} slot="start" />
<span class="text">Invite</span>
</ConsoleButton>
</div>
<div slot="tooltip">
{$organization?.billingPlan === BillingPlan.FREE
? 'Upgrade to add more members'
: `You've reached the members limit for the ${
tierToPlan($organization?.billingPlan)?.name
} plan`}
</div>
</Tooltip>
</Layout.Stack>
<Table.Root
@@ -24,7 +24,6 @@
let name = '';
let id: string = null;
let showCustomId = false;
let showPlanUpgradeAlert = true;
const trackEvents = (policies) => {
policies.forEach((policy) => {
@@ -103,10 +102,6 @@
trackError(error, Submit.DatabaseCreate);
}
};
$: if (!showCreate) {
showPlanUpgradeAlert = true;
}
</script>
<Modal title="Create database" onSubmit={create} bind:show={showCreate}>
@@ -132,18 +127,12 @@
{#if isCloud}
{#if $organization?.billingPlan === BillingPlan.FREE}
{#if showPlanUpgradeAlert}
<Alert.Inline
dismissible
title="This database won't be backed up"
status="warning"
on:dismiss={() => (showPlanUpgradeAlert = false)}>
Upgrade your plan to ensure your data stays safe and backed up.
<svelte:fragment slot="actions">
<Button compact href={$upgradeURL}>Upgrade plan</Button>
</svelte:fragment>
</Alert.Inline>
{/if}
<Alert.Inline title="This database won't be backed up" status="warning">
Upgrade your plan to ensure your data stays safe and backed up.
<svelte:fragment slot="actions">
<Button compact href={$upgradeURL}>Upgrade plan</Button>
</svelte:fragment>
</Alert.Inline>
{:else}
<CreatePolicy
bind:totalPolicies
@@ -34,12 +34,13 @@
const filterColumns = writable<Column[]>([]);
$: selected = preferences.getCustomCollectionColumns(page.params.collection);
$: columns.set(
$collection.attributes.map((attribute) => ({
id: attribute.key,
title: attribute.key,
type: attribute.type as ColumnType,
hide: !selected?.includes(attribute.key),
hide: !!selected?.includes(attribute.key),
array: attribute?.array,
format: 'format' in attribute && attribute?.format === 'enum' ? attribute.format : null,
elements: 'elements' in attribute ? attribute.elements : null
@@ -50,7 +51,7 @@
...['$id', '$createdAt', '$updatedAt'].map((id) => ({
id,
title: id,
hide: false,
show: true,
type: (id === '$id' ? 'string' : 'datetime') as ColumnType
}))
]);
@@ -1,5 +1,5 @@
<script lang="ts">
import { goto, invalidate } from '$app/navigation';
import { goto } from '$app/navigation';
import { base } from '$app/paths';
import { page } from '$app/state';
import { InputChoice } from '$lib/elements/forms';
@@ -7,11 +7,9 @@
import { collection } from '../store';
import type { Attributes } from '../store';
import { sdk } from '$lib/stores/sdk';
import { Dependencies } from '$lib/constants';
import { Submit, trackEvent, trackError } from '$lib/actions/analytics';
import { isRelationship } from '../document-[document]/attributes/store';
import Confirm from '$lib/components/confirm.svelte';
import { preferences } from '$lib/stores/preferences';
export let showDelete = false;
export let selectedAttribute: Attributes;
@@ -20,23 +18,12 @@
let error: string;
let checked = false;
async function updateCollectionColumns() {
const selectedColumns = preferences
.getCustomCollectionColumns($collection.$id)
.filter((attribute) => attribute != selectedAttribute.key);
await preferences.setCustomCollectionColumns($collection.$id, selectedColumns);
await invalidate(Dependencies.COLLECTION);
}
async function handleDelete() {
try {
await sdk
.forProject(page.params.region, page.params.project)
.databases.deleteAttribute(databaseId, $collection.$id, selectedAttribute.key);
await updateCollectionColumns();
showDelete = false;
addNotification({
type: 'success',
@@ -130,7 +130,10 @@
{#if showEncrypt}
<Layout.Stack gap="xs" direction="column">
<div class="popover-holder" class:disabled-checkbox={!supportsStringEncryption || editing}>
<div
class="popover-holder"
class:cursor-not-allowed={editing}
class:disabled-checkbox={!supportsStringEncryption || editing}>
<Layout.Stack inline gap="s" alignItems="flex-start" direction="row">
<Popover let:toggle placement="bottom-start">
<Selector.Checkbox
@@ -142,7 +145,9 @@
<Layout.Stack gap="xxs" direction="column">
<button
type="button"
class="u-cursor-pointer"
disabled={editing}
class:cursor-pointer={!editing}
class:cursor-not-allowed={editing}
on:click={(e) => {
if (!supportsStringEncryption) {
toggle(e);
@@ -158,8 +163,8 @@
</Layout.Stack>
</button>
<Typography.Text color="--fgcolor-neutral-tertiary">
Indicate whether this attribute is encrypted. Encrypted attributes
cannot be queried.
Protect attribute against data leaks for best privacy compliance.
Encrypted attributes cannot be queried.
</Typography.Text>
</Layout.Stack>
@@ -185,7 +190,16 @@
// no cursor when disabled
&.disabled-checkbox :global(button) {
cursor: unset !important;
cursor: unset;
}
}
.cursor-pointer {
// !important is needed
cursor: pointer !important;
}
.cursor-not-allowed {
cursor: not-allowed;
}
</style>
@@ -9,7 +9,6 @@
import { base } from '$app/paths';
import type { Attributes } from './store';
import { Submit, trackEvent, trackError } from '$lib/actions/analytics';
import { preferences } from '$lib/stores/preferences';
export let showCreate = false;
export let selectedOption: Option['name'] = null;
@@ -24,17 +23,10 @@
};
let error: string;
async function updateCollectionColumns() {
const selectedColumns = preferences.getCustomCollectionColumns(collectionId);
selectedColumns.push(key ?? data?.key);
await preferences.setCustomCollectionColumns(collectionId, selectedColumns);
await invalidate(Dependencies.COLLECTION);
}
async function submit() {
try {
await $option.create(databaseId, collectionId, key, data);
await updateCollectionColumns();
await invalidate(Dependencies.COLLECTION);
if (!page.url.pathname.includes('attributes')) {
await goto(
@@ -117,9 +117,29 @@
$: totalCount = relatedList?.length ?? 0;
$: options =
documentList?.documents?.map((n) => {
const data = displayNames.filter((name) => name !== '$id').map((name) => n?.[name]);
return { value: n.$id, label: n.$id, data };
documentList?.documents?.map((document) => {
const names = displayNames.filter((name) => name !== '$id');
const values = names
.map((name) => document?.[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
? document.$id
: // values are in `$id (a | b)` format
// previously used to have a `$id a | b`.
`${document.$id} (${displayValues.join(' | ')})`;
return {
label,
value: document.$id,
data: names.map((name) => document?.[name])
};
}) ?? [];
$: hasItems = totalCount > 0;
@@ -22,15 +22,15 @@
data = null;
selectedRelationship = null;
}
$: tableColumns = [{ id: '$id', width: 200 }, ...args.map((id) => ({ id }))];
</script>
<Modal bind:show title={selectedRelationship?.key} hideFooter>
{#if data?.length}
<Paginator items={data} {limit}>
{#snippet children(paginatedItems: typeof data)}
<Table.Root
let:root
columns={[{ id: '$id', width: 150 }, ...args.map((id) => ({ id }))]}>
<Table.Root let:root columns={tableColumns}>
<svelte:fragment slot="header" let:root>
<Table.Header.Cell column="$id" {root}>Document ID</Table.Header.Cell>
{#if args?.length}
@@ -15,12 +15,24 @@
import { organization } from '$lib/stores/organization';
const collectionId = page.params.collection;
let names: string[] = [...(preferences.getDisplayNames()?.[collectionId] ?? [])];
function getDisplayNames() {
return [...(preferences.getDisplayNames()?.[collectionId] ?? [])].filter(
(name) => name !== '$id'
); // edge case with `$id`? got saved during tests!
}
let names: string[] = $state(getDisplayNames());
async function updateDisplayName() {
try {
await preferences.setDisplayNames($organization.$id, collectionId, names);
names = [...(preferences.getDisplayNames()?.[collectionId] ?? [])];
// $state makes proxy,
// structuredClone doesn't work
const regularArray = [...names];
await preferences.setDisplayNames($organization.$id, collectionId, regularArray);
names = getDisplayNames();
await invalidate(Dependencies.TEAM);
addNotification({
message: 'Display names has been updated',
@@ -36,23 +48,32 @@
}
}
$: options = ($attributes as Models.AttributeString[])
.filter(
(attr) =>
attr.type === 'string' && !attr?.array && !names?.some((name) => name === attr.key)
)
.map((attr) => {
return {
function getValidAttributes() {
return ($attributes as Models.AttributeString[]).filter(
(attr) => attr.type === 'string' && !attr?.array
);
}
function getOptions(index: number) {
const current = names?.[index];
return getValidAttributes()
.filter((attr) => !names?.includes(attr.key) || attr.key === current)
.map((attr) => ({
value: attr.key,
label: attr.key
};
});
}));
}
$: addAttributeDisabled = names?.length >= 5 || (names?.length && !names[names?.length - 1]);
const addAttributeDisabled = $derived(
names?.length >= 5 || (names?.length && !names[names?.length - 1])
);
$: updateBtnDisabled =
const updateBtnDisabled = $derived(
!symmetricDifference(names, preferences.getDisplayNames()?.[collectionId] ?? [])?.length ||
(names?.length && !last(names));
(names?.length && !last(names))
);
const hasExhaustedOptions = $derived(getValidAttributes().length === names?.length);
</script>
<Form onSubmit={updateDisplayName}>
@@ -72,19 +93,22 @@
</span>
</Layout.Stack>
{#if names?.length}
{#each names as name, i}
{#each names as name, index}
<Layout.Stack direction="row" gap="xxs">
{@const options = getOptions(index)}
{@const disabled =
(!!names[index] && names.length > index + 1) || hasExhaustedOptions}
<InputSelect
id={name}
placeholder="Select attribute"
bind:value={names[i]}
disabled={!!names[i] && names.length > i + 1}
{options} />
{options}
{disabled}
bind:value={names[index]}
placeholder="Select attribute" />
<Button
icon
extraCompact
on:click={() => {
names.splice(i, 1);
names.splice(index, 1);
names = names;
}}>
<Icon icon={IconX} />
@@ -92,18 +116,22 @@
</Layout.Stack>
{/each}
{/if}
<div>
<Button
compact
disabled={addAttributeDisabled}
on:click={() => {
names[names.length] = null;
names = names;
}}>
<Icon icon={IconPlus} slot="start" size="s" />
Add attribute
</Button>
</div>
<!-- show only when options don't have all the attributes -->
{#if !hasExhaustedOptions}
<div>
<Button
compact
disabled={addAttributeDisabled}
on:click={() => {
names[names.length] = null;
names = names;
}}>
<Icon icon={IconPlus} slot="start" size="s" />
Add attribute
</Button>
</div>
{/if}
</Layout.Stack>
</svelte:fragment>
@@ -10,7 +10,7 @@
import { preferences } from '$lib/stores/preferences';
import { sdk } from '$lib/stores/sdk';
import type { Models } from '@appwrite.io/console';
import { afterUpdate, onMount } from 'svelte';
import { onMount } from 'svelte';
import type { PageData } from './$types';
import {
isRelationship,
@@ -38,30 +38,16 @@
const databaseId = page.params.database;
const collectionId = page.params.collection;
let displayNames = {};
let showRelationships = false;
let selectedRelationship: Models.AttributeRelationship = null;
let relationshipData: Partial<Models.Document>[];
let displayNames = {};
onMount(async () => {
displayNames = preferences.getDisplayNames();
updateMaxWidth();
});
afterUpdate(() => updateMaxWidth());
function updateMaxWidth() {
const tableCells = Array.from(document.querySelectorAll('.less-width-truncated'));
const visibleColumnsCount = $columns.filter((col) => !col.hide).length;
const newMaxWidth = Math.max(50 - (visibleColumnsCount - 1) * 5, 25);
tableCells.forEach((cell) => {
const cellItem = cell as HTMLElement;
cellItem.style.maxWidth = `${newMaxWidth}vw`;
});
}
function formatArray(array: unknown[]) {
if (array.length === 0) return '[ ]';
@@ -108,7 +94,7 @@
id: attribute.key,
title: attribute.key,
type: attribute.type as ColumnType,
hide: !selected?.includes(attribute.key),
hide: !!selected?.includes(attribute.key),
array: attribute?.array,
width: { min: 168 },
format:
@@ -44,7 +44,7 @@
AngularFrameworkIcon,
JavascriptFrameworkIcon
} from './components/index';
import { hostnameRegex } from '$lib/helpers/string';
import { extendedHostnameRegex } from '$lib/helpers/string';
export let key;
@@ -143,7 +143,7 @@ ${prefix}APPWRITE_ENDPOINT = "${sdk.forProject(page.params.region, page.params.p
$: selectedFrameworkIcon = selectedFramework ? selectedFramework.icon : NoFrameworkIcon;
async function createWebPlatform() {
hostnameError = hostname !== '' ? !new RegExp(hostnameRegex).test(hostname) : null;
hostnameError = hostname !== '' ? !new RegExp(extendedHostnameRegex).test(hostname) : null;
if (hostnameError) {
return;
+1 -1
View File
@@ -16,7 +16,7 @@ export const ssr = false;
export const load: LayoutLoad = async ({ depends, url, route }) => {
depends(Dependencies.ACCOUNT);
depends(Dependencies.CREATE_ORGANIZATION);
depends(Dependencies.ORGANIZATIONS);
const [account, error] = (await sdk.forConsole.account
.get()