diff --git a/src/lib/elements/forms/Seekbar.svelte b/src/lib/elements/forms/Seekbar.svelte new file mode 100644 index 000000000..7fa184e8e --- /dev/null +++ b/src/lib/elements/forms/Seekbar.svelte @@ -0,0 +1,315 @@ + + +
+ + + {#if exactBreakpoints().length > 0} +
+ {#each exactBreakpoints() as breakPoint, index (index)} + {@const breakPercentage = ((breakPoint - min) / range) * 100} +
+
+ {/each} +
+ {/if} +
+ + diff --git a/src/lib/helpers/faker.ts b/src/lib/helpers/faker.ts new file mode 100644 index 000000000..33d624a0b --- /dev/null +++ b/src/lib/helpers/faker.ts @@ -0,0 +1,135 @@ +import { faker } from '@faker-js/faker'; +import type { Attributes } from '$routes/(console)/project-[region]-[project]/databases/database-[database]/collection-[collection]/store'; +import type { Models } from '@appwrite.io/console'; +import { sdk } from '$lib/stores/sdk'; + +export async function generateAttributes( + project: Models.Project, + databaseId: string, + collectionId: string +): Promise { + const client = sdk.forProject(project.region, project.$id); + + return await Promise.all([ + client.databases.createStringAttribute(databaseId, collectionId, 'name', 255, false), + client.databases.createEmailAttribute(databaseId, collectionId, 'email', false), + client.databases.createIntegerAttribute(databaseId, collectionId, 'age', false, 0, 150), + client.databases.createStringAttribute(databaseId, collectionId, 'city', 100, false), + client.databases.createStringAttribute( + databaseId, + collectionId, + 'description', + 1000, + false + ), + client.databases.createBooleanAttribute(databaseId, collectionId, 'active', false) + ]); +} + +export function generateFakeDocuments(columns: Attributes[], count: number): object[] { + if (count <= 0) return []; + + const filteredColumns = columns.filter((col) => col.type !== 'relationship'); + + if (filteredColumns.length === 0) { + return Array.from({ length: count }, () => ({ + name: faker.person.fullName(), + email: faker.internet.email(), + age: faker.number.int({ min: 18, max: 80 }), + city: faker.location.city(), + description: faker.lorem.sentence(), + active: faker.datatype.boolean() + })); + } + + return Array.from({ length: count }, () => { + const document: object = {}; + + for (const column of filteredColumns) { + document[column.key] = generateValueForAttribute(column); + } + + return document; + }); +} + +function generateStringValue(key: string, maxLength: number): string { + const lowerKey = key.toLowerCase(); + + const generators: Record string> = { + name: () => faker.person.fullName(), + email: () => faker.internet.email(), + title: () => faker.lorem.words({ min: 1, max: 3 }), + description: () => faker.lorem.paragraph(), + content: () => faker.lorem.paragraph(), + address: () => faker.location.streetAddress(), + city: () => faker.location.city(), + country: () => faker.location.country(), + company: () => faker.company.name() + }; + + const matchingKey = Object.keys(generators).find((pattern) => lowerKey.includes(pattern)); + + const text = matchingKey ? generators[matchingKey]() : faker.lorem.words({ min: 1, max: 5 }); + + return text.length <= maxLength ? text : text.substring(0, maxLength); +} + +function generateValueForAttribute(attribute: Attributes): string | number | boolean | null { + switch (attribute.type) { + case 'string': { + const stringAttr = attribute as Models.AttributeString; + const maxLength = Math.min(stringAttr.size ?? 255, 1000); + return generateStringValue(attribute.key, maxLength); + } + + case 'integer': { + const intAttr = attribute as Models.AttributeInteger; + const min = intAttr.min ?? 0; + const max = intAttr.max ?? 1000000; + return faker.number.int({ min, max }); + } + + case 'float': { + const floatAttr = attribute as Models.AttributeFloat; + const min = floatAttr.min ?? 0; + const max = floatAttr.max ?? 1000000; + const precision = 2; + return parseFloat( + faker.number.float({ min, max, fractionDigits: precision }).toFixed(precision) + ); + } + + case 'boolean': { + return faker.datatype.boolean(); + } + + case 'datetime': { + return faker.date.recent({ days: 365 }).toISOString(); + } + + case 'email': { + return faker.internet.email(); + } + + case 'ip': { + return faker.internet.ip(); + } + + case 'url': { + return faker.internet.url(); + } + + case 'enum': { + const enumAttr = attribute as Models.AttributeEnum; + if (enumAttr.elements && enumAttr.elements.length > 0) { + return faker.helpers.arrayElement(enumAttr.elements); + } + return null; + } + + default: { + return faker.lorem.word(); + } + } +} diff --git a/src/routes/(console)/project-[region]-[project]/databases/database-[database]/collection-[collection]/layout/emptySheet.svelte b/src/routes/(console)/project-[region]-[project]/databases/database-[database]/collection-[collection]/layout/emptySheet.svelte index d72b92730..dfe3d7a5b 100644 --- a/src/routes/(console)/project-[region]-[project]/databases/database-[database]/collection-[collection]/layout/emptySheet.svelte +++ b/src/routes/(console)/project-[region]-[project]/databases/database-[database]/collection-[collection]/layout/emptySheet.svelte @@ -5,7 +5,6 @@ Icon, Layout, Spreadsheet, - Tooltip, Typography } from '@appwrite.io/pink-svelte';