From 5b4aab356c81344db1ec6bc45f00ef7bb5fb8789 Mon Sep 17 00:00:00 2001 From: Mitan Omar Date: Mon, 16 Sep 2024 15:01:29 +0200 Subject: [PATCH] refactor(document-view): change document search URL in document dossier --- addon/components/document-view.js | 26 +++++++++++++++++++++----- addon/controllers/index.js | 6 ++++-- tests/dummy/mirage/config.js | 1 + 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/addon/components/document-view.js b/addon/components/document-view.js index f680f7e0..0eb9c1ac 100644 --- a/addon/components/document-view.js +++ b/addon/components/document-view.js @@ -61,11 +61,27 @@ export default class DocumentViewComponent extends Component { @task *fetchDocuments() { - const documents = yield this.store.query("document", { - include: "category,files,tags", - filter: this.args.filters || {}, - sort: this.sort ? `${this.sortDirection}${this.sort}` : "", - }); + const files = yield this.store.query( + "file", + { + include: "document,renderings", + filter: this.args.filters || {}, + }, + { + adapterOptions: { + customEndpoint: "search", + }, + }, + ); + + const documents = Array.from( + new Map( + files.map((file) => [ + file.document.id, + this.store.peekRecord("document", file.document.id), + ]), + ).values(), + ); return yield this.config.documentsPostProcess(documents); } diff --git a/addon/controllers/index.js b/addon/controllers/index.js index b391ab28..2393cd08 100644 --- a/addon/controllers/index.js +++ b/addon/controllers/index.js @@ -28,14 +28,16 @@ export default class IndexController extends Controller { category: this.category, tags: this.tags.length ? this.tags.join(",") : undefined, marks: this.marks.length ? this.marks.join(",") : undefined, - search: this.search, + query: this.search, activeGroup: this.activeGroup, }; if (this.config && this.config.modelMetaFilters?.document) { filters = { ...filters, - metainfo: JSON.stringify(this.config.modelMetaFilters.document), + document_metainfo: JSON.stringify( + this.config.modelMetaFilters.document, + ), }; } diff --git a/tests/dummy/mirage/config.js b/tests/dummy/mirage/config.js index 6050fbfa..b98887ed 100644 --- a/tests/dummy/mirage/config.js +++ b/tests/dummy/mirage/config.js @@ -27,6 +27,7 @@ export default function makeServer(config) { }); this.get("/files/multi", () => new Response(200, {}, {})); + this.get("/search", () => []); }, }); }