Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for date modified field on cards #3346

Merged
merged 40 commits into from
Feb 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
1b889be
IN PROGRESS: Added support for date modified field on cards
grafitto Nov 27, 2020
19e9f1d
Merge branch 'development' into 1893-add-date-modified
grafitto Dec 2, 2020
13c3a29
Reverted some of the changes
grafitto Dec 2, 2020
6ebdfac
Reverted file changes
grafitto Dec 2, 2020
2bf5849
Merge branch 'development' into 1893-add-date-modified
grafitto Dec 7, 2020
1e56422
Added support for filter with date modified
grafitto Dec 8, 2020
cc3c1c3
Fixed edittemplates tests
grafitto Dec 8, 2020
96c4ace
Fixed failed tests
grafitto Dec 9, 2020
7e9bff5
Merge branch 'development' into 1893-add-date-modified
grafitto Dec 9, 2020
9b63f05
Merge branch 'development' into 1893-add-date-modified
grafitto Dec 11, 2020
e5301f3
Merge branch 'development' into 1893-add-date-modified
grafitto Dec 15, 2020
42223b5
Merge branch 'development' into 1893-add-date-modified
grafitto Dec 17, 2020
3dac6d8
Added tests for editDate
grafitto Dec 23, 2020
b480020
Returned localhost
grafitto Dec 23, 2020
f245ecc
Added tests for date modified
grafitto Dec 23, 2020
1bd8810
Merge branch 'development' into 1893-add-date-modified
grafitto Dec 23, 2020
787f310
Merge branch 'development' into 1893-add-date-modified
grafitto Jan 4, 2021
e314b70
Merge branch 'development' into 1893-add-date-modified
grafitto Jan 6, 2021
aa57209
Fixed a failing test
grafitto Jan 6, 2021
adc9418
updated snapshots
grafitto Jan 6, 2021
05dcff2
Merge branch 'development' into 1893-add-date-modified
grafitto Jan 12, 2021
3c2aee6
Fixed failing tests
grafitto Jan 13, 2021
e72ca4b
Merge branch 'development' into 1893-add-date-modified
grafitto Jan 13, 2021
50b2167
Fixed template e2e tests
grafitto Jan 13, 2021
3ad7406
Fixed connection e2e tests
grafitto Jan 13, 2021
d0f0cbe
Refactored react tests
grafitto Jan 13, 2021
ce98085
Merge branch 'development' into 1893-add-date-modified
daneryl Jan 14, 2021
7c2c8ca
Reverted some tests
grafitto Jan 15, 2021
b69a5ac
Merge branch 'development' into 1893-add-date-modified
daneryl Jan 15, 2021
a5108e2
Merge branch 'development' into 1893-add-date-modified
grafitto Jan 15, 2021
e159733
Merge branch 'development' into 1893-add-date-modified
grafitto Jan 18, 2021
226c6f8
Merge branch 'development' into 1893-add-date-modified
grafitto Jan 18, 2021
efe016a
Merge branch 'development' into 1893-add-date-modified
grafitto Jan 21, 2021
c5ce2b6
Merge branch 'development' into 1893-add-date-modified
grafitto Jan 25, 2021
c3a6138
Merge branch 'development' into 1893-add-date-modified
grafitto Jan 26, 2021
c8ddbaa
Added migrations
grafitto Feb 1, 2021
0c102ab
Merge branch 'development' into 1893-add-date-modified
grafitto Feb 1, 2021
56ccb23
Merge branch 'development' into 1893-add-date-modified
grafitto Feb 1, 2021
2a8c4d2
Merge branch 'development' into 1893-add-date-modified
grafitto Feb 2, 2021
e6c288d
Added editDate to document query builder
grafitto Feb 3, 2021
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
1 change: 1 addition & 0 deletions app/api/entities/entities.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ export default {
templates.get({ default: true }),
]);
let docTemplate = template;
doc.editDate = date.currentUTC();
grafitto marked this conversation as resolved.
Show resolved Hide resolved
if (doc.sharedId) {
await this.updateEntity(this.sanitize(doc, template), template);
} else {
Expand Down
1 change: 1 addition & 0 deletions app/api/entities/entitiesModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const mongoSchema = new mongoose.Schema(
},
],
creationDate: Number,
editDate: Number,
metadata: mongoose.Schema.Types.Mixed,
suggestedMetadata: mongoose.Schema.Types.Mixed,
user: { type: mongoose.Schema.Types.ObjectId, ref: 'users' },
Expand Down
16 changes: 12 additions & 4 deletions app/api/entities/specs/entities.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ describe('entities', () => {
expect(createdDocumentEs.user.equals(user._id)).toBe(true);
expect(createdDocumentEs.published).toBe(false);
expect(createdDocumentEs.creationDate).toEqual(universalTime);
expect(createdDocumentEs.editDate).toEqual(universalTime);

expect(createdDocumentEn.title).toBe(doc.title);
expect(createdDocumentEn.user.equals(user._id)).toBe(true);
Expand Down Expand Up @@ -152,21 +153,28 @@ describe('entities', () => {
.catch(catchErrors(done));
});

it('should return updated entity', done => {
it('should return updated entity with updated editDate', done => {
const updateTime = 2;
const doc = {
title: 'the dark knight',
fullText: { 0: 'the full text!' },
metadata: { data: [{ value: 'should not be here' }] },
};

const user = { _id: db.id() };

entities
.save(doc, { user, language: 'en' })
.then(createdDocument =>
entities.save({ ...createdDocument, title: 'updated title' }, { user, language: 'en' })
)
.then(createdDocument => {
spyOn(date, 'currentUTC').and.returnValue(updateTime);
return entities.save(
{ ...createdDocument, title: 'updated title' },
{ user, language: 'en' }
);
})
.then(updatedDocument => {
expect(updatedDocument.title).toBe('updated title');
expect(updatedDocument.editDate).toEqual(updateTime);
done();
})
.catch(catchErrors(done));
Expand Down
32 changes: 32 additions & 0 deletions app/api/migrations/migrations/31-editDate/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
export default {
delta: 31,

name: 'editDate',

description: 'Adds editDate property on all entities',

async up(db) {
process.stdout.write(`${this.name}...\r\n`);
const cursor = await db.collection('entities').find({});

// eslint-disable-next-line no-await-in-loop
while (await cursor.hasNext()) {
// eslint-disable-next-line no-await-in-loop
const entity = await cursor.next();
// eslint-disable-next-line no-await-in-loop
let time = entity.creationDate; //entity.creationDate;

// eslint-disable-next-line no-await-in-loop
const logs = await db
.collection('updatelogs')
.find({ mongoId: entity._id })
.toArray();

if (logs.length) {
time = logs[0].timestamp;
}
// eslint-disable-next-line no-await-in-loop
await db.collection('entities').updateOne({ _id: entity._id }, { $set: { editDate: time } });
}
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import testingDB from 'api/utils/testing_db';
import migration from '../index.js';
import fixtures from './fixtures.js';

describe('migration editDate', () => {
beforeEach(async () => {
spyOn(process.stdout, 'write');
await testingDB.clearAllAndLoad(fixtures);
});

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

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

it('should populate editDate with timestamp from updatelogs', async () => {
await migration.up(testingDB.mongodb);
const entities = await testingDB.mongodb
.collection('entities')
.find({})
.toArray();

const [entity1, entity2, entity3] = entities;
const updatelog1 = await testingDB.mongodb
.collection('updatelogs')
.findOne({ mongoId: entity1._id });
const updatelog2 = await testingDB.mongodb
.collection('updatelogs')
.findOne({ mongoId: entity2._id });
const updatelog3 = await testingDB.mongodb
.collection('updatelogs')
.findOne({ mongoId: entity3._id });
expect(entity1.editDate).toEqual(updatelog1.timestamp);
expect(entity2.editDate).toEqual(updatelog2.timestamp);
expect(entity3.editDate).toEqual(updatelog3.timestamp);
});

it('should populate editDate with creationDate if updateLogs do not exist', async () => {
const entity = {
_id: '7654',
title: 'new entity',
creationDate: '198',
};
await testingDB.clearAllAndLoad({
entities: [...fixtures.entities, entity],
updatelogs: [...fixtures.updatelogs],
});

await migration.up(testingDB.mongodb);

const savedEntity = await testingDB.mongodb.collection('entities').findOne({ _id: entity._id });
expect(savedEntity.editDate).toEqual(savedEntity.creationDate);
});
});
12 changes: 12 additions & 0 deletions app/api/migrations/migrations/31-editDate/specs/fixtures.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export default {
entities: [
{ _id: 'id1', title: 'test_doc' },
{ _id: 'id2', title: 'test_doc_1' },
{ _id: 'id3', title: 'test_doc_2' },
],
updatelogs: [
{ mongoId: 'id1', timestamp: '1234' },
{ mongoId: 'id2', timestamp: '4567' },
{ mongoId: 'id3', timestamp: '8901' },
],
};
1 change: 1 addition & 0 deletions app/api/search/documentQueryBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export default function() {
'icon',
'processed',
'creationDate',
'editDate',
'template',
'metadata',
'type',
Expand Down
5 changes: 5 additions & 0 deletions app/react/Library/components/SortButtons.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,11 @@ export class SortButtons extends Component {
search,
type: 'date',
})}
{this.createSortItem('editDate', 'editDate', 'System', 'Date modified', {
isActive: search.sort === 'editDate',
search,
type: 'date',
})}
{search.searchTerm && (
<li
key="relevance"
Expand Down
4 changes: 2 additions & 2 deletions app/react/Library/components/specs/SortButtons.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ describe('SortButtons', () => {
]);
render();

expect(component.find('.Dropdown:not(.width-placeholder) li').length).toBe(3);
expect(component.find('.Dropdown:not(.width-placeholder) li').length).toBe(4);

expect(
component
Expand Down Expand Up @@ -104,7 +104,7 @@ describe('SortButtons', () => {
expect(
component
.find('li')
.at(2)
.at(3)
.children()
.at(0)
.find('span')
Expand Down
Loading