Skip to content
Snippets Groups Projects
Unverified Commit 57c7bbe6 authored by Gustavo Saiani's avatar Gustavo Saiani Committed by GitHub
Browse files

Clean up prop destructuring in Dashboard component file (#17338)

parent 74b02afd
No related branches found
No related tags found
No related merge requests found
...@@ -4,6 +4,8 @@ import React, { Component } from "react"; ...@@ -4,6 +4,8 @@ import React, { Component } from "react";
import PropTypes from "prop-types"; import PropTypes from "prop-types";
import { Box } from "grid-styled"; import { Box } from "grid-styled";
import { t } from "ttag"; import { t } from "ttag";
import _ from "underscore";
import cx from "classnames";
import DashboardHeader from "./DashboardHeader"; import DashboardHeader from "./DashboardHeader";
import DashboardGrid from "./DashboardGrid"; import DashboardGrid from "./DashboardGrid";
...@@ -14,9 +16,6 @@ import { DashboardSidebars } from "./DashboardSidebars"; ...@@ -14,9 +16,6 @@ import { DashboardSidebars } from "./DashboardSidebars";
import DashboardControls from "../hoc/DashboardControls"; import DashboardControls from "../hoc/DashboardControls";
import _ from "underscore";
import cx from "classnames";
// NOTE: move DashboardControls HoC to container // NOTE: move DashboardControls HoC to container
@DashboardControls @DashboardControls
export default class Dashboard extends Component { export default class Dashboard extends Component {
...@@ -78,21 +77,25 @@ export default class Dashboard extends Component { ...@@ -78,21 +77,25 @@ export default class Dashboard extends Component {
} }
async loadDashboard(dashboardId) { async loadDashboard(dashboardId) {
this.props.initialize();
this.props.loadDashboardParams();
const { const {
addCardOnLoad, addCardOnLoad,
fetchDashboard,
addCardToDashboard, addCardToDashboard,
setErrorPage, fetchDashboard,
initialize,
loadDashboardParams,
location, location,
setErrorPage,
} = this.props; } = this.props;
initialize();
loadDashboardParams();
try { try {
await fetchDashboard(dashboardId, location.query); await fetchDashboard(dashboardId, location.query);
if (addCardOnLoad != null) { if (addCardOnLoad != null) {
// if we destructure this.props.dashboard, for some reason
// if will render dashboards as empty
this.setEditing(this.props.dashboard); this.setEditing(this.props.dashboard);
addCardToDashboard({ dashId: dashboardId, cardId: addCardOnLoad }); addCardToDashboard({ dashId: dashboardId, cardId: addCardOnLoad });
} }
...@@ -139,21 +142,27 @@ export default class Dashboard extends Component { ...@@ -139,21 +142,27 @@ export default class Dashboard extends Component {
onEmbeddingClick = () => {}; onEmbeddingClick = () => {};
render() { render() {
let { const {
dashboard, dashboard,
isEditing,
editingParameter, editingParameter,
parameters, hideParameters,
parameterValues, isEditing,
location,
isFullscreen, isFullscreen,
isNightMode, isNightMode,
isSharing, isSharing,
hideParameters, location,
parameterValues,
parameters,
removeParameter,
setEditingParameter,
setParameterDefaultValue,
setParameterIndex,
setParameterName,
setParameterValue,
} = this.props; } = this.props;
const { error, showAddQuestionSidebar } = this.state; const { error, showAddQuestionSidebar } = this.state;
isNightMode = isNightMode && isFullscreen; const shouldRenderAsNightMode = isNightMode && isFullscreen;
let parametersWidget; let parametersWidget;
if (parameters && parameters.length > 0) { if (parameters && parameters.length > 0) {
...@@ -163,7 +172,7 @@ export default class Dashboard extends Component { ...@@ -163,7 +172,7 @@ export default class Dashboard extends Component {
dashboard={dashboard} dashboard={dashboard}
isEditing={isEditing} isEditing={isEditing}
isFullscreen={isFullscreen} isFullscreen={isFullscreen}
isNightMode={isNightMode} isNightMode={shouldRenderAsNightMode}
hideParameters={hideParameters} hideParameters={hideParameters}
parameters={parameters.map(p => ({ parameters={parameters.map(p => ({
...p, ...p,
...@@ -171,12 +180,12 @@ export default class Dashboard extends Component { ...@@ -171,12 +180,12 @@ export default class Dashboard extends Component {
}))} }))}
query={location.query} query={location.query}
editingParameter={editingParameter} editingParameter={editingParameter}
setEditingParameter={this.props.setEditingParameter} setEditingParameter={setEditingParameter}
setParameterName={this.props.setParameterName} setParameterName={setParameterName}
setParameterIndex={this.props.setParameterIndex} setParameterIndex={setParameterIndex}
setParameterDefaultValue={this.props.setParameterDefaultValue} setParameterDefaultValue={setParameterDefaultValue}
removeParameter={this.props.removeParameter} removeParameter={removeParameter}
setParameterValue={this.props.setParameterValue} setParameterValue={setParameterValue}
/> />
); );
} }
...@@ -185,7 +194,7 @@ export default class Dashboard extends Component { ...@@ -185,7 +194,7 @@ export default class Dashboard extends Component {
<LoadingAndErrorWrapper <LoadingAndErrorWrapper
className={cx("Dashboard flex-full", { className={cx("Dashboard flex-full", {
"Dashboard--fullscreen": isFullscreen, "Dashboard--fullscreen": isFullscreen,
"Dashboard--night": isNightMode, "Dashboard--night": shouldRenderAsNightMode,
// prevents header from scrolling so we can have a fixed sidebar // prevents header from scrolling so we can have a fixed sidebar
"full-height": isEditing || isSharing, "full-height": isEditing || isSharing,
})} })}
...@@ -223,7 +232,10 @@ export default class Dashboard extends Component { ...@@ -223,7 +232,10 @@ export default class Dashboard extends Component {
)} )}
<div className="wrapper"> <div className="wrapper">
{dashboard.ordered_cards.length === 0 ? ( {dashboard.ordered_cards.length === 0 ? (
<Box mt={[2, 4]} color={isNightMode ? "white" : "inherit"}> <Box
mt={[2, 4]}
color={shouldRenderAsNightMode ? "white" : "inherit"}
>
<EmptyState <EmptyState
illustrationElement={ illustrationElement={
<span className="QuestionCircle">?</span> <span className="QuestionCircle">?</span>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment