Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEAT Enable/Disable all services - UI #365

Merged
merged 19 commits into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/routes/console/organization-[organization]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import CreateOrganization from '../createOrganization.svelte';
import type { PageData } from './$types';
import { page } from '$app/stores';
import { services } from '$lib/stores/project-services';
import type { Models } from '@appwrite.io/console';

export let data: PageData;

Expand Down Expand Up @@ -38,6 +40,17 @@
return { name, icon };
};

function allServiceDisabled(project: Models.Project): boolean {
let disabled = true;
services.load(project);
$services.list.forEach((service) => {
if (service.value) {
disabled = false;
}
});
return disabled;
}

function filterPlatforms(platforms: { name: string; icon: string }[]) {
return platforms.filter(
(value, index, self) => index === self.findIndex((t) => t.name === value.name)
Expand Down Expand Up @@ -67,6 +80,11 @@
<svelte:fragment slot="title">
{project.name}
</svelte:fragment>
{#if allServiceDisabled(project)}
<p>
<span class="icon-pause" aria-hidden="true" /> All services are disabled.
</p>
{/if}
{@const platforms = filterPlatforms(
project.platforms.map((platform) => getPlatformInfo(platform.type))
)}
Expand Down
62 changes: 61 additions & 1 deletion src/routes/console/project-[project]/settings/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import { base } from '$app/paths';
import { page } from '$app/stores';
import { Submit, trackEvent, trackError } from '$lib/actions/analytics';
import EnableAllServices from './enableAllServices.svelte';
import DisableAllServices from './disableAllServices.svelte';
import Transfer from './transferProject.svelte';

let name: string = null;
Expand All @@ -30,6 +32,8 @@
let showTransfer = false;
const endpoint = sdk.forConsole.client.config.endpoint;
const projectId = $page.params.project;
let showDisableAll = false;
let showEnableAll = false;

onMount(async () => {
name ??= $project.name;
Expand All @@ -54,6 +58,50 @@
}
}

async function toggleAllServices(status: boolean) {
if (status && !showEnableAll) {
showEnableAll = true;
return;
}
if (!status && !showDisableAll) {
showDisableAll = true;
return;
}

try {
const path = '/projects/' + $project.$id + '/service/all';
await sdk.forConsole.client.call(
'PATCH',
new URL(sdk.forConsole.client.config.endpoint + path),
{
'content-type': 'application/json'
},
{
status: status
}
);
invalidate(Dependencies.PROJECT);
addNotification({
type: 'success',
message:
'All services for ' +
$project.name +
' has been ' +
(status ? 'enabled.' : 'disabled.')
});
trackEvent(Submit.ProjectService);
} catch (error) {
addNotification({
type: 'error',
message: error.message
});
trackError(error, Submit.ProjectService);
} finally {
showDisableAll = false;
showEnableAll = false;
}
}

async function serviceUpdate(service: Service) {
try {
await sdk.forConsole.projects.updateServiceStatus(
Expand Down Expand Up @@ -132,8 +180,18 @@
services are not accessible to client SDKs but remain accessible to server SDKs.
</p>
<svelte:fragment slot="aside">
<ul class="buttons-list u-main-end">
<li class="buttons-list-item">
<Button text={true} on:click={() => toggleAllServices(true)}
>Enable all</Button>
</li>
<li class="buttons-list-item">
<Button text={true} on:click={() => toggleAllServices(false)}
>Disable all</Button>
</li>
</ul>
<FormList>
<form class="form">
<form class="form card-separator">
<ul class="form-list is-multiple">
{#each $services.list as service}
<InputSwitch
Expand Down Expand Up @@ -198,6 +256,8 @@
</Container>

<Delete bind:showDelete />
<DisableAllServices handleDisableAll={() => toggleAllServices(false)} bind:show={showDisableAll} />
<EnableAllServices handleEnableAll={() => toggleAllServices(true)} bind:show={showEnableAll} />
{#if teamId}
<Transfer
bind:teamId
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<script lang="ts">
import { Modal } from '$lib/components';
import { Button } from '$lib/elements/forms';

export let show = false;
export let handleDisableAll;
</script>

<Modal icon="exclamation" state="warning" bind:show onSubmit={handleDisableAll}>
<svelte:fragment slot="header">Disable all services</svelte:fragment>
<p class="text" data-private>
Are you sure you want to disable all services? This will disable API requests to your
project.
</p>
<svelte:fragment slot="footer">
<Button text on:click={() => (show = false)}>Cancel</Button>
<Button secondary submit>Disable All</Button>
</svelte:fragment>
</Modal>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<script lang="ts">
import { Modal } from '$lib/components';
import { Button } from '$lib/elements/forms';

export let show = false;
export let handleEnableAll;
</script>

<Modal bind:show onSubmit={handleEnableAll}>
<svelte:fragment slot="header">Enable all services</svelte:fragment>
<p class="text" data-private>All project services will be enabled.</p>
<svelte:fragment slot="footer">
<Button text on:click={() => (show = false)}>Cancel</Button>
<Button secondary submit>Enable all</Button>
</svelte:fragment>
</Modal>