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

Show participant is sharing with DSP when allow_sites is null #207

Merged
merged 5 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
25 changes: 11 additions & 14 deletions src/api/services/adminServiceClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,22 @@ const adminServiceClient = axios.create({
},
});

const DEFAULT_SHARING_SETTINGS: Pick<SharingListResponse, 'allowed_sites' | 'allowed_types'> = {
allowed_types: ['DSP'],
allowed_sites: [],
};

export const getSharingList = async (siteId: number): Promise<SharingListResponse> => {
try {
const response = await adminServiceClient.get<SharingListResponse>(
`/api/sharing/list/${siteId}`,
{
validateStatus: (status) => (status >= 200 && status < 300) || status === 404,
validateStatus: (status) => status >= 200 && status < 300,
}
);
return response.status === 200
return response.data.allowed_sites
? response.data
: {
allowed_sites: [],
allowed_types: [],
hash: 0,
};
: { ...response.data, ...DEFAULT_SHARING_SETTINGS };
} catch (error: unknown) {
const [logger] = getLoggers();
logger.error(`Get ACLs failed: ${error}`);
Expand All @@ -52,16 +53,12 @@ export const updateSharingList = async (
hash,
},
{
validateStatus: (status) => (status >= 200 && status < 300) || status === 404,
validateStatus: (status) => status >= 200 && status < 300,
}
);
return response.status === 200
return response.data.allowed_sites
? response.data
: {
allowed_sites: [],
allowed_types: [],
hash: 0,
};
: { ...response.data, ...DEFAULT_SHARING_SETTINGS };
} catch (error: unknown) {
const [logger] = getLoggers();
logger.error(`Update ACLs failed: ${error}`);
Expand Down
22 changes: 14 additions & 8 deletions src/web/screens/sharingPermissions.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useCallback, useContext, useEffect, useState } from 'react';
import { useContext, useEffect, useState } from 'react';

import { ClientType } from '../../api/services/adminServiceHelpers';
import { Collapsible } from '../components/Core/Collapsible';
Expand All @@ -14,6 +14,8 @@ import {
GetSharingList,
UpdateSharingTypes,
} from '../services/participant';
import { ApiError } from '../utils/apiError';
import { useAsyncError } from '../utils/errorHandler';
import { PortalRoute } from './routeUtils';

import './sharingPermissions.scss';
Expand All @@ -24,6 +26,7 @@ function SharingPermissions() {
const [sharedSiteIds, setSharedSiteIds] = useState<number[]>([]);
const [sharedTypes, setSharedTypes] = useState<ClientType[]>([]);
const [statusPopup, setStatusPopup] = useState<StatusNotificationType>();
const throwError = useAsyncError();

const handleSaveSharingType = async (selectedTypes: ClientType[]) => {
try {
Expand Down Expand Up @@ -91,15 +94,18 @@ function SharingPermissions() {
}
};

const loadSharingList = useCallback(async () => {
const response = await GetSharingList();
setSharedSiteIds(response.allowed_sites);
setSharedTypes(response.allowed_types ?? []);
}, []);

useEffect(() => {
const loadSharingList = async () => {
try {
const response = await GetSharingList();
setSharedSiteIds(response.allowed_sites);
setSharedTypes(response.allowed_types ?? []);
} catch (e: unknown) {
if (e instanceof ApiError) throwError(e);
}
};
loadSharingList();
}, [loadSharingList]);
}, [throwError]);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should provide a better error experience here - if there's a 404 from the admin service, we know exactly what's wrong. Just dumping the user to an error where they can't even see the menu any more isn't the right move.


return (
<div className='sharingPermissions'>
Expand Down