< Summary

Class:SearchBarView
Assembly:BuilderProjectsPanel
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/HUD/ProjectsPanelHUD/Scripts/Views/SearchBarView/SearchBarView.cs
Covered lines:54
Uncovered lines:5
Coverable lines:59
Total lines:138
Line coverage:91.5% (54 of 59)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Awake()0%110100%
SetResultCount(...)0%110100%
ShowFilters(...)0%110100%
SetSortTypes(...)0%110100%
OnSortButtonPressed()0%220100%
OnSortTypeSelected(...)0%220100%
OnToggleOwner(...)0%110100%
OnToggleOperator(...)0%110100%
OnToggleContributor(...)0%110100%
ReportFilter()0%220100%
SetSearchBar(...)0%44095.65%
OnUpdateResultCount()0%6200%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/HUD/ProjectsPanelHUD/Scripts/Views/SearchBarView/SearchBarView.cs

#LineLine coverage
 1using TMPro;
 2using UnityEngine;
 3using UnityEngine.UI;
 4
 5internal class SearchBarConfig
 6{
 7    public bool showFilterOwner;
 8    public bool showFilterOperator;
 9    public bool showFilterContributor;
 10    public bool showResultLabel;
 11}
 12
 13internal class SearchBarView : MonoBehaviour
 14{
 15    private const string RESULT_FORMAT = "Results ({0})";
 16
 17    [SerializeField] internal SearchInputField inputField;
 18    [SerializeField] internal Button sortButton;
 19    [SerializeField] internal TextMeshProUGUI sortTypeLabel;
 20    [SerializeField] internal Toggle ownerToggle;
 21    [SerializeField] internal Toggle operatorToggle;
 22    [SerializeField] internal Toggle contributorToggle;
 23    [SerializeField] private TextMeshProUGUI resultLabel;
 24    [SerializeField] internal SortDropdownView sortDropdown;
 25
 26    private bool filterOwner = false;
 27    private bool filterOperator = false;
 28    private bool filterContributor = false;
 29
 30    private ISectionSearchHandler searchHandler;
 31
 32    private void Awake()
 33    {
 1134        sortButton.onClick.AddListener(OnSortButtonPressed);
 35
 1136        ownerToggle.onValueChanged.AddListener(OnToggleOwner);
 1137        operatorToggle.onValueChanged.AddListener(OnToggleOperator);
 1138        contributorToggle.onValueChanged.AddListener(OnToggleContributor);
 39
 1140        filterOwner = ownerToggle.isOn;
 1141        filterOperator = operatorToggle.isOn;
 1142        filterContributor = contributorToggle.isOn;
 43
 1444        inputField.OnSearchText += text => searchHandler?.SetSearchString(text);
 1145        sortDropdown.OnSortTypeSelected += OnSortTypeSelected;
 1146    }
 47
 848    public void SetResultCount(int count) { resultLabel.text = string.Format(RESULT_FORMAT, count); }
 49
 50    public void ShowFilters(bool filterOwner, bool filterOperator, bool filterContributor)
 51    {
 352        ownerToggle.gameObject.SetActive(filterOwner);
 353        operatorToggle.gameObject.SetActive(filterOperator);
 354        contributorToggle.gameObject.SetActive(filterContributor);
 355    }
 56
 657    public void SetSortTypes(string[] types) { sortDropdown.AddSortType(types); }
 58
 59    private void OnSortButtonPressed()
 60    {
 261        if (sortDropdown.GetSortTypesCount() > 1)
 62        {
 163            sortDropdown.Show();
 64        }
 265    }
 66
 67    private void OnSortTypeSelected(string type)
 68    {
 169        sortTypeLabel.text = type;
 170        searchHandler?.SetSortType(type);
 171    }
 72
 73    private void OnToggleOwner(bool isOn)
 74    {
 275        filterOwner = isOn;
 276        ReportFilter();
 277    }
 78
 79    private void OnToggleOperator(bool isOn)
 80    {
 281        filterOperator = isOn;
 282        ReportFilter();
 283    }
 84
 85    private void OnToggleContributor(bool isOn)
 86    {
 287        filterContributor = isOn;
 288        ReportFilter();
 289    }
 90
 1291    private void ReportFilter() { searchHandler?.SetFilter(filterOwner, filterOperator, filterContributor); }
 92
 93    public void SetSearchBar(ISectionSearchHandler handler, SearchBarConfig config)
 94    {
 595        if (searchHandler != null)
 96        {
 097            searchHandler.OnUpdated -= OnUpdateResultCount;
 98        }
 99
 5100        searchHandler = handler;
 101
 5102        if (searchHandler == null)
 103        {
 1104            gameObject.SetActive(false);
 1105            return;
 106        }
 4107        gameObject.SetActive(true);
 108
 4109        sortDropdown.Clear();
 4110        sortDropdown.AddSortType(handler.sortTypes);
 111
 4112        if (config != null)
 113        {
 1114            ShowFilters(config.showFilterOwner, config.showFilterOperator, config.showFilterContributor);
 1115            resultLabel.gameObject.SetActive(config.showResultLabel);
 116        }
 117
 4118        ownerToggle.SetIsOnWithoutNotify(handler.filterOwner);
 4119        operatorToggle.SetIsOnWithoutNotify(handler.filterOperator);
 4120        contributorToggle.SetIsOnWithoutNotify(handler.filterContributor);
 4121        filterOwner = handler.filterOwner;
 4122        filterOperator = handler.filterOperator;
 4123        filterContributor = handler.filterContributor;
 124
 4125        sortTypeLabel.text = handler.sortType;
 4126        inputField.inputField.SetTextWithoutNotify(handler.searchString);
 4127        SetResultCount(handler.resultCount);
 128
 4129        searchHandler.OnUpdated += OnUpdateResultCount;
 4130    }
 131
 132    private void OnUpdateResultCount()
 133    {
 0134        if (searchHandler == null)
 0135            return;
 0136        SetResultCount(searchHandler.resultCount);
 0137    }
 138}