From 8698e5f67444d13a87dcb98c599f3708e2ddabca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Mierzwa?= Date: Mon, 30 Mar 2020 20:42:18 +0100 Subject: [PATCH] feat(ui): render per grid state count --- ui/src/Components/Grid/AlertGrid/Grid.js | 71 +++++++++------ ui/src/Components/Grid/AlertGrid/index.js | 4 +- .../Components/Grid/AlertGrid/index.test.js | 86 +++++++++++++++---- ui/src/Models/API.js | 20 +++-- 4 files changed, 132 insertions(+), 49 deletions(-) diff --git a/ui/src/Components/Grid/AlertGrid/Grid.js b/ui/src/Components/Grid/AlertGrid/Grid.js index 06803eab6..bf7687023 100644 --- a/ui/src/Components/Grid/AlertGrid/Grid.js +++ b/ui/src/Components/Grid/AlertGrid/Grid.js @@ -16,8 +16,9 @@ import { faAngleDoubleDown } from "@fortawesome/free-solid-svg-icons/faAngleDoub import { AlertStore } from "Stores/AlertStore"; import { Settings } from "Stores/Settings"; import { SilenceFormStore } from "Stores/SilenceFormStore"; -import { APIGroup } from "Models/API"; +import { APIGrid } from "Models/API"; import { FilteringLabel } from "Components/Labels/FilteringLabel"; +import { FilteringCounterBadge } from "Components/Labels/FilteringCounterBadge"; import { TooltipWrapper } from "Components/TooltipWrapper"; import { AlertGroup } from "./AlertGroup"; @@ -29,9 +30,7 @@ const Grid = observer( silenceFormStore: PropTypes.instanceOf(SilenceFormStore).isRequired, gridSizesConfig: PropTypes.array.isRequired, groupWidth: PropTypes.number.isRequired, - gridLabelName: PropTypes.string.isRequired, - gridLabelValue: PropTypes.string.isRequired, - gridAlertGroups: PropTypes.arrayOf(APIGroup).isRequired, + grid: APIGrid.isRequired, }; // store reference to generated masonry component so we can call it @@ -74,11 +73,11 @@ const Grid = observer( loadMoreStep = 30; loadMore = action(() => { - const { gridAlertGroups } = this.props; + const { grid } = this.props; this.groupsToRender.value = Math.min( this.groupsToRender.value + this.loadMoreStep, - gridAlertGroups.length + grid.alertGroups.length ); }); @@ -95,13 +94,13 @@ const Grid = observer( ); componentDidUpdate() { - const { gridAlertGroups } = this.props; + const { grid } = this.props; this.masonryRepack(); - if (this.groupsToRender.value > gridAlertGroups.length) { + if (this.groupsToRender.value > grid.alertGroups.length) { this.groupsToRender.setValue( - Math.max(this.initial, gridAlertGroups.length) + Math.max(this.initial, grid.alertGroups.length) ); } } @@ -113,28 +112,50 @@ const Grid = observer( silenceFormStore, gridSizesConfig, groupWidth, - gridLabelName, - gridLabelValue, - gridAlertGroups, + grid, } = this.props; return ( - {gridLabelName !== "" && gridLabelValue !== "" && ( -
- - {gridAlertGroups.length} - + {alertStore.data.grids.length > 1 && ( +
+ {grid.alertGroups.length > 1 && ( + + + + + + )} - + {grid.labelName !== "" && grid.labelValue !== "" && ( + + )} {this.gridToggle.show - ? gridAlertGroups + ? grid.alertGroups .slice(0, this.groupsToRender.value) .map((group) => ( - {gridAlertGroups.length > this.groupsToRender.value && ( + {grid.alertGroups.length > this.groupsToRender.value && (