From c4e546e96390e807f658a70caac0cda49e4fc8fa Mon Sep 17 00:00:00 2001 From: dyatlov-a Date: Sat, 9 Nov 2024 19:09:31 +0200 Subject: [PATCH] Added WidgetsDataFactory for dashboard stories --- .../Dashboard/Dashboard.stories.razor | 185 +------------ .../Features/Dashboard/WidgetsDataFactory.cs | 257 ++++++++++++++++++ src/Inc.TeamAssistant.Stories/Program.cs | 2 + 3 files changed, 269 insertions(+), 175 deletions(-) create mode 100644 src/Inc.TeamAssistant.Stories/Features/Dashboard/WidgetsDataFactory.cs diff --git a/src/Inc.TeamAssistant.Stories/Features/Dashboard/Dashboard.stories.razor b/src/Inc.TeamAssistant.Stories/Features/Dashboard/Dashboard.stories.razor index 968e8b56..c32ad646 100644 --- a/src/Inc.TeamAssistant.Stories/Features/Dashboard/Dashboard.stories.razor +++ b/src/Inc.TeamAssistant.Stories/Features/Dashboard/Dashboard.stories.razor @@ -1,6 +1,6 @@ @attribute [Stories("Features/Dashboard/Widgets")] -@inject IDateSelectorFactory DateSelectorFactory +@inject WidgetsDataFactory WidgetsDataFactory @@ -224,7 +224,7 @@ typeof(RandomCoffeeHistoryWidget), typeof(MapWidget) ]; - + private readonly IReadOnlyCollection _reviewerWidgets = [ typeof(TeammatesWidget), @@ -232,20 +232,20 @@ typeof(ReviewHistoryWidget), typeof(ReviewTotalStatsWidget) ]; - + private readonly IReadOnlyCollection _appraiserWidgets = [ typeof(TeammatesWidget), typeof(AppraiserHistoryWidget), typeof(AppraiserIntegrationWidget) ]; - + private readonly IReadOnlyCollection _randomCoffeeWidgets = [ typeof(TeammatesWidget), typeof(RandomCoffeeHistoryWidget) ]; - + private readonly IReadOnlyCollection _mapWidgets = [ typeof(TeammatesWidget), @@ -258,7 +258,8 @@ Id: Guid.NewGuid(), Name: "Bot 1", OwnerId: 1, - Teams: [ + Teams: + [ new TeamDto(Id: TeamId, Name: "Team 1"), new TeamDto(Id: Guid.NewGuid(), Name: "Team 2") ]), @@ -266,7 +267,8 @@ Id: Guid.NewGuid(), Name: "Bot 2", OwnerId: 1, - Teams: [ + Teams: + [ new TeamDto(Id: TeamId, Name: "Team 3") ]), new( @@ -281,172 +283,5 @@ LinkForConnect: "#", Code: CodeForConnectFactory.CreateDark()); - private Dictionary CreateWidgetParameters(Type type) - { - var weeks = DateSelectorFactory.CreateWeeks(); - var months = DateSelectorFactory.CreateMonths(); - - if (type == typeof(TeammatesWidget)) - return new Dictionary - { - ["TeamId"] = TeamId, - ["State"] = LoadingState.Done(), - ["Item"] = new GetTeammatesResult( - HasManagerAccess: true, - Teammates: - [ - new TeammateDto( - TeamId: TeamId, - PersonId: 1, - Name: "Aleksandr", - UserName: "adiatlov", - LeaveUntil: null), - new TeammateDto( - TeamId: TeamId, - PersonId: 2, - Name: "Alex", - UserName: null, - LeaveUntil: null) - ]), - ["Retry"] = () => Task.CompletedTask - }; - if (type == typeof(ReviewAverageStatsWidget)) - return new Dictionary - { - ["TeamId"] = TeamId, - ["Date"] = weeks.First().Value, - ["DateItems"] = weeks, - ["State"] = LoadingState.Done(), - ["Items"] = new[] - { - new ReviewAverageStatsDto( - Created: new DateOnly(2024, 10, 28), - FirstTouch: TimeSpan.FromMinutes(10), - Review: TimeSpan.FromMinutes(40), - Correction: TimeSpan.FromMinutes(20)) - }, - ["Retry"] = () => Task.CompletedTask - }; - if (type == typeof(ReviewHistoryWidget)) - return new Dictionary - { - ["TeamId"] = TeamId, - ["Date"] = weeks.First().Value, - ["DateItems"] = weeks, - ["State"] = LoadingState.Done(), - ["Items"] = new[] - { - new TaskForReviewDto( - Id: Guid.NewGuid(), - Created: DateTimeOffset.UtcNow, - State: "Accept", - Description: "Description", - FirstTouch: TimeSpan.FromMinutes(10), - Correction: TimeSpan.FromMinutes(20), - Review: TimeSpan.FromMinutes(40), - Iterations: 2, - ReviewerId: 1, - ReviewerName: "Aleksandr", - ReviewerUserName: "adiatlov", - OwnerId: 2, - OwnerName: "Alex", - OwnerUserName: null, - HasConcreteReviewer: false, - IsOriginalReviewer: false) - }, - ["Retry"] = () => Task.CompletedTask - }; - if (type == typeof(ReviewTotalStatsWidget)) - return new Dictionary - { - ["TeamId"] = TeamId, - ["Date"] = weeks.First().Value, - ["DateItems"] = weeks, - ["State"] = LoadingState.Done(), - ["FormModel"] = new ReviewTotalStatsWidgetFormModel().Apply(new GetHistoryByTeamResult( - Review: - [ - new HistoryByTeamItemDto(PersonName: "Aleksandr (adiatlov)", Count: 10), - new HistoryByTeamItemDto(PersonName: "Alex", Count: 6) - ], - Requests: - [ - new HistoryByTeamItemDto(PersonName: "Aleksandr (adiatlov)", Count: 6), - new HistoryByTeamItemDto(PersonName: "Alex", Count: 10) - ]), weeks.First().Value), - ["Retry"] = () => Task.CompletedTask - }; - if (type == typeof(AppraiserHistoryWidget)) - return new Dictionary - { - ["TeamId"] = TeamId, - ["Date"] = months.First().Value, - ["DateItems"] = months, - ["State"] = LoadingState.Done(), - ["Items"] = new[] - { - new AssessmentHistoryDto( - AssessmentDate: new DateOnly(2024, 10, 28), - StoriesCount: 10, - AssessmentSum: 80) - }, - ["LinkFactory"] = (string _) => new NavRoute(LanguageId: null, RouteSegment: "#"), - ["Retry"] = () => Task.CompletedTask - }; - if (type == typeof(AppraiserIntegrationWidget)) - return new Dictionary - { - ["TeamId"] = TeamId, - ["State"] = LoadingState.Done(), - ["FormModel"] = new AppraiserIntegrationFromModel().Apply(new GetIntegrationPropertiesResult( - Properties: new IntegrationProperties( - AccessToken: Guid.NewGuid().ToString("N"), - ProjectKey: "test", - ScrumMasterId: 1), - HasManagerAccess: true, - Teammates: - [ - new Person(Id: 1, Name: "Aleksandr", Username: "adiatlov"), - new Person(Id: 2, Name: "Alex", Username: null) - ])), - ["Retry"] = () => Task.CompletedTask - }; - if (type == typeof(RandomCoffeeHistoryWidget)) - return new Dictionary - { - ["State"] = LoadingState.Done(), - ["FormModel"] = new RandomCoffeeHistoryWidgetFormModel().Apply( - new RandomCoffeeHistoryWidgetFormModel.Parameters( - new GetChatsResult([new ChatDto(Id: 1, Name: "Chat 1")]), - ChatId: 1, - History: new GetHistoryResult( - [ - new RandomCoffeeHistoryDto( - Created: new DateOnly(2024, 10, 28), - Pairs: - [ - new PairDto( - FirstName: "Aleksandr", - FirstUserName: "adiatlov", - SecondName: "Alex", - SecondUserName: null) - ], - ExcludedPersonName: null, - ExcludedPersonUserName: null) - ]))) - }; - if (type == typeof(MapWidget)) - return new Dictionary - { - ["State"] = LoadingState.Done(), - ["FormModel"] = new MapWidgetFormModel().Apply(new GetMapsResult( - [ - new MapDto(Id: Guid.NewGuid(), Name: "Chat 1") - ])), - ["Retry"] = () => Task.CompletedTask, - ["LinkFactory"] = (string _) => "/imgs/map.png" - }; - - throw new NotSupportedException($"{type.Name} is not supported."); - } + private Dictionary CreateWidgetParameters(Type type) => WidgetsDataFactory.Create(type, TeamId); } \ No newline at end of file diff --git a/src/Inc.TeamAssistant.Stories/Features/Dashboard/WidgetsDataFactory.cs b/src/Inc.TeamAssistant.Stories/Features/Dashboard/WidgetsDataFactory.cs new file mode 100644 index 00000000..6164618b --- /dev/null +++ b/src/Inc.TeamAssistant.Stories/Features/Dashboard/WidgetsDataFactory.cs @@ -0,0 +1,257 @@ +using Inc.TeamAssistant.Appraiser.Model.Queries.GetAssessmentHistory; +using Inc.TeamAssistant.CheckIn.Model.Queries.GetMaps; +using Inc.TeamAssistant.Connector.Model.Queries.GetIntegrationProperties; +using Inc.TeamAssistant.Connector.Model.Queries.GetTeammates; +using Inc.TeamAssistant.Primitives; +using Inc.TeamAssistant.RandomCoffee.Model.Queries.GetChats; +using Inc.TeamAssistant.RandomCoffee.Model.Queries.GetHistory; +using Inc.TeamAssistant.Reviewer.Model.Queries.GetAverageByTeam; +using Inc.TeamAssistant.Reviewer.Model.Queries.GetHistoryByTeam; +using Inc.TeamAssistant.Reviewer.Model.Queries.GetLastTasks; +using Inc.TeamAssistant.WebUI.Components; +using Inc.TeamAssistant.WebUI.Contracts; +using Inc.TeamAssistant.WebUI.Features.Dashboard.Appraiser; +using Inc.TeamAssistant.WebUI.Features.Dashboard.CheckIn; +using Inc.TeamAssistant.WebUI.Features.Dashboard.RandomCoffee; +using Inc.TeamAssistant.WebUI.Features.Dashboard.Reviewer; +using Inc.TeamAssistant.WebUI.Features.Dashboard.Teams; +using Inc.TeamAssistant.WebUI.Routing; + +namespace Inc.TeamAssistant.Stories.Features.Dashboard; + +internal sealed class WidgetsDataFactory +{ + private readonly IDateSelectorFactory _dateFactory; + + public WidgetsDataFactory(IDateSelectorFactory dateFactory) + { + _dateFactory = dateFactory ?? throw new ArgumentNullException(nameof(dateFactory)); + } + + public Dictionary Create(Type type, Guid teamId) + { + ArgumentNullException.ThrowIfNull(type); + + var weeks = _dateFactory.CreateWeeks(); + var months = _dateFactory.CreateMonths(); + + if (type == typeof(TeammatesWidget)) + return CreateDataForTeammatesWidget(teamId); + if (type == typeof(ReviewAverageStatsWidget)) + return CreateDataForReviewAverageStatsWidget(teamId, weeks); + if (type == typeof(ReviewHistoryWidget)) + return CreateDataForReviewHistoryWidget(teamId, weeks); + if (type == typeof(ReviewTotalStatsWidget)) + return CreateDataForReviewTotalStatsWidget(teamId, weeks); + if (type == typeof(AppraiserHistoryWidget)) + return CreateDataForAppraiserHistoryWidget(teamId, months); + if (type == typeof(AppraiserIntegrationWidget)) + return CreateDataForAppraiserIntegrationWidget(teamId); + if (type == typeof(RandomCoffeeHistoryWidget)) + return CreateDataForRandomCoffeeHistoryWidget(); + if (type == typeof(MapWidget)) + return CreateDataForMapWidget(); + + throw new NotSupportedException($"{type.Name} is not supported."); + } + + private Dictionary CreateDataForTeammatesWidget(Guid teamId) + { + return new Dictionary + { + ["TeamId"] = teamId, + ["State"] = LoadingState.Done(), + ["Item"] = new GetTeammatesResult( + HasManagerAccess: true, + Teammates: + [ + new TeammateDto( + TeamId: teamId, + PersonId: 1, + Name: "Aleksandr", + UserName: "adiatlov", + LeaveUntil: null), + new TeammateDto( + TeamId: teamId, + PersonId: 2, + Name: "Alex", + UserName: null, + LeaveUntil: null) + ]), + ["Retry"] = () => Task.CompletedTask + }; + } + + private Dictionary CreateDataForReviewAverageStatsWidget( + Guid teamId, + IReadOnlyDictionary weeks) + { + ArgumentNullException.ThrowIfNull(weeks); + + return new Dictionary + { + ["TeamId"] = teamId, + ["Date"] = weeks.First().Value, + ["DateItems"] = weeks, + ["State"] = LoadingState.Done(), + ["Items"] = new[] + { + new ReviewAverageStatsDto( + Created: new DateOnly(2024, 10, 28), + FirstTouch: TimeSpan.FromMinutes(10), + Review: TimeSpan.FromMinutes(40), + Correction: TimeSpan.FromMinutes(20)) + }, + ["Retry"] = () => Task.CompletedTask + }; + } + + private Dictionary CreateDataForReviewHistoryWidget( + Guid teamId, + IReadOnlyDictionary weeks) + { + ArgumentNullException.ThrowIfNull(weeks); + + return new Dictionary + { + ["TeamId"] = teamId, + ["Date"] = weeks.First().Value, + ["DateItems"] = weeks, + ["State"] = LoadingState.Done(), + ["Items"] = new[] + { + new TaskForReviewDto( + Id: Guid.NewGuid(), + Created: DateTimeOffset.UtcNow, + State: "Accept", + Description: "Description", + FirstTouch: TimeSpan.FromMinutes(10), + Correction: TimeSpan.FromMinutes(20), + Review: TimeSpan.FromMinutes(40), + Iterations: 2, + ReviewerId: 1, + ReviewerName: "Aleksandr", + ReviewerUserName: "adiatlov", + OwnerId: 2, + OwnerName: "Alex", + OwnerUserName: null, + HasConcreteReviewer: false, + IsOriginalReviewer: false) + }, + ["Retry"] = () => Task.CompletedTask + }; + } + + private Dictionary CreateDataForReviewTotalStatsWidget( + Guid teamId, + IReadOnlyDictionary weeks) + { + ArgumentNullException.ThrowIfNull(weeks); + + return new Dictionary + { + ["TeamId"] = teamId, + ["Date"] = weeks.First().Value, + ["DateItems"] = weeks, + ["State"] = LoadingState.Done(), + ["FormModel"] = new ReviewTotalStatsWidgetFormModel().Apply(new GetHistoryByTeamResult( + Review: + [ + new HistoryByTeamItemDto(PersonName: "Aleksandr (adiatlov)", Count: 10), + new HistoryByTeamItemDto(PersonName: "Alex", Count: 6) + ], + Requests: + [ + new HistoryByTeamItemDto(PersonName: "Aleksandr (adiatlov)", Count: 6), + new HistoryByTeamItemDto(PersonName: "Alex", Count: 10) + ]), weeks.First().Value), + ["Retry"] = () => Task.CompletedTask + }; + } + + private Dictionary CreateDataForAppraiserHistoryWidget( + Guid teamId, + IReadOnlyDictionary months) + { + ArgumentNullException.ThrowIfNull(months); + + return new Dictionary + { + ["TeamId"] = teamId, + ["Date"] = months.First().Value, + ["DateItems"] = months, + ["State"] = LoadingState.Done(), + ["Items"] = new[] + { + new AssessmentHistoryDto( + AssessmentDate: new DateOnly(2024, 10, 28), + StoriesCount: 10, + AssessmentSum: 80) + }, + ["LinkFactory"] = (string _) => new NavRoute(LanguageId: null, RouteSegment: "#"), + ["Retry"] = () => Task.CompletedTask + }; + } + + private Dictionary CreateDataForAppraiserIntegrationWidget(Guid teamId) + { + return new Dictionary + { + ["TeamId"] = teamId, + ["State"] = LoadingState.Done(), + ["FormModel"] = new AppraiserIntegrationFromModel().Apply(new GetIntegrationPropertiesResult( + Properties: new IntegrationProperties( + AccessToken: Guid.NewGuid().ToString("N"), + ProjectKey: "test", + ScrumMasterId: 1), + HasManagerAccess: true, + Teammates: + [ + new Person(Id: 1, Name: "Aleksandr", Username: "adiatlov"), + new Person(Id: 2, Name: "Alex", Username: null) + ])), + ["Retry"] = () => Task.CompletedTask + }; + } + + private Dictionary CreateDataForRandomCoffeeHistoryWidget() + { + return new Dictionary + { + ["State"] = LoadingState.Done(), + ["FormModel"] = new RandomCoffeeHistoryWidgetFormModel().Apply( + new RandomCoffeeHistoryWidgetFormModel.Parameters( + new GetChatsResult([new ChatDto(Id: 1, Name: "Chat 1")]), + ChatId: 1, + History: new GetHistoryResult( + [ + new RandomCoffeeHistoryDto( + Created: new DateOnly(2024, 10, 28), + Pairs: + [ + new PairDto( + FirstName: "Aleksandr", + FirstUserName: "adiatlov", + SecondName: "Alex", + SecondUserName: null) + ], + ExcludedPersonName: null, + ExcludedPersonUserName: null) + ]))) + }; + } + + private Dictionary CreateDataForMapWidget() + { + return new Dictionary + { + ["State"] = LoadingState.Done(), + ["FormModel"] = new MapWidgetFormModel().Apply(new GetMapsResult( + [ + new MapDto(Id: Guid.NewGuid(), Name: "Chat 1") + ])), + ["Retry"] = () => Task.CompletedTask, + ["LinkFactory"] = (string _) => "/imgs/map.png" + }; + } +} \ No newline at end of file diff --git a/src/Inc.TeamAssistant.Stories/Program.cs b/src/Inc.TeamAssistant.Stories/Program.cs index 2cd6332a..05fb8505 100644 --- a/src/Inc.TeamAssistant.Stories/Program.cs +++ b/src/Inc.TeamAssistant.Stories/Program.cs @@ -1,6 +1,7 @@ using FluentValidation; using Inc.TeamAssistant.Primitives.Languages; using Inc.TeamAssistant.Stories; +using Inc.TeamAssistant.Stories.Features.Dashboard; using Inc.TeamAssistant.WebUI.Services; using Microsoft.AspNetCore.Components.Web; using Microsoft.AspNetCore.Components.WebAssembly.Hosting; @@ -11,6 +12,7 @@ builder.Services .AddScoped(_ => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }) + .AddScoped() .AddClientServices() .AddIsomorphicServices();