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

Austenem/CAT-790 Remove last modified sections #3607

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions CHANGELOG-remove-last-modified-sections.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Switch to using "Creation Date" for samples/donors and switch to using "Publication Date" or "Last Modified" for datasets.
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import { WorkspacesIcon } from 'js/shared-styles/icons';
import { useAnimatedSidebarPosition } from 'js/shared-styles/sections/TableOfContents/hooks';
import { LineClampWithTooltip } from 'js/shared-styles/text';
import { SecondaryBackgroundTooltip } from 'js/shared-styles/tooltips';
import { getEntityCreationInfo } from 'js/helpers/functions';

import { formatDate } from 'date-fns/format';
import ProcessedDataGroup from 'js/components/detailPage/ProcessedData/ProcessedDatasetGroup';
import { HelperPanelPortal } from '../../DetailLayout/DetailLayout';
import StatusIcon from '../../StatusIcon';
import { getDateLabelAndValue, useCurrentDataset } from '../../utils';
import { useCurrentDataset } from '../../utils';
import { HelperPanelButton } from './styles';
import { useTrackEntityPageEvent } from '../../useTrackEntityPageEvent';
import ProcessedDataWorkspaceMenu from '../ProcessedDataWorkspaceMenu';
Expand Down Expand Up @@ -68,7 +68,7 @@ function HelperPanelBody() {
if (!currentDataset) {
return null;
}
const [dateLabel, date] = getDateLabelAndValue(currentDataset);
const { creationLabel, creationDate } = getEntityCreationInfo(currentDataset);

const { title, description, pipeline, assay_display_name, creation_action, group_name } = currentDataset;
return (
Expand All @@ -87,7 +87,7 @@ function HelperPanelBody() {
<HelperPanelBodyItem label="Group">
<ProcessedDataGroup creation_action={creation_action} group_name={group_name} />
</HelperPanelBodyItem>
<HelperPanelBodyItem label={dateLabel}>{date && formatDate(date, 'yyyy-MM-dd')}</HelperPanelBodyItem>
<HelperPanelBodyItem label={creationLabel}>{creationDate}</HelperPanelBodyItem>
</>
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, { useState } from 'react';
import { formatDate } from 'date-fns/format';

import FactCheckRounded from '@mui/icons-material/FactCheckRounded';
import SummarizeRounded from '@mui/icons-material/SummarizeRounded';
Expand All @@ -22,11 +21,11 @@ import DataProducts from 'js/components/detailPage/files/DataProducts';
import VisualizationWrapper from 'js/components/detailPage/visualization/VisualizationWrapper';
import AnalysisDetails from 'js/components/detailPage/AnalysisDetails';
import Protocol from 'js/components/detailPage/Protocol';
import { getDateLabelAndValue } from 'js/components/detailPage/utils';
import { useSelectedVersionStore } from 'js/components/detailPage/VersionSelect/SelectedVersionStore';
import { useVersions } from 'js/components/detailPage/VersionSelect/hooks';
import { useTrackEntityPageEvent } from 'js/components/detailPage/useTrackEntityPageEvent';
import ProcessedDataGroup from 'js/components/detailPage/ProcessedData/ProcessedDatasetGroup';
import { getEntityCreationInfo } from 'js/helpers/functions';

import { DatasetTitle } from './DatasetTitle';
import { ProcessedDatasetAccordion } from './ProcessedDatasetAccordion';
Expand Down Expand Up @@ -72,7 +71,7 @@ function Contact() {
function SummaryAccordion() {
const { dataset } = useProcessedDatasetContext();
const { group_name, mapped_consortium, creation_action } = dataset;
const [dateLabel, dateValue] = getDateLabelAndValue(dataset);
const { creationLabel, creationDate } = getEntityCreationInfo(dataset);

return (
<Subsection title="Summary" icon={<SummarizeRounded />}>
Expand All @@ -83,9 +82,7 @@ function SummaryAccordion() {
</LabelledSectionText>
<LabelledSectionText label="Consortium">{mapped_consortium}</LabelledSectionText>
<Contact />
<LabelledSectionText label={dateLabel}>
{dateValue ? formatDate(new Date(dateValue), 'yyyy-MM-dd') : 'N/A'}
</LabelledSectionText>
<LabelledSectionText label={creationLabel}>{creationDate}</LabelledSectionText>
</Stack>
</Subsection>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ export type ProcessedDatasetDetails = ProcessedDatasetInfo &
| 'created_by_user_displayname'
| 'created_by_user_email'
| 'title'
| 'published_timestamp'
| 'created_timestamp'
| 'published_timestamp'
| 'last_modified_timestamp'
| 'metadata'
| 'protocol_url' // TODO: This is present for non-dataset entities, but not for datasets.
| 'dataset_type'
Expand Down Expand Up @@ -44,8 +45,9 @@ export function useProcessedDatasetDetails(uuid: string) {
'created_by_user_displayname',
'created_by_user_email',
'title',
'published_timestamp',
'created_timestamp',
'published_timestamp',
'last_modified_timestamp',
'metadata.dag_provenance_list',
'metadata.metadata',
'protocol_url',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { format } from 'date-fns/format';
import { isDataset, isSample, PartialEntity } from 'js/components/types';
import { Dataset, isDataset, isSample, PartialEntity } from 'js/components/types';
import { getEntityCreationInfo } from 'js/helpers/functions';

interface Column {
id: string;
label: string;
renderColumnCell: (entity: PartialEntity) => string | number;
renderColumnCell: (entity: PartialEntity & Partial<Pick<Dataset, 'published_timestamp'>>) => string | number;
}

const descendantCountsCol: Column = {
Expand All @@ -13,10 +13,18 @@ const descendantCountsCol: Column = {
renderColumnCell: ({ descendant_counts }) => descendant_counts?.entity_type?.Dataset ?? 0,
};

const lastModifiedTimestampCol: Column = {
id: 'last_modified_timestamp',
label: 'Last Modified',
renderColumnCell: ({ last_modified_timestamp }) => format(last_modified_timestamp ?? 0, 'yyyy-MM-dd'),
const createdTimestampCol: Column = {
id: 'created_timestamp',
label: 'Creation Date',
renderColumnCell: ({ entity_type, created_timestamp }) =>
getEntityCreationInfo({ entity_type, created_timestamp }).creationDate,
};

const publishedTimestampCol: Column = {
id: 'published_timestamp',
label: 'Publication Date',
renderColumnCell: ({ entity_type, published_timestamp }) =>
getEntityCreationInfo({ entity_type, published_timestamp }).creationDate,
};

const organCol: Column = {
Expand Down Expand Up @@ -46,9 +54,17 @@ const derivedSamplesColumns: Column[] = [
renderColumnCell: (entity) => (isSample(entity) ? entity.sample_category : ''),
},
descendantCountsCol,
lastModifiedTimestampCol,
createdTimestampCol,
];

const derivedDatasetsColumns = [dataTypesCol, statusCol, descendantCountsCol, lastModifiedTimestampCol];
const derivedDatasetsColumns = [dataTypesCol, statusCol, descendantCountsCol, publishedTimestampCol];

export { derivedSamplesColumns, derivedDatasetsColumns, lastModifiedTimestampCol, organCol, dataTypesCol, statusCol };
export {
derivedSamplesColumns,
derivedDatasetsColumns,
createdTimestampCol,
publishedTimestampCol,
organCol,
dataTypesCol,
statusCol,
};
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,15 @@ function MultiTileStack({ datasets, title }: { datasets: MultiAssayEntity[]; tit
</Stack>
<Stack direction="row" justifyContent="center" spacing={1} flexWrap="wrap">
{datasets?.map(
({ uuid, entity_type, hubmap_id, assay_display_name, descendant_counts, last_modified_timestamp }) => (
({
uuid,
entity_type,
hubmap_id,
assay_display_name,
descendant_counts,
published_timestamp,
created_timestamp,
}) => (
<EntityTile
key={uuid}
uuid={uuid}
Expand All @@ -38,7 +46,8 @@ function MultiTileStack({ datasets, title }: { datasets: MultiAssayEntity[]; tit
mapped_data_types: [assay_display_name[0]],
origin_samples,
origin_samples_unique_mapped_organs,
last_modified_timestamp,
published_timestamp,
created_timestamp,
entity_type,
descendant_counts,
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { produce } from 'immer';
import { useSearchHits } from 'js/hooks/useSearchData';
import { useFlaskDataContext } from 'js/components/Contexts';
import { Dataset, isDataset } from 'js/components/types';
import { getEntityCreationInfo } from 'js/helpers/functions';

const source = [
'uuid',
Expand All @@ -15,7 +16,8 @@ const source = [
'is_component',
'metadata',
'descendant_counts',
'last_modified_timestamp',
'published_timestamp',
'created_timestamp',
];

function getPrimaryMultiAssay(uuid: string) {
Expand Down Expand Up @@ -91,7 +93,8 @@ export type MultiAssayEntity = Pick<
| 'is_component'
| 'metadata'
| 'descendant_counts'
| 'last_modified_timestamp'
| 'published_timestamp'
| 'created_timestamp'
>;

function getMultiAssayType({ processing, is_component }: Pick<MultiAssayEntity, 'processing' | 'is_component'>) {
Expand All @@ -111,12 +114,17 @@ function buildRelatedDatasets({ entities }: { entities: MultiAssayEntity[] }) {
const multiAssayType = getMultiAssayType({ processing: curr.processing, is_component: curr.is_component });
if (draft[multiAssayType]) {
draft[multiAssayType].push(curr);
// Sort by if pushlished, and then by last_modified_timestamp
draft[multiAssayType].sort((a, b) => {
if (a.mapped_status === 'published' && b.mapped_status !== 'published') return -1;
if (a.mapped_status !== 'published' && b.mapped_status === 'published') return 1;
return b.last_modified_timestamp - a.last_modified_timestamp;
});
draft[multiAssayType]
.map((item) => ({
...item,
creationTimestamp: getEntityCreationInfo(item).creationTimestamp,
}))
// Sort by if published, and then by creation timestamp
.sort((a, b) => {
if (a.mapped_status === 'published' && b.mapped_status !== 'published') return -1;
if (a.mapped_status !== 'published' && b.mapped_status === 'published') return 1;
return b.creationTimestamp - a.creationTimestamp;
});
}
});
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ const provTableSource = [
'entity_type',
'descendant_counts',
'mapped_data_types',
'published_timestamp',
'last_modified_timestamp',
'created_timestamp',
'origin_samples_unique_mapped_organs',
'mapped_metadata',
'sample_category',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ describe('Summary', () => {
</FlaskDataContext.Provider>,
);

expect(screen.getByText('Creation Date')).toBeInTheDocument();
expect(screen.getAllByText('Undefined')).toHaveLength(1);
expect(screen.getByText('Last Modified')).toBeInTheDocument();
expect(screen.getAllByText('N/A')).toHaveLength(1);
});

test('collection name displays when defined', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import SummaryPaper from 'js/shared-styles/sections/SectionPaper';
import LabelledSectionText from 'js/shared-styles/sections/LabelledSectionText';
import OutboundIconLink from 'js/shared-styles/Links/iconLinks/OutboundIconLink';
import Citation from 'js/components/detailPage/Citation';
import { Entity, isCollection, isDataset, isPublication } from 'js/components/types';
import { isCollection, isDataset, isPublication } from 'js/components/types';
import { useFlaskDataContext } from 'js/components/Contexts';
import { getCollectionDOI } from 'js/pages/Collection/utils';
import { getEntityCreationInfo } from 'js/helpers/functions';
import { StyledCreationDate } from './style';
import PublicationSummaryBody from './PublicationSummaryBody';
import SummaryDescription from './SummaryDescription';
Expand Down Expand Up @@ -116,16 +117,11 @@ function CollectionCitation() {
function SummaryBodyContent({
isEntityHeader = false,
direction = 'column',
published_timestamp,
created_timestamp,
description,
...stackProps
}: { isEntityHeader?: boolean } & Partial<StackProps> &
Pick<Entity, 'description' | 'created_timestamp' | 'published_timestamp'>) {
const creationLabel = published_timestamp ? 'Publication Date' : 'Creation Date';
const creationTimestamp = published_timestamp ?? created_timestamp;

}: { isEntityHeader?: boolean } & Partial<StackProps>) {
const { entity } = useFlaskDataContext();
const { description } = entity;
const { creationLabel, creationDate } = getEntityCreationInfo(entity);

if (isPublication(entity)) {
return (
Expand All @@ -143,25 +139,13 @@ function SummaryBodyContent({
<DatasetConsortium />
<DatasetCitation />
<CollectionCitation />
<StyledCreationDate label={creationLabel} timestamp={creationTimestamp} />
<StyledCreationDate label={creationLabel}>{creationDate}</StyledCreationDate>
</Stack>
);
}

function SummaryBody({ isEntityHeader = false, ...stackProps }: { isEntityHeader?: boolean } & Partial<StackProps>) {
const { entity } = useFlaskDataContext();

const { created_timestamp, published_timestamp, description } = entity;

return (
<SummaryBodyContent
created_timestamp={created_timestamp}
published_timestamp={published_timestamp}
description={description}
isEntityHeader={isEntityHeader}
{...stackProps}
/>
);
return <SummaryBodyContent isEntityHeader={isEntityHeader} {...stackProps} />;
}

export { SummaryBodyContent };
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { styled } from '@mui/material/styles';

import LabelledSectionDate from 'js/shared-styles/sections/LabelledSectionDate';
import LabelledSectionText from 'js/shared-styles/sections/LabelledSectionText';

const StyledCreationDate = styled(LabelledSectionDate)({
const StyledCreationDate = styled(LabelledSectionText)({
flexGrow: 1,
flexShrink: 0,
});
Expand Down
19 changes: 0 additions & 19 deletions context/app/static/js/components/detailPage/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Dataset, Donor, isDataset, isDonor, isSample, Sample } from 'js/components/types';
import useProcessedDataStore from 'js/components/detailPage/ProcessedData/store';
import { ProcessedDatasetDetails } from './ProcessedData/ProcessedDataset/hooks';

export function getSectionOrder(
possibleSections: string[],
Expand All @@ -15,24 +14,6 @@ export function getCombinedDatasetStatus({ sub_status, status }: { sub_status?:
return sub_status ?? status;
}

/**
* Helper function to handle different date labels for creation and publication dates
* depending on dataset status
* @param dataset
* @returns [label: string, value: number]
*/
export function getDateLabelAndValue(
dataset: Pick<ProcessedDatasetDetails, 'published_timestamp' | 'created_timestamp' | 'status'>,
): [string, number] {
const { published_timestamp, created_timestamp, status } = dataset;

if (status.toLowerCase() === 'published') {
return ['Publication Date', published_timestamp];
}

return ['Creation Date', created_timestamp];
}

export function getDonorMetadata(entity: Donor | Sample | Dataset) {
if (isDonor(entity)) {
return entity?.mapped_metadata ?? {};
Expand Down
Loading
Loading