Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

query factory parameter #802

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/client/views/cube-view/center-panel/center-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import {
} from "../../../components/split-tile/split-tiles-row";
import { VisSelector } from "../../../components/vis-selector/vis-selector";
import { classNames } from "../../../utils/dom/dom";
import { DataProvider } from "../../../visualizations/data-provider/data-provider";
import { DataProvider, QueryFactory } from "../../../visualizations/data-provider/data-provider";
import { HighlightController } from "../../../visualizations/highlight-controller/highlight-controller";
import { PartialFilter, PartialSeries } from "../partial-tiles-provider";

Expand Down Expand Up @@ -106,6 +106,7 @@ interface ChartPanelProps {
clicker: Clicker;
stage: Stage;
chartComponent: React.ComponentType<ChartProps>;
queryFactory: QueryFactory;
timekeeper: Timekeeper;
lastRefreshRequestTimestamp: number;
dragEnter: Unary<React.DragEvent<HTMLElement>, void>;
Expand All @@ -118,6 +119,7 @@ interface ChartPanelProps {
export const ChartPanel: React.SFC<ChartPanelProps> = props => {
const {
chartComponent,
queryFactory,
essence,
clicker,
timekeeper,
Expand All @@ -136,6 +138,7 @@ export const ChartPanel: React.SFC<ChartPanelProps> = props => {
<div className="visualization">
<ChartWrapper
chartComponent={chartComponent}
queryFactory={queryFactory}
essence={essence}
clicker={clicker}
timekeeper={timekeeper}
Expand All @@ -162,10 +165,11 @@ type ChartWrapperProps = Pick<ChartPanelProps,
"clicker" |
"stage" |
"lastRefreshRequestTimestamp" |
"queryFactory" |
"chartComponent">;

function ChartWrapper(props: ChartWrapperProps) {
const { chartComponent: ChartComponent, essence, clicker, timekeeper, stage, lastRefreshRequestTimestamp } = props;
const { chartComponent: ChartComponent, queryFactory, essence, clicker, timekeeper, stage, lastRefreshRequestTimestamp } = props;
if (essence.visResolve.isManual()) {
return <ManualFallback clicker={clicker} essence={essence}/>;
}
Expand All @@ -174,6 +178,7 @@ function ChartWrapper(props: ChartWrapperProps) {
{highlightProps =>
<DataProvider
refreshRequestTimestamp={lastRefreshRequestTimestamp}
queryFactory={queryFactory}
essence={essence}
timekeeper={timekeeper}
stage={stage}>
Expand All @@ -191,4 +196,4 @@ function ChartWrapper(props: ChartWrapperProps) {
}

type VisualizationPanelProps = ChartPanelProps & VisualizationControlsBaseProps;
export type VisualizationProps = Omit<VisualizationPanelProps, "chartComponent">;
export type VisualizationProps = Omit<VisualizationPanelProps, "chartComponent" | "queryFactory">;
3 changes: 2 additions & 1 deletion src/client/visualizations/bar-chart/bar-chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import { Splits } from "../../../common/models/splits/splits";
import { Stage } from "../../../common/models/stage/stage";
import { formatValue } from "../../../common/utils/formatter/formatter";
import { or } from "../../../common/utils/functional/functional";
import makeQuery from "../../../common/utils/query/visualization-query";
import { Predicates } from "../../../common/utils/rules/predicates";
import { BAR_CHART_MANIFEST } from "../../../common/visualization-manifests/bar-chart/bar-chart";
import { BucketMarks } from "../../components/bucket-marks/bucket-marks";
Expand Down Expand Up @@ -159,7 +160,7 @@ function padDataset(originalDataset: Dataset, dimension: Dimension, measures: Me
export function BarChartVisualization(props: VisualizationProps) {
return <React.Fragment>
<DefaultVisualizationControls {...props} />
<ChartPanel {...props} chartComponent={BarChart}/>
<ChartPanel {...props} queryFactory={makeQuery} chartComponent={BarChart}/>
</React.Fragment>;
}

Expand Down
34 changes: 15 additions & 19 deletions src/client/visualizations/data-provider/data-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import { Dataset, Expression } from "plywood";
import * as React from "react";
import { ReactNode } from "react";
import {
DatasetRequest,
DatasetRequestStatus,
Expand All @@ -29,20 +28,21 @@ import {
import { Essence } from "../../../common/models/essence/essence";
import { Stage } from "../../../common/models/stage/stage";
import { Timekeeper } from "../../../common/models/timekeeper/timekeeper";
import { debounceWithPromise, Unary } from "../../../common/utils/functional/functional";
import visualizationQuery from "../../../common/utils/query/visualization-query";
import { Binary, debounceWithPromise, Unary } from "../../../common/utils/functional/functional";
import { Loader } from "../../components/loader/loader";
import { QueryError } from "../../components/query-error/query-error";
import { reportError } from "../../utils/error-reporter/error-reporter";
import { DownloadableDataset, DownloadableDatasetContext } from "../../views/cube-view/downloadable-dataset-context";
import gridQuery from "../grid/make-query";

export type QueryFactory = Binary<Essence, Timekeeper, Expression>;

interface DataProviderProps {
refreshRequestTimestamp: number;
essence: Essence;
timekeeper: Timekeeper;
stage: Stage;
children: Unary<Dataset, ReactNode>;
queryFactory: QueryFactory;
children: Unary<Dataset, React.ReactNode>;
}

interface DataProviderState {
Expand All @@ -58,8 +58,8 @@ export class DataProvider extends React.Component<DataProviderProps, DataProvide
private lastQueryEssence: Essence = null;

componentDidMount() {
const { essence, timekeeper } = this.props;
this.loadData(essence, timekeeper);
const { essence, timekeeper, queryFactory } = this.props;
this.loadData(essence, timekeeper, queryFactory);
}

componentWillUnmount() {
Expand All @@ -69,16 +69,16 @@ export class DataProvider extends React.Component<DataProviderProps, DataProvide

componentWillReceiveProps(nextProps: DataProviderProps) {
if (this.shouldFetchData(nextProps) && this.visualisationNotResized(nextProps)) {
const { essence, timekeeper } = nextProps;
const { essence, timekeeper, queryFactory } = nextProps;
const hadDataLoaded = isLoaded(this.state.dataset);
const essenceChanged = !essence.equals(this.props.essence);
this.loadData(essence, timekeeper, hadDataLoaded && essenceChanged);
this.loadData(essence, timekeeper, queryFactory, hadDataLoaded && essenceChanged);
}
}

private loadData(essence: Essence, timekeeper: Timekeeper, showSpinner = true) {
private loadData(essence: Essence, timekeeper: Timekeeper, queryFactory: QueryFactory, showSpinner = true) {
if (showSpinner) this.handleDatasetLoad(loading);
this.fetchData(essence, timekeeper)
this.fetchData(essence, timekeeper, queryFactory)
.then(loadedDataset => {
// TODO: encode it better
// null is here when we get out of order request, so we just ignore it
Expand All @@ -92,17 +92,13 @@ export class DataProvider extends React.Component<DataProviderProps, DataProvide
});
}

private fetchData(essence: Essence, timekeeper: Timekeeper): Promise<DatasetRequest | null> {
private fetchData(essence: Essence, timekeeper: Timekeeper, queryFactory: QueryFactory): Promise<DatasetRequest | null> {
this.lastQueryEssence = essence;
return this.debouncedCallExecutor(essence, timekeeper);
}

protected getQuery(essence: Essence, timekeeper: Timekeeper): Expression {
return essence.visualization.name === "grid" ? gridQuery(essence, timekeeper) : visualizationQuery(essence, timekeeper);
return this.debouncedCallExecutor(essence, timekeeper, queryFactory);
}

private callExecutor = (essence: Essence, timekeeper: Timekeeper): Promise<DatasetRequest | null> =>
essence.dataCube.executor(this.getQuery(essence, timekeeper), { timezone: essence.timezone })
private callExecutor = (essence: Essence, timekeeper: Timekeeper, queryFactory: QueryFactory): Promise<DatasetRequest | null> =>
essence.dataCube.executor(queryFactory(essence, timekeeper), { timezone: essence.timezone })
.then((dataset: Dataset) => {
// signal out of order requests with null
if (!this.wasUsedForLastQuery(essence)) return null;
Expand Down
3 changes: 2 additions & 1 deletion src/client/visualizations/grid/grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import { visibleIndexRange } from "../../components/tabular-scroller/visible-row
import { selectFirstSplitDatums } from "../../utils/dataset/selectors/selectors";
import { ChartPanel, VisualizationProps } from "../../views/cube-view/center-panel/center-panel";
import "./grid.scss";
import makeQuery from "./make-query";
import { MeasureRows } from "./measure-rows";
import { GridVisualizationControls } from "./visualization-controls";

Expand All @@ -49,7 +50,7 @@ interface GridState {
export function GridVisualization(props: VisualizationProps) {
return <React.Fragment>
<GridVisualizationControls {...props} />
<ChartPanel {...props} chartComponent={Grid}/>
<ChartPanel {...props} queryFactory={makeQuery} chartComponent={Grid}/>
</React.Fragment>;
}

Expand Down
3 changes: 2 additions & 1 deletion src/client/visualizations/heat-map/heat-map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import * as React from "react";
import { ChartProps } from "../../../common/models/chart-props/chart-props";
import { ConcreteSeries } from "../../../common/models/series/concrete-series";
import { Split } from "../../../common/models/split/split";
import makeQuery from "../../../common/utils/query/visualization-query";
import { HEAT_MAP_MANIFEST } from "../../../common/visualization-manifests/heat-map/heat-map";
import { SPLIT } from "../../config/constants";
import { fillDatasetWithMissingValues } from "../../utils/dataset/sparse-dataset/dataset";
Expand All @@ -38,7 +39,7 @@ import scales from "./utils/scales";
export function HeatMapVisualization(props: VisualizationProps) {
return <React.Fragment>
<DefaultVisualizationControls {...props} />
<ChartPanel {...props} chartComponent={HeatMap}/>
<ChartPanel {...props} queryFactory={makeQuery} chartComponent={HeatMap}/>
</React.Fragment>;
}

Expand Down
3 changes: 2 additions & 1 deletion src/client/visualizations/line-chart/line-chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import * as React from "react";
import { ChartProps } from "../../../common/models/chart-props/chart-props";
import makeQuery from "../../../common/utils/query/visualization-query";
import { LINE_CHART_MANIFEST } from "../../../common/visualization-manifests/line-chart/line-chart";
import { MessageCard } from "../../components/message-card/message-card";
import { ChartPanel, DefaultVisualizationControls, VisualizationProps } from "../../views/cube-view/center-panel/center-panel";
Expand All @@ -33,7 +34,7 @@ const X_AXIS_HEIGHT = 30;
export function LineChartVisualization(props: VisualizationProps) {
return <React.Fragment>
<DefaultVisualizationControls {...props} />
<ChartPanel {...props} chartComponent={LineChart}/>
<ChartPanel {...props} queryFactory={makeQuery} chartComponent={LineChart}/>
</React.Fragment>;
}

Expand Down
3 changes: 2 additions & 1 deletion src/client/visualizations/table/table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { FlattenOptions, PseudoDatum } from "plywood";
import * as React from "react";
import { ChartProps } from "../../../common/models/chart-props/chart-props";
import { ImmutableRecord } from "../../../common/utils/immutable-utils/immutable-utils";
import makeQuery from "../../../common/utils/query/visualization-query";
import { TableSettings } from "../../../common/visualization-manifests/table/settings";
import { ChartPanel, DefaultVisualizationControls, VisualizationProps } from "../../views/cube-view/center-panel/center-panel";
import { InteractionController } from "./interactions/interaction-controller";
Expand All @@ -28,7 +29,7 @@ import "./table.scss";
export function TableVisualization(props: VisualizationProps) {
return <React.Fragment>
<DefaultVisualizationControls {...props} />
<ChartPanel {...props} chartComponent={Table}/>
<ChartPanel {...props} queryFactory={makeQuery} chartComponent={Table}/>
</React.Fragment>;
}

Expand Down
3 changes: 2 additions & 1 deletion src/client/visualizations/totals/totals.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import * as React from "react";
import { ChartProps } from "../../../common/models/chart-props/chart-props";
import makeQuery from "../../../common/utils/query/visualization-query";
import { ChartPanel, DefaultVisualizationControls, VisualizationProps } from "../../views/cube-view/center-panel/center-panel";
import { Total } from "./total";
import "./totals.scss";
Expand All @@ -38,6 +39,6 @@ const BigNumbers: React.SFC<ChartProps> = ({ essence, data }) => {
export function TotalsVisualization(props: VisualizationProps) {
return <React.Fragment>
<DefaultVisualizationControls {...props} />
<ChartPanel {...props} chartComponent={BigNumbers}/>
<ChartPanel {...props} queryFactory={makeQuery} chartComponent={BigNumbers}/>
</React.Fragment>;
}