Skip to content

Commit

Permalink
fix: region calls and realtime connections
Browse files Browse the repository at this point in the history
  • Loading branch information
TorstenDittmann committed Feb 13, 2025
1 parent 2cc527e commit 81516f9
Show file tree
Hide file tree
Showing 17 changed files with 67 additions and 66 deletions.
46 changes: 23 additions & 23 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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!**

Expand Down Expand Up @@ -175,22 +175,22 @@ $ 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

Page load times are a key consideration for users of all browsers and device types.

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)

Expand All @@ -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

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions src/lib/components/backupRestoreBox.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts">
import { sdk } from '$lib/stores/sdk';
import { realtime } from '$lib/stores/sdk';
import { type Payload } from '@appwrite.io/console';
import { onMount } from 'svelte';
import { isCloud, isSelfHosted } from '$lib/system';
Expand Down Expand Up @@ -125,9 +125,9 @@
// fast path: don't subscribe if org is on a free plan or is self-hosted.
if (isSelfHosted || (isCloud && $organization.billingPlan === BillingPlan.FREE)) return;
return sdk
return realtime
.forProject($page.params.region, $page.params.project)
.client.subscribe('console', (response) => {
.subscribe('console', (response) => {
if (!response.channels.includes(`projects.${getProjectId()}`)) return;
if (
Expand Down
6 changes: 3 additions & 3 deletions src/lib/components/migrationBox.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { page } from '$app/stores';
import { parseIfString } from '$lib/helpers/object';
import { getProjectId } from '$lib/helpers/project';
import { sdk } from '$lib/stores/sdk';
import { realtime } from '$lib/stores/sdk';
import type { Models } from '@appwrite.io/console';
import { onMount } from 'svelte';
import { writable } from 'svelte/store';
Expand Down Expand Up @@ -50,9 +50,9 @@
})();
onMount(() => {
return sdk
return realtime
.forProject($page.params.region, $page.params.project)
.client.subscribe<Models.Migration>(['console'], async (response) => {
.subscribe<Models.Migration>(['console'], async (response) => {
if (!response.channels.includes(`projects.${getProjectId()}`)) return;
if (response.events.includes('migrations.*')) {
if (response.payload.source === 'Backup') return;
Expand Down
6 changes: 3 additions & 3 deletions src/lib/pages/domains/create.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
import Step1 from './wizard/step1.svelte';
import Step2 from './wizard/step2.svelte';
import { onMount } from 'svelte';
import { sdk } from '$lib/stores/sdk';
import type { Models } from '@appwrite.io/console';
import { page } from '$app/stores';
import { realtime } from '$lib/stores/sdk';
onMount(() => {
domain.set({ $id: '', domain: '' });
return sdk
return realtime
.forProject($page.params.region, $page.params.region)
.client.subscribe<Models.ProxyRule>('console', (data) => domain.set(data.payload));
.subscribe<Models.ProxyRule>('console', (data) => domain.set(data.payload));
});
async function onFinish() {
Expand Down
6 changes: 4 additions & 2 deletions src/lib/sdk/billing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1098,9 +1098,11 @@ export class Billing {
);
}

async listRegions(): Promise<RegionList> {
async listRegions(teamId: string): Promise<RegionList> {
const path = `/console/regions`;
const params = {};
const params = {
teamId
};
const uri = new URL(this.client.config.endpoint + path);
return await this.client.call(
'GET',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
let regions: RegionList;
onMount(async () => {
if (isCloud) {
regions = await sdk.forConsole.billing.listRegions();
regions = await sdk.forConsole.billing.listRegions($page.params.organization);
checkPricingRefAndRedirect($page.url.searchParams);
}
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script lang="ts">
import { page } from '$app/stores';
import { CustomId } from '$lib/components';
import { Pill } from '$lib/elements';
import { InputText, FormList } from '$lib/elements/forms';
Expand All @@ -8,7 +9,7 @@
let showCustomId = false;
sdk.forConsole.billing.listRegions().then(regions.set);
sdk.forConsole.billing.listRegions($page.params.organization).then(regions.set);
</script>

<WizardStep>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts">
import { BackupRestoreBox, MigrationBox, UploadBox } from '$lib/components';
import { realtime, sdk } from '$lib/stores/sdk';
import { realtime } from '$lib/stores/sdk';
import { onMount } from 'svelte';
import { project, stats } from './store';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import CreatePolicy from './createPolicy.svelte';
import { Button } from '$lib/elements/forms';
import { addNotification, dismissAllNotifications } from '$lib/stores/notifications';
import { sdk } from '$lib/stores/sdk';
import { realtime, sdk } from '$lib/stores/sdk';
import { invalidate } from '$app/navigation';
import { Dependencies } from '$lib/constants';
import { isCloud, isSelfHosted } from '$lib/system';
Expand Down Expand Up @@ -159,9 +159,9 @@
};
onMount(() => {
return sdk
return realtime
.forProject($page.params.region, $page.params.project)
.client.subscribe(['project', 'console'], (response) => {
.subscribe(['project', 'console'], (response) => {
// fast path return.
if (!response.channels.includes(`projects.${getProjectId()}`)) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<script lang="ts">
import { goto, invalidate } from '$app/navigation';
import { Dependencies } from '$lib/constants';
import { sdk } from '$lib/stores/sdk';
import { realtime } from '$lib/stores/sdk';
import { onMount } from 'svelte';
import { collection } from './store';
import { addSubPanel, registerCommands, updateCommandGroupRanks } from '$lib/commandCenter';
Expand All @@ -35,9 +35,9 @@
import { canWriteCollections } from '$lib/stores/roles';
onMount(() => {
return sdk
return realtime
.forProject($page.params.region, $page.params.project)
.client.subscribe(['project', 'console'], (response) => {
.subscribe(['project', 'console'], (response) => {
if (
response.events.includes('databases.*.collections.*.attributes.*') ||
response.events.includes('databases.*.collections.*.indexes.*')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts">
import { onMount } from 'svelte';
import { page } from '$app/stores';
import { sdk } from '$lib/stores/sdk';
import { realtime } from '$lib/stores/sdk';
import { Dependencies } from '$lib/constants';
import { invalidate, goto } from '$app/navigation';
import { registerCommands } from '$lib/commandCenter';
Expand All @@ -13,9 +13,9 @@
onMount(() => {
let previousStatus = null;
return sdk
return realtime
.forProject($page.params.region, $page.params.project)
.client.subscribe<Models.Deployment>('console', (message) => {
.subscribe<Models.Deployment>('console', (message) => {
if (previousStatus === message.payload.status) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { Button } from '$lib/elements/forms';
import { Container } from '$lib/layout';
import { func } from '../store';
import { sdk } from '$lib/stores/sdk';
import { realtime, sdk } from '$lib/stores/sdk';
import { onMount } from 'svelte';
import type { Models } from '@appwrite.io/console';
import { page } from '$app/stores';
Expand Down Expand Up @@ -56,9 +56,9 @@
return;
}
const unsubscribe = sdk
const unsubscribe = realtime
.forProject($page.params.region, $page.params.project)
.client.subscribe<Models.Deployment>('console', (message) => {
.subscribe<Models.Deployment>('console', (message) => {
if (
message.events.includes(
`functions.${$page.params.function}.deployments.${$page.params.deployment}.update`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
<script lang="ts">
import { invalidate } from '$app/navigation';
import { Alert, EmptySearch, PaginationWithLimit, ViewSelector } from '$lib/components';
import { BillingPlan, Dependencies } from '$lib/constants';
import { BillingPlan } from '$lib/constants';
import { Button } from '$lib/elements/forms';
import { hoursToDays } from '$lib/helpers/date';
import { Container, ContainerHeader } from '$lib/layout';
import { realtime, sdk } from '$lib/stores/sdk';
import { onMount } from 'svelte';
import { func } from '../store';
import { organization } from '$lib/stores/organization';
Expand All @@ -22,7 +20,6 @@
import QuickFilters from './quickFilters.svelte';
import { Pill } from '$lib/elements';
import { tags } from '$lib/components/filters/store';
import { page } from '$app/stores';
export let data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,9 @@
id={`${rowIndex}-key`}
isMultiple
fullWidth
bind:value={
$messageParams[MessagingProviderType.Push].data[rowIndex][0]
}
bind:value={$messageParams[MessagingProviderType.Push].data[
rowIndex
][0]}
placeholder="Enter key"
label="Key"
showLabel={false} />
Expand All @@ -184,9 +184,9 @@
id={`${rowIndex}-value`}
isMultiple
fullWidth
bind:value={
$messageParams[MessagingProviderType.Push].data[rowIndex][1]
}
bind:value={$messageParams[MessagingProviderType.Push].data[
rowIndex
][1]}
placeholder="Enter value"
label="Value"
showLabel={false}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@
import { onMount } from 'svelte';
import { project } from '../store';
import type { RegionList } from '$lib/sdk/billing';
import { page } from '$app/stores';
let showDelete = false;
let name: string = null;
let regions: RegionList;
onMount(async () => {
if (isCloud) {
regions = await sdk.forConsole.billing.listRegions();
regions = await sdk.forConsole.billing.listRegions($page.params.organization);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import Table from '$lib/elements/table/table.svelte';
import { isSameDay, toLocaleDate } from '$lib/helpers/date';
import { Container } from '$lib/layout';
import { sdk } from '$lib/stores/sdk';
import { realtime, sdk } from '$lib/stores/sdk';
import { GRACE_PERIOD_OVERRIDE, isSelfHosted } from '$lib/system';
import { onMount } from 'svelte';
import { project } from '../../store';
Expand Down Expand Up @@ -46,9 +46,9 @@
};
onMount(() => {
return sdk
return realtime
.forProject($page.params.region, $page.params.project)
.client.subscribe(['project', 'console'], (response) => {
.subscribe(['project', 'console'], (response) => {
if (response.events.includes('migrations.*')) {
invalidate(Dependencies.MIGRATIONS);
}
Expand Down

0 comments on commit 81516f9

Please sign in to comment.