mirror of
https://github.com/appwrite/console.git
synced 2026-06-06 19:27:48 +00:00
function commands
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { debounce } from '$lib/helpers/debounce';
|
||||
import { isMac } from '$lib/helpers/platform';
|
||||
import { onMount } from 'svelte';
|
||||
import { derived, writable, type Updater } from 'svelte/store';
|
||||
import { derived, writable } from 'svelte/store';
|
||||
|
||||
const groups = [
|
||||
'ungrouped',
|
||||
@@ -241,23 +241,24 @@ export const disableCommands = {
|
||||
}
|
||||
};
|
||||
|
||||
type CommandGroupRanks = Record<CommandGroup, number>;
|
||||
type CommandGroupRanks = Partial<Record<CommandGroup, number>>;
|
||||
|
||||
type GroupRanksMap = Map<string, CommandGroupRanks>;
|
||||
const groupRanksMap = writable<GroupRanksMap>(new Map());
|
||||
|
||||
type CommandGroupRankTransformations = Map<string, Updater<CommandGroupRanks>>;
|
||||
const groupRankTransformations = writable<CommandGroupRankTransformations>(new Map());
|
||||
export const updateCommandGroupRanks = {
|
||||
subscribe(runner: (cb: (updater: Updater<CommandGroupRanks>) => void) => void) {
|
||||
subscribe(runner: (cb: (updater: CommandGroupRanks) => void) => void) {
|
||||
const uuid = crypto.randomUUID();
|
||||
|
||||
runner((updater: Updater<CommandGroupRanks>) => {
|
||||
groupRankTransformations.update((curr) => {
|
||||
curr.set(uuid, updater);
|
||||
runner((groupRank: CommandGroupRanks) => {
|
||||
groupRanksMap.update((curr) => {
|
||||
curr.set(uuid, groupRank);
|
||||
return curr;
|
||||
});
|
||||
});
|
||||
|
||||
return () => {
|
||||
groupRankTransformations.update((curr) => {
|
||||
groupRanksMap.update((curr) => {
|
||||
curr.delete(uuid);
|
||||
return curr;
|
||||
});
|
||||
@@ -265,7 +266,7 @@ export const updateCommandGroupRanks = {
|
||||
}
|
||||
};
|
||||
|
||||
export const commandGroupRanks = derived(groupRankTransformations, ($groupRankTransformations) => {
|
||||
export const commandGroupRanks = derived(groupRanksMap, ($groupRankTransformations) => {
|
||||
const initialRanks = {
|
||||
...Object.fromEntries(groups.map((group) => [group, 0])),
|
||||
ungrouped: 9999,
|
||||
@@ -277,7 +278,7 @@ export const commandGroupRanks = derived(groupRankTransformations, ($groupRankTr
|
||||
} as CommandGroupRanks;
|
||||
|
||||
const transformations = Array.from($groupRankTransformations.values());
|
||||
return transformations.reduce((prev, curr) => curr(prev), initialRanks);
|
||||
return transformations.reduce((prev, curr) => ({ ...prev, ...curr }), initialRanks);
|
||||
});
|
||||
|
||||
export type Searcher = (query: string) => Promise<Command[]>;
|
||||
|
||||
@@ -12,8 +12,8 @@ import {
|
||||
Projects,
|
||||
Storage,
|
||||
Teams,
|
||||
Users,
|
||||
Migrations
|
||||
Users
|
||||
// Migrations
|
||||
} from '@appwrite.io/console';
|
||||
|
||||
const endpoint = VARS.APPWRITE_ENDPOINT ?? `${globalThis?.location?.origin}/v1`;
|
||||
@@ -34,8 +34,8 @@ const sdkForProject = {
|
||||
project: new Project(clientProject),
|
||||
storage: new Storage(clientProject),
|
||||
teams: new Teams(clientProject),
|
||||
users: new Users(clientProject),
|
||||
migrations: new Migrations(clientProject)
|
||||
users: new Users(clientProject)
|
||||
// migrations: new Migrations(clientProject)
|
||||
};
|
||||
|
||||
export const getSdkForProject = (projectId: string) => {
|
||||
@@ -56,8 +56,8 @@ export const sdk = {
|
||||
locale: new Locale(clientConsole),
|
||||
projects: new Projects(clientConsole),
|
||||
teams: new Teams(clientConsole),
|
||||
users: new Users(clientConsole),
|
||||
migrations: new Migrations(clientConsole)
|
||||
users: new Users(clientConsole)
|
||||
// migrations: new Migrations(clientConsole)
|
||||
},
|
||||
get forProject() {
|
||||
const projectId = getProjectId();
|
||||
|
||||
@@ -5,9 +5,19 @@
|
||||
import { project, stats } from './store';
|
||||
|
||||
import { goto } from '$app/navigation';
|
||||
import { addSubPanel, registerCommands, registerSearchers } from '$lib/commandCenter';
|
||||
import {
|
||||
addSubPanel,
|
||||
registerCommands,
|
||||
registerSearchers,
|
||||
updateCommandGroupRanks
|
||||
} from '$lib/commandCenter';
|
||||
|
||||
import { dbSearcher, userSearcher } from '$lib/commandCenter/searchers';
|
||||
import {
|
||||
dbSearcher,
|
||||
functionsSearcher,
|
||||
teamSearcher,
|
||||
userSearcher
|
||||
} from '$lib/commandCenter/searchers';
|
||||
import { MigrationBox } from '$lib/components';
|
||||
import {
|
||||
UsersPanel,
|
||||
@@ -115,7 +125,9 @@
|
||||
}
|
||||
]);
|
||||
|
||||
$: $registerSearchers(userSearcher, dbSearcher);
|
||||
$registerSearchers(userSearcher, teamSearcher, dbSearcher, functionsSearcher);
|
||||
|
||||
$updateCommandGroupRanks({ functions: 10 });
|
||||
</script>
|
||||
|
||||
<slot />
|
||||
|
||||
@@ -122,7 +122,7 @@
|
||||
}
|
||||
]);
|
||||
|
||||
$: $updateCommandGroupRanks((prev) => ({ ...prev, users: 300, teams: 200, security: 100 }));
|
||||
$: $updateCommandGroupRanks({ users: 300, teams: 200, security: 100 });
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
|
||||
@@ -17,10 +17,7 @@
|
||||
}
|
||||
]);
|
||||
|
||||
$: $updateCommandGroupRanks((prev) => ({
|
||||
...prev,
|
||||
databases: 100
|
||||
}));
|
||||
$: $updateCommandGroupRanks({ databases: 100 });
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
|
||||
@@ -1,6 +1,64 @@
|
||||
<script lang="ts">
|
||||
import { execute } from './store';
|
||||
import { execute, func } from './store';
|
||||
import Execute from './execute.svelte';
|
||||
import { registerCommands } from '$lib/commandCenter';
|
||||
import { goto } from '$app/navigation';
|
||||
import { project } from '../../store';
|
||||
import { page } from '$app/stores';
|
||||
import { showCreateDeployment } from './+page.svelte';
|
||||
|
||||
$: $registerCommands([
|
||||
{
|
||||
label: 'Create deployment',
|
||||
async callback() {
|
||||
await goto(`/console/project-${$project.$id}/functions/function-${$func.$id}`);
|
||||
showCreateDeployment();
|
||||
},
|
||||
keys: $page.url.pathname.endsWith($func.$id) ? ['c'] : ['c', 'd'],
|
||||
group: 'functions',
|
||||
icon: 'plus'
|
||||
},
|
||||
{
|
||||
label: 'Go to deployments',
|
||||
callback() {
|
||||
goto(`/console/project-${$project.$id}/functions/function-${$func.$id}`);
|
||||
},
|
||||
keys: ['g', 'd'],
|
||||
group: 'navigation',
|
||||
rank: 10,
|
||||
disabled: $page.url.pathname.endsWith($func.$id)
|
||||
},
|
||||
{
|
||||
label: 'Go to usage',
|
||||
callback() {
|
||||
goto(`/console/project-${$project.$id}/functions/function-${$func.$id}/usage`);
|
||||
},
|
||||
keys: ['g', 'u'],
|
||||
group: 'navigation',
|
||||
rank: 10,
|
||||
disabled: $page.url.pathname.endsWith('usage')
|
||||
},
|
||||
{
|
||||
label: 'Go to executions',
|
||||
callback() {
|
||||
goto(`/console/project-${$project.$id}/functions/function-${$func.$id}/executions`);
|
||||
},
|
||||
keys: ['g', 'e'],
|
||||
group: 'navigation',
|
||||
rank: 10,
|
||||
disabled: $page.url.pathname.endsWith('executions')
|
||||
},
|
||||
{
|
||||
label: 'Go to settings',
|
||||
callback() {
|
||||
goto(`/console/project-${$project.$id}/functions/function-${$func.$id}/settings`);
|
||||
},
|
||||
keys: ['g', 's'],
|
||||
group: 'navigation',
|
||||
rank: 10,
|
||||
disabled: $page.url.pathname.endsWith('settings')
|
||||
}
|
||||
]);
|
||||
</script>
|
||||
|
||||
<slot />
|
||||
|
||||
@@ -1,3 +1,10 @@
|
||||
<script lang="ts" context="module">
|
||||
let showCreate = false;
|
||||
export const showCreateDeployment = () => {
|
||||
showCreate = true;
|
||||
};
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
import { Button } from '$lib/elements/forms';
|
||||
import {
|
||||
@@ -40,7 +47,6 @@
|
||||
|
||||
export let data: PageData;
|
||||
|
||||
let showCreate = false;
|
||||
let showDropdown = [];
|
||||
let showDelete = false;
|
||||
let showActivate = false;
|
||||
|
||||
Reference in New Issue
Block a user