Skip to content
Open
Show file tree
Hide file tree
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
22 changes: 22 additions & 0 deletions src/components/repos/__tests__/seededFrom.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import test from 'node:test'
import assert from 'node:assert/strict'

const { getSeededFromLabel } = await import('../seededFrom.js')

const t = key => ({'repo.seeded_from_import': 'Import'})[key]

test('a version seeded from HEAD or another version shows that version', () => {
assert.equal(getSeededFromLabel({type: 'repo_version', url: '/orgs/MyOrg/sources/MySource/HEAD/'}, t), 'HEAD')
assert.equal(getSeededFromLabel({type: 'repo_version', url: '/orgs/MyOrg/sources/MySource/2.82/'}, t), '2.82')
})

test('a version seeded from an import shows Import', () => {
assert.equal(getSeededFromLabel({type: 'import', task: 'task-id'}, t), 'Import')
assert.equal(getSeededFromLabel({type: 'import', task: null}, t), 'Import')
})

test('no seed, or one this page does not know, shows nothing rather than raw JSON', () => {
assert.equal(getSeededFromLabel(null, t), undefined)
assert.equal(getSeededFromLabel({type: 'repo_version', url: null}, t), undefined)
assert.equal(getSeededFromLabel({type: 'other'}, t), undefined)
})
10 changes: 10 additions & 0 deletions src/components/repos/seededFrom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// A version's seed for display: HEAD, the version id it was seeded from, or the import that seeded it.
export const getSeededFromLabel = (seededFrom, t) => {
if(!seededFrom?.type)
return undefined
if(seededFrom.type === 'import')
return t('repo.seeded_from_import')
if(seededFrom.type === 'repo_version' && seededFrom.url)
return seededFrom.url.replace(/\/+$/, '').split('/').pop()
return undefined
}
8 changes: 7 additions & 1 deletion src/components/repos/versionsTab.styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import isNumber from 'lodash/isNumber';
import isObject from 'lodash/isObject';
import keys from 'lodash/keys';
import startCase from 'lodash/startCase';
import { getSeededFromLabel } from './seededFrom';

export const REPO_VERSIONS_PAGE_SIZE = 25;

Expand Down Expand Up @@ -52,6 +53,7 @@ const VERSION_ATTRIBUTE_LABEL_KEYS = {
autoexpand: 'repo.autoexpand',
expansion_url: 'repo.expansion_url',
revision_date: 'repo.revision_date',
seeded_from: 'repo.seeded_from',
extras: 'custom_attributes.label',
'checksums.standard': 'checksums.standard',
'checksums.smart': 'checksums.smart',
Expand Down Expand Up @@ -95,6 +97,7 @@ const VERSION_ATTRIBUTE_ORDER = [
'autoexpand',
'expansion_url',
'revision_date',
'seeded_from',
'extras',
'checksums.standard',
'checksums.smart',
Expand All @@ -120,12 +123,15 @@ export const getVersionAttributeFields = (version, t) => {
const labelKey = VERSION_ATTRIBUTE_LABEL_KEYS[field];
const value = get(version, field);
const info = { label: labelKey ? t(labelKey) : startCase(field) };
const type = VERSION_ATTRIBUTE_TYPES[field] || (isObject(value) ? 'json' : undefined);
// the seed is shown as a label, never as raw JSON
const type = field === 'seeded_from' ? undefined : VERSION_ATTRIBUTE_TYPES[field] || (isObject(value) ? 'json' : undefined);
if(type)
info.type = type;
// the dialog renders a value only when it is truthy, so true/false needs a string
if(isBoolean(value))
info.value = value.toString();
if(field === 'seeded_from')
info.value = getSeededFromLabel(value, t);
fields[field] = info;
Comment on lines +133 to 135

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

[P2] With no label, EntityAttributesDialog falls back to get(entity, field), gets the object back and React throws, so the whole page shows "Something went wrong." This leaves the row out instead. I checked it in the dev build with {"type": "repo_version", "url": null}: the dialog opens without the row, and ESLint is clean.

Suggested change
if(field === 'seeded_from')
info.value = getSeededFromLabel(value, t);
fields[field] = info;
if(field === 'seeded_from') {
info.value = getSeededFromLabel(value, t);
// with no label the dialog falls back to the raw object, which React can't render
if(!info.value)
return;
}
fields[field] = info;

});
return fields;
Expand Down
4 changes: 3 additions & 1 deletion src/i18n/locales/en/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,9 @@
"could_not_clear_processing": "Could not clear the processing state",
"export_not_ready_tooltip": "Export is still being generated for this version",
"expansion_processing_tooltip": "This expansion is still being built",
"suggested_sources": "Suggested Sources"
"suggested_sources": "Suggested Sources",
"seeded_from": "Seeded From",
"seeded_from_import": "Import"
},
"org": {
"my": "My Organizations",
Expand Down
4 changes: 3 additions & 1 deletion src/i18n/locales/es/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,9 @@
"edit_title": "Editar versión de {{resourceType}}: {{version}}"
}
},
"repo_version": "Versión del repositorio"
"repo_version": "Versión del repositorio",
"seeded_from": "Creada a partir de",
"seeded_from_import": "Importación"
},
"org": {
"my": "Mis organizaciones",
Expand Down
4 changes: 3 additions & 1 deletion src/i18n/locales/pt-BR/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,9 @@
"could_not_clear_processing": "Não foi possível limpar o estado de processamento",
"export_not_ready_tooltip": "Exportação ainda está sendo gerada para esta versão",
"expansion_processing_tooltip": "Esta expansão ainda está sendo construída",
"suggested_sources": "Sources sugeridos"
"suggested_sources": "Sources sugeridos",
"seeded_from": "Criada a partir de",
"seeded_from_import": "Importação"
},
"org": {
"my": "Minhas organizações",
Expand Down
4 changes: 3 additions & 1 deletion src/i18n/locales/zh/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,9 @@
"edit_title": "编辑{{resourceType}}版本:{{version}}"
}
},
"repo_version": "仓库版本"
"repo_version": "仓库版本",
"seeded_from": "创建来源",
"seeded_from_import": "导入"
},
"org": {
"my": "我的组织机构",
Expand Down
Loading