-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show organizations in summary section on project page (#921)
Implements features that show organizations in summary on project page if any. If the project does not belong to any organizations, there would be a button to add an organization, but you have to be a project manager AND a member of the organization that you are trying to add the project to. * show org in project summary * show name of the org * create button to add org to project * only project manager can add org * add error handling & refactor type * extract getOrgs into its own method * cache invalidation for addProjectToOrg mutation
- Loading branch information
Showing
6 changed files
with
168 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
frontend/src/routes/(authenticated)/project/[project_code]/AddOrganization.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<script lang="ts"> | ||
import { z } from 'zod'; | ||
import t from '$lib/i18n'; | ||
import { Select } from '$lib/forms'; | ||
import { _addProjectToOrg, _getOrgs } from './+page'; | ||
import type { Organization } from '$lib/gql/types'; | ||
import { FormModal } from '$lib/components/modals'; | ||
import { BadgeButton } from '$lib/components/Badges'; | ||
type Org = Pick<Organization, 'id' | 'name'>; | ||
export let projectId: string; | ||
export let userIsAdmin: boolean; | ||
let orgList: Org[] = []; | ||
const schema = z.object({ | ||
orgId: z.string().trim() | ||
}); | ||
type Schema = typeof schema; | ||
let formModal: FormModal<Schema>; | ||
$: form = formModal?.form(); | ||
async function openModal(): Promise<void> { | ||
orgList = await _getOrgs(userIsAdmin); | ||
await formModal.open(async () => { | ||
const { error } = await _addProjectToOrg({ | ||
projectId, | ||
orgId: $form.orgId, | ||
}) | ||
if (error?.byType('NotFoundError')) { | ||
if (error.message === 'Organization not found') return $t('project_page.add_org.org_not_found'); | ||
if (error.message === 'Project not found') return $t('project_page.add_org.project_not_found'); | ||
} | ||
}); | ||
} | ||
</script> | ||
|
||
<BadgeButton variant="badge-success" icon="i-mdi-account-plus-outline" on:click={openModal}> | ||
{$t('project_page.add_org.add_button')} | ||
</BadgeButton> | ||
|
||
<FormModal bind:this={formModal} {schema} let:errors> | ||
<span slot="title">{$t('project_page.add_org.modal_title')}</span> | ||
<Select | ||
id="org" | ||
label={$t('project_page.organization.title')} | ||
bind:value={$form.orgId} | ||
error={errors.orgId} | ||
> | ||
{#each orgList as org} | ||
<option value={org.id}>{org.name}</option> | ||
{/each} | ||
</Select> | ||
<span slot="submitText">{$t('project_page.add_org.submit_button')}</span> | ||
</FormModal> |
31 changes: 31 additions & 0 deletions
31
frontend/src/routes/(authenticated)/project/[project_code]/OrgList.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<script lang="ts"> | ||
import t from '$lib/i18n'; | ||
import { Badge, BadgeList } from '$lib/components/Badges'; | ||
import type { Organization } from '$lib/gql/types'; | ||
type Org = Pick<Organization, 'id' | 'name'>; | ||
export let organizations: Org[] = []; | ||
const TRUNCATED_MEMBER_COUNT = 5; | ||
</script> | ||
|
||
|
||
<div> | ||
<p class="text-2xl mb-4 flex items-baseline gap-4 max-sm:flex-col"> | ||
{$t('project_page.organization.title')} | ||
</p> | ||
|
||
<BadgeList grid={organizations.length > TRUNCATED_MEMBER_COUNT}> | ||
{#if !organizations.length} | ||
<span class="text-secondary mx-2 my-1">{$t('common.none')}</span> | ||
<div class="flex grow flex-wrap place-self-end gap-3 place-content-end" style="grid-column: -2 / -1"> | ||
<slot name="extraButtons" /> | ||
</div> | ||
{/if} | ||
{#each organizations as org (org.id)} | ||
<Badge> | ||
{org.name} | ||
</Badge> | ||
{/each} | ||
</BadgeList> | ||
</div> |