Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query if projects are in LF #798

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using LexCore.ServiceInterfaces;
using LfClassicData;
using MongoDB.Driver;
using MongoDB.Driver.Linq;

namespace LexBoxApi.GraphQL.CustomTypes;

public class IsLanguageForgeProjectDataLoader : BatchDataLoader<string, bool>, IIsLanguageForgeProjectDataLoader
{
private readonly SystemDbContext _systemDbContext;

public IsLanguageForgeProjectDataLoader(
SystemDbContext systemDbContext,
IBatchScheduler batchScheduler,
DataLoaderOptions? options = null)
: base(batchScheduler, options)
{
_systemDbContext = systemDbContext;
}

protected override async Task<IReadOnlyDictionary<string, bool>> LoadBatchAsync(
IReadOnlyList<string> projectCodes,
CancellationToken cancellationToken)
{
return await MongoExtensions.ToAsyncEnumerable(_systemDbContext.Projects.AsQueryable()
myieye marked this conversation as resolved.
Show resolved Hide resolved
.Select(p => p.ProjectCode)
.Where(projectCode => projectCodes.Contains(projectCode)))

Check warning on line 27 in backend/LexBoxApi/GraphQL/CustomTypes/IsLanguageForgeProjectDataLoader.cs

View workflow job for this annotation

GitHub Actions / Build API / publish-api

Method referencing lambda parameter is not supported LINQ expression. (https://www.mongodb.com/docs/mongodb-analyzer/current/rules/#MALinq2001)
.ToDictionaryAsync(projectCode => projectCode, _ => true, cancellationToken);
}
}
1 change: 1 addition & 0 deletions backend/LexBoxApi/GraphQL/GraphQlSetupKernel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public static void AddLexGraphQL(this IServiceCollection services, IHostEnvironm
.InitializeOnStartup()
.RegisterDbContext<LexBoxDbContext>()
.RegisterService<IHgService>()
.RegisterService<IIsLanguageForgeProjectDataLoader>()
.RegisterService<LoggedInContext>()
.RegisterService<EmailService>()
.RegisterService<LexAuthService>()
Expand Down
2 changes: 2 additions & 0 deletions backend/LexBoxApi/LexBoxKernel.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using LexBoxApi.Auth;
using LexBoxApi.Config;
using LexBoxApi.GraphQL;
using LexBoxApi.GraphQL.CustomTypes;
using LexBoxApi.Services;
using LexCore.Config;
using LexCore.ServiceInterfaces;
Expand Down Expand Up @@ -52,6 +53,7 @@ public static void AddLexBoxApi(this IServiceCollection services,
services.AddScoped<TusService>();
services.AddScoped<TurnstileService>();
services.AddScoped<IHgService, HgService>();
services.AddScoped<IIsLanguageForgeProjectDataLoader, IsLanguageForgeProjectDataLoader>();
services.AddScoped<ILexProxyService, LexProxyService>();
services.AddSingleton<ISendReceiveService, SendReceiveService>();
services.AddSingleton<LexboxLinkGenerator>();
Expand Down
9 changes: 9 additions & 0 deletions backend/LexCore/Entities/Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ public bool GetHasAbandonedTransactions(IHgService hgService)
{
return hgService.HasAbandonedTransactions(Code);
}

public Task<bool> GetIsLanguageForgeProject(IIsLanguageForgeProjectDataLoader loader)
{
if (Type is ProjectType.Unknown or ProjectType.FLEx)
{
return loader.LoadAsync(Code);
}
return Task.FromResult(false);
}
}

public enum ProjectMigrationStatus
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace LexCore.ServiceInterfaces;

public interface IIsLanguageForgeProjectDataLoader
{
public Task<bool> LoadAsync(string projectCode, CancellationToken cancellationToken = default);
}
1 change: 1 addition & 0 deletions frontend/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ type Project {
users: [ProjectUsers!]!
changesets: [Changeset!]!
hasAbandonedTransactions: Boolean!
isLanguageForgeProject: Boolean!
parentId: UUID
name: String!
description: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,14 @@
<HeaderPage wide title={project.name}>
<svelte:fragment slot="actions">
{#if project.type === ProjectType.FlEx && $isDev}
{#if project.isLanguageForgeProject}
<a href="./{project.code}/viewer" class="btn btn-neutral text-[#DCA54C] flex items-center gap-2">
{$t('project_page.open_with_viewer')}
<span class="i-mdi-dictionary text-2xl" />
</a>
<OpenInFlexModal bind:this={openInFlexModal} {project}/>
<OpenInFlexButton projectId={project.id} on:click={openInFlexModal.open}/>
{/if}
<OpenInFlexModal bind:this={openInFlexModal} {project}/>
<OpenInFlexButton projectId={project.id} on:click={openInFlexModal.open}/>
{:else}
<Dropdown>
<button class="btn btn-primary">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export async function load(event: PageLoadEvent) {
createdDate
retentionPolicy
isConfidential
isLanguageForgeProject
users {
id
role
Expand Down
Loading