Add logging toggle settings

This commit is contained in:
Matej Bačo committed 2023-06-06 09:49:40 +02:00
1 parent da58902008
commit 9f78abf208
12 files changed
+126 -11

No files matched your search

+9 -1
View File
@@ -2,6 +2,7 @@
import { createEventDispatcher } from 'svelte';
import type { Buttons } from '../stores/notifications';
export let isInline = false;
export let dismissible = false;
export let type: 'info' | 'success' | 'warning' | 'error' = 'info';
export let buttons: Buttons[] = [];
@@ -14,7 +15,8 @@
class:is-success={type === 'success'}
class:is-warning={type === 'warning'}
class:is-danger={type === 'error'}
class:is-info={type === 'info'}>
class:is-info={type === 'info'}
class:is-inline={isInline}>
<div class="alert-grid">
{#if dismissible}
<button
@@ -51,3 +53,9 @@
</div>
</div>
</section>
<style lang="scss">
.is-inline {
background-color: white;
}
</style>
@@ -43,6 +43,7 @@
</div>
<div class="choice-item-content">
<div class="choice-item-title">{label}</div>
<slot name="description" />
</div>
</label>
{#if error}
+6 -2
View File
@@ -14,7 +14,9 @@
let selectedTab: string;
let rawData: string;
function isDeployment(data: Models.Deployment | Models.Execution): data is Models.Deployment {
function isDeployment(
data: Models.Deployment | Models.Execution<any>
): data is Models.Deployment {
if ('buildId' in data) {
selectedTab = 'logs';
rawData = `${sdk.forConsole.client.config.endpoint}/functions/${$log.func.$id}/deployment/${$log.data.$id}?mode=admin&project=${$page.params.project}`;
@@ -22,7 +24,9 @@
}
}
function isExecution(data: Models.Deployment | Models.Execution): data is Models.Execution {
function isExecution(
data: Models.Deployment | Models.Execution<any>
): data is Models.Execution<any> {
if ('trigger' in data) {
selectedTab = 'response';
rawData = `${sdk.forConsole.client.config.endpoint}/functions/${$log.func.$id}/execution/${$log.data.$id}?mode=admin&project=${$page.params.project}`;
+1 -1
View File
@@ -4,7 +4,7 @@ import { writable } from 'svelte/store';
export const log = writable<{
show: boolean;
func: Models.Function;
data: Models.Execution | Models.Deployment;
data: Models.Execution<any> | Models.Deployment;
}>({
show: false,
func: null,
@@ -23,6 +23,8 @@
import CreateDeployment from '../create.svelte';
import type { Models } from '@appwrite.io/console';
import type { PageData } from './$types';
import Alert from '$lib/components/alert.svelte';
import { project } from '$routes/console/project-[project]/store';
export let data: PageData;
@@ -43,7 +45,7 @@
}
});
function showLogs(execution: Models.Execution) {
function showLogs(execution: Models.Execution<any>) {
$log.show = true;
$log.func = $func;
$log.data = execution;
@@ -52,8 +54,22 @@
<Container>
<div class="u-flex u-gap-12 common-section u-main-space-between">
<Heading tag="h2" size="5">Logs</Heading>
<Heading tag="h2" size="5">Executions</Heading>
</div>
{#if !$func.logging}
<div class="common-section">
<Alert type="info" isInline={true}>
<svelte:fragment slot="title">Your execution logs are disabled</svelte:fragment>
To see the latest execution logs, enable them in your
<a
href={`/console/project-${$project.$id}/functions/function-${$func.$id}/settings`}
class="link">
Function settings</a
>.
</Alert>
</div>
{/if}
{#if data.executions.total}
<TableScroll>
<TableHeader>
@@ -13,6 +13,7 @@
import { sdk } from '$lib/stores/sdk';
import { Dependencies } from '$lib/constants';
import { invalidate } from '$app/navigation';
import UpdateLogging from './updateLogging.svelte';
export let data;
@@ -35,6 +36,7 @@
<Container>
<ExecuteFunction />
<UpdateName />
<UpdateLogging />
<UpdatePermissions />
<UpdateEvents />
<UpdateSchedule />
@@ -36,7 +36,8 @@
Array.from($eventSet),
$func.schedule || undefined,
$func.timeout || undefined,
$func.enabled
$func.enabled,
$func.logging
);
await invalidate(Dependencies.FUNCTION);
addNotification({
@@ -0,0 +1,79 @@
<script lang="ts">
import { invalidate } from '$app/navigation';
import { page } from '$app/stores';
import { Submit, trackError, trackEvent } from '$lib/actions/analytics';
import { CardGrid, Heading } from '$lib/components';
import { Dependencies } from '$lib/constants';
import { Button, Form, FormList, InputCron } from '$lib/elements/forms';
import InputSwitch from '$lib/elements/forms/inputSwitch.svelte';
import { addNotification } from '$lib/stores/notifications';
import { sdk } from '$lib/stores/sdk';
import { project } from '$routes/console/project-[project]/store';
import { onMount } from 'svelte';
import { func } from '../store';
const functionId = $page.params.function;
let functionLogging: boolean = null;
onMount(async () => {
functionLogging ??= $func.logging;
});
async function updateSchedule() {
try {
await sdk.forProject.functions.update(
functionId,
$func.name,
$func.execute || undefined,
$func.events || undefined,
$func.schedule || undefined,
$func.timeout || undefined,
$func.enabled,
functionLogging
);
await invalidate(Dependencies.FUNCTION);
addNotification({
type: 'success',
message:
$func.name +
' execution logs settings have been ' +
(functionLogging ? 'enabled' : 'disabled')
});
trackEvent(Submit.FunctionUpdateSchedule);
} catch (error) {
addNotification({
type: 'error',
message: error.message
});
trackError(error, Submit.FunctionUpdateSchedule);
}
}
</script>
<Form onSubmit={updateSchedule}>
<CardGrid>
<Heading tag="h6" size="7">Execution logs</Heading>
<p>
Enable or disable execution logs. We recommend disabling logs when transferring critical
data or for performance reasons.
</p>
<svelte:fragment slot="aside">
<FormList>
<InputSwitch label="Logs" id="logging" bind:value={functionLogging}>
<svelte:fragment slot="description">
<p>
When enabled, all execution responses will be accessible in the <a
href={`/console/project-${$project.$id}/functions/function-${$func.$id}/executions`}
class="link">
Executions</a> tab
</p>
</svelte:fragment>
</InputSwitch>
</FormList>
</svelte:fragment>
<svelte:fragment slot="actions">
<Button disabled={$func.logging === functionLogging} submit>Update</Button>
</svelte:fragment>
</CardGrid>
</Form>
@@ -26,7 +26,8 @@
$func.events || undefined,
$func.schedule || undefined,
$func.timeout || undefined,
$func.enabled
$func.enabled,
$func.logging
);
await invalidate(Dependencies.FUNCTION);
addNotification({
@@ -30,7 +30,8 @@
$func.events || undefined,
$func.schedule || undefined,
$func.timeout || undefined,
$func.enabled
$func.enabled,
$func.logging
);
await invalidate(Dependencies.FUNCTION);
addNotification({
@@ -26,7 +26,8 @@
$func.events || undefined,
functionSchedule,
$func.timeout || undefined,
$func.enabled
$func.enabled,
$func.logging
);
await invalidate(Dependencies.FUNCTION);
addNotification({
@@ -26,7 +26,8 @@
$func.events || undefined,
$func.schedule || undefined,
timeout,
$func.enabled
$func.enabled,
$func.logging
);
await invalidate(Dependencies.FUNCTION);
addNotification({