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

Bugfix/api delegations/384 list scopes in overview #422

Merged
merged 3 commits into from
Jun 13, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
13 changes: 3 additions & 10 deletions src/components/DelegationActionBar/DelegationActionBar.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Button, List, ListItem } from '@digdir/design-system-react';
import { Button } from '@digdir/design-system-react';
import { useState } from 'react';
import * as React from 'react';
import { useTranslation } from 'react-i18next';
Expand All @@ -8,6 +8,7 @@ import { ReactComponent as AddCircle } from '@/assets/AddCircle.svg';

import { Line } from '../Line';
import { ActionBar, type ActionBarProps } from '../ActionBar';
import ScopeList from '../ScopeList/ScopeList';

import classes from './DelegationActionBar.module.css';

Expand Down Expand Up @@ -73,15 +74,7 @@ export const DelegationActionBar = ({
{scopeList.length > 0 && (
<div>
<p className={classes.scopeText}>{t('api_delegation.scopes')}:</p>
<List borderStyle='dashed'>
{scopeList.map((scope, i) => {
return (
<ListItem key={i}>
<div className={classes.scopeItems}>{scope}</div>
</ListItem>
);
})}
</List>
<ScopeList scopeList={scopeList} />
</div>
)}
{topContentText && (
Expand Down
9 changes: 9 additions & 0 deletions src/components/DeletableListItem/DeletableListItem.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,13 @@
margin-bottom: 0.7rem;
word-break: break-word;
font-weight: 400;
}

.scopeText{
font-weight: 300;
}

.scopeListContainer{
margin-top: 30px;
margin-bottom: 30px;
}
10 changes: 10 additions & 0 deletions src/components/DeletableListItem/DeletableListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,24 @@ import { ReactComponent as MinusCircle } from '@/assets/MinusCircle.svg';
import { ReactComponent as Cancel } from '@/assets/Cancel.svg';
import { useMediaQuery } from '@/resources/hooks';

import ScopeList from '../ScopeList/ScopeList';

import classes from './DeletableListItem.module.css';

export interface DeletableListItemProps {
softDeleteCallback: () => void;
softRestoreCallback: () => void;
item: ApiListItem;
isEditable: boolean;
scopes?: string[];
}

export const DeletableListItem = ({
softDeleteCallback,
softRestoreCallback,
item,
isEditable,
scopes,
}: DeletableListItemProps) => {
const { t } = useTranslation('common');
const isSm = useMediaQuery('(max-width: 768px)');
Expand Down Expand Up @@ -64,6 +68,12 @@ export const DeletableListItem = ({
<div className={classes.listItemTexts}>
<div className={classes.apiListItem}>{item.apiName}</div>
<div className={classes.ownerListItem}>{item.owner}</div>
{scopes && (
<div className={classes.scopeListContainer}>
<p className={classes.scopeText}>{t('api_delegation.scopes')}:</p>
<ScopeList scopeList={scopes} />
</div>
)}
<div>{item.description}</div>
</div>
</div>
Expand Down
4 changes: 4 additions & 0 deletions src/components/ScopeList/ScopeList.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.scopeItems {
word-break: break-word;
margin: 10px;
}
22 changes: 22 additions & 0 deletions src/components/ScopeList/ScopeList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { List, ListItem } from '@digdir/design-system-react';
import * as React from 'react';

import classes from './ScopeList.module.css';

export interface ScopeListProps {
scopeList: string[];
}

const ScopeList = ({ scopeList }: ScopeListProps) => {
return (
<List borderStyle='dashed'>
{scopeList.map((scope, i) => (
<ListItem key={i}>
<div className={classes.scopeItems}>{scope}</div>
</ListItem>
))}
</List>
);
};

export default ScopeList;
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export const OrgDelegationActionBar = ({
softRestoreCallback={() => dispatch(softRestore([organization.id, item.id]))}
item={item}
isEditable={isEditable}
scopes={item.scopes}
></DeletableListItem>
));

Expand Down Expand Up @@ -135,7 +136,7 @@ export const OrgDelegationActionBar = ({
}
>
<div className={classes.actionBarContent}>
<List borderStyle={'dashed'}>{listItems}</List>
<List borderStyle={'solid'}>{listItems}</List>
</div>
</ActionBar>
);
Expand Down
14 changes: 14 additions & 0 deletions src/rtk/features/apiDelegation/overviewOrg/overviewOrgSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export interface ApiListItem {
isSoftDelete: boolean;
owner: string;
description: string;
scopes: string[];
}

export interface OverviewOrg {
Expand All @@ -22,6 +23,11 @@ export interface OverviewOrg {
apiList: ApiListItem[];
}

interface ResourceReference {
reference: string;
referenceSource: string;
referenceType: string;
}
interface DelegationDTO {
coveredByName: string;
offeredByName: string;
Expand All @@ -31,6 +37,7 @@ interface DelegationDTO {
resourceTitle: string;
resourceOwnerName: string;
rightDescription: string;
resourceReferences: ResourceReference[];
}

export interface SliceState {
Expand All @@ -56,13 +63,20 @@ const initialState: SliceState = {
const mapToOverviewOrgList = (delegationArray: DelegationDTO[], layout: LayoutState) => {
const overviewOrgList: OverviewOrg[] = [];
for (const delegation of delegationArray) {
console.log('delegationblabla', delegation);
Albertlarsen marked this conversation as resolved.
Show resolved Hide resolved
const api: ApiListItem = {
id: delegation.resourceId,
apiName: delegation.resourceTitle,
isSoftDelete: false,
owner: delegation.resourceOwnerName,
description: delegation.rightDescription,
scopes: [],
};
for (const ref of delegation.resourceReferences) {
if (ref.referenceType === 'MaskinportenScope') {
api.scopes.push(ref.reference);
}
}

let delegationOrg = '';
let delegationOrgNumber = '';
Expand Down