-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add VisualizationControls and use it in Grid component. * Parametrize DataProvider with query factory function (#802) * Parametrize DataProvider with query factory function * SplitMenuBase * Split controls for Grid * Use real limits in grid queries * Fix key on React.Fragment for efficient array diff Rename commonSort prop to sort. * Remove "sort by each dimension" feature on table * Flatten props on split header components. * Add 10 000 limit for grid * Show sort indicator on split columns * mainSplit util for grid - it selects split where are defined sort and limit * Split grid into visual component and interaction controller.
- Loading branch information
1 parent
a3fd142
commit e02ade2
Showing
32 changed files
with
974 additions
and
304 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 |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/* | ||
* Copyright 2017-2021 Allegro.pl | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import * as React from "react"; | ||
import { Dimension } from "../../../common/models/dimension/dimension"; | ||
import { coerceGranularity, isGranularityValid } from "../../../common/models/granularity/granularity"; | ||
import { Sort } from "../../../common/models/sort/sort"; | ||
import { Split } from "../../../common/models/split/split"; | ||
import { Stage } from "../../../common/models/stage/stage"; | ||
import { Fn } from "../../../common/utils/general/general"; | ||
import { STRINGS } from "../../config/constants"; | ||
import { enterKey } from "../../utils/dom/dom"; | ||
import { BubbleMenu } from "../bubble-menu/bubble-menu"; | ||
import { Button } from "../button/button"; | ||
|
||
interface SplitAssembly { | ||
dimension: Dimension; | ||
split: Split; | ||
granularity?: string; | ||
limit?: number; | ||
sort?: Sort; | ||
} | ||
|
||
export function validateSplit(splitAssembly: SplitAssembly): boolean { | ||
const { granularity, split, dimension: { kind } } = splitAssembly; | ||
if (!isGranularityValid(kind, granularity)) { | ||
return false; | ||
} | ||
const newSplit = createSplit(splitAssembly); | ||
return !split.equals(newSplit); | ||
} | ||
|
||
export function createSplit({ | ||
split: { type, reference }, | ||
limit, | ||
granularity, | ||
sort, | ||
dimension: { kind } | ||
}: SplitAssembly): Split { | ||
const bucket = coerceGranularity(granularity, kind); | ||
return new Split({ type, reference, limit, sort, bucket }); | ||
} | ||
|
||
interface SplitMenuBaseProps { | ||
openOn: Element; | ||
containerStage: Stage; | ||
onClose: Fn; | ||
onSave: Fn; | ||
dimension: Dimension; | ||
isValid: boolean; | ||
} | ||
|
||
export class SplitMenuBase extends React.Component<SplitMenuBaseProps> { | ||
|
||
componentDidMount() { | ||
window.addEventListener("keydown", this.globalKeyDownListener); | ||
} | ||
|
||
componentWillUnmount() { | ||
window.removeEventListener("keydown", this.globalKeyDownListener); | ||
} | ||
|
||
globalKeyDownListener = (e: KeyboardEvent) => enterKey(e) && this.onOkClick(); | ||
|
||
onCancelClick = () => this.props.onClose(); | ||
|
||
onOkClick = () => { | ||
const { isValid, onSave, onClose } = this.props; | ||
if (!isValid) return; | ||
onSave(); | ||
onClose(); | ||
}; | ||
|
||
render() { | ||
const { containerStage, openOn, dimension, onClose, children, isValid } = this.props; | ||
if (!dimension) return null; | ||
|
||
return <BubbleMenu | ||
className="split-menu" | ||
direction="down" | ||
containerStage={containerStage} | ||
stage={Stage.fromSize(250, 240)} | ||
openOn={openOn} | ||
onClose={onClose} | ||
> | ||
{children} | ||
<div className="button-bar"> | ||
<Button className="ok" type="primary" disabled={!isValid} onClick={this.onOkClick} title={STRINGS.ok}/> | ||
<Button type="secondary" onClick={this.onCancelClick} title={STRINGS.cancel}/> | ||
</div> | ||
</BubbleMenu>; | ||
} | ||
} |
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
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
Oops, something went wrong.