mirror of
https://github.com/appwrite/console.git
synced 2026-06-06 19:27:48 +00:00
add checkbo and rudimentary api key detail page
This commit is contained in:
1 parent
31ae2109c9
commit
c98ac6bc1d
7 files changed
+128
-15
No files matched your search
@@ -0,0 +1,25 @@
|
||||
export const scopes = [
|
||||
'users.read',
|
||||
'users.write',
|
||||
'teams.read',
|
||||
'teams.write',
|
||||
'collections.read',
|
||||
'collections.write',
|
||||
'attributes.read',
|
||||
'attributes.write',
|
||||
'indexes.read',
|
||||
'indexes.write',
|
||||
'documents.read',
|
||||
'documents.write',
|
||||
'files.read',
|
||||
'files.write',
|
||||
'buckets.read',
|
||||
'buckets.write',
|
||||
'functions.read',
|
||||
'functions.write',
|
||||
'execution.read',
|
||||
'execution.write',
|
||||
'locale.read',
|
||||
'avatars.read',
|
||||
'health.read'
|
||||
];
|
||||
@@ -12,3 +12,4 @@ export { default as InputCustomId } from './inputCustomId.svelte';
|
||||
export { default as InputSearch } from './inputSearch.svelte';
|
||||
export { default as InputRadio } from './inputRadio.svelte';
|
||||
export { default as InputSelect } from './inputSelect.svelte';
|
||||
export { default as InputCheckbox } from './inputCheckbox.svelte';
|
||||
@@ -0,0 +1,16 @@
|
||||
<script lang="ts">
|
||||
import { FormItem } from '.';
|
||||
|
||||
export let label: string;
|
||||
export let id: string;
|
||||
export let value = false;
|
||||
export let required = false;
|
||||
export let disabled = false;
|
||||
</script>
|
||||
|
||||
<FormItem>
|
||||
<label class="label" for={id}>{label}</label>
|
||||
<div class="input-text-wrapper">
|
||||
<input {id} {disabled} {required} type="checkbox" bind:checked={value} />
|
||||
</div>
|
||||
</FormItem>
|
||||
@@ -0,0 +1,52 @@
|
||||
<script lang="ts">
|
||||
import { Modal } from '$lib/components';
|
||||
import { InputText, Button, Form, InputCheckbox } from '$lib/elements/forms';
|
||||
import { addNotification } from '$lib/stores/notifications';
|
||||
import { sdkForConsole } from '$lib/stores/sdk';
|
||||
import { project } from '../store';
|
||||
import { scopes } from '$lib/constants';
|
||||
export let show = false;
|
||||
|
||||
let name: string;
|
||||
const activeScopes = scopes.reduce((prev, next) => {
|
||||
prev[next] = false;
|
||||
|
||||
return prev;
|
||||
}, {});
|
||||
|
||||
const create = async () => {
|
||||
try {
|
||||
await sdkForConsole.projects.createKey(
|
||||
$project.$id,
|
||||
name,
|
||||
scopes.filter((scope) => activeScopes[scope])
|
||||
);
|
||||
name = null;
|
||||
for (const scope in activeScopes) {
|
||||
activeScopes[scope] = false;
|
||||
}
|
||||
|
||||
await project.load($project.$id);
|
||||
show = false;
|
||||
} catch (error) {
|
||||
addNotification({
|
||||
type: 'error',
|
||||
message: error.message
|
||||
});
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<Form on:submit={create}>
|
||||
<Modal bind:show>
|
||||
<svelte:fragment slot="header">Add API Key</svelte:fragment>
|
||||
<InputText id="name" label="Name" bind:value={name} required />
|
||||
{#each scopes as scope}
|
||||
<InputCheckbox id={scope} label={scope} bind:value={activeScopes[scope]} />
|
||||
{/each}
|
||||
<svelte:fragment slot="footer">
|
||||
<Button submit>Create</Button>
|
||||
<Button secondary on:click={() => (show = false)}>Cancel</Button>
|
||||
</svelte:fragment>
|
||||
</Modal>
|
||||
</Form>
|
||||
@@ -1,40 +1,44 @@
|
||||
<script lang="ts">
|
||||
import { page } from '$app/stores';
|
||||
import { Empty } from '$lib/components';
|
||||
import { Button } from '$lib/elements/forms';
|
||||
import {
|
||||
Table,
|
||||
TableBody,
|
||||
TableCellHead,
|
||||
TableCellLink,
|
||||
TableCellText,
|
||||
TableHeader
|
||||
TableHeader,
|
||||
TableRow
|
||||
} from '$lib/elements/table';
|
||||
import { Container } from '$lib/layout';
|
||||
import { sdkForConsole } from '$lib/stores/sdk';
|
||||
import { project } from '../store';
|
||||
import Create from './_create.svelte';
|
||||
|
||||
const projectId = $page.params.project;
|
||||
const request = sdkForConsole.projects.listKeys(projectId);
|
||||
|
||||
let showCreate = false;
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
<title>Appwrite - API Keys</title>
|
||||
</svelte:head>
|
||||
<Container>
|
||||
{#await request}
|
||||
<div aria-busy="true" />
|
||||
{:then response}
|
||||
{#if response.total}
|
||||
{#if $project}
|
||||
{#if $project.keys}
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableCellHead>Name</TableCellHead>
|
||||
<TableCellHead>Scopes</TableCellHead>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{#each response.keys as key}
|
||||
<TableCellLink href={`/console/${projectId}/keys/key/${key.$id}`} title="Name">
|
||||
{key.name}
|
||||
</TableCellLink>
|
||||
<TableCellText title="Scopes">{key.scopes.length}</TableCellText>
|
||||
{#each $project.keys as key}
|
||||
<TableRow>
|
||||
<TableCellLink href={`/console/${projectId}/keys/key/${key.$id}`} title="Name">
|
||||
{key.name}
|
||||
</TableCellLink>
|
||||
<TableCellText title="Scopes">{key.scopes.length}</TableCellText>
|
||||
</TableRow>
|
||||
{/each}
|
||||
</TableBody>
|
||||
</Table>
|
||||
@@ -44,5 +48,7 @@
|
||||
You haven't created any API keys for your project yet.
|
||||
</Empty>
|
||||
{/if}
|
||||
{/await}
|
||||
<Button on:click={() => (showCreate = true)}>Add API Key</Button>
|
||||
{/if}
|
||||
</Container>
|
||||
<Create bind:show={showCreate} />
|
||||
@@ -1,10 +1,20 @@
|
||||
<script lang="ts">
|
||||
import { Card } from '$lib/components';
|
||||
import { Container } from '$lib/layout';
|
||||
import { sdkForConsole } from '$lib/stores/sdk';
|
||||
import { page } from '$app/stores';
|
||||
|
||||
const projectId = $page.params.project;
|
||||
const keyId = $page.params.key;
|
||||
const request = sdkForConsole.projects.getKey(projectId, keyId);
|
||||
</script>
|
||||
|
||||
<Container>
|
||||
<Card>
|
||||
<p>TBD</p>
|
||||
{#await request}
|
||||
loading
|
||||
{:then response}
|
||||
<p>{response.name}</p>
|
||||
{/await}
|
||||
</Card>
|
||||
</Container>
|
||||
@@ -9,7 +9,10 @@ function createProject() {
|
||||
subscribe,
|
||||
set,
|
||||
load: async (projectId: string) => {
|
||||
set(await sdkForConsole.projects.get(projectId));
|
||||
console.log('loasd');
|
||||
const project = await sdkForConsole.projects.get(projectId);
|
||||
console.log(project);
|
||||
set(project);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user