Skip to content

Commit 6a892de

Browse files
committed
Add synchronize team
1 parent f958c27 commit 6a892de

File tree

2 files changed

+74
-1
lines changed

2 files changed

+74
-1
lines changed

src/lib/GraphErrors.svelte

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<script lang="ts">
2+
import { Alert, Button } from '@nais/ds-svelte-community';
3+
4+
type error = { message: string };
5+
6+
export let size: 'small' | 'medium' = 'medium';
7+
export let errors: error[];
8+
export let dismissable = false;
9+
10+
const pick = (errors: error[]) => {
11+
const unique: string[] = [];
12+
errors.forEach((error) => {
13+
if (!unique.includes(error.message)) {
14+
unique.push(error.message);
15+
}
16+
});
17+
return unique;
18+
};
19+
</script>
20+
21+
{#if errors.length > 0}
22+
<Alert variant="error" {size}>
23+
{#each pick(errors) as error}
24+
{error}
25+
{/each}
26+
{#if dismissable}
27+
<Button variant="tertiary" size="small" on:click={() => (errors = [])}>Dismiss</Button>
28+
{/if}
29+
</Alert>
30+
{/if}

src/routes/team/[team]/(teamTabs)/settings/+page.svelte

+44-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import { page } from '$app/stores';
44
import { PendingValue, graphql } from '$houdini';
55
import Card from '$lib/Card.svelte';
6+
import GraphErrors from '$lib/GraphErrors.svelte';
67
import Time from '$lib/Time.svelte';
78
import { Alert, Button, CopyButton, Loader, Modal, Skeleton } from '@nais/ds-svelte-community';
89
import {
@@ -11,6 +12,7 @@
1112
EyeIcon,
1213
EyeSlashIcon
1314
} from '@nais/ds-svelte-community/icons';
15+
import { slide } from 'svelte/transition';
1416
import type { PageData } from './$houdini';
1517
import EditText from './EditText.svelte';
1618
@@ -103,6 +105,16 @@
103105
const [, projectId, , location, , repository] = repo.split('/');
104106
return `${location}-docker.pkg.dev/${projectId}/${repository}`;
105107
};
108+
109+
const synchronizeTeam = graphql(`
110+
mutation SynchronizeTeam($slug: Slug!) {
111+
synchronizeTeam(slug: $slug) {
112+
correlationID
113+
}
114+
}
115+
`);
116+
117+
let synchronizeClicked = false;
106118
</script>
107119

108120
{#if $TeamSettings.errors}
@@ -232,7 +244,32 @@
232244
{/if}
233245
</Card>
234246
<Card columns={6}>
235-
<h3>Managed resources</h3>
247+
<h3 class="with_button">
248+
Managed resources
249+
<Button
250+
size="xsmall"
251+
variant="secondary"
252+
loading={$synchronizeTeam.fetching}
253+
on:click={async () => {
254+
await synchronizeTeam.mutate({ slug: team });
255+
synchronizeClicked = true;
256+
}}
257+
>
258+
Synchronize team
259+
</Button>
260+
</h3>
261+
{#if $synchronizeTeam.errors}
262+
<GraphErrors errors={$synchronizeTeam.errors} dismissable={true} />
263+
{:else if synchronizeClicked}
264+
<div transition:slide={{ duration: 200 }}>
265+
<Alert variant="success" size="small">
266+
Synchronization started, team resources will soon be updated.
267+
<Button size="xsmall" variant="tertiary" on:click={() => (synchronizeClicked = false)}>
268+
Dismiss
269+
</Button>
270+
</Alert>
271+
</div>
272+
{/if}
236273
{#if teamSettings.id === PendingValue}
237274
<Loader />
238275
{:else}
@@ -412,4 +449,10 @@
412449
flex-direction: row;
413450
gap: 0.5rem;
414451
}
452+
453+
h3.with_button {
454+
display: flex;
455+
justify-content: space-between;
456+
align-items: center;
457+
}
415458
</style>

0 commit comments

Comments
 (0)