Skip to content

Commit 35f6325

Browse files
committed
fix(playground): Multiple conflicting packages applied at the same time: check for creation state before applying
1 parent c4bcb41 commit 35f6325

File tree

4 files changed

+45
-16
lines changed

4 files changed

+45
-16
lines changed

packages/cubejs-playground/src/DashboardPage.js

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,13 @@ class DashboardPage extends Component {
3737
await this.loadDashboard();
3838
}
3939

40-
async loadDashboard(createApp) {
41-
const { chartLibrary, templatePackageName } = this.state;
40+
async loadDashboard() {
4241
this.setState({
4342
appCode: null,
4443
loadError: null
4544
});
4645
try {
47-
await this.dashboardSource.load(createApp, { chartLibrary, templatePackageName });
46+
await this.dashboardSource.load();
4847
this.setState({
4948
dashboardStarting: false,
5049
appCode: !this.dashboardSource.loadError && this.dashboardSource.dashboardCreated,
@@ -56,9 +55,6 @@ class DashboardPage extends Component {
5655
dashboardPort: dashboardStatus.dashboardPort,
5756
dashboardAppPath: dashboardStatus.dashboardAppPath
5857
});
59-
if (createApp) {
60-
await this.startDashboardApp();
61-
}
6258
} catch (e) {
6359
this.setState({
6460
dashboardStarting: false,
@@ -80,9 +76,28 @@ class DashboardPage extends Component {
8076
const {
8177
appCode, dashboardPort, loadError, dashboardRunning, dashboardStarting, dashboardAppPath
8278
} = this.state;
83-
if (loadError) {
79+
if (loadError && typeof loadError === 'string' && loadError.indexOf('Dashboard app not found') !== -1) {
8480
return <Redirect to="/template-gallery" />;
8581
}
82+
if (loadError) {
83+
return (
84+
<Frame>
85+
<h2>
86+
{loadError}
87+
</h2>
88+
<p style={{ marginTop: 25 }}>
89+
<Link to="/template-gallery">
90+
<Button
91+
type="primary"
92+
>
93+
Create dashboard app in your project directory
94+
</Button>
95+
</Link>
96+
</p>
97+
<Hint />
98+
</Frame>
99+
);
100+
}
86101
if (!appCode) {
87102
return (
88103
<Frame>

packages/cubejs-playground/src/DashboardSource.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,11 @@ import fetch from './playgroundFetch';
44
const fetchWithRetry = (url, options, retries) => fetch(url, { ...options, retries });
55

66
class DashboardSource {
7-
async load(createApp, templatePackages) {
7+
async load(instant) {
88
this.loadError = null;
9-
if (createApp) {
10-
await this.applyTemplatePackages(
11-
templatePackages
12-
);
13-
}
14-
const res = await fetchWithRetry('/playground/dashboard-app-create-status', undefined, 10);
9+
const res = await fetchWithRetry(
10+
`/playground/dashboard-app-create-status${instant ? '?instant=true' : ''}`, undefined, 10
11+
);
1512
const result = await res.json();
1613
if (result.error) {
1714
this.loadError = result.error;

packages/cubejs-playground/src/TemplateGallery/TemplateGalleryPage.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { Component } from 'react';
22
import styled from 'styled-components';
33
import { Switch, Menu, Dropdown, Icon, Form, Row, Col, Card, Modal, Typography } from 'antd';
4-
import { withRouter } from "react-router-dom";
4+
import { withRouter, Redirect } from "react-router-dom";
55
import DashboardSource from "../DashboardSource";
66
import fetch from '../playgroundFetch';
77
import { frameworks } from "../ChartContainer";
@@ -120,10 +120,23 @@ class TemplateGalleryPage extends Component {
120120

121121
async componentDidMount() {
122122
this.dashboardSource = new DashboardSource();
123+
await this.dashboardSource.load(true);
124+
this.setState({
125+
loadError: this.dashboardSource.loadError
126+
});
123127
}
124128

125129
render() {
126-
const { chartLibrary, framework, templatePackageName, createOwnModalVisible, enableWebSocketTransport } = this.state;
130+
const {
131+
loadError
132+
} = this.state;
133+
if (loadError && loadError.indexOf('Dashboard app not found') === -1) {
134+
return <Redirect to="/dashboard" />;
135+
}
136+
137+
const {
138+
chartLibrary, framework, templatePackageName, createOwnModalVisible, enableWebSocketTransport
139+
} = this.state;
127140
const { history } = this.props;
128141
const currentLibraryItem = chartLibraries.find(m => m.value === chartLibrary);
129142
const frameworkItem = frameworks.find(m => m.id === framework);

packages/cubejs-server-core/core/DevServer.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ class DevServer {
9595
}
9696

9797
if (this.applyTemplatePackagesPromise) {
98+
if (req.query.instant) {
99+
res.status(404).json({ error: 'Dashboard app creating' });
100+
return;
101+
}
98102
await this.applyTemplatePackagesPromise;
99103
}
100104

0 commit comments

Comments
 (0)