2017-07-07 05:02:55 +00:00
|
|
|
// @flow
|
|
|
|
import { Collection } from '../models';
|
2018-03-01 07:00:41 +00:00
|
|
|
import naturalSort from '../../shared/utils/naturalSort';
|
2017-06-26 00:21:33 +00:00
|
|
|
|
2018-02-07 07:26:14 +00:00
|
|
|
type Document = {
|
|
|
|
children: Document[],
|
|
|
|
id: string,
|
|
|
|
title: string,
|
|
|
|
url: string,
|
|
|
|
};
|
|
|
|
|
2018-12-05 06:24:30 +00:00
|
|
|
const sortDocuments = (documents: Document[]): Document[] => {
|
2018-03-01 07:00:41 +00:00
|
|
|
const orderedDocs = naturalSort(documents, 'title');
|
2018-12-05 06:24:30 +00:00
|
|
|
|
2018-02-07 07:26:14 +00:00
|
|
|
return orderedDocs.map(document => ({
|
|
|
|
...document,
|
|
|
|
children: sortDocuments(document.children),
|
|
|
|
}));
|
|
|
|
};
|
|
|
|
|
2019-04-18 02:11:23 +00:00
|
|
|
export default function present(collection: Collection) {
|
2017-06-26 00:21:33 +00:00
|
|
|
const data = {
|
|
|
|
id: collection.id,
|
2018-11-04 07:59:52 +00:00
|
|
|
url: collection.url,
|
2017-06-26 00:21:33 +00:00
|
|
|
name: collection.name,
|
|
|
|
description: collection.description,
|
2020-06-20 00:18:03 +00:00
|
|
|
icon: collection.icon,
|
2017-10-30 06:22:46 +00:00
|
|
|
color: collection.color || '#4E5C6E',
|
2017-06-26 00:21:33 +00:00
|
|
|
type: collection.type,
|
2019-01-05 21:37:33 +00:00
|
|
|
private: collection.private,
|
2017-06-26 00:21:33 +00:00
|
|
|
createdAt: collection.createdAt,
|
|
|
|
updatedAt: collection.updatedAt,
|
2019-04-18 02:11:23 +00:00
|
|
|
deletedAt: collection.deletedAt,
|
2017-07-07 05:02:55 +00:00
|
|
|
documents: undefined,
|
2017-06-26 00:21:33 +00:00
|
|
|
};
|
|
|
|
|
2017-07-07 05:02:55 +00:00
|
|
|
if (collection.type === 'atlas') {
|
2018-02-07 07:26:14 +00:00
|
|
|
// Force alphabetical sorting
|
|
|
|
data.documents = sortDocuments(collection.documentStructure);
|
2017-07-07 05:02:55 +00:00
|
|
|
}
|
2017-06-26 00:21:33 +00:00
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|