-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ui): allow configuring grid size
- Loading branch information
Showing
13 changed files
with
300 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,7 @@ | ||
.components-animation-fade-appear, | ||
.components-animation-fade-enter { | ||
.components-animation-fade-appear { | ||
opacity: 0.01; | ||
} | ||
.components-animation-fade-appear-active, | ||
.components-animation-fade-enter-active { | ||
.components-animation-fade-appear-active { | ||
opacity: 1; | ||
transition: all 0.3s ease-in; | ||
} | ||
|
||
.components-animation-fade-exit { | ||
opacity: 1; | ||
} | ||
.components-animation-fade-exit-active { | ||
opacity: 0.01; | ||
transition: all 0.3s ease-out; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,25 @@ | ||
const baseWidth = 400; | ||
|
||
const MinWidth = canvasWidth => | ||
Math.floor( | ||
baseWidth + (canvasWidth / Math.min(canvasWidth, baseWidth * 2)) * 10 | ||
); | ||
|
||
// grid sizes, defines how many columns are used depending on the screen width | ||
// this is config as expected by https://github.com/callmecavs/bricks.js#sizes | ||
const GridSizesConfig = canvasWidth => { | ||
const GridSizesConfig = (canvasWidth, baseWidth) => { | ||
const generatedSizes = []; | ||
for (let i = 2; i < 20; i++) { | ||
generatedSizes.push({ | ||
mq: `${i * MinWidth(i * baseWidth)}px`, | ||
mq: `${i * baseWidth}px`, | ||
columns: i, | ||
gutter: 0 | ||
}); | ||
} | ||
//console.info(JSON.stringify(generatedSizes)); | ||
return [...[{ columns: 1, gutter: 0 }], ...generatedSizes]; | ||
}; | ||
|
||
const GetGridElementWidth = canvasWidth => { | ||
const mw = MinWidth(canvasWidth); | ||
return Math.floor( | ||
Math.min( | ||
mw + (canvasWidth % mw) / Math.floor(canvasWidth / mw), | ||
canvasWidth | ||
) | ||
); | ||
}; | ||
const GetColumnsCount = (canvasWidth, baseWidth) => | ||
[{ mq: "0px", columns: 1 }, ...GridSizesConfig(canvasWidth, baseWidth)] | ||
.filter(gs => gs.mq !== undefined) | ||
.filter(gs => canvasWidth >= Number.parseInt(gs.mq)) | ||
.map(gs => gs.columns) | ||
.pop(); | ||
|
||
const GetGridElementWidth = (canvasWidth, baseWidth) => | ||
Math.floor(canvasWidth / GetColumnsCount(canvasWidth, baseWidth)); | ||
|
||
export { MinWidth, GridSizesConfig, GetGridElementWidth }; | ||
export { GridSizesConfig, GetColumnsCount, GetGridElementWidth }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
ui/src/Components/MainModal/Configuration/AlertGroupWidthConfiguration.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import React, { Component } from "react"; | ||
import PropTypes from "prop-types"; | ||
|
||
import { observable, action, toJS } from "mobx"; | ||
import { observer } from "mobx-react"; | ||
|
||
import { debounce } from "lodash"; | ||
|
||
import InputRange from "react-input-range"; | ||
|
||
import { Settings } from "Stores/Settings"; | ||
|
||
import "./InputRange.scss"; | ||
|
||
const AlertGroupWidthConfiguration = observer( | ||
class AlertGroupWidthConfiguration extends Component { | ||
static propTypes = { | ||
settingsStore: PropTypes.instanceOf(Settings).isRequired | ||
}; | ||
|
||
constructor(props) { | ||
super(props); | ||
|
||
this.config = observable({ | ||
groupWidth: toJS(props.settingsStore.gridConfig.config.groupWidth) | ||
}); | ||
} | ||
|
||
onChange = action(value => { | ||
this.config.groupWidth = value; | ||
}); | ||
|
||
onChangeComplete = debounce( | ||
action(value => { | ||
const { settingsStore } = this.props; | ||
|
||
settingsStore.gridConfig.config.groupWidth = value; | ||
}), | ||
200 | ||
); | ||
|
||
render() { | ||
return ( | ||
<div className="form-group text-center"> | ||
<label className="mb-4 font-weight-bold"> | ||
Minimal alert group width | ||
</label> | ||
<InputRange | ||
minValue={300} | ||
maxValue={800} | ||
step={20} | ||
value={this.config.groupWidth} | ||
id="formControlRange" | ||
formatLabel={this.formatLabel} | ||
onChange={this.onChange} | ||
onChangeComplete={this.onChangeComplete} | ||
/> | ||
</div> | ||
); | ||
} | ||
} | ||
); | ||
|
||
export { AlertGroupWidthConfiguration }; |
42 changes: 42 additions & 0 deletions
42
ui/src/Components/MainModal/Configuration/AlertGroupWidthConfiguration.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import React from "react"; | ||
|
||
import { mount } from "enzyme"; | ||
|
||
import toDiffableHtml from "diffable-html"; | ||
|
||
import { Settings } from "Stores/Settings"; | ||
import { AlertGroupWidthConfiguration } from "./AlertGroupWidthConfiguration"; | ||
|
||
let settingsStore; | ||
beforeEach(() => { | ||
settingsStore = new Settings(); | ||
}); | ||
|
||
const FakeConfiguration = () => { | ||
return mount(<AlertGroupWidthConfiguration settingsStore={settingsStore} />); | ||
}; | ||
|
||
describe("<AlertGroupWidthConfiguration />", () => { | ||
it("matches snapshot with default values", () => { | ||
const tree = FakeConfiguration(); | ||
expect(toDiffableHtml(tree.html())).toMatchSnapshot(); | ||
}); | ||
|
||
it("call to onChange() updates internal state", () => { | ||
const tree = FakeConfiguration(); | ||
tree.instance().onChange(500); | ||
expect(tree.instance().config.groupWidth).toBe(500); | ||
}); | ||
|
||
it("settings are updated on completed change", () => { | ||
const tree = FakeConfiguration(); | ||
tree.instance().onChangeComplete(555); | ||
expect(settingsStore.gridConfig.config.groupWidth).toBe(555); | ||
}); | ||
|
||
it("custom interval value is rendered correctly", () => { | ||
settingsStore.gridConfig.config.groupWidth = 455; | ||
const component = FakeConfiguration(); | ||
expect(component.find("InputRange").props().value).toBe(455); | ||
}); | ||
}); |
49 changes: 49 additions & 0 deletions
49
...omponents/MainModal/Configuration/__snapshots__/AlertGroupWidthConfiguration.test.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`<AlertGroupWidthConfiguration /> matches snapshot with default values 1`] = ` | ||
" | ||
<div class=\\"form-group text-center\\"> | ||
<label class=\\"mb-4 font-weight-bold\\"> | ||
Minimal alert group width | ||
</label> | ||
<div aria-disabled=\\"false\\" | ||
class=\\"input-range\\" | ||
> | ||
<span class=\\"input-range__label input-range__label--min\\"> | ||
<span class=\\"input-range__label-container\\"> | ||
300 | ||
</span> | ||
</span> | ||
<div class=\\"input-range__track input-range__track--background\\"> | ||
<div style=\\"left: 0%; width: 24%;\\" | ||
class=\\"input-range__track input-range__track--active\\" | ||
> | ||
</div> | ||
<span class=\\"input-range__slider-container\\" | ||
style=\\"position: absolute; left: 24%;\\" | ||
> | ||
<span class=\\"input-range__label input-range__label--value\\"> | ||
<span class=\\"input-range__label-container\\"> | ||
420 | ||
</span> | ||
</span> | ||
<div aria-valuemax=\\"800\\" | ||
aria-valuemin=\\"300\\" | ||
aria-valuenow=\\"420\\" | ||
class=\\"input-range__slider\\" | ||
draggable=\\"false\\" | ||
role=\\"slider\\" | ||
tabindex=\\"0\\" | ||
> | ||
</div> | ||
</span> | ||
</div> | ||
<span class=\\"input-range__label input-range__label--max\\"> | ||
<span class=\\"input-range__label-container\\"> | ||
800 | ||
</span> | ||
</span> | ||
</div> | ||
</div> | ||
" | ||
`; |
Oops, something went wrong.