diff --git a/backend/src/Squidex.Infrastructure/Commands/DomainObject.cs b/backend/src/Squidex.Infrastructure/Commands/DomainObject.cs index 9ade10d14..12b1e7b2e 100644 --- a/backend/src/Squidex.Infrastructure/Commands/DomainObject.cs +++ b/backend/src/Squidex.Infrastructure/Commands/DomainObject.cs @@ -105,7 +105,7 @@ namespace Squidex.Infrastructure.Commands }), @event => { - if (@event is IMigratedStateEvent migratable) + if (@event.Payload is IMigratedStateEvent migratable) { var payload = migratable.Migrate(Snapshot); diff --git a/backend/src/Squidex/Config/Domain/MigrationServices.cs b/backend/src/Squidex/Config/Domain/MigrationServices.cs index 4e2338e18..520bafceb 100644 --- a/backend/src/Squidex/Config/Domain/MigrationServices.cs +++ b/backend/src/Squidex/Config/Domain/MigrationServices.cs @@ -1,4 +1,4 @@ -// ========================================================================== +// ========================================================================== // Squidex Headless CMS // ========================================================================== // Copyright (c) Squidex UG (haftungsbeschraenkt) @@ -35,9 +35,6 @@ namespace Squidex.Config.Domain services.AddTransientAs() .As(); - services.AddTransientAs() - .As(); - services.AddTransientAs() .As(); @@ -72,4 +69,4 @@ namespace Squidex.Config.Domain .As(); } } -} \ No newline at end of file +} diff --git a/backend/tests/Squidex.Infrastructure.Tests/Commands/DomainObjectTests.cs b/backend/tests/Squidex.Infrastructure.Tests/Commands/DomainObjectTests.cs index 9f2255b0d..b03fe0def 100644 --- a/backend/tests/Squidex.Infrastructure.Tests/Commands/DomainObjectTests.cs +++ b/backend/tests/Squidex.Infrastructure.Tests/Commands/DomainObjectTests.cs @@ -84,6 +84,18 @@ namespace Squidex.Infrastructure.Commands AssertSnapshot(sut.Snapshot, 4, 0); } + [Fact] + public async Task Should_create_old_event() + { + SetupCreated(new ValueChanged { Value = 10 }, new MultipleByTwiceEvent()); + + await sut.EnsureLoadedAsync(); + + Assert.Equal(1, sut.Version); + Assert.Equal(1, sut.Snapshot.Version); + Assert.Equal(20, sut.Snapshot.Value); + } + [Fact] public async Task Should_recreate_with_create_command_if_deleted_before() { @@ -449,6 +461,11 @@ namespace Squidex.Infrastructure.Commands } private void SetupCreated(int value) + { + SetupCreated(new ValueChanged { Value = value }); + } + + private void SetupCreated(params IEvent[] @events) { var handleEvent = new HandleEvent(_ => true); @@ -457,9 +474,12 @@ namespace Squidex.Infrastructure.Commands A.CallTo(() => persistence.ReadAsync(-2)) .Invokes(() => { - version = 0; + version++; - handleEvent(Envelope.Create(new ValueChanged { Value = value })); + foreach (var @event in events) + { + handleEvent(Envelope.Create(@event)); + } }); A.CallTo(() => persistenceFactory.WithSnapshotsAndEventSourcing(typeof(MyDomainObject), id, A>._, A._)) diff --git a/backend/tests/Squidex.Infrastructure.Tests/TestHelpers/MyDomainState.cs b/backend/tests/Squidex.Infrastructure.Tests/TestHelpers/MyDomainState.cs index 32bedeba9..b47bc9d21 100644 --- a/backend/tests/Squidex.Infrastructure.Tests/TestHelpers/MyDomainState.cs +++ b/backend/tests/Squidex.Infrastructure.Tests/TestHelpers/MyDomainState.cs @@ -34,6 +34,17 @@ namespace Squidex.Infrastructure.TestHelpers } } + public sealed class MultipleByTwiceEvent : IEvent, IMigratedStateEvent + { + public IEvent Migrate(MyDomainState state) + { + return new ValueChanged + { + Value = state.Value * 2 + }; + } + } + public sealed class ValueChanged : IEvent { public long Value { get; set; } diff --git a/frontend/app/features/rules/module.ts b/frontend/app/features/rules/module.ts index 85fb52231..38a193b1c 100644 --- a/frontend/app/features/rules/module.ts +++ b/frontend/app/features/rules/module.ts @@ -25,6 +25,10 @@ const routes: Routes = [ path: 'events', component: RuleEventsPageComponent }, + { + path: 'simulator', + component: RuleSimulatorPageComponent + }, { path: 'help', component: HelpComponent, diff --git a/frontend/app/features/rules/pages/events/rule-event.component.html b/frontend/app/features/rules/pages/events/rule-event.component.html index 4858f25b7..5503fbedf 100644 --- a/frontend/app/features/rules/pages/events/rule-event.component.html +++ b/frontend/app/features/rules/pages/events/rule-event.component.html @@ -45,7 +45,7 @@
- +
diff --git a/frontend/app/features/rules/pages/events/rule-events-page.component.ts b/frontend/app/features/rules/pages/events/rule-events-page.component.ts index b1df9a70c..120d79784 100644 --- a/frontend/app/features/rules/pages/events/rule-events-page.component.ts +++ b/frontend/app/features/rules/pages/events/rule-events-page.component.ts @@ -6,7 +6,8 @@ */ import { Component, OnInit } from '@angular/core'; -import { Router2State, RuleEventDto, RuleEventsState } from '@app/shared'; +import { ActivatedRoute } from '@angular/router'; +import { ResourceOwner, Router2State, RuleEventDto, RuleEventsState } from '@app/shared'; @Component({ selector: 'sqx-rule-events-page', @@ -16,24 +17,30 @@ import { Router2State, RuleEventDto, RuleEventsState } from '@app/shared'; Router2State ] }) -export class RuleEventsPageComponent implements OnInit { +export class RuleEventsPageComponent extends ResourceOwner implements OnInit { public selectedEventId: string | null = null; constructor( + private readonly route: ActivatedRoute, public readonly ruleEventsRoute: Router2State, public readonly ruleEventsState: RuleEventsState ) { + super(); } public ngOnInit() { - const initial = - this.ruleEventsRoute.mapTo(this.ruleEventsState) - .withPaging('rules', 30) - .withString('query') - .getInitial(); - - this.ruleEventsState.load(false, initial); - this.ruleEventsRoute.unlisten(); + this.own( + this.route.queryParams + .subscribe(() => { + const initial = + this.ruleEventsRoute.mapTo(this.ruleEventsState) + .withPaging('rules', 30) + .withString('ruleId') + .withString('query') + .getInitial(); + + this.ruleEventsState.load(false, initial); + })); } public reload() { diff --git a/frontend/app/features/rules/pages/rule/rule-page.component.html b/frontend/app/features/rules/pages/rule/rule-page.component.html index 25c902387..cf325d7f5 100644 --- a/frontend/app/features/rules/pages/rule/rule-page.component.html +++ b/frontend/app/features/rules/pages/rule/rule-page.component.html @@ -34,7 +34,7 @@
- +
@@ -97,7 +97,7 @@
- +
diff --git a/frontend/app/features/rules/pages/rules/rule.component.html b/frontend/app/features/rules/pages/rules/rule.component.html index 585296494..5e5d1361f 100644 --- a/frontend/app/features/rules/pages/rules/rule.component.html +++ b/frontend/app/features/rules/pages/rules/rule.component.html @@ -103,6 +103,10 @@ {{ 'common.logs' | sqxTranslate }} + + + {{ 'rules.simulator' | sqxTranslate }} +
diff --git a/frontend/app/features/rules/shared/actions/formattable-input.component.html b/frontend/app/features/rules/shared/actions/formattable-input.component.html index 1d9f28e70..f6eb31e70 100644 --- a/frontend/app/features/rules/shared/actions/formattable-input.component.html +++ b/frontend/app/features/rules/shared/actions/formattable-input.component.html @@ -1,6 +1,6 @@
- +