-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Hide browser extension links * added preserve icon * Remove info * migration
- Loading branch information
Showing
7 changed files
with
277 additions
and
7 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
app/api/migrations/migrations/108-add_system_key_translations/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
This migration is meant to be repeatable. | ||
After copy pasting: | ||
- change the contents of system_keys.csv to the new keyset | ||
- change the file location in the readCsvToSystemKeys call | ||
- change the tests, if necessary | ||
*/ | ||
|
||
async function insertSystemKeys(db, newKeys) { | ||
const translations = await db.collection('translations').find().toArray(); | ||
const locales = translations.map(tr => tr.locale); | ||
|
||
const locToSystemContext = {}; | ||
translations.forEach(tr => { | ||
locToSystemContext[tr.locale] = tr.contexts.find(c => c.id === 'System'); | ||
}); | ||
const locToKeys = {}; | ||
Object.entries(locToSystemContext).forEach(([loc, context]) => { | ||
locToKeys[loc] = new Set(context.values.map(v => v.key)); | ||
}); | ||
|
||
newKeys.forEach(row => { | ||
const { key, value: optionalValue } = row; | ||
|
||
locales.forEach(loc => { | ||
if (!locToKeys[loc].has(key)) { | ||
const newValue = optionalValue || key; | ||
locToSystemContext[loc].values.push({ key, value: newValue }); | ||
locToKeys[loc].add(key); | ||
} | ||
}); | ||
}); | ||
|
||
await Promise.all( | ||
translations.map(tr => db.collection('translations').replaceOne({ _id: tr._id }, tr)) | ||
); | ||
} | ||
|
||
export default { | ||
delta: 108, | ||
|
||
reindex: false, | ||
|
||
name: 'add_system_key_translations', | ||
|
||
description: 'Adding missing translations for system keys.', | ||
|
||
async up(db) { | ||
process.stdout.write(`${this.name}...\r\n`); | ||
const systemKeys = [ | ||
{ | ||
key: 'Preserve', | ||
}, | ||
]; | ||
await insertSystemKeys(db, systemKeys); | ||
}, | ||
}; |
64 changes: 64 additions & 0 deletions
64
.../migrations/108-add_system_key_translations/specs/108-add_system_key_translations.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { testingDB } from 'api/utils/testing_db'; | ||
import migration from '../index.js'; | ||
import { fixtures, templateId, defaultTemplateName, defaultTemplateTitle } from './fixtures.js'; | ||
|
||
const locales = ['en', 'es', 'hu']; | ||
const newKeyValues = [ | ||
{ | ||
key: 'Preserve', | ||
value: 'Preserve', | ||
}, | ||
]; | ||
const alreadyInAllContexts = { | ||
key: 'Duplicated label', | ||
en: 'Duplicated label', | ||
es: 'Nombre duplicado', | ||
hu: 'Ismétlődő címke', | ||
}; | ||
|
||
describe('migration add_system_key_translations', () => { | ||
beforeEach(async () => { | ||
spyOn(process.stdout, 'write'); | ||
await testingDB.setupFixturesAndContext(fixtures); | ||
}); | ||
|
||
afterAll(async () => { | ||
await testingDB.disconnect(); | ||
}); | ||
|
||
it('should have a delta number', () => { | ||
expect(migration.delta).toBe(108); | ||
}); | ||
|
||
it('should append new keys, leave existing keys intact.', async () => { | ||
await migration.up(testingDB.mongodb); | ||
|
||
const allTranslations = await testingDB.mongodb.collection('translations').find().toArray(); | ||
function testKeyValue(key, value, locale, contextId) { | ||
expect( | ||
allTranslations | ||
.find(tr => tr.locale === locale) | ||
.contexts.find(c => c.id === contextId) | ||
.values.find(v => v.key === key).value | ||
).toBe(value); | ||
} | ||
|
||
newKeyValues.forEach(({ key, value }) => { | ||
locales.forEach(loc => { | ||
testKeyValue(key, value, loc, 'System'); | ||
}); | ||
}); | ||
locales.forEach(loc => { | ||
testKeyValue(alreadyInAllContexts.key, alreadyInAllContexts[loc], loc, 'System'); | ||
}); | ||
locales.forEach(loc => { | ||
expect( | ||
allTranslations | ||
.find(tr => tr.locale === loc) | ||
.contexts.find(c => c.id === templateId.toString()).values | ||
).toHaveLength(2); | ||
testKeyValue(defaultTemplateName, defaultTemplateName, loc, templateId.toString()); | ||
testKeyValue(defaultTemplateTitle, defaultTemplateTitle, loc, templateId.toString()); | ||
}); | ||
}); | ||
}); |
90 changes: 90 additions & 0 deletions
90
app/api/migrations/migrations/108-add_system_key_translations/specs/fixtures.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import db from 'api/utils/testing_db'; | ||
|
||
const templateId = db.id(); | ||
const defaultTemplateName = 'default template'; | ||
const defaultTemplateTitle = 'Title'; | ||
|
||
//contexts | ||
const commonContext = { | ||
id: 'System', | ||
label: 'User Interface', | ||
type: 'Uwazi UI', | ||
values: [ | ||
{ | ||
key: 'existing-key-in-system', | ||
value: 'existing-key-in-system', | ||
}, | ||
], | ||
}; | ||
const templateContext = { | ||
id: templateId.toString(), | ||
label: defaultTemplateName, | ||
type: 'Entity', | ||
values: [ | ||
{ | ||
key: defaultTemplateName, | ||
value: defaultTemplateName, | ||
}, | ||
{ | ||
key: defaultTemplateTitle, | ||
value: defaultTemplateTitle, | ||
}, | ||
], | ||
}; | ||
|
||
const fixtures = { | ||
templates: [ | ||
//default template name - correct | ||
{ | ||
_id: templateId, | ||
name: defaultTemplateName, | ||
commonProperties: [{ name: 'title', label: defaultTemplateTitle, type: 'text' }], | ||
properties: [], | ||
}, | ||
], | ||
translations: [ | ||
{ | ||
_id: db.id(), | ||
locale: 'es', | ||
contexts: [ | ||
{ | ||
...commonContext, | ||
values: commonContext.values.concat([ | ||
{ key: 'Drag properties here', value: 'Arrastra propiedades aquí' }, | ||
{ key: 'Duplicated label', value: 'Nombre duplicado' }, | ||
]), | ||
}, | ||
templateContext, | ||
], | ||
}, | ||
{ | ||
_id: db.id(), | ||
locale: 'en', | ||
contexts: [ | ||
{ | ||
...commonContext, | ||
values: commonContext.values.concat([ | ||
{ key: 'Priority sorting', value: 'Priority sort' }, | ||
{ key: 'Duplicated label', value: 'Duplicated label' }, | ||
]), | ||
}, | ||
templateContext, | ||
], | ||
}, | ||
{ | ||
_id: db.id(), | ||
locale: 'hu', | ||
contexts: [ | ||
{ | ||
...commonContext, | ||
values: commonContext.values.concat([ | ||
{ key: 'Duplicated label', value: 'Ismétlődő címke' }, | ||
]), | ||
}, | ||
templateContext, | ||
], | ||
}, | ||
], | ||
}; | ||
|
||
export { fixtures, templateId, defaultTemplateName, defaultTemplateTitle }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import React from 'react'; | ||
|
||
type preserveIconProps = { | ||
width?: string; | ||
height?: string; | ||
color?: string; | ||
}; | ||
|
||
const PreserveIcon = ({ width = '24', height = '24', color }: preserveIconProps) => ( | ||
<svg | ||
width={width} | ||
height={height} | ||
viewBox="0 0 24 24" | ||
fill="none" | ||
xmlns="http://www.w3.org/2000/svg" | ||
> | ||
<path | ||
d="M12 15C13.6569 15 15 13.6569 15 12C15 10.3431 13.6569 9 12 9C10.3431 9 9 10.3431 9 12C9 13.6569 10.3431 15 12 15Z" | ||
stroke={color || 'currentColor'} | ||
strokeWidth="2" | ||
strokeLinecap="round" | ||
strokeLinejoin="round" | ||
/> | ||
<path | ||
d="M3 7V5C3 4.46957 3.21071 3.96086 3.58579 3.58579C3.96086 3.21071 4.46957 3 5 3H7" | ||
stroke={color || 'currentColor'} | ||
strokeWidth="2" | ||
strokeLinecap="round" | ||
strokeLinejoin="round" | ||
/> | ||
<path | ||
d="M17 3H19C19.5304 3 20.0391 3.21071 20.4142 3.58579C20.7893 3.96086 21 4.46957 21 5V7" | ||
stroke={color || 'currentColor'} | ||
strokeWidth="2" | ||
strokeLinecap="round" | ||
strokeLinejoin="round" | ||
/> | ||
<path | ||
d="M21 17V19C21 19.5304 20.7893 20.0391 20.4142 20.4142C20.0391 20.7893 19.5304 21 19 21H17" | ||
stroke={color || 'currentColor'} | ||
strokeWidth="2" | ||
strokeLinecap="round" | ||
strokeLinejoin="round" | ||
/> | ||
<path | ||
d="M7 21H5C4.46957 21 3.96086 20.7893 3.58579 20.4142C3.21071 20.0391 3 19.5304 3 19V17" | ||
stroke={color || 'currentColor'} | ||
strokeWidth="2" | ||
strokeLinecap="round" | ||
strokeLinejoin="round" | ||
/> | ||
</svg> | ||
); | ||
|
||
export { PreserveIcon }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters