From b3460c1b8364995a004875b415f66b88056827cd Mon Sep 17 00:00:00 2001 From: Darshan Date: Thu, 20 Feb 2025 11:09:35 +0530 Subject: [PATCH 1/4] fix: realtime on backups. --- src/lib/helpers/project.ts | 26 ++++++++++++++++++- .../project-[region]-[project]/+layout.svelte | 1 - 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/lib/helpers/project.ts b/src/lib/helpers/project.ts index 91cfc90ac..04bbbcc89 100644 --- a/src/lib/helpers/project.ts +++ b/src/lib/helpers/project.ts @@ -1,6 +1,30 @@ +import { page } from '$app/stores'; +import { get } from 'svelte/store'; + +/** + * Returns the current project ID. + * + * The function first checks for a `project` parameter in the Svelte `$page` store. + * If not found, it extracts the project ID from the pathname. + * + * Supports: + * - Legacy structure: `/project-{projectID}/` + * - Multi-region structure: `/project-{region}-{projectID}/` + * + * Example: + * - `/project-console/` → `console` + * - `/project-fra-console/` → `console` + * - `/project-us-console/` → `console` + */ export function getProjectId() { + // safety check! + const projectFromParams = get(page)?.params?.project; + if (projectFromParams) { + return projectFromParams; + } + const pathname = window.location.pathname + '/'; - const projectMatch = pathname.match(/\/project-(.*?)\//); + const projectMatch = pathname.match(/\/project-(?:[a-z]+-)?(.*?)\//); return projectMatch?.[1] || null; } diff --git a/src/routes/(console)/project-[region]-[project]/+layout.svelte b/src/routes/(console)/project-[region]-[project]/+layout.svelte index 45464ca7c..8e0bdba63 100644 --- a/src/routes/(console)/project-[region]-[project]/+layout.svelte +++ b/src/routes/(console)/project-[region]-[project]/+layout.svelte @@ -28,7 +28,6 @@ return realtime .forProject($page.params.region, $page.params.project) .subscribe(['project', 'console'], (response) => { - console.log(response); if (response.events.includes('stats.connections')) { for (const [projectId, value] of Object.entries(response.payload)) { stats.add(projectId, [new Date(response.timestamp).toISOString(), value]); From cd2825f4e8712bd533bd25a5e9f4acc267838740 Mon Sep 17 00:00:00 2001 From: Darshan Date: Thu, 20 Feb 2025 14:46:27 +0530 Subject: [PATCH 2/4] fix: tests. --- CONTRIBUTING.md | 46 +++++++++---------- README.md | 4 +- src/lib/components/consent.svelte | 2 +- src/lib/components/modalSideCol.svelte | 2 +- src/lib/components/modalWrapper.svelte | 2 +- src/lib/elements/forms/inputDigits.svelte | 2 +- src/lib/helpers/project.ts | 2 +- src/lib/layout/unauthenticated.svelte | 2 +- src/routes/(authenticated)/mfa/+page.svelte | 2 +- src/routes/(console)/account/updateMfa.svelte | 2 +- .../function-[function]/deploymentCard.svelte | 2 +- .../messaging/wizard/pushFormList.svelte | 12 ++--- .../overview/onboard.svelte | 2 +- .../(public)/auth/oauth2/failure/+page.svelte | 2 +- .../(public)/auth/oauth2/success/+page.svelte | 2 +- src/routes/+layout.svelte | 2 +- tests/unit/helpers/project.test.ts | 23 ++++++++++ 17 files changed, 67 insertions(+), 44 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8fcb73389..3d78e77a4 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -108,9 +108,9 @@ pnpm run lint Diagnostic tool that checks for the following: -- Unused CSS -- Svelte A11y hints -- TypeScript compiler errors +- Unused CSS +- Svelte A11y hints +- TypeScript compiler errors ```bash pnpm run check @@ -130,11 +130,11 @@ doc-548-submit-a-pull-request-section-to-contribution-guide When `TYPE` can be: -- **feat** - is a new feature -- **doc** - documentation only changes -- **cicd** - changes related to CI/CD system -- **fix** - a bug fix -- **refactor** - code change that neither fixes a bug nor adds a feature +- **feat** - is a new feature +- **doc** - documentation only changes +- **cicd** - changes related to CI/CD system +- **fix** - a bug fix +- **refactor** - code change that neither fixes a bug nor adds a feature **All PRs must include a commit message with a description of the changes made!** @@ -175,12 +175,12 @@ $ git push origin [name_of_your_new_branch] Before committing always make sure to run all available tools to improve the codebase: -- Formatter - - `pnpm run format` -- Tests - - `pnpm test` -- Diagnostics - - `pnpm run check` +- Formatter + - `pnpm run format` +- Tests + - `pnpm test` +- Diagnostics + - `pnpm run check` ### Performance @@ -188,9 +188,9 @@ Page load times are a key consideration for users of all browsers and device typ There are some general things we can do in front-end development: -- Minimize HTTP requests -- Minimize blocking – content should be readable before client-side processing -- Lazy load "supplementary" content, especially images +- Minimize HTTP requests +- Minimize blocking – content should be readable before client-side processing +- Lazy load "supplementary" content, especially images ### Don't Repeat Yourself (DRY) @@ -202,12 +202,12 @@ If you stick to this principle, you will ensure that you will only ever need to Separate _structure_ from _presentation_ from _behavior_ to aid maintainability and understanding. -- Keep CSS (presentation), JS (behavior) and HTML (structure) in the same respective Svelte component -- Avoid writing inline CSS or Javascript in HTML -- Avoid writing CSS or HTML in Javascript -- Don't choose HTML elements to imply style -- Where appropriate, use CSS or Svelte rather than Javascript for animations and transitions -- Try to use templates when defining markup in Javascript +- Keep CSS (presentation), JS (behavior) and HTML (structure) in the same respective Svelte component +- Avoid writing inline CSS or Javascript in HTML +- Avoid writing CSS or HTML in Javascript +- Don't choose HTML elements to imply style +- Where appropriate, use CSS or Svelte rather than Javascript for animations and transitions +- Try to use templates when defining markup in Javascript ### Write code to be read diff --git a/README.md b/README.md index e37369791..9e113f121 100644 --- a/README.md +++ b/README.md @@ -10,8 +10,8 @@ Appwrite Console has been built with the following frameworks: -- [Svelte](https://svelte.dev/) -- [Svelte Kit](https://kit.svelte.dev/) +- [Svelte](https://svelte.dev/) +- [Svelte Kit](https://kit.svelte.dev/) ## Developer Experience diff --git a/src/lib/components/consent.svelte b/src/lib/components/consent.svelte index 630cd4efb..322a48ca1 100644 --- a/src/lib/components/consent.svelte +++ b/src/lib/components/consent.svelte @@ -122,7 +122,7 @@