Skip to content

Commit

Permalink
lmb-1222: instead of providing three action do it in one and make it …
Browse files Browse the repository at this point in the history
…an object, only one consumer has to be added to the component
  • Loading branch information
JonasVanHoof committed Jan 22, 2025
1 parent 09736f4 commit 587cd0d
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 52 deletions.
8 changes: 4 additions & 4 deletions app/components/editable-form.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<SemanticForms::Instance
@show={{@isReadOnly}}
@instanceId={{@instanceId}}
@form={{this.currentForm}}
@form={{this.formContext.formDefinition}}
@onCancel={{@onCancel}}
@onSave={{@onSave}}
@formInitialized={{@formInitialized}}
Expand All @@ -11,7 +11,7 @@
@saveTitle={{@saveTitle}}
>
{{#if this.editableFormsEnabled}}
{{#unless this.isReadOnly}}
{{#unless @isReadOnly}}
<AuButton
@skin="link"
@icon="plus"
Expand All @@ -27,8 +27,8 @@
<RdfInputFields::CrudCustomFieldModal
@isCreating={{true}}
@showModal={{this.showModal}}
@onCloseModal={{this.onFormUpdate}}
@form={{this.currentForm}}
@onCloseModal={{this.formContext.onFormUpdate}}
@form={{this.formContext.formDefinition}}
@field={{@field}}
/>
{{/if}}
Expand Down
22 changes: 7 additions & 15 deletions app/components/editable-form.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Component from '@glimmer/component';

import { action } from '@ember/object';
import { tracked } from '@glimmer/tracking';
import { service } from '@ember/service';

Expand Down Expand Up @@ -38,19 +37,12 @@ export default class EditableFormComponent extends Component {
return this.features.isEnabled('editable-forms');
}

@provide('on-form-update')
@action
onFormUpdate() {
this.updateForm();
}

@provide('form-definition')
get formDefinition() {
return this.currentForm;
}

@provide('is-read-only')
get isReadOnly() {
return this.args.isReadOnly;
@provide('form-context')
get formContext() {
return {
onFormUpdate: () => this.updateForm(),
formDefinition: this.currentForm,
isReadOnly: this.args.isReadOnly,
};
}
}
51 changes: 30 additions & 21 deletions app/components/rdf-input-fields/crud-custom-field-modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ import {
} from 'frontend-lmb/utils/well-known-uris';

export default class RdfInputFieldCrudCustomFieldModalComponent extends Component {
@consume('form-definition') formDefinition;
@consume('on-form-update') onFormUpdate;
@consume('form-context') formContext;

@service store;
@service toaster;
Expand Down Expand Up @@ -64,19 +63,22 @@ export default class RdfInputFieldCrudCustomFieldModalComponent extends Componen

updateField = task(async () => {
try {
await fetch(`/form-content/${this.formDefinition.id}/fields`, {
method: 'PUT',
headers: {
'Content-Type': JSON_API_TYPE,
},
body: JSON.stringify({
field: this.args.field.uri.value,
displayType: this.displayType.uri,
name: this.fieldName,
isRequired: !!this.isFieldRequired,
}),
});
this.onFormUpdate();
await fetch(
`/form-content/${this.formContext.formDefinition.id}/fields`,
{
method: 'PUT',
headers: {
'Content-Type': JSON_API_TYPE,
},
body: JSON.stringify({
field: this.args.field.uri.value,
displayType: this.displayType.uri,
name: this.fieldName,
isRequired: !!this.isFieldRequired,
}),
}
);
this.formContext.onFormUpdate();
} catch (error) {
showErrorToast(
this.toaster,
Expand All @@ -89,7 +91,7 @@ export default class RdfInputFieldCrudCustomFieldModalComponent extends Componen
createField = task(async () => {
try {
const result = await fetch(
`/form-content/${this.formDefinition.id}/fields`,
`/form-content/${this.formContext.formDefinition.id}/fields`,
{
method: 'POST',
headers: {
Expand All @@ -106,8 +108,11 @@ export default class RdfInputFieldCrudCustomFieldModalComponent extends Componen

const body = await result.json();
const newFormId = body.id;
this.formReplacements.setReplacement(this.formDefinition.id, newFormId);
this.onFormUpdate();
this.formReplacements.setReplacement(
this.formContext.formDefinition.id,
newFormId
);
this.formContext.onFormUpdate();
} catch (error) {
showErrorToast(
this.toaster,
Expand Down Expand Up @@ -145,7 +150,7 @@ export default class RdfInputFieldCrudCustomFieldModalComponent extends Componen
formUri: this.args.form.uri,
}),
});
this.onFormUpdate();
this.formContext.onFormUpdate();
this.isRemovingField = false;
}

Expand All @@ -171,7 +176,11 @@ export default class RdfInputFieldCrudCustomFieldModalComponent extends Componen
}

const localStore = new ForkingStore();
localStore.parse(this.formDefinition.formTtl, SOURCE_GRAPH, 'text/turtle');
localStore.parse(
this.formContext.formDefinition.formTtl,
SOURCE_GRAPH,
'text/turtle'
);
const libraryEntree = localStore.any(
this.args.field.uri,
PROV('wasDerivedFrom'),
Expand All @@ -185,7 +194,7 @@ export default class RdfInputFieldCrudCustomFieldModalComponent extends Componen
get libraryFieldOptions() {
const forkingStore = new ForkingStore();
forkingStore.parse(
this.formDefinition.formTtl,
this.formContext.formDefinition.formTtl,
SOURCE_GRAPH,
'text/turtle'
);
Expand Down
4 changes: 2 additions & 2 deletions app/components/rdf-input-fields/custom-field-wrapper.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="au-u-flex au-u-flex--between">
<div class="flex-grow">
<div class="au-u-flex au-u-flex--row">
{{#unless this.isReadOnly}}
{{#unless this.formContext.isReadOnly}}
<AuLabel @required={{this.isRequired}}>{{this.title}}</AuLabel>
<AuButton
@skin="link-secondary"
Expand All @@ -29,7 +29,7 @@
</div>
</div>
</div>
{{#unless this.isReadOnly}}
{{#unless this.formContext.isReadOnly}}
<div class="au-u-flex au-u-flex--column au-u-flex--vertical-center">
<AuButton
@skin="naked"
Expand Down
10 changes: 4 additions & 6 deletions app/components/rdf-input-fields/custom-field-wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ import { JSON_API_TYPE } from 'frontend-lmb/utils/constants';
import { ADRES_CUSTOM_DISPLAY_TYPE } from 'frontend-lmb/utils/well-known-uris';

export default class RdfInputFieldsCustomFieldWrapperComponent extends Component {
@consume('on-form-update') onFormUpdate;
@consume('form-definition') formDefinition;
@consume('is-read-only') isReadOnly;
@consume('form-context') formContext;

@tracked showModal;

Expand All @@ -22,14 +20,14 @@ export default class RdfInputFieldsCustomFieldWrapperComponent extends Component

get isFieldReadOnly() {
return (
this.isReadOnly &&
this.formContext.isReadOnly &&
![ADRES_CUSTOM_DISPLAY_TYPE].includes(this.args.field.displayType)
);
}

moveField = task(async (direction) => {
const result = await fetch(
`/form-content/${this.formDefinition.id}/fields/move`,
`/form-content/${this.formContext.formDefinition.id}/fields/move`,
{
method: 'POST',
headers: {
Expand All @@ -44,7 +42,7 @@ export default class RdfInputFieldsCustomFieldWrapperComponent extends Component
);

if (result.ok) {
this.onFormUpdate();
this.formContext.onFormUpdate();
}
});

Expand Down
3 changes: 0 additions & 3 deletions app/components/rdf-input-fields/custom-string-input.js

This file was deleted.

2 changes: 1 addition & 1 deletion app/components/read-only-field-for-display-type.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{{#if this.value}}
<div class="au-u-flex au-u-flex--column">
<AuLabel class="au-c-description-label">
{{@field.label}}:
{{@field.label}}
</AuLabel>
<p class="au-c-description-value">{{this.value}}</p>
</div>
Expand Down

0 comments on commit 587cd0d

Please sign in to comment.