Skip to content

Commit a45c54a

Browse files
Merge pull request #98 from appwrite/fix-realtime
fix: realtime
2 parents 707b43b + a7b557d commit a45c54a

File tree

19 files changed

+215
-121
lines changed

19 files changed

+215
-121
lines changed

src/lib/charts/base.svelte

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,5 +86,6 @@
8686
.echart {
8787
width: 100%;
8888
min-height: 12rem;
89+
height: 100%;
8990
}
9091
</style>

src/lib/constants.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,14 @@ export enum Dependencies {
1515
COLLECTION = 'collection',
1616
DOCUMENT = 'document',
1717
DOCUMENTS = 'documents',
18-
ATTRIBUTES = 'attributes',
19-
INDEXES = 'indexes',
2018
BUCKET = 'bucket',
2119
FILE = 'file',
2220
FILES = 'files',
2321
FUNCTION = 'function',
2422
FUNCTIONS = 'functions',
2523
VARIABLES = 'variables',
2624
DEPLOYMENTS = 'deployments',
25+
EXECUTIONS = 'executions',
2726
PLATFORM = 'platform',
2827
PLATFORMS = 'platforms',
2928
KEY = 'key',

src/lib/layout/usage.svelte

Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -75,59 +75,67 @@
7575
<Heading tag="h6" size="6">{total(created)}</Heading>
7676
<p>{createdMetadata.title}</p>
7777
<div class="u-margin-block-start-16" />
78-
<LineChart
79-
series={[
80-
{
81-
name: createdMetadata.legend,
82-
data: [...created.map((e) => [e.date, e.value])],
83-
color: Colors.Secondary
84-
}
85-
]} />
78+
<div style="height: 12rem;">
79+
<LineChart
80+
series={[
81+
{
82+
name: createdMetadata.legend,
83+
data: [...created.map((e) => [e.date, e.value])],
84+
color: Colors.Secondary
85+
}
86+
]} />
87+
</div>
8688
{/if}
8789
</Card>
8890
<Card isTile>
8991
{#if read}
9092
<Heading tag="h6" size="6">{total(read)}</Heading>
9193
<p>{readMetadata.title}</p>
9294
<div class="u-margin-block-start-16" />
93-
<LineChart
94-
series={[
95-
{
96-
name: readMetadata.legend,
97-
data: [...read.map((e) => [e.date, e.value])],
98-
color: Colors.Tertiary
99-
}
100-
]} />
95+
<div style="height: 12rem;">
96+
<LineChart
97+
series={[
98+
{
99+
name: readMetadata.legend,
100+
data: [...read.map((e) => [e.date, e.value])],
101+
color: Colors.Tertiary
102+
}
103+
]} />
104+
</div>
101105
{/if}
102106
</Card>
103107
<Card isTile>
104108
{#if updated}
105109
<Heading tag="h6" size="6">{total(updated)}</Heading>
106110
<p>{updatedMetadata.title}</p>
107111
<div class="u-margin-block-start-16" />
108-
<LineChart
109-
series={[
110-
{
111-
name: updatedMetadata.legend,
112-
data: [...updated.map((e) => [e.date, e.value])],
113-
color: Colors.Quaternary
114-
}
115-
]} />
112+
<div style="height: 12rem;">
113+
<LineChart
114+
series={[
115+
{
116+
name: updatedMetadata.legend,
117+
data: [...updated.map((e) => [e.date, e.value])],
118+
color: Colors.Quaternary
119+
}
120+
]} />
121+
</div>
116122
{/if}
117123
</Card>
118124
<Card isTile>
119125
{#if deleted}
120126
<Heading tag="h6" size="6">{total(deleted)}</Heading>
121127
<p>{deletedMetadata.title}</p>
122128
<div class="u-margin-block-start-16" />
123-
<LineChart
124-
series={[
125-
{
126-
name: deletedMetadata.legend,
127-
data: [...deleted.map((e) => [e.date, e.value])],
128-
color: Colors.Quinary
129-
}
130-
]} />
129+
<div style="height: 12rem;">
130+
<LineChart
131+
series={[
132+
{
133+
name: deletedMetadata.legend,
134+
data: [...deleted.map((e) => [e.date, e.value])],
135+
color: Colors.Quinary
136+
}
137+
]} />
138+
</div>
131139
{/if}
132140
</Card>
133141
</Tiles>

src/routes/console/project-[project]/+layout.svelte

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,26 @@
11
<script lang="ts">
22
import { UploadBox } from '$lib/components';
3+
import { sdkForConsole } from '$lib/stores/sdk';
4+
import { onDestroy, onMount } from 'svelte';
5+
import { stats } from './store';
6+
7+
let unsubscribe: { (): void };
8+
9+
onMount(() => {
10+
unsubscribe = sdkForConsole.client.subscribe(['project', 'console'], (response) => {
11+
if (response.events.includes('stats.connections')) {
12+
for (const [projectId, value] of Object.entries(response.payload)) {
13+
stats.add(projectId, [new Date(response.timestamp).toISOString(), value]);
14+
}
15+
}
16+
});
17+
});
18+
19+
onDestroy(() => {
20+
if (unsubscribe) {
21+
unsubscribe();
22+
}
23+
});
324
</script>
425

526
<slot />

src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/+layout.svelte

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,28 @@
11
<script lang="ts">
2+
import { invalidate } from '$app/navigation';
3+
import { Dependencies } from '$lib/constants';
4+
import { sdkForConsole } from '$lib/stores/sdk';
5+
import { onDestroy, onMount } from 'svelte';
26
import { collection } from './store';
7+
8+
let unsubscribe: { (): void };
9+
10+
onMount(() => {
11+
unsubscribe = sdkForConsole.client.subscribe('console', (response) => {
12+
if (
13+
response.events.includes('databases.*.collections.*.attributes.*') ||
14+
response.events.includes('databases.*.collections.*.indexes.*')
15+
) {
16+
invalidate(Dependencies.COLLECTION);
17+
}
18+
});
19+
});
20+
21+
onDestroy(() => {
22+
if (unsubscribe) {
23+
unsubscribe();
24+
}
25+
});
326
</script>
427

528
<svelte:head>

src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/+layout.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import Header from './header.svelte';
66
import { error } from '@sveltejs/kit';
77

88
export const load: LayoutLoad = async ({ params, parent, depends }) => {
9-
await parent();
109
depends(Dependencies.COLLECTION);
10+
await parent();
1111

1212
try {
1313
return {

src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/attributes/+page.svelte

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,13 @@
1010
} from '$lib/elements/table';
1111
import { Button } from '$lib/elements/forms';
1212
import { DropList, DropListItem, Empty, Heading } from '$lib/components';
13-
import type { Attributes } from '../store';
13+
import { attributes, type Attributes } from '../store';
1414
import { Container } from '$lib/layout';
1515
import { Pill } from '$lib/elements';
1616
import Create from './createAttribute.svelte';
1717
import CreateIndex from '../indexes/createIndex.svelte';
1818
import Delete from './deleteAttribute.svelte';
1919
import Overview from './overview.svelte';
20-
import type { PageData } from './$types';
21-
22-
export let data: PageData;
2320
2421
let showDropdown = [];
2522
let selectedAttribute: Attributes = null;
@@ -39,7 +36,7 @@
3936
</Button>
4037
</div>
4138

42-
{#if data.attributes.total}
39+
{#if $attributes.length}
4340
<Table>
4441
<TableHeader>
4542
<TableCellHead>Key</TableCellHead>
@@ -48,7 +45,7 @@
4845
<TableCellHead width={30} />
4946
</TableHeader>
5047
<TableBody>
51-
{#each data.attributes.attributes as attribute, index}
48+
{#each $attributes as attribute, index}
5249
<TableRow>
5350
<TableCell title="Key">
5451
<div class="u-flex u-main-space-between">
@@ -110,7 +107,7 @@
110107
</TableBody>
111108
</Table>
112109
<div class="u-flex common-section u-main-space-between">
113-
<p class="text">Total results: {data.attributes.total}</p>
110+
<p class="text">Total results: {$attributes.length}</p>
114111
</div>
115112
{:else}
116113
<Empty isButton single on:click={() => (showCreate = true)}>

src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/attributes/+page.ts

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/attributes/createAttribute.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
let submitted = false;
1313
1414
const created = async () => {
15-
invalidate(Dependencies.ATTRIBUTES);
15+
invalidate(Dependencies.COLLECTION);
1616
showCreate = false;
1717
};
1818

src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/attributes/deleteAttribute.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
$collection.$id,
2222
selectedAttribute.key
2323
);
24-
invalidate(Dependencies.ATTRIBUTES);
24+
invalidate(Dependencies.COLLECTION);
2525
showDelete = false;
2626
await goto(
2727
`${base}/console/project-${$page.params.project}/databases/database-${databaseId}/collection-${$page.params.collection}/attributes`

0 commit comments

Comments
 (0)