Skip to content

Commit

Permalink
Filter branches by date creation Last week/Last month/Last 3 months/L…
Browse files Browse the repository at this point in the history
…ast year/All time
  • Loading branch information
SRombautsU committed Nov 15, 2023
1 parent 31b1bb9 commit eb510bb
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#else
#include "EditorStyleSet.h"
#endif
#include "Widgets/Input/SComboButton.h"
#include "Widgets/Input/SSearchBox.h"
#include "Widgets/Text/STextBlock.h"
#include "Widgets/Views/SHeaderRow.h"
Expand All @@ -34,6 +35,12 @@ void SPlasticSourceControlBranchesWidget::Construct(const FArguments& InArgs)
SearchTextFilter = MakeShared<TTextFilter<const FPlasticSourceControlBranch&>>(TTextFilter<const FPlasticSourceControlBranch&>::FItemToStringArray::CreateSP(this, &SPlasticSourceControlBranchesWidget::PopulateItemSearchStrings));
SearchTextFilter->OnChanged().AddSP(this, &SPlasticSourceControlBranchesWidget::OnRefreshUI);

FromDateInDaysValues.Add({ 7, FText::FromString(TEXT("Last week")) });
FromDateInDaysValues.Add({ 30, FText::FromString(TEXT("Last month")) });
FromDateInDaysValues.Add({ 90, FText::FromString(TEXT("Last 3 months")) });
FromDateInDaysValues.Add({ 365, FText::FromString(TEXT("Last year")) });
FromDateInDaysValues.Add({ -1, FText::FromString(TEXT("All time")) });

ChildSlot
[
SNew(SVerticalBox)
Expand Down Expand Up @@ -70,6 +77,20 @@ void SPlasticSourceControlBranchesWidget::Construct(const FArguments& InArgs)
.ToolTipText(LOCTEXT("PlasticBranchesSearch_Tooltip", "Filter the list of branches by keyword."))
.OnTextChanged(this, &SPlasticSourceControlBranchesWidget::OnSearchTextChanged)
]
+SHorizontalBox::Slot()
.VAlign(VAlign_Center)
.MaxWidth(125)
.Padding(FMargin(10.f, 0.f))
[
SNew(SComboButton)
.ToolTipText(LOCTEXT("PlasticBranchesDate_Tooltip", "Filter the list of branches by date of creation."))
.OnGetMenuContent(this, &SPlasticSourceControlBranchesWidget::BuildFromDateDropDownMenu)
.ButtonContent()
[
SNew(STextBlock)
.Text_Lambda([this]() { return FromDateInDaysValues[FromDateInDays]; })
]
]
]
]
+SVerticalBox::Slot() // The main content: the list of branches
Expand Down Expand Up @@ -273,6 +294,26 @@ void SPlasticSourceControlBranchesWidget::PopulateItemSearchStrings(const FPlast
InItem.PopulateSearchString(OutStrings);
}

void SPlasticSourceControlBranchesWidget::OnFromDateChanged(int32 InFromDateInDays)
{
FromDateInDays = InFromDateInDays;

RequestBranchesRefresh();
}

TSharedRef<SWidget> SPlasticSourceControlBranchesWidget::BuildFromDateDropDownMenu()
{
FMenuBuilder MenuBuilder(true, NULL);

for (const auto & FromDateInDaysValue : FromDateInDaysValues)
{
FUIAction MenuAction(FExecuteAction::CreateSP(this, &SPlasticSourceControlBranchesWidget::OnFromDateChanged, FromDateInDaysValue.Key));
MenuBuilder.AddMenuEntry(FromDateInDaysValue.Value, FromDateInDaysValue.Value, FSlateIcon(), MenuAction);
}

return MenuBuilder.MakeWidget();
}

void SPlasticSourceControlBranchesWidget::OnRefreshUI()
{
TRACE_CPUPROFILER_EVENT_SCOPE(SPlasticSourceControlBranchesWidget::OnRefreshUI);
Expand Down Expand Up @@ -529,8 +570,10 @@ void SPlasticSourceControlBranchesWidget::RequestBranchesRefresh()
StartRefreshStatus();

TSharedRef<FPlasticGetBranches, ESPMode::ThreadSafe> GetBranchesOperation = ISourceControlOperation::Create<FPlasticGetBranches>();
// TODO POC FAKE:
GetBranchesOperation->FromDate = FDateTime(2023, 10, 18);
if (FromDateInDays > -1)
{
GetBranchesOperation->FromDate = FDateTime::Now() - FTimespan::FromDays(FromDateInDays);
}

ISourceControlProvider& SourceControlProvider = ISourceControlModule::Get().GetProvider();
SourceControlProvider.Execute(GetBranchesOperation, EConcurrency::Asynchronous, FSourceControlOperationComplete::CreateSP(this, &SPlasticSourceControlBranchesWidget::OnBranchesUpdated));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ typedef TSharedRef<class FPlasticSourceControlBranch, ESPMode::ThreadSafe> FPlas

class SSearchBox;


// Widget displaying the list of branches in the tab window, see FPlasticSourceControlBranchesWindow
class SPlasticSourceControlBranchesWidget : public SCompoundWidget
{
Expand All @@ -34,6 +33,10 @@ class SPlasticSourceControlBranchesWidget : public SCompoundWidget

void OnSearchTextChanged(const FText& InFilterText);
void PopulateItemSearchStrings(const FPlasticSourceControlBranch& InItem, TArray<FString>& OutStrings);

TSharedRef<SWidget> BuildFromDateDropDownMenu();
void OnFromDateChanged(int32 InFromDateInDays);

void OnRefreshUI();

EColumnSortPriority::Type GetColumnSortPriority(const FName InColumnId) const;
Expand Down Expand Up @@ -81,6 +84,9 @@ class SPlasticSourceControlBranchesWidget : public SCompoundWidget
TSharedPtr<SListView<FPlasticSourceControlBranchRef>> BranchesListView;
TSharedPtr<TTextFilter<const FPlasticSourceControlBranch&>> SearchTextFilter;

TMap<int32, FText> FromDateInDaysValues;
int32 FromDateInDays = 30;

TArray<FPlasticSourceControlBranchRef> SourceControlBranches; // Full list from source (filtered by date)
TArray<FPlasticSourceControlBranchRef> BranchRows; // Filtered list to display based on the search text filter
};

0 comments on commit eb510bb

Please sign in to comment.