Merge branch 'main' into 'spreadsheet'.

This commit is contained in:
Darshan
2025-07-21 14:24:22 +05:30
9 changed files with 52 additions and 33 deletions
@@ -4,10 +4,13 @@ import { sdk } from '$lib/stores/sdk';
import { Query } from '@appwrite.io/console';
import type { PageLoad } from './$types';
import { queries, queryParamToMap } from '$lib/components/filters';
import { buildWildcardAttributesQuery } from './document-[document]/attributes/store';
export const load: PageLoad = async ({ params, depends, url, route }) => {
export const load: PageLoad = async ({ params, depends, url, route, parent }) => {
const { collection } = await parent();
depends(Dependencies.DOCUMENT); /* TODO: we could just invalidate the documents maybe*/
depends(Dependencies.DOCUMENTS);
const page = getPage(url);
// TODO: apply pagination
const limit = getLimit(url, route, 96 /*PAGE_LIMIT*/);
@@ -17,6 +20,7 @@ export const load: PageLoad = async ({ params, depends, url, route }) => {
const paramQueries = url.searchParams.get('query');
const parsedQueries = queryParamToMap(paramQueries || '[]');
queries.set(parsedQueries);
return {
@@ -30,7 +34,8 @@ export const load: PageLoad = async ({ params, depends, url, route }) => {
Query.limit(limit),
Query.offset(offset),
Query.orderDesc(''),
...parsedQueries.values()
...parsedQueries.values(),
...buildWildcardAttributesQuery(collection)
])
};
};
@@ -4,14 +4,20 @@ import type { LayoutLoad } from './$types';
import Breadcrumbs from './breadcrumbs.svelte';
import Header from './header.svelte';
import type { Attributes } from '../store';
import { buildWildcardAttributesQuery } from './attributes/store';
export const load: LayoutLoad = async ({ params, parent, depends }) => {
depends(Dependencies.DOCUMENT);
const { collection } = await parent();
depends(Dependencies.DOCUMENT);
const document = await sdk
.forProject(params.region, params.project)
.databases.getDocument(params.database, params.collection, params.document);
.databases.getDocument(
params.database,
params.collection,
params.document,
buildWildcardAttributesQuery(collection)
);
/**
* Sanitize DateTime to remove UTC Timezone section.
@@ -12,6 +12,7 @@
<InputSelect
{id}
{label}
bind:value
{optionalText}
placeholder="Select a value"
required={attribute.required}
@@ -19,5 +20,4 @@
!attribute.required && { label: 'NULL', value: null },
{ label: 'True', value: true },
{ label: 'False', value: false }
].filter(Boolean)}
bind:value />
].filter(Boolean)} />
@@ -6,14 +6,12 @@
export let label: string;
export let value: string | null;
export let attribute: Models.AttributeUrl;
$: nullable = attribute.required ? false : !value;
</script>
<InputEmail
{id}
{label}
{nullable}
bind:value
placeholder="Enter URL"
required={attribute.required}
bind:value />
nullable={!attribute.required} />
@@ -6,16 +6,14 @@
export let label: string;
export let value: number;
export let attribute: Models.AttributeInteger;
$: nullable = attribute.required ? false : !value;
</script>
<InputNumber
{id}
{label}
{nullable}
required={attribute.required}
bind:value
min={attribute.min}
max={attribute.max}
step={attribute.type === 'double' ? 'any' : 1}
bind:value />
required={attribute.required}
nullable={!attribute.required}
step={attribute.type === 'double' ? 'any' : 1} />
@@ -39,8 +39,6 @@
}
}
documentList = await getDocuments();
if (editing && $doc?.[attribute.key]) {
if ($doc[attribute.key]?.length) {
relatedList =
@@ -59,7 +57,10 @@
});
async function getDocuments(search: string = null) {
const queries = search ? [Query.startsWith('$id', search), Query.orderDesc('')] : [];
const queries = search
? [Query.select(['$id']), Query.startsWith('$id', search), Query.orderDesc('')]
: [Query.select(['$id'])];
return await sdk
.forProject(page.params.region, page.params.project)
.databases.listDocuments(databaseId, attribute.relatedCollection, queries);
@@ -103,7 +104,7 @@
showInput = false;
}
//Reactive statements
// Reactive statements
$: getDocuments(search).then((res) => (documentList = res));
$: paginatedItems = editing
@@ -1,4 +1,4 @@
import type { Models } from '@appwrite.io/console';
import { type Models, Query } from '@appwrite.io/console';
import type { Attributes } from '../../store';
export function isRelationshipToMany(attribute: Models.AttributeRelationship) {
@@ -20,3 +20,18 @@ export function isString(attribute: Attributes): attribute is Models.AttributeSt
if (!attribute) return false;
return attribute?.type === 'string';
}
/**
* Returns select queries for all main and related fields in a collection.
*/
export function buildWildcardAttributesQuery(
collection: Models.Collection | null = null
): string[] {
return [
...(collection?.attributes
?.filter((attr) => isRelationship(attr))
?.map((attr) => Query.select([`${attr.key}.*`])) ?? []),
Query.select(['*'])
];
}
@@ -6,26 +6,24 @@
export let label: string;
export let value: string;
export let attribute: Models.AttributeString;
$: nullable = attribute.required ? false : !value;
</script>
{#if attribute.size >= 50}
<InputTextarea
{id}
{label}
{nullable}
bind:value
placeholder="Enter string"
required={attribute.required}
maxlength={attribute.size}
bind:value />
required={attribute.required}
nullable={!attribute.required} />
{:else}
<InputText
{id}
{label}
{nullable}
bind:value
placeholder="Enter string"
required={attribute.required}
maxlength={attribute.size}
bind:value />
required={attribute.required}
nullable={!attribute.required} />
{/if}
@@ -6,14 +6,12 @@
export let label: string;
export let value: string | null;
export let attribute: Models.AttributeUrl;
$: nullable = attribute.required ? false : !value;
</script>
<InputURL
{id}
{label}
{nullable}
bind:value
placeholder="Enter URL"
required={attribute.required}
bind:value />
nullable={!attribute.required} />