@@ -69,18 +69,18 @@
{{ 'rules.triggerHint' | sqxTranslate }}
-
+
-
+
-
+
+ [trigger]="currentTrigger.form.value"
+ [triggerForm]="currentTrigger">
@@ -112,7 +112,7 @@
@@ -134,9 +134,9 @@
diff --git a/frontend/src/app/features/rules/pages/rule/rule-page.component.ts b/frontend/src/app/features/rules/pages/rule/rule-page.component.ts
index 146cae2d7..d816942fd 100644
--- a/frontend/src/app/features/rules/pages/rule/rule-page.component.ts
+++ b/frontend/src/app/features/rules/pages/rule/rule-page.component.ts
@@ -12,8 +12,6 @@ import { debounceTime, Subscription } from 'rxjs';
import { ActionForm, ALL_TRIGGERS, MessageBus, ResourceOwner, RuleDto, RuleElementDto, RulesService, RulesState, SchemasState, TriggerForm, value$ } from '@app/shared';
import { RuleConfigured } from '../messages';
-type ComponentState
= { type: string; values: any; form: T };
-
@Component({
selector: 'sqx-rule-page',
styleUrls: ['./rule-page.component.scss'],
@@ -28,8 +26,8 @@ export class RulePageComponent extends ResourceOwner implements OnInit {
public rule?: RuleDto | null;
- public currentTrigger?: ComponentState;
- public currentAction?: ComponentState;
+ public currentTrigger?: TriggerForm;
+ public currentAction?: ActionForm;
public isEnabled = false;
public isEditable = false;
@@ -39,11 +37,11 @@ export class RulePageComponent extends ResourceOwner implements OnInit {
}
public get actionElement() {
- return this.supportedActions![this.currentAction?.type || ''];
+ return this.supportedActions![this.currentAction?.actionType || ''];
}
public get triggerElement() {
- return this.supportedTriggers[this.currentTrigger?.type || ''];
+ return this.supportedTriggers[this.currentTrigger?.triggerType || ''];
}
constructor(
@@ -92,30 +90,32 @@ export class RulePageComponent extends ResourceOwner implements OnInit {
}
}
- public selectAction(type: string, values = {}) {
- if (this.currentAction?.type !== type && this.supportedActions) {
- const form = new ActionForm(this.supportedActions[type], type);
+ public selectAction(type: string, values?: any) {
+ const definition = this.supportedActions[type];
- this.currentAction = { form, type, values };
- this.currentAction.form.setEnabled(this.isEditable);
+ if (this.currentAction?.actionType !== type && definition) {
+ this.currentAction = new ActionForm(definition, type);
+ this.currentAction.setEnabled(this.isEditable);
this.currentActionSubscription?.unsubscribe();
- this.currentActionSubscription = this.subscribe(form.form);
+ this.currentActionSubscription = this.subscribe(this.currentAction.form);
}
- this.currentAction!.form.load(values);
+ if (values) {
+ this.currentAction?.load(values);
+ }
}
- public selectTrigger(type: string, values = {}) {
- if (this.currentTrigger?.type !== type) {
- const form = new TriggerForm(type);
-
- this.currentTrigger = { form, type, values };
- this.currentTrigger.form.setEnabled(this.isEditable);
+ public selectTrigger(type: string, values?: any) {
+ if (this.currentTrigger?.triggerType !== type) {
+ this.currentTrigger = new TriggerForm(type);
+ this.currentTrigger.setEnabled(this.isEditable);
this.currentTriggerSubscription?.unsubscribe();
- this.currentTriggerSubscription = this.subscribe(form.form);
+ this.currentTriggerSubscription = this.subscribe(this.currentTrigger.form);
}
- this.currentTrigger.form.load(values);
+ if (values) {
+ this.currentTrigger?.load(values || {});
+ }
}
private subscribe(form: AbstractControl) {
@@ -139,13 +139,13 @@ export class RulePageComponent extends ResourceOwner implements OnInit {
return;
}
- const action = this.currentAction.form.submit();
+ const action = this.currentAction.submit();
if (!action) {
return;
}
- const trigger = this.currentTrigger.form.submit();
+ const trigger = this.currentTrigger.submit();
if (!trigger || !action) {
return;
@@ -183,23 +183,23 @@ export class RulePageComponent extends ResourceOwner implements OnInit {
return;
}
- if (!this.currentAction.form.form.valid || !this.currentTrigger.form.form.valid) {
+ if (!this.currentAction.form.valid || !this.currentTrigger.form.valid) {
return;
}
this.messageBus.emit(new RuleConfigured(
- this.currentTrigger.form.getValue(),
- this.currentAction.form.getValue()));
+ this.currentTrigger.getValue(),
+ this.currentAction.getValue()));
}
private submitCompleted() {
- this.currentAction?.form.submitCompleted({ noReset: true });
- this.currentTrigger?.form.submitCompleted({ noReset: true });
+ this.currentAction?.submitCompleted({ noReset: true });
+ this.currentTrigger?.submitCompleted({ noReset: true });
}
private submitFailed(error: any) {
- this.currentAction?.form?.submitFailed(error);
- this.currentTrigger?.form?.submitFailed(error);
+ this.currentAction?.submitFailed(error);
+ this.currentTrigger?.submitFailed(error);
}
public back() {
diff --git a/frontend/src/app/features/rules/shared/triggers/content-changed-trigger.component.ts b/frontend/src/app/features/rules/shared/triggers/content-changed-trigger.component.ts
index 8ebef1f07..af2983159 100644
--- a/frontend/src/app/features/rules/shared/triggers/content-changed-trigger.component.ts
+++ b/frontend/src/app/features/rules/shared/triggers/content-changed-trigger.component.ts
@@ -75,13 +75,13 @@ export class ContentChangedTriggerComponent implements OnChanges {
}
public updateCondition(schema: SchemaDto, condition: string) {
- this.triggerSchemas = this.triggerSchemas.map(s => (s.schema === schema ? { schema, condition } : s));
+ this.triggerSchemas.replaceBy('schema', { schema, condition });
this.updateValue();
}
public updateValue() {
- const schemas = this.triggerSchemas.map(s => ({ schemaId: s.schema.id, condition: s.condition }));
+ const schemas = this.triggerSchemas.map(({ schema, condition }) => ({ schemaId: schema.id, condition }));
this.triggerForm.form.patchValue({ schemas });
}
diff --git a/frontend/src/app/shared/state/languages.state.ts b/frontend/src/app/shared/state/languages.state.ts
index 15830e724..273656e01 100644
--- a/frontend/src/app/shared/state/languages.state.ts
+++ b/frontend/src/app/shared/state/languages.state.ts
@@ -189,8 +189,7 @@ export class LanguagesState extends State {
.map(l => languages.find(x => x.iso2Code === l)).defined(),
fallbackLanguagesNew:
languages
- .filter(l => language.iso2Code !== l.iso2Code && !language.fallback.includes(l.iso2Code))
- .sortByString(x => x.englishName),
+ .filter(l => language.iso2Code !== l.iso2Code && !language.fallback.includes(l.iso2Code)).sortByString(x => x.englishName),
};
}
}
diff --git a/frontend/src/app/shared/state/rules.forms.ts b/frontend/src/app/shared/state/rules.forms.ts
index 53475ffa4..a68de081c 100644
--- a/frontend/src/app/shared/state/rules.forms.ts
+++ b/frontend/src/app/shared/state/rules.forms.ts
@@ -11,7 +11,7 @@ import { RuleElementDto } from '../services/rules.service';
export class ActionForm extends Form {
constructor(public readonly definition: RuleElementDto,
- private readonly actionType: string,
+ public readonly actionType: string,
) {
super(ActionForm.builForm(definition));
}
@@ -40,7 +40,7 @@ export class ActionForm extends Form {
export class TriggerForm extends Form {
constructor(
- private readonly triggerType: string,
+ public readonly triggerType: string,
) {
super(TriggerForm.builForm(triggerType));
}