Skip to content

Commit

Permalink
Merge pull request #75 from dyatlov-a/hotfix-264
Browse files Browse the repository at this point in the history
Hotfix 264
  • Loading branch information
dyatlov-a authored Sep 13, 2024
2 parents a06ed2d + 16c8822 commit 99b39df
Show file tree
Hide file tree
Showing 36 changed files with 216 additions and 158 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public SetIntegrationPropertiesCommandValidator()

RuleFor(e => e.ProjectKey)
.NotEmpty()
.MinimumLength(3)
.MaximumLength(50);

RuleFor(e => e.ScrumMasterId)
Expand Down
2 changes: 0 additions & 2 deletions src/Inc.TeamAssistant.Gateway/wwwroot/langs/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@
"GUI_Tasks": "tasks",
"GUI_StoryList": "Tasks list",
"GUI_AssessmentSession": "Assessment Session",
"GUI_RequestDemo": "Request a demo",
"GUI_RequestDemoBody": "Hello there! I would like to try out the team assistant bot",
"GUI_MainTitle": "Team assistant",
"GUI_MainHeader": "Chatbots for optimization",
"GUI_MainSubHeader": "processes in teams",
Expand Down
2 changes: 0 additions & 2 deletions src/Inc.TeamAssistant.Gateway/wwwroot/langs/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@
"GUI_Tasks": "задач",
"GUI_StoryList": "Список историй",
"GUI_AssessmentSession": "Оценка задач",
"GUI_RequestDemo": "Запросить демо",
"GUI_RequestDemoBody": "Добрый день. Прошу провести демо продукта team-assessment bot",
"GUI_MainTitle": "Team assistant | ассистент для команд",
"GUI_MainHeader": "Чат-боты для оптимизации",
"GUI_MainSubHeader": "процессов в командах",
Expand Down
2 changes: 0 additions & 2 deletions src/Inc.TeamAssistant.Primitives/GlobalSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ namespace Inc.TeamAssistant.Primitives;
public static class GlobalSettings
{
public static readonly string CanonicalName = "teamassist.bot";

public static readonly string RequestDemoEmail = "dyatlovall@gmail.com";

public static readonly IReadOnlyCollection<string> LinksPrefix = ["http://", "https://"];

Expand Down
14 changes: 14 additions & 0 deletions src/Inc.TeamAssistant.WebUI/AnalyticEvents.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace Inc.TeamAssistant.WebUI;

internal static class AnalyticEvents
{
public const string ConstructorOpened = "constructor-opened";
public const string BotChecked = "bot-checked";
public const string FeatureSelected = "feature-selected";
public const string SettingsSpecified = "settings-specified";
public const string CalendarChanged = "calendar-changed";
public const string BotDetailsChanged = "bot-details-changed";
public const string BotCreated = "bot-created";
public const string BotUpdated = "bot-updated";
public const string AppraiserIntegrationEnabled = "appraiser-integration-enabled";
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public DateSelectorFactory(ResourcesManager resources)
_resources = resources ?? throw new ArgumentNullException(nameof(resources));
}

public IReadOnlyCollection<SelectItem<DateOnly>> CreateShortPeriods()
public IReadOnlyCollection<SelectItem<DateOnly>> CreateWeeks()
{
return
[
Expand All @@ -27,7 +27,7 @@ public IReadOnlyCollection<SelectItem<DateOnly>> CreateShortPeriods()
];
}

public IReadOnlyCollection<SelectItem<DateOnly>> CreateLongPeriods()
public IReadOnlyCollection<SelectItem<DateOnly>> CreateMonths()
{
return
[
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@inject IServiceProvider ServiceProvider
@inject ResourcesManager Resources

<EditForm EditContext="_editContext" OnSubmit="SubmitForm">
<EditForm id="@AnalyticEvents.BotChecked" EditContext="_editContext" OnSubmit="SubmitForm">
<FluentValidationValidator @ref="_fluentValidationValidator" />
<CheckBotFormTracker OnChange="StateHasChanged" />
<Panel Header="@Resources[Messages.Constructor_ConnectingTelegram]" IsOpen="true">
Expand Down Expand Up @@ -33,6 +33,7 @@
class="form-control form-control_disabled"
id="bot-username"
disabled="disabled"/>
<ValidationMessage For="@(() => _formModel.UserName)"/>
</Content>
</FormFieldSet>
</Content>
Expand Down Expand Up @@ -68,8 +69,8 @@
if (_fluentValidationValidator is null || !await _fluentValidationValidator.ValidateAsync())
return;

var dataEditor = ServiceProvider.GetRequiredService<DataEditor>();
await dataEditor.Attach(BotStorageKey, StagesState.Apply(_formModel));
var appLocalStorage = ServiceProvider.GetRequiredService<AppLocalStorage>();
await appLocalStorage.Attach(BotStorageKey, StagesState.Apply(_formModel));

await MoveToNext(Stage.SelectFeatures);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using Inc.TeamAssistant.Constructor.Model.Queries.GetBotUserName;

namespace Inc.TeamAssistant.WebUI.Features.Constructor.Stages.Stage1;

public sealed class CheckBotFormModel
Expand All @@ -15,4 +17,22 @@ public CheckBotFormModel Apply(StagesState stagesState)

return this;
}

public CheckBotFormModel Apply(GetBotUserNameResult checkResult)
{
ArgumentNullException.ThrowIfNull(checkResult);

UserName = checkResult.UserName;
HasAccess = checkResult.HasAccess;

return this;
}

public CheckBotFormModel Clear()
{
UserName = string.Empty;
HasAccess = false;

return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public sealed class CheckBotFormTracker : ComponentBase, IDisposable

[CascadingParameter]
private EditContext CascadedEditContext { get; set; } = default!;
private CheckBotFormModel? _oldValues;

protected override void OnInitialized()
{
Expand All @@ -27,35 +26,19 @@ protected override void OnInitialized()

private async void OnFieldChanged(object? sender, FieldChangedEventArgs e)
{
var model = (CheckBotFormModel)e.FieldIdentifier.Model;

if (_oldValues is not null &&
_oldValues.HasAccess == model.HasAccess &&
_oldValues.Token == model.Token &&
_oldValues.UserName == model.UserName)
if (e.FieldIdentifier.FieldName != nameof(CheckBotFormModel.Token))
return;

var model = (CheckBotFormModel)e.FieldIdentifier.Model;

if (string.IsNullOrWhiteSpace(model.Token))
{
model.UserName = string.Empty;
model.HasAccess = false;
}
model.Clear();
else
{
var getBotUserNameResult = await BotService.Check(new GetBotUserNameQuery(model.Token));
model.UserName = getBotUserNameResult.UserName;
model.HasAccess = getBotUserNameResult.HasAccess;
model.Apply(getBotUserNameResult);
}

_oldValues = new CheckBotFormModel
{
HasAccess = model.HasAccess,
Token = model.Token,
UserName = model.UserName
};

CascadedEditContext.NotifyFieldChanged(e.FieldIdentifier);
CascadedEditContext.NotifyFieldChanged(new FieldIdentifier(model, nameof(model.UserName)));
OnChange();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@inject IServiceProvider ServiceProvider
@inject ResourcesManager Resources

<EditForm EditContext="_editContext" OnSubmit="SubmitForm">
<EditForm id="@AnalyticEvents.FeatureSelected" EditContext="_editContext" OnSubmit="SubmitForm">
<FluentValidationValidator @ref="_fluentValidationValidator" />
<Panel Header="@Resources[Messages.Constructor_FeaturesStore]" IsOpen="true">
<Actions>
Expand Down Expand Up @@ -59,8 +59,8 @@
if (_fluentValidationValidator is null || !await _fluentValidationValidator!.ValidateAsync())
return;

var dataEditor = ServiceProvider.GetRequiredService<DataEditor>();
await dataEditor.Attach(BotStorageKey, StagesState.Apply(_formModel));
var appLocalStorage = ServiceProvider.GetRequiredService<AppLocalStorage>();
await appLocalStorage.Attach(BotStorageKey, StagesState.Apply(_formModel));

await MoveToNext(Stage.SetSettings);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
@inject RequestProcessor RequestProcessor
@inject IRenderContext RenderContext

<EditForm EditContext="_editContext" OnSubmit="SubmitForm">
<EditForm id="@AnalyticEvents.BotDetailsChanged" EditContext="_editContext" OnSubmit="SubmitForm">
<FluentValidationValidator @ref="_fluentValidationValidator" />
<Panel Header="@Resources[Messages.Constructor_BotDetailsTelegram]" Opened="Load" IsOpen="_isOpen">
<Actions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
@inject IRenderContext RenderContext
@inject IJSRuntime JsRuntime

<EditForm EditContext="_editContext" OnSubmit="SubmitForm">
<EditForm id="@AnalyticEvents.CalendarChanged" EditContext="_editContext" OnSubmit="SubmitForm">
<FluentValidationValidator @ref="_fluentValidationValidator" />
<Panel Header="@Resources[Messages.Constructor_WorkCalendar]" Opened="Load" IsOpen="_isOpen">
<Actions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
@inject IServiceProvider ServiceProvider
@inject ResourcesManager Resources

<EditForm EditContext="_editContext" OnSubmit="SubmitForm">
<EditForm id="@AnalyticEvents.SettingsSpecified" EditContext="_editContext" OnSubmit="SubmitForm">
<FluentValidationValidator @ref="_fluentValidationValidator" />
<Panel Header="@Resources[Messages.Constructor_Configuration]" IsOpen="true">
<Actions>
Expand Down Expand Up @@ -101,20 +101,20 @@

private async Task SelectedCalendar(Guid calendarId)
{
var dataEditor = ServiceProvider.GetRequiredService<DataEditor>();
var appLocalStorage = ServiceProvider.GetRequiredService<AppLocalStorage>();

_formModel.CalendarId = calendarId;

await dataEditor.Attach(BotStorageKey, StagesState.Apply(calendarId));
await appLocalStorage.Attach(BotStorageKey, StagesState.Apply(calendarId));
}

private async Task SubmitForm()
{
if (_fluentValidationValidator is null || !await _fluentValidationValidator.ValidateAsync())
return;

var dataEditor = ServiceProvider.GetRequiredService<DataEditor>();
await dataEditor.Attach(BotStorageKey, StagesState.Apply(_formModel));
var appLocalStorage = ServiceProvider.GetRequiredService<AppLocalStorage>();
await appLocalStorage.Attach(BotStorageKey, StagesState.Apply(_formModel));

await MoveToNext(Stage.Complete);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
@inject RequestProcessor RequestProcessor
@inject FeaturesFactory FeaturesFactory

<EditForm EditContext="_editContext" OnSubmit="SubmitForm">
<EditForm id="@FormId" EditContext="_editContext" OnSubmit="SubmitForm">
<FluentValidationValidator @ref="_fluentValidationValidator" />
<Panel Header="@PanelHeader" IsOpen="true">
<Actions>
Expand Down Expand Up @@ -164,6 +164,10 @@
? Messages.Constructor_ButtonUpdateText
: Messages.Constructor_ButtonCreateText];

private string FormId => StagesState.Id.HasValue
? AnalyticEvents.BotUpdated
: AnalyticEvents.BotCreated;

private string PanelHeader => string.Format(
Resources[Messages.Constructor_CheckConfigurationTemplate],
ButtonText.ToLowerInvariant());
Expand Down Expand Up @@ -192,7 +196,7 @@
if (_fluentValidationValidator is null || !await _fluentValidationValidator!.ValidateAsync())
return;

var dataEditor = ServiceProvider.GetRequiredService<DataEditor>();
var appLocalStorage = ServiceProvider.GetRequiredService<AppLocalStorage>();

await RequestProcessor.Process(
async () =>
Expand All @@ -202,7 +206,7 @@
else
await BotService.Create(_formModel.ToCreateBotCommand());

await dataEditor.Detach(BotStorageKey);
await appLocalStorage.Detach<StagesState>(BotStorageKey);
},
() => MoveToNext(null),
s => _state = s);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@

private async Task Load()
{
var dataEditor = ServiceProvider.GetRequiredService<DataEditor>();
var appLocalStorage = ServiceProvider.GetRequiredService<AppLocalStorage>();

await RequestProcessor.Process(
() =>
{
return dataEditor.GetValueOrDefault(BotStorageKey, async t =>
return appLocalStorage.GetValueOrDefault(BotStorageKey, async t =>
{
var getBotResult = BotId.HasValue ? await BotService.GetBotById(BotId.Value, t) : null;
var getFeaturesResult = await BotService.GetFeatures(t);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public static StagesState Create(

return new StagesState(
bot.Id,
bot.Id,
bot.CalendarId,
bot.UserName,
bot.Token,
bot.SupportedLanguages,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
private readonly PaginationState _pagination = new();

private LoadingState _state = LoadingState.Done();
private IReadOnlyCollection<SelectItem<DateOnly>> DateItems => DateSelectorFactory.CreateLongPeriods();
private IReadOnlyCollection<SelectItem<DateOnly>> DateItems => DateSelectorFactory.CreateMonths();
private IReadOnlyCollection<AssessmentHistoryDto> _items = Array.Empty<AssessmentHistoryDto>();
private IQueryable<AssessmentHistoryDto> HistoryItems => _items.AsQueryable();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ namespace Inc.TeamAssistant.WebUI.Features.Dashboard.Appraiser;

public sealed class AppraiserIntegrationFromModel
{
public bool IsDisableControls { get; set; }
public bool IsEnabled { get; set; }
public bool HasManagerAccess { get; private set; }
public bool IsEnabled { get; private set; }
public string AccessToken { get; set; } = string.Empty;
public string ProjectKey { get; set; } = string.Empty;
public long ScrumMasterId { get; set; }
Expand All @@ -19,26 +19,14 @@ public AppraiserIntegrationFromModel Apply(GetIntegrationPropertiesResult integr
{
ArgumentNullException.ThrowIfNull(integration);

if (integration.Properties is not null)
{
AccessToken = integration.Properties.AccessToken;
ProjectKey = integration.Properties.ProjectKey;
ScrumMasterId = integration.Properties.ScrumMasterId;
}
else
{
AccessToken = string.Empty;
ProjectKey = string.Empty;
ScrumMasterId = 0;
}

IsEnabled = integration.Properties is not null;
IsDisableControls = !integration.HasManagerAccess;
HasManagerAccess = integration.HasManagerAccess;

_teammates.Clear();
_teammates.AddRange(integration.Teammates);

return this;
return integration.Properties is null
? Clear()
: Apply(integration.Properties);
}

public AppraiserIntegrationFromModel Clear()
Expand All @@ -58,4 +46,16 @@ public SetIntegrationPropertiesCommand ToCommand(Guid teamId)
ProjectKey,
ScrumMasterId);
}

private AppraiserIntegrationFromModel Apply(IntegrationProperties properties)
{
ArgumentNullException.ThrowIfNull(properties);

AccessToken = properties.AccessToken;
ProjectKey = properties.ProjectKey;
ScrumMasterId = properties.ScrumMasterId;
IsEnabled = true;

return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public AppraiserIntegrationFromModelValidator()
{
RuleFor(e => e.ProjectKey)
.NotEmpty()
.MinimumLength(3)
.MaximumLength(50);

RuleFor(e => e.ScrumMasterId)
Expand Down
Loading

0 comments on commit 99b39df

Please sign in to comment.