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

fix(website): don't display data as "restricted" when the last restricted data use terms expired #2914

Merged
merged 1 commit into from
Oct 1, 2024
Merged
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
19 changes: 9 additions & 10 deletions website/src/components/SequenceDetailsPage/SequenceDataUI.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import type { FC } from 'react';

import DataTable from './DataTable';
import { RevokeButton } from './RevokeButton';
import { SequencesContainer } from './SequencesContainer';
import { getDataTableData } from './getDataTableData';
import { type TableDataEntry } from './types';
import { routes } from '../../routes/routes';
import { type DataUseTermsHistoryEntry, type Group } from '../../types/backend';
import { DATA_USE_TERMS_FIELD } from '../../settings.ts';
import { type DataUseTermsHistoryEntry, type Group, type RestrictedDataUseTerms } from '../../types/backend';
import { type Schema } from '../../types/config';
import { type ReferenceGenomesSequenceNames } from '../../types/referencesGenomes';
import { type RuntimeConfig, type ClientConfig } from '../../types/runtimeConfig';
import { type ClientConfig, type RuntimeConfig } from '../../types/runtimeConfig';
import { EditDataUseTermsButton } from '../DataUseTerms/EditDataUseTermsButton';
import ErrorBox from '../common/ErrorBox';
import MdiEye from '~icons/mdi/eye';
Expand All @@ -25,7 +28,7 @@ interface Props {
referenceGenomeSequenceNames: ReferenceGenomesSequenceNames;
}

export const SequenceDataUI: React.FC<Props> = ({
export const SequenceDataUI: FC<Props> = ({
tableData,
organism,
accessionVersion,
Expand All @@ -44,12 +47,8 @@ export const SequenceDataUI: React.FC<Props> = ({
dataUseTermsHistory.sort((a, b) => (a.changeDate > b.changeDate ? -1 : 1));
const currentDataUseTerms = dataUseTermsHistory[0].dataUseTerms;

const dataUseTermsIndex = tableData.findIndex((entry) => entry.name === 'dataUseTerms');
if (dataUseTermsIndex !== -1) {
tableData[dataUseTermsIndex].value = currentDataUseTerms.type;
}

const isRestricted = currentDataUseTerms.type === 'RESTRICTED';
const dataUseTerms = tableData.find((entry) => entry.name === DATA_USE_TERMS_FIELD);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const dataUseTerms = tableData.find((entry) => entry.name === DATA_USE_TERMS_FIELD);
const dataUseTerms = tableData.find((entry) => entry.name === DATA_USE_TERMS_FIELD);
// Calculation below is based on the assumption that dataUseTerms is a string
// Hence assert to get loud error instead of quiet false data
if (typeof dataUseTerms?.value !== 'string') {
throw new Error('Code assumes dataUseTerms are of type string. If it isn't, then need to change the calculation of isRestricted.');
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry - already merged. If you still think it's necessary, you can open a separate PR.

const isRestricted = dataUseTerms?.value.toString().toUpperCase() === 'RESTRICTED';

const genes = referenceGenomeSequenceNames.genes;
const nucleotideSegmentNames = referenceGenomeSequenceNames.nucleotideSequences;
Expand Down Expand Up @@ -95,7 +94,7 @@ export const SequenceDataUI: React.FC<Props> = ({
clientConfig={clientConfig}
accessToken={accessToken}
accessionVersion={[accessionVersion.split('.')[0]]}
dataUseTerms={currentDataUseTerms}
dataUseTerms={currentDataUseTerms as RestrictedDataUseTerms}
/>
)}

Expand Down
Loading