Skip to content

Commit

Permalink
NickAkhmetov/CAT-881 deduplicate errored processed datasets' urls (#3558
Browse files Browse the repository at this point in the history
)
  • Loading branch information
NickAkhmetov authored Oct 7, 2024
1 parent 9c5c84e commit 507ecaa
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-cat-881.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Append HuBMAP ID to errored datasets' URL anchors to avoid anchor duplication on dataset pages with multiple failed processing attempts.
42 changes: 42 additions & 0 deletions context/app/static/js/pages/Dataset/utils.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { datasetSectionId } from './utils';

const prefix = 'prefix';

describe('datasetSectionId', () => {
it('should format the dataset section id correctly', () => {
const dataset = {
pipeline: 'pipeline',
hubmap_id: 'hubmap_id',
status: 'status',
};
expect(datasetSectionId(dataset, prefix)).toBe('prefix-pipeline-status');
});
it('Should include the hubmap id if the pipeline is missing', () => {
const dataset = {
hubmap_id: 'hubmap_id',
status: 'status',
};
expect(datasetSectionId(dataset, prefix)).toBe('prefix-hubmap_id-status');
});
it('should include the pipeline and hubmap_id if the pipeline is errored', () => {
const dataset = {
pipeline: 'pipeline',
hubmap_id: 'hubmap_id',
status: 'error',
};
expect(datasetSectionId(dataset, prefix)).toBe('prefix-pipeline-error-hubmap_id');
});
it('should generate unique ids for different errored datasets', () => {
const dataset1 = {
pipeline: 'pipeline',
hubmap_id: 'hubmap_id',
status: 'error',
};
const dataset2 = {
pipeline: 'pipeline',
hubmap_id: 'hubmap_id_2',
status: 'error',
};
expect(datasetSectionId(dataset1, prefix)).not.toBe(datasetSectionId(dataset2, prefix));
});
});
9 changes: 7 additions & 2 deletions context/app/static/js/pages/Dataset/utils.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import { ProcessedDatasetInfo } from './hooks';

const potentialDuplicateStates = ['error'];

export function datasetSectionId(
dataset: Pick<ProcessedDatasetInfo, 'pipeline' | 'hubmap_id' | 'status'>,
dataset: Pick<ProcessedDatasetInfo, 'hubmap_id' | 'status'> & { pipeline?: string },
prefix = '',
) {
const { pipeline, hubmap_id, status } = dataset;
const formattedDatasetIdentifier = (pipeline ?? hubmap_id).replace(/\s/g, '');
const formattedStatus = status.replace(/\s/g, '');
return `${prefix}-${encodeURIComponent(formattedDatasetIdentifier)}-${encodeURIComponent(formattedStatus)}`.toLowerCase();
const deduplicatedFormattedStatus = potentialDuplicateStates.includes(formattedStatus.toLowerCase())
? `${formattedStatus}-${hubmap_id}`
: formattedStatus;
return `${prefix}-${encodeURIComponent(formattedDatasetIdentifier)}-${encodeURIComponent(deduplicatedFormattedStatus)}`.toLowerCase();
}

0 comments on commit 507ecaa

Please sign in to comment.