mirror of
https://github.com/appwrite/console.git
synced 2026-06-06 19:27:48 +00:00
feat: root directory fixes
This commit is contained in:
+1
-1
@@ -25,7 +25,7 @@
|
||||
"@appwrite.io/pink-icons": "0.25.0",
|
||||
"@appwrite.io/pink-icons-svelte": "https://pkg.pr.new/appwrite/pink/@appwrite.io/pink-icons-svelte@6b17cb23",
|
||||
"@appwrite.io/pink-legacy": "^1.0.3",
|
||||
"@appwrite.io/pink-svelte": "https://pkg.pr.new/appwrite/pink/@appwrite.io/pink-svelte@12075ba",
|
||||
"@appwrite.io/pink-svelte": "https://pkg.pr.new/appwrite/pink/@appwrite.io/pink-svelte@6426e19",
|
||||
"@popperjs/core": "^2.11.8",
|
||||
"@sentry/sveltekit": "^8.38.0",
|
||||
"@stripe/stripe-js": "^3.5.0",
|
||||
|
||||
Generated
+9
-9
@@ -21,8 +21,8 @@ importers:
|
||||
specifier: ^1.0.3
|
||||
version: 1.0.3
|
||||
'@appwrite.io/pink-svelte':
|
||||
specifier: https://pkg.pr.new/appwrite/pink/@appwrite.io/pink-svelte@12075ba
|
||||
version: https://pkg.pr.new/appwrite/pink/@appwrite.io/pink-svelte@12075ba(react-dom@18.3.1(react@18.3.1))(svelte@5.25.3)
|
||||
specifier: https://pkg.pr.new/appwrite/pink/@appwrite.io/pink-svelte@6426e19
|
||||
version: https://pkg.pr.new/appwrite/pink/@appwrite.io/pink-svelte@6426e19(react-dom@18.3.1(react@18.3.1))(svelte@5.25.3)
|
||||
'@popperjs/core':
|
||||
specifier: ^2.11.8
|
||||
version: 2.11.8
|
||||
@@ -221,8 +221,8 @@ packages:
|
||||
resolution: {tarball: https://pkg.pr.new/appwrite/appwrite/@appwrite.io/console@e2f082e}
|
||||
version: 1.2.1
|
||||
|
||||
'@appwrite.io/pink-icons-svelte@https://pkg.pr.new/appwrite/pink/@appwrite.io/pink-icons-svelte@12075ba0a81ce1c8ef6f31a9951b42369eab478c':
|
||||
resolution: {tarball: https://pkg.pr.new/appwrite/pink/@appwrite.io/pink-icons-svelte@12075ba0a81ce1c8ef6f31a9951b42369eab478c}
|
||||
'@appwrite.io/pink-icons-svelte@https://pkg.pr.new/appwrite/pink/@appwrite.io/pink-icons-svelte@6426e1980a3f63db2602ed98d36d021f10d9c7d7':
|
||||
resolution: {tarball: https://pkg.pr.new/appwrite/pink/@appwrite.io/pink-icons-svelte@6426e1980a3f63db2602ed98d36d021f10d9c7d7}
|
||||
version: 1.0.0-next.7
|
||||
peerDependencies:
|
||||
svelte: ^4.0.0
|
||||
@@ -242,8 +242,8 @@ packages:
|
||||
'@appwrite.io/pink-legacy@1.0.3':
|
||||
resolution: {integrity: sha512-GGde5fmPhs+s6/3aFeMPc/kKADG/gTFkYQSy6oBN8pK0y0XNCLrZZgBv+EBbdhwdtqVEWXa0X85Mv9w7jcIlwQ==}
|
||||
|
||||
'@appwrite.io/pink-svelte@https://pkg.pr.new/appwrite/pink/@appwrite.io/pink-svelte@12075ba':
|
||||
resolution: {tarball: https://pkg.pr.new/appwrite/pink/@appwrite.io/pink-svelte@12075ba}
|
||||
'@appwrite.io/pink-svelte@https://pkg.pr.new/appwrite/pink/@appwrite.io/pink-svelte@6426e19':
|
||||
resolution: {tarball: https://pkg.pr.new/appwrite/pink/@appwrite.io/pink-svelte@6426e19}
|
||||
version: 1.0.0-next.85
|
||||
peerDependencies:
|
||||
react-dom: ^18.0.0
|
||||
@@ -3536,7 +3536,7 @@ snapshots:
|
||||
|
||||
'@appwrite.io/console@https://pkg.pr.new/appwrite/appwrite/@appwrite.io/console@e2f082e': {}
|
||||
|
||||
'@appwrite.io/pink-icons-svelte@https://pkg.pr.new/appwrite/pink/@appwrite.io/pink-icons-svelte@12075ba0a81ce1c8ef6f31a9951b42369eab478c(svelte@5.25.3)':
|
||||
'@appwrite.io/pink-icons-svelte@https://pkg.pr.new/appwrite/pink/@appwrite.io/pink-icons-svelte@6426e1980a3f63db2602ed98d36d021f10d9c7d7(svelte@5.25.3)':
|
||||
dependencies:
|
||||
svelte: 5.25.3
|
||||
|
||||
@@ -3553,9 +3553,9 @@ snapshots:
|
||||
'@appwrite.io/pink-icons': 1.0.0
|
||||
the-new-css-reset: 1.11.3
|
||||
|
||||
'@appwrite.io/pink-svelte@https://pkg.pr.new/appwrite/pink/@appwrite.io/pink-svelte@12075ba(react-dom@18.3.1(react@18.3.1))(svelte@5.25.3)':
|
||||
'@appwrite.io/pink-svelte@https://pkg.pr.new/appwrite/pink/@appwrite.io/pink-svelte@6426e19(react-dom@18.3.1(react@18.3.1))(svelte@5.25.3)':
|
||||
dependencies:
|
||||
'@appwrite.io/pink-icons-svelte': https://pkg.pr.new/appwrite/pink/@appwrite.io/pink-icons-svelte@12075ba0a81ce1c8ef6f31a9951b42369eab478c(svelte@5.25.3)
|
||||
'@appwrite.io/pink-icons-svelte': https://pkg.pr.new/appwrite/pink/@appwrite.io/pink-icons-svelte@6426e1980a3f63db2602ed98d36d021f10d9c7d7(svelte@5.25.3)
|
||||
'@floating-ui/dom': 1.6.13
|
||||
'@melt-ui/pp': 0.3.2(@melt-ui/svelte@0.86.6(svelte@5.25.3))(svelte@5.25.3)
|
||||
'@melt-ui/svelte': 0.86.6(svelte@5.25.3)
|
||||
|
||||
@@ -4,9 +4,10 @@
|
||||
import { iconPath } from '$lib/stores/app';
|
||||
import { sdk } from '$lib/stores/sdk';
|
||||
import { installation, repository } from '$lib/stores/vcs';
|
||||
import { VCSDetectionType } from '@appwrite.io/console';
|
||||
import { VCSDetectionType, type Models } from '@appwrite.io/console';
|
||||
import { DirectoryPicker } from '@appwrite.io/pink-svelte';
|
||||
import { onMount } from 'svelte';
|
||||
import { writable } from 'svelte/store';
|
||||
|
||||
type Directory = {
|
||||
title: string;
|
||||
@@ -14,6 +15,7 @@
|
||||
fileCount: number;
|
||||
thumbnailUrl: string;
|
||||
children?: Directory[];
|
||||
loading?: boolean;
|
||||
};
|
||||
|
||||
export let show = false;
|
||||
@@ -27,10 +29,13 @@
|
||||
fullPath: './',
|
||||
fileCount: 0,
|
||||
thumbnailUrl: 'root',
|
||||
children: []
|
||||
children: [],
|
||||
loading: false
|
||||
}
|
||||
];
|
||||
let currentPath: string = './';
|
||||
let currentDir: Directory;
|
||||
export let expanded = writable(['lib-0', 'tree-0']);
|
||||
|
||||
onMount(async () => {
|
||||
try {
|
||||
@@ -47,8 +52,10 @@
|
||||
title: dir.name,
|
||||
fullPath: currentPath + dir.name,
|
||||
fileCount: undefined,
|
||||
thumbnailUrl: dir.name
|
||||
thumbnailUrl: dir.name,
|
||||
loading: false
|
||||
}));
|
||||
currentDir = directories[0];
|
||||
// console.log(directories);
|
||||
isLoading = false;
|
||||
} catch (e) {
|
||||
@@ -57,47 +64,70 @@
|
||||
});
|
||||
|
||||
async function fetchContents(e: CustomEvent) {
|
||||
const path = e.detail.fullPath;
|
||||
const path = e.detail.fullPath as string;
|
||||
currentPath = path;
|
||||
try {
|
||||
const content = await sdk.forProject.vcs.getRepositoryContents(
|
||||
$installation.$id,
|
||||
$repository.id,
|
||||
path
|
||||
);
|
||||
// console.log(content);
|
||||
const fileCount = content.contents?.length ?? 0;
|
||||
const contentDirectories = content.contents.filter((e) => e.isDirectory);
|
||||
|
||||
if (contentDirectories.length === 0) {
|
||||
return;
|
||||
}
|
||||
let currentDir = directories[0];
|
||||
for (let i = 1; i < path.split('/').length; i++) {
|
||||
const dir = path.split('/')[i];
|
||||
currentDir = currentDir.children.find((d) => d.title === dir);
|
||||
}
|
||||
const pathSegments = path.split('/').filter((segment) => segment !== '.' && segment !== '');
|
||||
let traversedDir = directories[0]; // Start at root
|
||||
|
||||
currentDir.fileCount = fileCount;
|
||||
currentDir.children = contentDirectories.map((dir) => ({
|
||||
title: dir.name,
|
||||
fullPath: path + '/' + dir.name,
|
||||
fileCount: undefined,
|
||||
thumbnailUrl: undefined
|
||||
}));
|
||||
const runtime = await sdk.forProject.vcs.createRepositoryDetection(
|
||||
$installation.$id,
|
||||
$repository.id,
|
||||
product === 'sites' ? VCSDetectionType.Framework : VCSDetectionType.Runtime,
|
||||
path
|
||||
);
|
||||
//TODO: Fix runtime after passing type: runtime.framework || runtime.runtime
|
||||
currentDir.children.forEach((dir) => {
|
||||
dir.thumbnailUrl = $iconPath(runtime.framework, 'color');
|
||||
});
|
||||
for (const segment of pathSegments) {
|
||||
const nextDir = traversedDir.children?.find((dir) => dir.title === segment);
|
||||
if (!nextDir) break;
|
||||
traversedDir = nextDir;
|
||||
}
|
||||
|
||||
currentDir = traversedDir;
|
||||
|
||||
if (!currentDir.fileCount) {
|
||||
currentDir.loading = true;
|
||||
directories = [...directories];
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
|
||||
try {
|
||||
const content = await sdk.forProject.vcs.getRepositoryContents(
|
||||
$installation.$id,
|
||||
$repository.id,
|
||||
path
|
||||
);
|
||||
// console.log(content);
|
||||
const fileCount = content.contents?.length ?? 0;
|
||||
const contentDirectories = content.contents.filter((e) => e.isDirectory);
|
||||
|
||||
if (contentDirectories.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
currentDir.fileCount = fileCount;
|
||||
currentDir.children = contentDirectories.map((dir) => ({
|
||||
title: dir.name,
|
||||
fullPath: path + '/' + dir.name,
|
||||
fileCount: undefined,
|
||||
thumbnailUrl: undefined
|
||||
}));
|
||||
const runtime = await sdk.forProject.vcs.createRepositoryDetection(
|
||||
$installation.$id,
|
||||
$repository.id,
|
||||
product === 'sites' ? VCSDetectionType.Framework : VCSDetectionType.Runtime,
|
||||
path
|
||||
);
|
||||
if (product === 'sites') {
|
||||
currentDir.children.forEach((dir) => {
|
||||
dir.thumbnailUrl = $iconPath(runtime.framework, 'color');
|
||||
});
|
||||
} else if (product === 'functions') {
|
||||
currentDir.children.forEach((dir) => {
|
||||
dir.thumbnailUrl = $iconPath(
|
||||
(runtime as unknown as Models.DetectionRuntime).runtime,
|
||||
'color'
|
||||
);
|
||||
});
|
||||
}
|
||||
directories = [...directories];
|
||||
$expanded = [...$expanded, path];
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
} finally {
|
||||
currentDir.loading = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,15 +135,13 @@
|
||||
rootDir = currentPath;
|
||||
show = false;
|
||||
}
|
||||
|
||||
// $: console.log(rootDir);
|
||||
</script>
|
||||
|
||||
<Modal title="Root directory" bind:show onSubmit={handleSubmit}>
|
||||
<span slot="description">
|
||||
Select the directory where your site code is located using the menu below.
|
||||
</span>
|
||||
<DirectoryPicker {directories} {isLoading} on:select={fetchContents} />
|
||||
<DirectoryPicker {directories} {isLoading} on:select={fetchContents} bind:expanded />
|
||||
|
||||
<svelte:fragment slot="footer">
|
||||
<Button secondary on:click={() => (show = false)}>Cancel</Button>
|
||||
|
||||
Reference in New Issue
Block a user