feat: function setting configuration (style missing)

This commit is contained in:
Arman committed 2023-06-08 17:58:42 +02:00
1 parent 64eb85e409
commit a1501b4fe7
6 files changed
+194 -163

No files matched your search

+4 -4
View File
@@ -7,7 +7,7 @@
"name": "@appwrite/console",
"dependencies": {
"@analytics/google-analytics": "^1.0.5",
"@appwrite.io/console": "npm:matej-appwrite-console@7.1.68",
"@appwrite.io/console": "npm:matej-appwrite-console@7.1.74",
"@appwrite.io/pink": "0.0.6-rc.10",
"@popperjs/core": "^2.11.6",
"@sentry/svelte": "^7.44.2",
@@ -148,9 +148,9 @@
},
"node_modules/@appwrite.io/console": {
"name": "matej-appwrite-console",
"version": "7.1.68",
"resolved": "https://registry.npmjs.org/matej-appwrite-console/-/matej-appwrite-console-7.1.68.tgz",
"integrity": "sha512-as9TjhuBpIXoUtVNTvvVV7umdrNp2cpnKuMC2HusQLlAtrZOdVjZfaoaEyCxpAdkbUIrIuvmEwW8fvb39UNsFA==",
"version": "7.1.74",
"resolved": "https://registry.npmjs.org/matej-appwrite-console/-/matej-appwrite-console-7.1.74.tgz",
"integrity": "sha512-cFpQNAf7lfnCoZDvXEu0JPiN3Bh1aWsX9VOa3h3C3UCDcpxtq8/UPnOeXJReMSrDgT4GoMUV2ug1oRvlzci4pw==",
"dependencies": {
"cross-fetch": "3.1.5",
"isomorphic-form-data": "2.0.0"
+1 -1
View File
@@ -19,7 +19,7 @@
},
"dependencies": {
"@analytics/google-analytics": "^1.0.5",
"@appwrite.io/console": "npm:matej-appwrite-console@7.1.68",
"@appwrite.io/console": "npm:matej-appwrite-console@7.1.74",
"@appwrite.io/pink": "0.0.6-rc.10",
"@popperjs/core": "^2.11.6",
"@sentry/svelte": "^7.44.2",
+2 -1
View File
@@ -3,6 +3,7 @@
export let label: string;
export let optionalText: string | undefined = undefined;
export let tooltip: string = null;
export let showLabel = true;
export let id: string;
export let value = false;
@@ -27,7 +28,7 @@
</script>
<FormItem>
<Label {required} {optionalText} hide={!showLabel} for={id}>
<Label {required} {tooltip} {optionalText} hide={!showLabel} for={id}>
{label}
</Label>
+17 -1
View File
@@ -8,6 +8,7 @@
export let value = false;
export let required = false;
export let disabled = false;
export let tooltip: string = null;
let element: HTMLInputElement;
let error: string;
@@ -39,7 +40,22 @@
on:invalid={handleInvalid} />
<div class="choice-item-content">
<div class:u-hide={!showLabel} class="choice-item-title">{label}</div>
<div class:u-hide={!showLabel} class="choice-item-title u-flex u-cross-center u-gap-4">
{label}
{#if tooltip}
<button class="tooltip" aria-label="variables info">
<span
class="icon-info"
aria-hidden="true"
style="font-size: var(--icon-size-small)" />
<span class="tooltip-popup" role="tooltip">
<p class="text">
{tooltip}
</p>
</span>
</button>
{/if}
</div>
{#if $$slots}
<p class="choice-item-paragraph"><slot /></p>
{/if}
@@ -1,83 +0,0 @@
<script lang="ts">
import { invalidate } from '$app/navigation';
import { Submit, trackError, trackEvent } from '$lib/actions/analytics';
import Modal from '$lib/components/modal.svelte';
import { Dependencies } from '$lib/constants';
import Button from '$lib/elements/forms/button.svelte';
import { base } from '$app/paths';
import { app } from '$lib/stores/app';
import { addNotification } from '$lib/stores/notifications';
import { sdk } from '$lib/stores/sdk';
import type { Models } from '@appwrite.io/console';
import { Avatar } from '$lib/components';
export let showGitDisconnect: boolean;
export let selectedInstallation: Models.Installation;
async function handleSubmit() {
try {
await sdk.forProject.vcs.deleteInstallation(selectedInstallation.$id);
await invalidate(Dependencies.PROJECT_INSTALLATIONS);
addNotification({
message: `${selectedInstallation.organization} has been disconnected from your project`,
type: 'success'
});
trackEvent(Submit.InstallationDelete, {
customId: selectedInstallation.$id
});
showGitDisconnect = false;
} catch (error) {
addNotification({
message: error.message,
type: 'error'
});
trackError(error, Submit.InstallationDelete);
showGitDisconnect = false;
}
}
</script>
<Modal
icon="exclamation"
state="warning"
headerDivider={false}
bind:show={showGitDisconnect}
onSubmit={handleSubmit}
size="small">
<svelte:fragment slot="header">Disconnect installation</svelte:fragment>
{#if selectedInstallation.functions.length > 0}
<p>
Are you sure you want to disconnect this git installation? This will affect future
deployments to the following functions:
</p>
<div class="u-flex u-flex-vertical u-gap-12">
{#each selectedInstallation.functions as func}
<div class="u-flex u-main-space-between u-cross-center u-width-full-line">
<div class="u-flex u-main-start u-cross-center u-gap-8">
<Avatar
size={24}
name={func.runtime.split('-')[0]}
src={`${base}/icons/${$app.themeInUse}/color/${
func.runtime.split('-')[0]
}.svg`} />
<h6>{func.name}</h6>
</div>
<p class="u-x-small" style="color: hsl(var(--color-neutral-70));">
Last deployed: 12m ago
</p>
</div>
{/each}
</div>
{:else}
<p>Are you sure you want to disconnect this git installation?</p>
{/if}
<svelte:fragment slot="footer">
<Button text on:click={() => (showGitDisconnect = false)}>Cancel</Button>
<Button secondary submit={true}>Disconnect</Button>
</svelte:fragment>
</Modal>
@@ -1,112 +1,209 @@
<script lang="ts">
import { base } from '$app/paths';
import { page } from '$app/stores';
import { EmptySearch, PaginationInline } from '$lib/components';
import Modal from '$lib/components/modal.svelte';
import { InputSearch, InputSelect } from '$lib/elements/forms';
import Button from '$lib/elements/forms/button.svelte';
import { app } from '$lib/stores/app';
import { Submit, trackError, trackEvent } from '$lib/actions/analytics';
import { Box, EmptySearch, Modal, PaginationInline } from '$lib/components';
import { Dependencies } from '$lib/constants';
import { InputChoice, InputSearch, InputSelect, InputText, Button } from '$lib/elements/forms';
import { toLocaleDateTime } from '$lib/helpers/date';
import { addNotification } from '$lib/stores/notifications';
import { sdk } from '$lib/stores/sdk';
import { type Models } from '@appwrite.io/console';
import type { Models } from '@appwrite.io/console';
import { func } from '../store';
import { invalidate } from '$app/navigation';
export let show: boolean;
export let installations: Models.InstallationList;
const functionId = $page.params.function;
let selectedRepo: string;
let step = 1;
let installation: string;
let search: string;
let repositories: Models.RepositoryList;
let repositoriesList: Models.RepositoryList;
let branchesList: Models.BranchList;
let offset = 0;
let selectedBranch: string;
let selectedDir: string;
let silentMode = false;
let options = installations.installations.map((installation) => {
let installationsOptions = installations.installations.map((installation) => {
return {
value: installation.$id,
label: installation.provider
};
});
async function request() {
if (!show) return;
repositories = await sdk.forProject.vcs.listRepositories(installation, search);
async function handleSubmit() {
try {
await sdk.forProject.functions.update(
functionId,
$func.name,
$func.execute || undefined,
$func.events || undefined,
$func.schedule || undefined,
$func.timeout || undefined,
$func.enabled,
$func.logging,
$func.entrypoint,
$func.buildCommand,
$func.installCommand,
installation,
selectedRepo,
selectedBranch,
silentMode,
selectedDir
);
await invalidate(Dependencies.FUNCTION);
addNotification({
type: 'success',
message: `${$func.name} git configuration has been updated successfully`
});
trackEvent(Submit.FunctionUpdateConfiguration);
show = false;
} catch (error) {
addNotification({
type: 'error',
message: error.message
});
trackError(error, Submit.FunctionUpdateConfiguration);
}
}
async function getRepos() {
if (!show || !installation) return;
repositoriesList = await sdk.forProject.vcs.listRepositories(installation, search);
}
async function getBranches() {
if (!show || !installation) return;
branchesList = await sdk.forProject.vcs.listRepositoryBranches(installation, selectedRepo);
selectedBranch = branchesList?.branches[0].name;
}
$: if (search !== null) {
offset = 0;
request();
getRepos();
}
</script>
<Modal headerDivider={false} bind:show size="big">
<Modal headerDivider={false} bind:show size="big" onSubmit={handleSubmit}>
<svelte:fragment slot="header">Git configuration</svelte:fragment>
<p class="text">
Configure a Git repository that will trigger your function deployments when updated.
</p>
{#if step === 1}
{#await getRepos()}
loading...
{:then}
<InputSelect
options={installationsOptions}
id="installations"
label="installation"
showLabel={false}
bind:value={installation} />
<InputSearch placeholder="Search repositories" bind:value={search} />
<InputSelect
{options}
id="installations"
label="installation"
showLabel={false}
bind:value={installation} />
<InputSearch placeholder="Search repositories" bind:value={search} />
<p class="text">
Manage organization configuration in your <a
class="link"
href={`${base}/console/project-${$page.params.project}/settings`}
>project settings</a
>.
</p>
{#if repositoriesList?.total}
{#each repositoriesList.repositories as repo}
<ul class="u-flex u-gap-16 u-cross-center">
<li>
<label class="input-radio">
<input
type="radio"
name={repo.name}
bind:group={selectedRepo}
value={repo.id} />
</label>
</li>
<p class="text">
Manage organization configuration in your <a
class="link"
href={`${base}/console/project-${$page.params.project}/settings`}>project settings</a
>.
</p>
{#if repositories?.total}
{#each repositories.repositories as repo}
<div class="u-flex u-gap-16 u-cross-center">
<!-- <div class="avatar is-medium">
<img
src={`${base}/icons/${$app.themeInUse}/color/${
repo.runtime.split('-')[0]
}.svg`}
alt="technology" />
</div> -->
<span class="text">{repo.name}</span>
</div>
{/each}
<div class="u-flex u-margin-block-start-32 u-main-space-between">
<p class="text">Total results: {repositories?.total}</p>
<PaginationInline limit={5} bind:offset sum={repositories?.total} hidePages />
</div>
{:else if search}
<EmptySearch hidePages>
<div class="common-section">
<div class="u-text-center common-section">
<b class="body-text-2 u-bold">Sorry we couldn't find "{search}"</b>
<p>There are no repositories that match your search.</p>
<span class="text">{repo.name}</span>
</ul>
{/each}
<div class="u-flex u-margin-block-start-32 u-main-space-between">
<p class="text">Total results: {repositoriesList?.total}</p>
<PaginationInline
limit={5}
bind:offset
sum={repositoriesList?.total}
hidePages />
</div>
<div class="u-flex u-gap-16 common-section u-main-center">
<Button external href="https://appwrite.io/docs/client/teams" text
>Documentation</Button>
<Button secondary on:click={() => (search = '')}>Clear search</Button>
</div>
</div>
</EmptySearch>
{:else if search}
<EmptySearch hidePages>
<div class="common-section">
<div class="u-text-center common-section">
<b class="body-text-2 u-bold">Sorry we couldn't find "{search}"</b>
<p>There are no repositories that match your search.</p>
</div>
<div class="u-flex u-gap-16 common-section u-main-center">
<Button external href="https://appwrite.io/docs/client/teams" text
>Documentation</Button>
<Button secondary on:click={() => (search = '')}>Clear search</Button>
</div>
</div>
</EmptySearch>
{:else}
<EmptySearch hidePages>
<div class="common-section">
<div class="u-text-center common-section">
<p class="text u-line-height-1-5">You have no repositories.</p>
<p class="text u-line-height-1-5">
Need a hand? Learn more in our <a
href="https://appwrite.io/docs/client/teams"
target="_blank"
rel="noopener noreferrer">
documentation</a
>.
</p>
</div>
</div>
</EmptySearch>
{/if}
{/await}
{:else}
<EmptySearch hidePages>
<div class="common-section">
<div class="u-text-center common-section">
<p class="text u-line-height-1-5">You have no repositories.</p>
<p class="text u-line-height-1-5">
Need a hand? Learn more in our <a
href="https://appwrite.io/docs/client/teams"
target="_blank"
rel="noopener noreferrer">
documentation</a
>.
</p>
</div>
</div>
</EmptySearch>
{#await getBranches()}
loading...
{:then}
<Box>
<svelte:fragment slot="title">
<h6 class="u-bold u-trim-1">{selectedRepo}</h6>
</svelte:fragment>
<p>Last updated: {toLocaleDateTime(selectedRepo)}</p>
</Box>
<InputSelect
id="branch"
label="Branch"
options={branchesList?.branches?.map((branch) => {
return {
value: branch.name,
label: branch.name
};
}) ?? []}
bind:value={selectedBranch} />
<InputText id="root" label="Root directory" bind:value={selectedDir} />
<InputChoice
id="silent"
label="Silent mode"
tooltip="I don't know 🤷"
bind:value={silentMode} />
{/await}
{/if}
<svelte:fragment slot="footer">
<Button secondary on:click={() => (show = false)}>Cancel</Button>
<Button secondary on:click={() => step++}>Next</Button>
{#if step === 1}
<Button secondary on:click={() => (show = false)}>Cancel</Button>
<Button secondary disabled={!selectedRepo} on:click={() => step++}>Next</Button>
{:else}
<Button secondary on:click={() => step--}>Back</Button>
<Button submit>Deploy now</Button>
{/if}
</svelte:fragment>
</Modal>