Addressed user feedback
This commit is contained in:
@ -16,8 +16,11 @@ import { DropdownMenu, DropdownMenuItem } from 'components/DropdownMenu';
|
|||||||
document: Document,
|
document: Document,
|
||||||
};
|
};
|
||||||
|
|
||||||
onCreateDocument = () => {
|
handleNewChild = () => {
|
||||||
this.props.history.push(`${this.props.document.collection.url}/new`);
|
const { history, document } = this.props;
|
||||||
|
history.push(
|
||||||
|
`${document.collection.url}/new?parentDocument=${document.id}`
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
handleDelete = () => {
|
handleDelete = () => {
|
||||||
@ -52,7 +55,12 @@ import { DropdownMenu, DropdownMenuItem } from 'components/DropdownMenu';
|
|||||||
Unstar
|
Unstar
|
||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
: <DropdownMenuItem onClick={this.handleStar}>Star</DropdownMenuItem>}
|
: <DropdownMenuItem onClick={this.handleStar}>Star</DropdownMenuItem>}
|
||||||
|
<DropdownMenuItem
|
||||||
|
onClick={this.handleNewChild}
|
||||||
|
title="Create a new child document for the current document"
|
||||||
|
>
|
||||||
|
New child
|
||||||
|
</DropdownMenuItem>
|
||||||
<DropdownMenuItem onClick={this.handleMove}>Move</DropdownMenuItem>
|
<DropdownMenuItem onClick={this.handleMove}>Move</DropdownMenuItem>
|
||||||
<DropdownMenuItem onClick={this.handleExport}>Export</DropdownMenuItem>
|
<DropdownMenuItem onClick={this.handleExport}>Export</DropdownMenuItem>
|
||||||
{allowDelete &&
|
{allowDelete &&
|
||||||
|
@ -97,7 +97,7 @@ class Document extends BaseModel {
|
|||||||
|
|
||||||
@computed get parentDocumentId(): ?string {
|
@computed get parentDocumentId(): ?string {
|
||||||
return this.pathToDocument.length > 1
|
return this.pathToDocument.length > 1
|
||||||
? this.pathToDocument[this.pathToDocument.length - 1].id
|
? this.pathToDocument[this.pathToDocument.length - 2].id
|
||||||
: null;
|
: null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,7 +175,6 @@ class Document extends BaseModel {
|
|||||||
if (this.parentDocument) {
|
if (this.parentDocument) {
|
||||||
data.parentDocument = this.parentDocument;
|
data.parentDocument = this.parentDocument;
|
||||||
}
|
}
|
||||||
debugger;
|
|
||||||
res = await client.post('/documents.create', data);
|
res = await client.post('/documents.create', data);
|
||||||
}
|
}
|
||||||
runInAction('Document#save', () => {
|
runInAction('Document#save', () => {
|
||||||
|
43
package.json
43
package.json
@ -4,11 +4,14 @@
|
|||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"clean": "rimraf dist",
|
"clean": "rimraf dist",
|
||||||
"build:webpack": "NODE_ENV=production webpack --config webpack.config.prod.js",
|
"build:webpack":
|
||||||
"build:analyze": "NODE_ENV=production webpack --config webpack.config.prod.js --json | webpack-bundle-size-analyzer",
|
"NODE_ENV=production webpack --config webpack.config.prod.js",
|
||||||
|
"build:analyze":
|
||||||
|
"NODE_ENV=production webpack --config webpack.config.prod.js --json | webpack-bundle-size-analyzer",
|
||||||
"build": "npm run clean && npm run build:webpack",
|
"build": "npm run clean && npm run build:webpack",
|
||||||
"start": "node index.js",
|
"start": "node index.js",
|
||||||
"dev": "NODE_ENV=development DEBUG=sql,cache,presenters ./node_modules/.bin/nodemon --watch server index.js",
|
"dev":
|
||||||
|
"NODE_ENV=development DEBUG=sql,cache,presenters ./node_modules/.bin/nodemon --inspect --watch server index.js",
|
||||||
"lint": "npm run lint:flow && npm run lint:js",
|
"lint": "npm run lint:flow && npm run lint:js",
|
||||||
"lint:js": "eslint frontend",
|
"lint:js": "eslint frontend",
|
||||||
"lint:flow": "flow",
|
"lint:flow": "flow",
|
||||||
@ -18,39 +21,24 @@
|
|||||||
"sequelize:migrate": "sequelize db:migrate",
|
"sequelize:migrate": "sequelize db:migrate",
|
||||||
"test": "npm run test:frontend && npm run test:server",
|
"test": "npm run test:frontend && npm run test:server",
|
||||||
"test:frontend": "jest",
|
"test:frontend": "jest",
|
||||||
"test:server": "jest --config=server/.jestconfig.json --runInBand --forceExit",
|
"test:server":
|
||||||
|
"jest --config=server/.jestconfig.json --runInBand --forceExit",
|
||||||
"precommit": "lint-staged"
|
"precommit": "lint-staged"
|
||||||
},
|
},
|
||||||
"lint-staged": {
|
"lint-staged": {
|
||||||
"*.js": [
|
"*.js": ["eslint --fix", "git add"]
|
||||||
"eslint --fix",
|
|
||||||
"git add"
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
"jest": {
|
"jest": {
|
||||||
"verbose": false,
|
"verbose": false,
|
||||||
"roots": [
|
"roots": ["frontend"],
|
||||||
"frontend"
|
|
||||||
],
|
|
||||||
"moduleNameMapper": {
|
"moduleNameMapper": {
|
||||||
"^.*[.](s?css|css)$": "<rootDir>/__mocks__/styleMock.js",
|
"^.*[.](s?css|css)$": "<rootDir>/__mocks__/styleMock.js",
|
||||||
"^.*[.](gif|ttf|eot|svg)$": "<rootDir>/__test__/fileMock.js"
|
"^.*[.](gif|ttf|eot|svg)$": "<rootDir>/__test__/fileMock.js"
|
||||||
},
|
},
|
||||||
"moduleFileExtensions": [
|
"moduleFileExtensions": ["js", "jsx", "json"],
|
||||||
"js",
|
"moduleDirectories": ["node_modules"],
|
||||||
"jsx",
|
"modulePaths": ["frontend"],
|
||||||
"json"
|
"setupFiles": ["<rootDir>/setupJest.js", "<rootDir>/__mocks__/window.js"]
|
||||||
],
|
|
||||||
"moduleDirectories": [
|
|
||||||
"node_modules"
|
|
||||||
],
|
|
||||||
"modulePaths": [
|
|
||||||
"frontend"
|
|
||||||
],
|
|
||||||
"setupFiles": [
|
|
||||||
"<rootDir>/setupJest.js",
|
|
||||||
"<rootDir>/__mocks__/window.js"
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">= 7.6"
|
"node": ">= 7.6"
|
||||||
@ -169,7 +157,8 @@
|
|||||||
"string-hash": "^1.1.0",
|
"string-hash": "^1.1.0",
|
||||||
"style-loader": "^0.18.2",
|
"style-loader": "^0.18.2",
|
||||||
"styled-components": "^2.0.0",
|
"styled-components": "^2.0.0",
|
||||||
"truncate-html": "https://github.com/jorilallo/truncate-html/tarball/master",
|
"truncate-html":
|
||||||
|
"https://github.com/jorilallo/truncate-html/tarball/master",
|
||||||
"url-loader": "0.5.7",
|
"url-loader": "0.5.7",
|
||||||
"uuid": "2.0.2",
|
"uuid": "2.0.2",
|
||||||
"validator": "5.2.0",
|
"validator": "5.2.0",
|
||||||
|
@ -3,6 +3,7 @@ import TestServer from 'fetch-test-server';
|
|||||||
import app from '..';
|
import app from '..';
|
||||||
import { View, Star } from '../models';
|
import { View, Star } from '../models';
|
||||||
import { flushdb, seed } from '../test/support';
|
import { flushdb, seed } from '../test/support';
|
||||||
|
import Document from '../models/Document';
|
||||||
|
|
||||||
const server = new TestServer(app.callback());
|
const server = new TestServer(app.callback());
|
||||||
|
|
||||||
@ -194,6 +195,49 @@ describe('#documents.unstar', async () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('#documents.create', async () => {
|
||||||
|
it('should create as a new document', async () => {
|
||||||
|
const { user, collection } = await seed();
|
||||||
|
const res = await server.post('/api/documents.create', {
|
||||||
|
body: {
|
||||||
|
token: user.getJwtToken(),
|
||||||
|
collection: collection.id,
|
||||||
|
title: 'new document',
|
||||||
|
text: 'hello',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const body = await res.json();
|
||||||
|
const newDocument = await Document.findOne({
|
||||||
|
where: {
|
||||||
|
id: body.data.id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(res.status).toEqual(200);
|
||||||
|
expect(newDocument.parentDocumentId).toBe(null);
|
||||||
|
expect(newDocument.collection.id).toBe(collection.id);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create as a child', async () => {
|
||||||
|
const { user, document, collection } = await seed();
|
||||||
|
const res = await server.post('/api/documents.create', {
|
||||||
|
body: {
|
||||||
|
token: user.getJwtToken(),
|
||||||
|
collection: collection.id,
|
||||||
|
title: 'new document',
|
||||||
|
text: 'hello',
|
||||||
|
parentDocument: document.id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const body = await res.json();
|
||||||
|
|
||||||
|
expect(res.status).toEqual(200);
|
||||||
|
expect(body.data.title).toBe('new document');
|
||||||
|
expect(body.data.collection.documents.length).toBe(2);
|
||||||
|
expect(body.data.collection.documents[1].children[0].id).toBe(body.data.id);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('#documents.update', async () => {
|
describe('#documents.update', async () => {
|
||||||
it('should update document details in the root', async () => {
|
it('should update document details in the root', async () => {
|
||||||
const { user, document } = await seed();
|
const { user, document } = await seed();
|
||||||
|
@ -133,16 +133,23 @@ Collection.prototype.addDocumentToStructure = async function(document, index) {
|
|||||||
// Sequelize doesn't seem to set the value with splice on JSONB field
|
// Sequelize doesn't seem to set the value with splice on JSONB field
|
||||||
this.documentStructure = this.documentStructure;
|
this.documentStructure = this.documentStructure;
|
||||||
} else {
|
} else {
|
||||||
this.documentStructure = this.documentStructure.map(childDocument => {
|
// Recursively place document
|
||||||
|
const placeDocument = documentList => {
|
||||||
|
return documentList.map(childDocument => {
|
||||||
if (document.parentDocumentId === childDocument.id) {
|
if (document.parentDocumentId === childDocument.id) {
|
||||||
childDocument.children.splice(
|
childDocument.children.splice(
|
||||||
index || childDocument.children.length,
|
index || childDocument.children.length,
|
||||||
0,
|
0,
|
||||||
document.toJSON()
|
document.toJSON()
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
childDocument.children = placeDocument(childDocument.children);
|
||||||
}
|
}
|
||||||
|
|
||||||
return childDocument;
|
return childDocument;
|
||||||
});
|
});
|
||||||
|
};
|
||||||
|
this.documentStructure = placeDocument(this.documentStructure);
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.save();
|
await this.save();
|
||||||
|
Reference in New Issue
Block a user