Skip to content

Commit 304985f

Browse files
authored
feat: custom date range (#1027)
* feat: custom date range * date range select fix * final fixes
1 parent 618c274 commit 304985f

File tree

4 files changed

+244
-196
lines changed

4 files changed

+244
-196
lines changed

packages/cubejs-client-core/src/ResultSet.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,11 @@ class ResultSet {
594594

595595
return this.loadResponses[0].query;
596596
}
597-
597+
598+
pivotQuery() {
599+
return this.loadResponse.pivotQuery || null;
600+
}
601+
598602
rawData() {
599603
if (this.queryType !== QUERY_TYPE.REGULAR_QUERY) {
600604
throw new Error(`Method is not supported for a '${this.queryType}' query type. Please use decompose`);

packages/cubejs-playground/src/PlaygroundQueryBuilder.js

Lines changed: 153 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -72,154 +72,165 @@ export default function PlaygroundQueryBuilder({
7272
updateOrder,
7373
pivotConfig,
7474
updatePivotConfig,
75-
}) => (
76-
<>
77-
<Row
78-
justify="space-around"
79-
align="top"
80-
gutter={24}
81-
style={{ marginBottom: 12 }}
82-
>
83-
<Col span={24}>
84-
<Card>
85-
<Row
86-
justify="space-around"
87-
align="top"
88-
gutter={24}
89-
style={{ marginBottom: 12 }}
90-
>
91-
<Col span={24}>
92-
<MemberGroup
93-
members={measures}
94-
availableMembers={availableMeasures}
95-
addMemberName="Measure"
96-
updateMethods={playgroundActionUpdateMethods(
97-
updateMeasures,
98-
'Measure'
99-
)}
100-
/>
101-
<Divider type="vertical" />
102-
<MemberGroup
103-
members={dimensions}
104-
availableMembers={availableDimensions}
105-
addMemberName="Dimension"
106-
updateMethods={playgroundActionUpdateMethods(
107-
updateDimensions,
108-
'Dimension'
109-
)}
110-
/>
111-
<Divider type="vertical" />
112-
<MemberGroup
113-
members={segments}
114-
availableMembers={availableSegments}
115-
addMemberName="Segment"
116-
updateMethods={playgroundActionUpdateMethods(
117-
updateSegments,
118-
'Segment'
119-
)}
120-
/>
121-
<Divider type="vertical" />
122-
<TimeGroup
123-
members={timeDimensions}
124-
availableMembers={availableTimeDimensions}
125-
addMemberName="Time"
126-
updateMethods={playgroundActionUpdateMethods(
127-
updateTimeDimensions,
128-
'Time'
129-
)}
130-
/>
131-
</Col>
132-
</Row>
75+
}) => {
76+
let parsedDateRange = null;
13377

134-
<Row
135-
justify="space-around"
136-
align="top"
137-
gutter={24}
138-
style={{ marginBottom: 12 }}
139-
>
140-
<Col span={24}>
141-
<FilterGroup
142-
members={filters}
143-
availableMembers={availableDimensions.concat(
144-
availableMeasures
145-
)}
146-
addMemberName="Filter"
147-
updateMethods={playgroundActionUpdateMethods(
148-
updateFilters,
149-
'Filter'
150-
)}
151-
/>
152-
</Col>
153-
</Row>
78+
if (resultSet) {
79+
const { timeDimensions = [] } =
80+
resultSet.pivotQuery() || resultSet.query() || {};
81+
parsedDateRange = timeDimensions[0]?.dateRange;
82+
}
83+
84+
return (
85+
<>
86+
<Row
87+
justify="space-around"
88+
align="top"
89+
gutter={24}
90+
style={{ marginBottom: 12 }}
91+
>
92+
<Col span={24}>
93+
<Card>
94+
<Row
95+
justify="space-around"
96+
align="top"
97+
gutter={24}
98+
style={{ marginBottom: 12 }}
99+
>
100+
<Col span={24}>
101+
<MemberGroup
102+
members={measures}
103+
availableMembers={availableMeasures}
104+
addMemberName="Measure"
105+
updateMethods={playgroundActionUpdateMethods(
106+
updateMeasures,
107+
'Measure'
108+
)}
109+
/>
110+
<Divider type="vertical" />
111+
<MemberGroup
112+
members={dimensions}
113+
availableMembers={availableDimensions}
114+
addMemberName="Dimension"
115+
updateMethods={playgroundActionUpdateMethods(
116+
updateDimensions,
117+
'Dimension'
118+
)}
119+
/>
120+
<Divider type="vertical" />
121+
<MemberGroup
122+
members={segments}
123+
availableMembers={availableSegments}
124+
addMemberName="Segment"
125+
updateMethods={playgroundActionUpdateMethods(
126+
updateSegments,
127+
'Segment'
128+
)}
129+
/>
130+
<Divider type="vertical" />
131+
<TimeGroup
132+
members={timeDimensions}
133+
availableMembers={availableTimeDimensions}
134+
addMemberName="Time"
135+
updateMethods={playgroundActionUpdateMethods(
136+
updateTimeDimensions,
137+
'Time'
138+
)}
139+
parsedDateRange={parsedDateRange}
140+
/>
141+
</Col>
142+
</Row>
143+
144+
<Row
145+
justify="space-around"
146+
align="top"
147+
gutter={24}
148+
style={{ marginBottom: 12 }}
149+
>
150+
<Col span={24}>
151+
<FilterGroup
152+
members={filters}
153+
availableMembers={availableDimensions.concat(
154+
availableMeasures
155+
)}
156+
addMemberName="Filter"
157+
updateMethods={playgroundActionUpdateMethods(
158+
updateFilters,
159+
'Filter'
160+
)}
161+
/>
162+
</Col>
163+
</Row>
154164

155-
<Row
156-
justify="space-around"
157-
align="top"
158-
gutter={24}
159-
style={{ marginBottom: 12 }}
160-
>
161-
<Col span={24}>
162-
<SelectChartType
163-
chartType={chartType}
164-
updateChartType={(type) => {
165-
playgroundAction('Change Chart Type');
166-
updateChartType(type);
167-
}}
168-
/>
165+
<Row
166+
justify="space-around"
167+
align="top"
168+
gutter={24}
169+
style={{ marginBottom: 12 }}
170+
>
171+
<Col span={24}>
172+
<SelectChartType
173+
chartType={chartType}
174+
updateChartType={(type) => {
175+
playgroundAction('Change Chart Type');
176+
updateChartType(type);
177+
}}
178+
/>
169179

170-
<Divider type="vertical" />
180+
<Divider type="vertical" />
171181

172-
<Popover
173-
content={
174-
<Settings
175-
limit={query.limit}
176-
pivotConfig={pivotConfig}
177-
orderMembers={orderMembers}
178-
onReorder={updateOrder.reorder}
179-
onOrderChange={updateOrder.set}
180-
onMove={updatePivotConfig.moveItem}
181-
onUpdate={updatePivotConfig.update}
182-
/>
183-
}
184-
placement="bottomLeft"
185-
trigger="click"
186-
>
187-
<Button
188-
disabled={!isQueryPresent}
189-
icon={<SettingOutlined />}
182+
<Popover
183+
content={
184+
<Settings
185+
limit={query.limit}
186+
pivotConfig={pivotConfig}
187+
orderMembers={orderMembers}
188+
onReorder={updateOrder.reorder}
189+
onOrderChange={updateOrder.set}
190+
onMove={updatePivotConfig.moveItem}
191+
onUpdate={updatePivotConfig.update}
192+
/>
193+
}
194+
placement="bottomLeft"
195+
trigger="click"
190196
>
191-
Settings
192-
</Button>
193-
</Popover>
194-
</Col>
195-
</Row>
196-
</Card>
197-
</Col>
198-
</Row>
197+
<Button
198+
disabled={!isQueryPresent}
199+
icon={<SettingOutlined />}
200+
>
201+
Settings
202+
</Button>
203+
</Popover>
204+
</Col>
205+
</Row>
206+
</Card>
207+
</Col>
208+
</Row>
199209

200-
<Row justify="space-around" align="top" gutter={24}>
201-
<Col span={24}>
202-
{isQueryPresent ? (
203-
<ChartRenderer
204-
query={validatedQuery}
205-
resultSet={resultSet}
206-
error={error}
207-
apiUrl={apiUrl}
208-
cubejsToken={cubejsToken}
209-
chartType={chartType}
210-
cubejsApi={cubejsApi}
211-
dashboardSource={dashboardSource}
212-
pivotConfig={pivotConfig}
213-
/>
214-
) : (
215-
<h2 style={{ textAlign: 'center' }}>
216-
Choose a measure or dimension to get started
217-
</h2>
218-
)}
219-
</Col>
220-
</Row>
221-
</>
222-
)}
210+
<Row justify="space-around" align="top" gutter={24}>
211+
<Col span={24}>
212+
{isQueryPresent ? (
213+
<ChartRenderer
214+
query={validatedQuery}
215+
resultSet={resultSet}
216+
error={error}
217+
apiUrl={apiUrl}
218+
cubejsToken={cubejsToken}
219+
chartType={chartType}
220+
cubejsApi={cubejsApi}
221+
dashboardSource={dashboardSource}
222+
pivotConfig={pivotConfig}
223+
/>
224+
) : (
225+
<h2 style={{ textAlign: 'center' }}>
226+
Choose a measure or dimension to get started
227+
</h2>
228+
)}
229+
</Col>
230+
</Row>
231+
</>
232+
);
233+
}}
223234
/>
224235
);
225236
}

packages/cubejs-playground/src/QueryBuilder/RemoveButtonGroup.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Button } from 'antd';
66
const RemoveButtonGroup = ({ onRemoveClick, children, ...props }) => (
77
<Button.Group style={{ marginRight: 8 }} {...props}>
88
{children}
9-
<Button type="danger" ghost onClick={onRemoveClick}>
9+
<Button danger ghost onClick={onRemoveClick}>
1010
<CloseOutlined />
1111
</Button>
1212
</Button.Group>

0 commit comments

Comments
 (0)