Skip to content

Commit

Permalink
Query if projects are in LF
Browse files Browse the repository at this point in the history
  • Loading branch information
myieye committed May 14, 2024
1 parent 2869a47 commit a4395b6
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 2 deletions.
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()
.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

0 comments on commit a4395b6

Please sign in to comment.