Skip to content

Commit

Permalink
Fix previous URL.
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastianStehle committed Jul 24, 2024
1 parent 266dbc9 commit cfc3855
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
using System.Text.Json.Serialization.Metadata;
using Squidex.Infrastructure.Reflection;

#pragma warning disable MA0084 // Local variables should not hide other symbols

namespace Squidex.Infrastructure.Json.System;

public sealed class PolymorphicConverter<T> : JsonConverter<T> where T : class
Expand Down Expand Up @@ -38,8 +40,8 @@ public static Action<JsonTypeInfo> Modifier(TypeRegistry typeRegistry)
{
if (typeRegistry.TryGetConfig(baseType, out var config) && config.TryGetName(typeInfo.Type, out var typeName))
{
var discriminiatorName = config.DiscriminatorProperty ?? Constants.DefaultDiscriminatorProperty;
var discriminatorField = typeInfo.CreateJsonPropertyInfo(typeof(string), discriminiatorName);
var discriminatorName = config.DiscriminatorProperty ?? Constants.DefaultDiscriminatorProperty;
var discriminatorField = typeInfo.CreateJsonPropertyInfo(typeof(string), discriminatorName);
discriminatorField.Get = x =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ public async Task Should_return_schemas_if_user_has_permission()
BaseContext = CreateContext(PermissionIds.ForApp(PermissionIds.AppSchemasRead, App.Name).Id)
};

var tool = await sut.GetToolsAsync(chatContext, default).FirstOrDefaultAsync();
var tool = await sut.GetToolsAsync(chatContext, CancellationToken).FirstOrDefaultAsync(CancellationToken);

Assert.NotNull(tool);
Assert.Equal("schemas", tool.Spec.Name);
Assert.Equal("Schemas", tool.Spec.DisplayName);

var result = await tool.ExecuteAsync(Activator.CreateInstance<ToolContext>(), default);
var result = await tool.ExecuteAsync(Activator.CreateInstance<ToolContext>(), CancellationToken);

Assert.Contains(Schema.Name, result, StringComparison.Ordinal);

Expand All @@ -56,7 +56,7 @@ public async Task Should_not_return_tools_if_user_no_permission()
BaseContext = FrontendContext
};

var tool = await sut.GetToolsAsync(chatContext, default).FirstOrDefaultAsync();
var tool = await sut.GetToolsAsync(chatContext, CancellationToken).FirstOrDefaultAsync(CancellationToken);

Assert.Null(tool);
}
Expand Down
24 changes: 17 additions & 7 deletions frontend/src/app/framework/services/previous-url.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,28 @@
*/

import { Injectable } from '@angular/core';
import { Router, RoutesRecognized } from '@angular/router';
import { filter, pairwise } from 'rxjs/operators';

@Injectable({
providedIn: 'root',
})
export class PreviousUrl {
public pathStartsWith(path: string) {
try {
const url = new URL(document.referrer);
private previousPath = '';

constructor(
private readonly router: Router,
) {
this.previousPath = router.url;

return url.pathname.startsWith(path);
} catch {
return false;
}
this.router.events
.pipe(filter(e => e instanceof RoutesRecognized), pairwise())
.subscribe((event: any[]) => {
this.previousPath = event[0].urlAfterRedirects;
});
}

public pathStartsWith(path: string) {
return this.previousPath && this.previousPath.startsWith(path);
}
}

0 comments on commit cfc3855

Please sign in to comment.