Skip to content

Commit

Permalink
fix: pivot control
Browse files Browse the repository at this point in the history
  • Loading branch information
vasilev-alex committed Sep 10, 2020
1 parent 9c4fd1d commit 05ce626
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 13 deletions.
1 change: 1 addition & 0 deletions packages/cubejs-api-gateway/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,7 @@ class ApiGateway {
}

async getNormalizedQueries(query, context) {
query = this.parseQueryParam(query);
let queryType = QUERY_TYPE.REGULAR_QUERY;

if (!Array.isArray(query)) {
Expand Down
10 changes: 7 additions & 3 deletions packages/cubejs-client-react/src/QueryBuilder.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,8 @@ export default class QueryBuilder extends React.Component {
sourceIndex,
destinationIndex,
sourceAxis,
destinationAxis
destinationAxis,
callback
}) => {
const nextPivotConfig = {
...pivotConfig,
Expand All @@ -257,6 +258,10 @@ export default class QueryBuilder extends React.Component {
nextPivotConfig[sourceAxis].splice(sourceIndex, 1);
nextPivotConfig[destinationAxis].splice(destinationIndex, 0, id);

if (callback) {
callback(nextPivotConfig);
}

this.updateVizState({
pivotConfig: nextPivotConfig
});
Expand Down Expand Up @@ -297,7 +302,7 @@ export default class QueryBuilder extends React.Component {

let pivotQuery = {};
let finalState = this.applyStateChangeHeuristics(state);
const { order: _, ...query } = finalState.query || {};
const { order: _, ...query } = finalState.query || stateQuery;

if (QueryRenderer.isQueryPresent(query)) {
try {
Expand Down Expand Up @@ -332,7 +337,6 @@ export default class QueryBuilder extends React.Component {
const nextOrder = fromPairs(currentOrderMembers.map(({ id, order }) => (order !== 'none' ? [id, order] : false)).filter(Boolean));

const nextQuery = {
...stateQuery,
...query,
order: nextOrder
};
Expand Down
8 changes: 4 additions & 4 deletions packages/cubejs-playground/src/QueryBuilder/TimeGroup.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { PlusOutlined } from '@ant-design/icons';
import { DatePicker, Menu } from 'antd';
import moment from 'moment';
import React, { useState } from 'react';
import React, { useState, Fragment } from 'react';
import ButtonDropdown from './ButtonDropdown';
import MemberDropdown from './MemberDropdown';
import RemoveButtonGroup from './RemoveButtonGroup';
Expand Down Expand Up @@ -72,8 +72,8 @@ const TimeGroup = ({

return (
<>
{members.map((m) => (
<>
{members.map((m, index) => (
<Fragment key={index}>
<RemoveButtonGroup onRemoveClick={() => updateMethods.remove(m)}>
<MemberDropdown
onClick={(updateWith) =>
Expand Down Expand Up @@ -128,7 +128,7 @@ const TimeGroup = ({
m.dimension.granularities.find((g) => g.name === m.granularity)
.title}
</ButtonDropdown>
</>
</Fragment>
))}

{!members.length && (
Expand Down
2 changes: 1 addition & 1 deletion packages/cubejs-playground/src/SchemaPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ class SchemaPage extends Component {

return (
<Layout style={{ height: '100%' }}>
<Sider width={300} className="schema-sidebar">
<Sider width={320} className="schema-sidebar">
<Tabs
activeKey={activeTab}
onChange={(tab) => this.setState({ activeTab: tab })}
Expand Down
18 changes: 13 additions & 5 deletions packages/cubejs-playground/src/components/Pivot/Axes.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,43 @@
import React from 'react';
import React, { useEffect, useState } from 'react';
import { DragDropContext } from 'react-beautiful-dnd';
import { Row, Col, Divider } from 'antd';
import DroppableArea from './DroppableArea';

export default function Axes({ pivotConfig, onMove }) {
const [uiPivotConfig, setUIPivotConfig] = useState(pivotConfig);

useEffect(() => {
setUIPivotConfig(pivotConfig);
}, [pivotConfig]);

return (
<DragDropContext
onDragEnd={({ source, destination }) => {
onDragEnd={({ source, destination, ...props }) => {
if (!destination) {
return;
}

onMove({
sourceIndex: source.index,
destinationIndex: destination.index,
sourceAxis: source.droppableId,
destinationAxis: destination.droppableId,
callback(updatedPivotConfig) {
setUIPivotConfig(updatedPivotConfig);
},
});
}}
>
<Row>
<Col span={11}>
<DroppableArea pivotConfig={pivotConfig} axis="x" />
<DroppableArea pivotConfig={uiPivotConfig} axis="x" />
</Col>

<Col span={2}>
<Divider style={{ height: '100%' }} type="vertical" />
</Col>

<Col span={11}>
<DroppableArea pivotConfig={pivotConfig} axis="y" />
<DroppableArea pivotConfig={uiPivotConfig} axis="y" />
</Col>
</Row>
</DragDropContext>
Expand Down
1 change: 1 addition & 0 deletions packages/cubejs-playground/src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ body {
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
background: #f8f8fb;
overflow-x: hidden;
}

code {
Expand Down

0 comments on commit 05ce626

Please sign in to comment.