Merge pull request #28 from appwrite/feat-improve-layout-stores

feat: improve layout stores
This commit is contained in:
Torsten Dittmann authored and GitHub committed 2022-07-19 16:22:27 +02:00
commit 9b74fb9a6d
18 files changed
+1462 -1372

No files matched your search

+1 -1
View File
@@ -19,7 +19,7 @@ jobs:
with:
node-version: 16
- name: Audit dependencies
run: npm audit --audit-level low
run: npm audit --audit-level high
- name: Install dependencies
run: npm ci
- name: Build Console
+1166 -1062
View File
File diff suppressed because it is too large. Load diff
+13 -13
View File
@@ -2,7 +2,7 @@
"name": "@appwrite/console",
"version": "0.0.1",
"engines": {
"node": ">=14"
"node": ">=16"
},
"scripts": {
"dev": "vite dev",
@@ -24,22 +24,22 @@
"echarts": "^5.3.3"
},
"devDependencies": {
"@playwright/test": "^1.23.2",
"@sveltejs/adapter-auto": "1.0.0-next.55",
"@sveltejs/kit": "1.0.0-next.367",
"@sveltejs/vite-plugin-svelte": "^1.0.0-next.49",
"@playwright/test": "^1.23.4",
"@sveltejs/adapter-auto": "1.0.0-next.62",
"@sveltejs/kit": "1.0.0-next.379",
"@sveltejs/vite-plugin-svelte": "^1.0.1",
"@testing-library/dom": "^8.16.0",
"@testing-library/jest-dom": "^5.16.4",
"@testing-library/svelte": "^3.1.3",
"@testing-library/user-event": "^14.2.1",
"@testing-library/user-event": "^14.3.0",
"@types/gtag.js": "^0.0.10",
"@typescript-eslint/eslint-plugin": "^5.30.5",
"@typescript-eslint/parser": "^5.30.5",
"eslint": "^8.19.0",
"@typescript-eslint/eslint-plugin": "^5.30.7",
"@typescript-eslint/parser": "^5.30.7",
"eslint": "^8.20.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-svelte3": "^4.0.0",
"jest": "^28.1.2",
"jest-environment-jsdom": "^28.1.2",
"jest": "^28.1.3",
"jest-environment-jsdom": "^28.1.3",
"pre-commit": "^1.2.2",
"prettier": "^2.7.1",
"prettier-plugin-svelte": "^2.7.0",
@@ -48,10 +48,10 @@
"svelte-check": "^2.8.0",
"svelte-jester": "^2.3.2",
"svelte-preprocess": "^4.10.7",
"ts-jest": "^28.0.5",
"ts-jest": "^28.0.7",
"tslib": "^2.4.0",
"typescript": "^4.7.4",
"vite": "^2.9.14"
"vite": "^3.0.0"
},
"type": "module",
"jest": {
+31 -1
View File
@@ -1,4 +1,5 @@
import { writable } from 'svelte/store';
import { project } from '../../routes/console/[project]/store';
import { get, writable } from 'svelte/store';
export type Tab = {
href: string;
@@ -12,3 +13,32 @@ export const copyData = writable({
value: ''
});
export const tabs = writable<Tab[]>([]);
export function updateLayout(args: {
title: string;
tabs?: Tab[];
back?: string;
copy?: {
text: string;
value: string;
};
navigate?: {
from: URL | null;
to: URL;
};
}) {
const projectId = get(project)?.$id;
const base = projectId ? `/console/${projectId}` : `/console`;
if (args?.navigate?.to) {
const oldTabs = get(tabs);
if (oldTabs.some((t) => `${base}/${t.href}` === args.navigate.to.pathname)) {
return;
}
}
title.set(args.title);
backButton.set(args.back ?? null);
copyData.set(args.copy ?? null);
tabs.set(args.tabs ?? []);
}
@@ -1,20 +1,19 @@
<script>
import { afterNavigate } from '$app/navigation';
import { tabs, title, backButton, copyData } from '$lib/stores/layout';
import { updateLayout } from '$lib/stores/layout';
import { onMount } from 'svelte';
onMount(handle);
afterNavigate(handle);
function handle() {
title.set('Databases');
backButton.set('');
tabs.set([]);
let loaded = false;
copyData.set({
text: '',
value: ''
function handle(event = null) {
updateLayout({
navigate: event,
title: 'Databases'
});
loaded = true;
}
</script>
@@ -22,4 +21,6 @@
<title>Appwrite - Databases</title>
</svelte:head>
<slot />
{#if loaded}
<slot />
{/if}
@@ -1,44 +1,38 @@
<script>
import { afterNavigate } from '$app/navigation';
import { page } from '$app/stores';
import { tabs, title, backButton, copyData } from '$lib/stores/layout';
import { updateLayout } from '$lib/stores/layout';
import { setDatabase } from '$lib/stores/sdk';
import { onMount } from 'svelte';
import { database } from './store';
const databaseId = $page.params.database;
const path = `databases/database/${databaseId}`;
onMount(handle);
afterNavigate(handle);
async function handle() {
async function handle(event = null) {
if ($database?.$id !== databaseId) {
setDatabase($page.params.database);
await database.load();
title.set(`Database - ${$database.name}`);
} else if ($database) {
title.set(`Database - ${$database.name}`);
}
backButton.set('');
copyData.set({
text: '',
value: ''
updateLayout({
navigate: event,
title: $database.name,
tabs: [
{
href: path,
title: 'Collections'
},
{
href: `${path}/usage`,
title: 'Usage'
}
]
});
tabs.set([
{
href: path,
title: 'Collections'
},
{
href: `${path}/usage`,
title: 'Usage'
}
]);
}
</script>
@@ -2,7 +2,7 @@
import { afterNavigate } from '$app/navigation';
import { base } from '$app/paths';
import { page } from '$app/stores';
import { tabs, title, backButton, copyData } from '$lib/stores/layout';
import { updateLayout } from '$lib/stores/layout';
import { onMount } from 'svelte';
import { collection } from './store';
@@ -14,39 +14,34 @@
onMount(handle);
afterNavigate(handle);
async function handle() {
async function handle(event = null) {
if ($collection?.$id !== collectionId) {
await collection.load(collectionId);
title.set($collection.name);
} else if ($collection) {
title.set($collection.name);
}
backButton.set(`${base}/console/${$page.params.project}/database`);
copyData.set({
text: '',
value: ''
updateLayout({
navigate: event,
title: $collection.name,
back: `${base}/console/${$page.params.project}/database`,
tabs: [
{
href: path,
title: 'Documents'
},
{
href: `${path}/attributes`,
title: 'Attributes'
},
{
href: `${path}/indexes`,
title: 'Indexes'
},
{
href: `${path}/settings`,
title: 'Settings'
}
]
});
tabs.set([
{
href: path,
title: 'Documents'
},
{
href: `${path}/attributes`,
title: 'Attributes'
},
{
href: `${path}/indexes`,
title: 'Indexes'
},
{
href: `${path}/settings`,
title: 'Settings'
}
]);
}
</script>
@@ -1,6 +1,6 @@
<script lang="ts">
import { page } from '$app/stores';
import { tabs, title, backButton, copyData } from '$lib/stores/layout';
import { updateLayout } from '$lib/stores/layout';
import { doc } from './store';
import { onMount } from 'svelte';
import { afterNavigate } from '$app/navigation';
@@ -13,31 +13,24 @@
onMount(handle);
afterNavigate(handle);
async function handle() {
async function handle(event = null) {
if ($doc?.$id !== documentId) {
await doc.load(collectionId, documentId);
title.set(`Document - ${$doc.$id}`);
} else if ($doc) {
title.set(`Document - ${$doc.$id}`);
}
backButton.set('');
copyData.set({
text: '',
value: ''
updateLayout({
navigate: event,
title: `Document - ${$doc.$id}`,
tabs: [
{
href: path,
title: 'Overview'
},
{
href: `${path}/activity`,
title: 'Activity'
}
]
});
tabs.set([
{
href: path,
title: 'Overview'
},
{
href: `${path}/activity`,
title: 'Activity'
}
]);
}
</script>
@@ -45,4 +38,6 @@
<title>Appwrite - Database Document</title>
</svelte:head>
<slot />
{#if $doc}
<slot />
{/if}
@@ -1,20 +1,15 @@
<script>
import { afterNavigate } from '$app/navigation';
import { tabs, title, backButton, copyData } from '$lib/stores/layout';
import { updateLayout } from '$lib/stores/layout';
import { onMount } from 'svelte';
onMount(handle);
afterNavigate(handle);
function handle() {
title.set('Functions');
backButton.set('');
tabs.set([]);
copyData.set({
text: '',
value: ''
function handle(event = null) {
updateLayout({
navigate: event,
title: 'Functions'
});
}
</script>
@@ -1,7 +1,7 @@
<script lang="ts">
import { afterNavigate } from '$app/navigation';
import { page } from '$app/stores';
import { tabs, title, backButton, copyData } from '$lib/stores/layout';
import { updateLayout } from '$lib/stores/layout';
import { onMount } from 'svelte';
import { func } from './store';
@@ -11,39 +11,33 @@
onMount(handle);
afterNavigate(handle);
async function handle() {
async function handle(event = null) {
if ($func?.$id !== functionId) {
await func.load(functionId);
title.set($func.name);
} else if ($func) {
title.set($func.name);
}
backButton.set('');
copyData.set({
text: '',
value: ''
updateLayout({
navigate: event,
title: $func.name,
tabs: [
{
href: path,
title: 'Overview'
},
{
href: `${path}/monitors`,
title: 'Monitors'
},
{
href: `${path}/logs`,
title: 'Logs'
},
{
href: `${path}/settings`,
title: 'Settings'
}
]
});
tabs.set([
{
href: path,
title: 'Overview'
},
{
href: `${path}/monitors`,
title: 'Monitors'
},
{
href: `${path}/logs`,
title: 'Logs'
},
{
href: `${path}/settings`,
title: 'Settings'
}
]);
}
</script>
@@ -1,20 +1,15 @@
<script>
import { afterNavigate } from '$app/navigation';
import { tabs, title, backButton, copyData } from '$lib/stores/layout';
import { updateLayout } from '$lib/stores/layout';
import { onMount } from 'svelte';
onMount(handle);
afterNavigate(handle);
function handle() {
title.set('API Keys');
backButton.set('');
tabs.set([]);
copyData.set({
text: '',
value: ''
function handle(event = null) {
updateLayout({
navigate: event,
title: 'API Keys'
});
}
</script>
@@ -1,7 +1,6 @@
<script>
import { afterNavigate } from '$app/navigation';
import { tabs, title, backButton, copyData } from '$lib/stores/layout';
import { updateLayout } from '$lib/stores/layout';
import { onMount } from 'svelte';
const path = 'settings';
@@ -9,32 +8,29 @@
onMount(handle);
afterNavigate(handle);
function handle() {
title.set('Settings');
backButton.set('');
copyData.set({
text: '',
value: ''
function handle(event = null) {
updateLayout({
navigate: event,
title: 'Settings',
tabs: [
{
href: path,
title: 'Overview'
},
{
href: `${path}/services`,
title: 'Services'
},
{
href: `${path}/domains`,
title: 'Custom Domains'
},
{
href: `${path}/members`,
title: 'Members'
}
]
});
tabs.set([
{
href: path,
title: 'Overview'
},
{
href: `${path}/services`,
title: 'Services'
},
{
href: `${path}/domains`,
title: 'Custom Domains'
},
{
href: `${path}/members`,
title: 'Members'
}
]);
}
</script>
@@ -1,7 +1,6 @@
<script>
import { afterNavigate } from '$app/navigation';
import { tabs, title, backButton, copyData } from '$lib/stores/layout';
import { updateLayout } from '$lib/stores/layout';
import { onMount } from 'svelte';
const path = 'storage';
@@ -9,24 +8,21 @@
onMount(handle);
afterNavigate(handle);
async function handle() {
title.set('Storage');
backButton.set('');
copyData.set({
text: '',
value: ''
async function handle(event = null) {
updateLayout({
navigate: event,
title: 'Storage',
tabs: [
{
href: path,
title: 'Buckets'
},
{
href: `${path}/usage`,
title: 'Usage'
}
]
});
tabs.set([
{
href: path,
title: 'Buckets'
},
{
href: `${path}/usage`,
title: 'Usage'
}
]);
}
</script>
@@ -1,7 +1,7 @@
<script lang="ts">
import { afterNavigate } from '$app/navigation';
import { page } from '$app/stores';
import { tabs, title, backButton, copyData } from '$lib/stores/layout';
import { updateLayout } from '$lib/stores/layout';
import { onMount } from 'svelte';
import { bucket } from './store';
@@ -11,34 +11,33 @@
onMount(handle);
afterNavigate(handle);
async function handle() {
async function handle(event = null) {
if ($bucket?.$id !== bucketId) {
await bucket.load(bucketId);
title.set($bucket.name);
} else if ($bucket) {
title.set($bucket.name);
}
backButton.set('');
copyData.set({
text: bucketId,
value: bucketId
updateLayout({
navigate: event,
title: $bucket.name,
copy: {
text: bucketId,
value: bucketId
},
tabs: [
{
href: path,
title: 'Files'
},
{
href: `${path}/usage`,
title: 'Usage'
},
{
href: `${path}/settings`,
title: 'Settings'
}
]
});
tabs.set([
{
href: path,
title: 'Files'
},
{
href: `${path}/usage`,
title: 'Usage'
},
{
href: `${path}/settings`,
title: 'Settings'
}
]);
}
</script>
@@ -1,43 +1,44 @@
<script lang="ts">
import { afterNavigate } from '$app/navigation';
import { tabs, title, backButton, copyData } from '$lib/stores/layout';
import { updateLayout } from '$lib/stores/layout';
import { onMount } from 'svelte';
const path = 'users';
onMount(handle);
afterNavigate(handle);
function handle() {
title.set('Users');
backButton.set('');
let loaded = false;
copyData.set({
text: '',
value: ''
function handle(event = null) {
updateLayout({
navigate: event,
title: 'Users',
tabs: [
{
href: path,
title: 'Users'
},
{
href: `${path}/teams`,
title: 'Teams'
},
{
href: `${path}/authentication`,
title: 'Authentication'
},
{
href: `${path}/usage`,
title: 'Usage'
},
{
href: `${path}/security`,
title: 'Security'
}
]
});
tabs.set([
{
href: path,
title: 'Users'
},
{
href: `${path}/teams`,
title: 'Teams'
},
{
href: `${path}/authentication`,
title: 'Authentication'
},
{
href: `${path}/usage`,
title: 'Usage'
},
{
href: `${path}/security`,
title: 'Security'
}
]);
loaded = true;
}
</script>
@@ -45,4 +46,6 @@
<title>Appwrite - Users</title>
</svelte:head>
<slot />
{#if loaded}
<slot />
{/if}
@@ -1,7 +1,7 @@
<script lang="ts">
import { page } from '$app/stores';
import { base } from '$app/paths';
import { tabs, title, backButton, copyData } from '$lib/stores/layout';
import { updateLayout } from '$lib/stores/layout';
import { team } from './store';
import { afterNavigate } from '$app/navigation';
import { onMount } from 'svelte';
@@ -12,39 +12,34 @@
onMount(handle);
afterNavigate(handle);
async function handle() {
async function handle(event = null) {
if ($team?.$id !== teamId) {
await team.load(teamId);
title.set($team.name);
} else if ($team) {
title.set($team.name);
}
backButton.set(`${base}/console/${$page.params.project}/users/teams`);
copyData.set({
text: 'Team ID',
value: teamId
updateLayout({
navigate: event,
title: $team.name,
back: `${base}/console/${$page.params.project}/users/teams`,
copy: {
text: 'Team ID',
value: teamId
},
tabs: [
{
href: path,
title: 'Overview'
},
{
href: `${path}/members`,
title: 'Members'
},
{
href: `${path}/activity`,
title: 'Activity'
}
]
});
tabs.set([
{
href: path,
title: 'Overview'
},
{
href: `${path}/members`,
title: 'Members'
},
{
href: `${path}/activity`,
title: 'Activity'
}
]);
}
$: if ($team) {
handle();
}
</script>
@@ -2,7 +2,7 @@
import { afterNavigate } from '$app/navigation';
import { base } from '$app/paths';
import { page } from '$app/stores';
import { tabs, title, backButton, copyData } from '$lib/stores/layout';
import { updateLayout } from '$lib/stores/layout';
import { onMount } from 'svelte';
import { user } from './store';
@@ -12,43 +12,38 @@
onMount(handle);
afterNavigate(handle);
async function handle() {
async function handle(event = null) {
if ($user?.$id !== userId) {
await user.load(userId);
title.set($user.name);
} else if ($user) {
title.set($user.name);
}
backButton.set(`${base}/console/${$page.params.project}/users`);
copyData.set({
text: 'User ID',
value: userId
updateLayout({
navigate: event,
title: $user.name,
back: `${base}/console/${$page.params.project}/users`,
copy: {
text: 'User ID',
value: userId
},
tabs: [
{
href: path,
title: 'Overview'
},
{
href: `${path}/memberships`,
title: 'Memberships'
},
{
href: `${path}/sessions`,
title: 'Sessions'
},
{
href: `${path}/activity`,
title: 'Activity'
}
]
});
tabs.set([
{
href: path,
title: 'Overview'
},
{
href: `${path}/memberships`,
title: 'Memberships'
},
{
href: `${path}/sessions`,
title: 'Sessions'
},
{
href: `${path}/activity`,
title: 'Activity'
}
]);
}
$: if ($user) {
handle();
}
</script>
+3
View File
@@ -8,6 +8,9 @@ const config = {
},
ssr: {
noExternal: ['echarts']
},
legacy: {
buildSsrCjsExternalHeuristics: true
}
};