feat: more searchers

This commit is contained in:
tglide
2023-07-20 15:10:52 +01:00
parent 7c03f05615
commit ece145d328
7 changed files with 53 additions and 29 deletions
+1
View File
@@ -258,6 +258,7 @@ export const commandGroupRanks = derived(groupRankTransformations, ($groupRankTr
const initialRanks = {
...Object.fromEntries(groups.map((group) => [group, 0])),
ungrouped: 9999,
users: 1,
help: -1
} as CommandGroupRanks;
@@ -1,31 +1,11 @@
<script lang="ts">
import { goto } from '$app/navigation';
import { sdk } from '$lib/stores/sdk';
import type { Models } from '@appwrite.io/console';
import { onMount } from 'svelte';
import { useSearcher } from '../commands';
import { orgSearcher } from '../searchers';
import Template from './template.svelte';
let search = '';
let organizations = [] as Models.TeamList<Models.Preferences>['teams'];
onMount(async () => {
organizations = (await sdk.forConsole.teams.list()).teams;
});
$: filteredOrganizations = organizations
.filter((organization) => organization.name.toLowerCase().includes(search.toLowerCase()))
.map((organization) => {
return {
label: organization.name,
callback: () => {
goto(`/console/organization-${organization.$id}`);
},
group: 'organizations'
} as const;
});
const { results, search } = useSearcher(orgSearcher);
</script>
<Template options={filteredOrganizations} bind:search>
<Template options={$results} bind:search={$search}>
<div class="option" slot="option" let:option>{option.label}</div>
</Template>
+1
View File
@@ -1,2 +1,3 @@
export * from './databases';
export * from './users';
export * from './organizations';
@@ -0,0 +1,18 @@
import { goto } from '$app/navigation';
import { sdk } from '$lib/stores/sdk';
import type { Searcher } from '../commands';
export const orgSearcher = (async (query: string) => {
const { teams } = await sdk.forConsole.teams.list();
return teams
.filter((organization) => organization.name.toLowerCase().includes(query.toLowerCase()))
.map((organization) => {
return {
label: organization.name,
callback: () => {
goto(`/console/organization-${organization.$id}`);
},
group: 'organizations'
} as const;
});
}) satisfies Searcher;
+9
View File
@@ -4,6 +4,7 @@ import { project } from '$routes/console/project-[project]/store';
import { get } from 'svelte/store';
import type { Command, Searcher } from '../commands';
import type { Models } from '@appwrite.io/console';
import { promptDeleteUser } from '$routes/console/project-[project]/auth/user-[user]/dangerZone.svelte';
const getUserCommand = (user: Models.User<Models.Preferences>, projectId: string) =>
({
@@ -22,6 +23,14 @@ export const userSearcher = (async (query: string) => {
if (users.length === 1) {
return [
getUserCommand(users[0], projectId),
{
label: 'Delete user',
callback: () => {
promptDeleteUser(users[0].$id);
},
group: 'users',
icon: 'trash'
},
{
label: 'Go to activity',
callback: () => {
+4 -1
View File
@@ -17,10 +17,11 @@
import { goto } from '$app/navigation';
import { CommandCenter, registerCommands } from '$lib/commandCenter';
import { CommandCenter, registerCommands, registerSearcher } from '$lib/commandCenter';
import { AIPanel, OrganizationsPanel } from '$lib/commandCenter/panels';
import { addSubPanel } from '$lib/commandCenter/subPanels';
import { openMigrationWizard } from './(migration-wizard)';
import { orgSearcher } from '$lib/commandCenter/searchers';
$: $registerCommands([
{
@@ -107,6 +108,8 @@
$: if ($requestedMigration) {
openMigrationWizard();
}
$registerSearcher(orgSearcher);
</script>
<CommandCenter />
@@ -1,10 +1,22 @@
<script lang="ts" context="module">
import { get } from 'svelte/store';
let showDelete = writable(false);
export const promptDeleteUser = (id: string) => {
showDelete.set(true);
goto(`/console/project-${get(project).$id}/auth/user-${id}`);
};
</script>
<script lang="ts">
import { CardGrid, Box, Heading, AvatarInitials } from '$lib/components';
import { Button } from '$lib/elements/forms';
import { writable } from 'svelte/store';
import DeleteUser from './deleteUser.svelte';
import { user } from './store';
let showDelete = false;
import { goto } from '$app/navigation';
import { project } from '../../store';
</script>
<CardGrid danger>
@@ -46,8 +58,8 @@
</svelte:fragment>
<svelte:fragment slot="actions">
<Button secondary on:click={() => (showDelete = true)} event="delete_user">Delete</Button>
<Button secondary on:click={() => ($showDelete = true)} event="delete_user">Delete</Button>
</svelte:fragment>
</CardGrid>
<DeleteUser bind:showDelete />
<DeleteUser bind:showDelete={$showDelete} />