fix: Allow selection of embeds (#1562)

* feat: Support importing .docx or .html files as new documents (#1551)

* Support importing .docx as new documents

* Add html file support, build types and interface for easily adding file types to importer

* fix: Upload embedded images in docx to storage

* refactor: Bulk of logic to command

* refactor: Do all importing on server, so we're not splitting logic for import into two places

* test: Add documentImporter tests


Co-authored-by: Lance Whatley <whatl3y@gmail.com>

* fix: Accessibility audit

* fix: Quick fix, non editable title
closes #1560

* fix: Embed selection

Co-authored-by: Lance Whatley <whatl3y@gmail.com>
This commit is contained in:
Tom Moor
2020-09-20 22:27:11 -07:00
committed by GitHub
parent e67d319e2b
commit 4ffc04bc5d
53 changed files with 735 additions and 218 deletions

View File

@@ -18,12 +18,23 @@ import Document from "models/Document";
import type { FetchOptions, PaginationParams, SearchResult } from "types";
import { client } from "utils/ApiClient";
type ImportOptions = {
publish?: boolean,
};
export default class DocumentsStore extends BaseStore<Document> {
@observable recentlyViewedIds: string[] = [];
@observable searchCache: Map<string, SearchResult[]> = new Map();
@observable starredIds: Map<string, boolean> = new Map();
@observable backlinks: Map<string, string[]> = new Map();
importFileTypes: string[] = [
"text/markdown",
"text/plain",
"text/html",
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
];
constructor(rootStore: RootStore) {
super(rootStore, Document);
}
@@ -455,6 +466,41 @@ export default class DocumentsStore extends BaseStore<Document> {
return this.add(res.data);
};
@action
import = async (
file: File,
parentDocumentId: string,
collectionId: string,
options: ImportOptions
) => {
const title = file.name.replace(/\.[^/.]+$/, "");
const formData = new FormData();
[
{ key: "parentDocumentId", value: parentDocumentId },
{ key: "collectionId", value: collectionId },
{ key: "title", value: title },
{ key: "publish", value: options.publish },
{ key: "file", value: file },
].map((info) => {
if (typeof info.value === "string" && info.value) {
formData.append(info.key, info.value);
}
if (typeof info.value === "boolean") {
formData.append(info.key, info.value.toString());
}
if (info.value instanceof File) {
formData.append(info.key, info.value);
}
});
const res = await client.post("/documents.import", formData);
invariant(res && res.data, "Data should be available");
this.addPolicies(res.policies);
return this.add(res.data);
};
_add = this.add;
@action