Order document structure alphabetically
This commit is contained in:
@ -279,7 +279,7 @@ describe('#documents.create', async () => {
|
|||||||
expect(res.status).toEqual(200);
|
expect(res.status).toEqual(200);
|
||||||
expect(body.data.title).toBe('new document');
|
expect(body.data.title).toBe('new document');
|
||||||
expect(body.data.collection.documents.length).toBe(2);
|
expect(body.data.collection.documents.length).toBe(2);
|
||||||
expect(body.data.collection.documents[1].children[0].id).toBe(body.data.id);
|
expect(body.data.collection.documents[0].children[0].id).toBe(body.data.id);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should create as a child', async () => {
|
it('should create as a child', async () => {
|
||||||
@ -318,7 +318,7 @@ describe('#documents.update', async () => {
|
|||||||
expect(res.status).toEqual(200);
|
expect(res.status).toEqual(200);
|
||||||
expect(body.data.title).toBe('Updated title');
|
expect(body.data.title).toBe('Updated title');
|
||||||
expect(body.data.text).toBe('Updated text');
|
expect(body.data.text).toBe('Updated text');
|
||||||
expect(body.data.collection.documents[1].title).toBe('Updated title');
|
expect(body.data.collection.documents[0].title).toBe('Updated title');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should fallback to a default title', async () => {
|
it('should fallback to a default title', async () => {
|
||||||
@ -338,7 +338,7 @@ describe('#documents.update', async () => {
|
|||||||
expect(res.status).toEqual(200);
|
expect(res.status).toEqual(200);
|
||||||
expect(body.data.title).toBe('Untitled document');
|
expect(body.data.title).toBe('Untitled document');
|
||||||
expect(body.data.text).toBe('# Untitled document');
|
expect(body.data.text).toBe('# Untitled document');
|
||||||
expect(body.data.collection.documents[1].title).toBe('Untitled document');
|
expect(body.data.collection.documents[0].title).toBe('Untitled document');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should fail if document lastRevision does not match', async () => {
|
it('should fail if document lastRevision does not match', async () => {
|
||||||
|
@ -147,6 +147,8 @@ Collection.prototype.addDocumentToStructure = async function(
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (!document.parentDocumentId) {
|
if (!document.parentDocumentId) {
|
||||||
|
// Note: Index is supported on DB level but it's being ignored
|
||||||
|
// by the API presentation until we build product support for it.
|
||||||
this.documentStructure.splice(
|
this.documentStructure.splice(
|
||||||
index !== undefined ? index : this.documentStructure.length,
|
index !== undefined ? index : this.documentStructure.length,
|
||||||
0,
|
0,
|
||||||
|
@ -362,9 +362,9 @@ export default function Pricing() {
|
|||||||
<Method method="documents.move" label="Move document in a collection">
|
<Method method="documents.move" label="Move document in a collection">
|
||||||
<Description>
|
<Description>
|
||||||
Move a document into a new location inside the collection. This is
|
Move a document into a new location inside the collection. This is
|
||||||
easily done by defining the parent document ID and optional index.
|
easily done by defining the parent document ID. If no parent
|
||||||
If no parent document is provided, the document will be moved to
|
document is provided, the document will be moved to the collection
|
||||||
the collection root.
|
root.
|
||||||
</Description>
|
</Description>
|
||||||
<Arguments>
|
<Arguments>
|
||||||
<Argument
|
<Argument
|
||||||
@ -376,7 +376,6 @@ export default function Pricing() {
|
|||||||
id="parentDocument"
|
id="parentDocument"
|
||||||
description="ID of the new parent document (if any)"
|
description="ID of the new parent document (if any)"
|
||||||
/>
|
/>
|
||||||
<Argument id="index" description="Index of the new location" />
|
|
||||||
</Arguments>
|
</Arguments>
|
||||||
</Method>
|
</Method>
|
||||||
|
|
||||||
|
@ -3,6 +3,21 @@ import _ from 'lodash';
|
|||||||
import { Collection } from '../models';
|
import { Collection } from '../models';
|
||||||
import presentDocument from './document';
|
import presentDocument from './document';
|
||||||
|
|
||||||
|
type Document = {
|
||||||
|
children: Document[],
|
||||||
|
id: string,
|
||||||
|
title: string,
|
||||||
|
url: string,
|
||||||
|
};
|
||||||
|
|
||||||
|
const sortDocuments = (documents: Document[]) => {
|
||||||
|
const orderedDocs = _.sortBy(documents, ['title']);
|
||||||
|
return orderedDocs.map(document => ({
|
||||||
|
...document,
|
||||||
|
children: sortDocuments(document.children),
|
||||||
|
}));
|
||||||
|
};
|
||||||
|
|
||||||
async function present(ctx: Object, collection: Collection) {
|
async function present(ctx: Object, collection: Collection) {
|
||||||
ctx.cache.set(collection.id, collection);
|
ctx.cache.set(collection.id, collection);
|
||||||
|
|
||||||
@ -20,7 +35,8 @@ async function present(ctx: Object, collection: Collection) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (collection.type === 'atlas') {
|
if (collection.type === 'atlas') {
|
||||||
data.documents = collection.documentStructure;
|
// Force alphabetical sorting
|
||||||
|
data.documents = sortDocuments(collection.documentStructure);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (collection.documents) {
|
if (collection.documents) {
|
||||||
|
Reference in New Issue
Block a user