Skip to content
Merged
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
20 changes: 0 additions & 20 deletions src/common/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,6 @@ export const formatDate = date => moment(date).format(DATE_FORMAT);
export const formatTime = date => moment(date).format(TIME_FORMAT);
export const formatDateTime = date => moment(date).format(DATETIME_FORMAT);

export const formatWebsiteLink = (value, style, text) => {
if(value && value.trim()) {
let href = value.trim();
if(!href.startsWith('http://') && !href.startsWith('https://'))
href = 'https://' + href;

return (
<a
target='_blank'
rel="noopener noreferrer"
href={href}
className="ellipsis-text"
style={merge({maxWidth: '100px'}, (style || {}))}>
{text || value.trim()}
</a>
);
}
return '';
}

export const formatWebsiteLinkTruncated = (value, style, text) => {
if(value && value.trim()) {
let href = value.trim();
Expand Down
34 changes: 0 additions & 34 deletions src/components/mappings/ConceptCell.jsx

This file was deleted.

58 changes: 0 additions & 58 deletions src/components/mappings/FromAndTargetSource.jsx

This file was deleted.

40 changes: 2 additions & 38 deletions src/components/search/ResultConstants.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import React from 'react';
import {
formatDate,
formatWebsiteLink,
} from '../../common/utils';
import Retired from '../common/Retired';
import OwnerIcon from '../common/OwnerIcon';
import RepoVersionButton from '../repos/RepoVersionButton';
import FromAndTargetSource from '../mappings/FromAndTargetSource'
import ConceptCell from '../mappings/ConceptCell'

// The Mapper lists only concepts, so they are the only resource with table
// columns (OpenConceptLab/ocl_issues#2917).
export const ALL_COLUMNS = {
concepts: [
{id: 'id', labelKey: 'common.id', value: 'id', sortOn: 'id_lowercase', className: 'searchable', permanent: true},
Expand All @@ -25,38 +21,6 @@ export const ALL_COLUMNS = {
{id: 'owner', labelKey: 'common.owner', value: 'owner', sortOn: 'owner', nested: false, renderer: item => (<span style={{display: 'flex', whiteSpace: 'nowrap'}}><OwnerIcon noTooltip ownerType={item.owner_type} fontSize='small' sx={{marginRight: '4px'}}/>{item.owner}</span>)},
{id: 'parent', labelKey: 'repo.repo', value: 'source', sortOn: 'source', nested: false, renderer: item => <RepoVersionButton repoType='Source' repo={item.source} version={item.latest_source_version} vertical />},
],
mappings: [
{id: 'fromAndTargetSource', labelKey: 'mapping.fromAndTargetSource', sortable: false, className: 'searchable', renderer: item => <FromAndTargetSource mapping={item} />},
{id: 'fromConcept', labelKey: 'mapping.fromConcept', value: 'fromConceptCode', className: 'searchable', sortable: false, renderer: item => <ConceptCell mapping={item} direction='from' />},
{id: 'mapType', labelKey: 'mapping.map_type', value: 'map_type', sortable: true},
{id: 'toConcept', labelKey: 'mapping.toConcept', value: 'toConceptCode', className: 'searchable', sortable: false, renderer: item => <ConceptCell mapping={item} direction='to' />},
],
repos: [
{id: 'id', labelKey: 'common.id', value: 'id', sortOn: 'id', className: 'searchable'},
{id: 'name', labelKey: 'common.name', value: 'name', sortOn: 'name', className: 'searchable'},
{id: 'type', labelKey: 'repo.repo_type', value: 'type', sortable: false},
{id: 'owner', labelKey: 'common.owner', value: 'owner', sortOn: 'owner', renderer: item => (<span style={{display: 'flex', alignItems: 'center'}}><OwnerIcon noTooltip ownerType={item.owner_type} fontSize='small' sx={{marginRight: '4px'}}/>{item.owner}</span>)}
],
orgs: [
{id: 'id', labelKey: 'common.id', value: 'id', sortOn: '_mnemonic', className: 'searchable'},
{id: 'name', labelKey: 'common.name', value: 'name', sortOn: '_name', sortBy: 'asc', className: 'searchable'},
{id: 'createdOn', labelKey: 'common.created_on', value: 'created_on', formatter: formatDate, sortOn: 'created_on', sortable: false},
],
users: [
{id: 'username', labelKey: 'user.username', value: 'username', sortOn: '_username', sortBy: 'asc', className: 'searchable'},
{id: 'name', labelKey: 'common.name', value: 'name', sortOn: '_name', sortBy: 'asc', className: 'searchable'},
{id: 'email', labelKey: 'user.email', value: 'email', sortable: false},
{id: 'company', labelKey: 'user.company', value: 'company'},
{id: 'location', labelKey: 'user.location', value: 'location'},
{id: 'website', labelKey: 'user.website', value: 'website', sortable: false, formatter: formatWebsiteLink},
{id: 'date_joined', labelKey: 'user.joined_on', value: 'date_joined', formatter: formatDate, sortOn: 'date_joined'},
],
url_registry: [
{id: 'url', labelKey: 'url_registry.canonical_url', value: 'url', className: 'searchable'},
{id: 'target_owner', labelKey: 'url_registry.target_owner', value: 'repo.owner_url', className: 'searchable'},
{id: 'repo_id', labelKey: 'repo.repo_id', value: 'repo.id', className: 'searchable'},
{id: 'repo_type', labelKey: 'repo.repo_type', value: 'repo.type', className: 'searchable'},
]
};


Expand Down
1 change: 0 additions & 1 deletion src/i18n/__tests__/aiAssistantNaming.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ const NAMES_THE_ASSISTANT = [
'preview_estimate_ai_partial',
'preview_estimate_ai_none',
'preview_estimate_ai_only_partial',
'ai_assistant_limit_reached',
'preview_limit_title_ai_assistant',
'preview_limit_body_ai_assistant',
'preview_limit_body_ai_assistant_no_count',
Expand Down
45 changes: 45 additions & 0 deletions src/i18n/__tests__/catalogKeys.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import test from 'node:test'
import assert from 'node:assert/strict'
import { readdirSync, readFileSync } from 'node:fs'
import path from 'node:path'
import { fileURLToPath } from 'node:url'

// OpenConceptLab/ocl_issues#2917: the catalogs hold the keys the code uses.
// i18next shows a key English lacks as the raw key, or as the English default
// the call passes, in every language. Each locale falls back to English, so a
// key only another locale has is never shown.
const LOCALES_DIR = new URL('../locales/', import.meta.url)
const SRC_DIR = fileURLToPath(new URL('../../', import.meta.url))

const flatten = (node, prefix = []) => typeof node === 'string' ?
[prefix.join('.')] :
Object.entries(node).flatMap(([key, value]) => flatten(value, [...prefix, key]))

const keysOf = locale =>
new Set(flatten(JSON.parse(readFileSync(new URL(`${locale}/translations.json`, LOCALES_DIR), 'utf8'))))

const LOCALES = readdirSync(LOCALES_DIR, { withFileTypes: true }).filter(entry => entry.isDirectory()).map(entry => entry.name)
const english = keysOf('en')

for (const locale of LOCALES)
test(`${locale}: has no key English lacks`, () => {
assert.deepEqual([...keysOf(locale)].filter(key => !english.has(key)), [])
})

// A literal key: t('a.b'), this.props.t("a.b"), t(`a.b`), i18nKey='a.b'.
// Keys built at run time ('a.' + id, `a.${id}`) aren't read.
const LITERAL_KEY = /(?:\bt\(\s*|\bi18nKey=\{?\s*)(['"`])([A-Za-z_]+(?:\.[A-Za-z0-9_]+)+)\1(?!\s*\+)/g

// The .js and .jsx files under src/, outside the test folders.
const SOURCES = readdirSync(SRC_DIR, { recursive: true })
.filter(file => /\.jsx?$/.test(file) && !/(^|[\\/])__(tests|integration)__[\\/]/.test(file))

test('every literal key in the source is in the English catalog', () => {
const missing = SOURCES.flatMap(file =>
[...readFileSync(path.join(SRC_DIR, file), 'utf8').matchAll(LITERAL_KEY)]
.map(match => match[2])
.filter(key => !english.has(key))
.map(key => `${file}: ${key}`)
)
assert.deepEqual(missing, [])
})
Loading
Loading