Skip to content

Commit

Permalink
v1.158.0
Browse files Browse the repository at this point in the history
  • Loading branch information
varovaro committed Mar 18, 2024
2 parents b2b7497 + 4fe88d3 commit c434c71
Show file tree
Hide file tree
Showing 42 changed files with 726 additions and 627 deletions.
57 changes: 57 additions & 0 deletions app/api/migrations/migrations/161-update-translations/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/* eslint-disable import/no-default-export */
import { Db } from 'mongodb';

interface Translation {
key: string;
}

const newKeys: Translation[] = [
{ key: 'Do you want to delete the following items?' },
{ key: 'Already exists' },
];

const deletedKeys: Translation[] = [
{ key: 'Are you sure you want to delete this relationship type?' },
{ key: 'Cannot delete relationship type:' },
{ key: 'Confirm deletion of relationship type:' },
{ key: 'Currently connections only need a title.' },
{ key: 'This relationship type is being used and cannot be deleted.' },
];

export default {
delta: 161,

reindex: false,

name: 'update_translations',

description: 'Updates some translations in settings',

async up(db: Db) {
const settings = await db.collection('settings').findOne();
const languages = settings?.languages
.map((l: any) => l.key)
.filter((value: string, index: number, array: any[]) => array.indexOf(value) === index);

await db.collection('translationsV2').deleteMany({
key: { $in: deletedKeys.concat(newKeys).map(k => k.key) },
'context.id': 'System',
});

const insertMany = languages.map(async (l: any) =>
db.collection('translationsV2').insertMany(
newKeys.map(k => ({
key: k.key,
value: k.key,
language: l,
context: { id: 'System', type: 'Uwazi UI', label: 'User Interface' },
}))
)
);
await Promise.all(insertMany);

process.stdout.write(`${this.name}...\r\n`);
},
};

export { newKeys, deletedKeys };
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { Db } from 'mongodb';
import testingDB from 'api/utils/testing_db';
import migration, { newKeys, deletedKeys } from '../index';
import { fixtures } from './fixtures';
import { Fixture } from '../types';

let db: Db | null;

const initTest = async (fixture: Fixture) => {
await testingDB.setupFixturesAndContext(fixture);
db = testingDB.mongodb!;
await migration.up(db);
};

describe('migration update translations of settings', () => {
beforeAll(async () => {
jest.spyOn(process.stdout, 'write').mockImplementation((_str: string | Uint8Array) => true);
await initTest(fixtures);
});

afterAll(async () => {
await testingDB.disconnect();
});

it('should have a delta number', () => {
expect(migration.delta).toBe(161);
});

it('should delete old translations', async () => {
const translations = await testingDB
.mongodb!.collection('translationsV2')
.find({ key: { $in: deletedKeys.map(k => k.key) } })
.toArray();

expect(translations).toEqual([]);
});

it('should NOT delete other translations', async () => {
const translations = await testingDB
.mongodb!.collection('translationsV2')
.find({ key: 'Im cool' })
.toArray();

expect(translations.length).toBe(2);
});

it('should add new translations per language', async () => {
const translations = await testingDB
.mongodb!.collection('translationsV2')
.find({ key: { $in: newKeys.map(k => k.key) } })
.toArray();

expect(translations.length).toBe(4);
});

it('should be idempotent (do not throw an error on multiple runs)', async () => {
await expect(migration.up(testingDB.mongodb!)).resolves.toBe(undefined);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import db from 'api/utils/testing_db';
import { Fixture } from '../types';

const fixtures: Fixture = {
settings: [{ _id: db.id(), languages: [{ key: 'en' }, { key: 'es' }] }],
translationsV2: [
{
_id: db.id(),
language: 'en',
context: { id: 'System', label: 'User Interface', type: 'Uwazi UI' },
key: 'Current value:',
value: 'Current value:',
},
{
_id: db.id(),
language: 'es',
context: { id: 'System', label: 'User Interface', type: 'Uwazi UI' },
key: 'Current value:',
value: 'Current value:',
},
{
_id: db.id(),
language: 'en',
context: { id: 'System', label: 'User Interface', type: 'Uwazi UI' },
key: 'Im cool',
value: 'Im cool',
},
{
_id: db.id(),
language: 'es',
context: { id: 'System', label: 'User Interface', type: 'Uwazi UI' },
key: 'Im cool',
value: 'Im cool',
},
],
};

export { fixtures };
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
interface Fixture {
settings: any;
translationsV2: any;
}

export type { Fixture };
20 changes: 20 additions & 0 deletions app/react/App/styles/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -2350,6 +2350,26 @@ input:checked + .toggle-bg {
min-width: 20px;
}

.min-w-\[24rem\] {
min-width: 24rem;
}

.min-w-\[28rem\] {
min-width: 28rem;
}

.min-w-\[32rem\] {
min-width: 32rem;
}

.min-w-\[36rem\] {
min-width: 36rem;
}

.min-w-\[40rem\] {
min-width: 40rem;
}

.min-w-full {
min-width: 100%;
}
Expand Down
28 changes: 0 additions & 28 deletions app/react/RelationTypes/EditRelationType.js

This file was deleted.

14 changes: 0 additions & 14 deletions app/react/RelationTypes/NewRelationType.js

This file was deleted.

118 changes: 0 additions & 118 deletions app/react/RelationTypes/components/RelationTypeForm.js

This file was deleted.

Loading

0 comments on commit c434c71

Please sign in to comment.