Skip to content

Commit

Permalink
GN-XXX: Fix agendapoint/regulatory attachment template "reload"
Browse files Browse the repository at this point in the history
  • Loading branch information
dkozickis committed Nov 16, 2023
1 parent 684815b commit 76e0461
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/wild-melons-dress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"frontend-gelinkt-notuleren": patch
---

GN-XXX: Fix agendapoint/regulatory attachment template "reload"
21 changes: 18 additions & 3 deletions app/components/document-creator.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,24 @@ export default class DocumentCreatorComponent extends Component {

async buildTemplate() {
if (this.template) {
if (this.template.reload) {
// regular templates from templatesForContext do not return body of template
await this.template.reload(this.template);
/**
* Document Creator component is used by two different screens:
* - Create agenda point flow
* - Create regulatory statements flow
*
* `templates` coming from regulatory statements flow are _NOT_ `TemplateModel` instances,
* they are just plain objects with a `title` and a `loadTemplateBody` property. So we
* have to use `loadTemplateBody` to load the template body if we need to build the template
* when creating a regulatory statement.
*
* This was previously checking and calling `this.template.reload`, but that was causing
* `reload` to mutate from function to a "boolean" when `TemplateModel` of `ember-data` is used,
* causing errors when calling `reload` on the template again, as it became a boolean.
*
* The fix was to change `reload` to `loadTemplateBody` in `RegulatoryAttachmentsFetcher`
*/
if (this.template.loadTemplateBody) {
await this.template.loadTemplateBody(this.template);
}
const trimmedHtml = this.template.body.replace(/>\s+</g, '><');
return instantiateUuids(trimmedHtml);
Expand Down
4 changes: 2 additions & 2 deletions app/services/regulatory-attachments-fetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default class RegulatoryAttachmentsFetcher extends Service {
pav:hasCurrentVersion ?container.
?container dct:title ?title;
mu:uuid ?fileId.
OPTIONAL {
OPTIONAL {
?container schema:validThrough ?validThrough.
}
FILTER( ! BOUND(?validThrough) || ?validThrough > NOW())
Expand Down Expand Up @@ -56,7 +56,7 @@ export default class RegulatoryAttachmentsFetcher extends Service {
const bindings = json.results.bindings;
const templates = bindings.map((binding) => ({
title: binding.title.value,
reload: async (template) => {
loadTemplateBody: async (template) => {
const response = await fetch(
`${config.regulatoryStatementFileEndpoint}/${binding.fileId.value}/download`,
);
Expand Down

0 comments on commit 76e0461

Please sign in to comment.