-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate Widget component to React (#4020)
* Improve sizing for Number inputs Co-Authored-By: Ran Byron <[email protected]> * Migrate WidgetDialog * Start migrating Widget * Update textbox to use HtmlContent * QueryLink migration and some updates * Add visualization rendering * Render widget * Add delete button * Update AutoHeight * Add widget bottom * Add Drodpown button * Split Widget component * Update with #4056 and trigger netlify * In progress: use composition * Add header and footer * Update widget actions positioning * Re-render when refreshing from widget * Add workaround to force DashboardGrid re-render * VisualizationWidgetFooter component * VisualizationWidget menu * Separate RestrictedWidget * Update tests * Update margin for Parameters * Remove widget files * Revert "Improve sizing for Number inputs" This reverts commit a02ce8f. * Some cleanup * Move refresh logic to the Dashboard * Add loadingWidgets logic to the public dashboard * Add onLoadWidget * Remove parameter from URL when empty * Recreate widget array instead of loadingWidgets * Add comment about re-rendering + whitespace missing * CR changes * Use plain html instead of string syntax Co-Authored-By: Ran Byron <[email protected]>
- Loading branch information
Showing
35 changed files
with
837 additions
and
473 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
visualization-renderer { | ||
.visualization-renderer { | ||
display: block; | ||
|
||
.pagination, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
.pivot-table-renderer > table, | ||
visualization-renderer > .visualization-renderer-wrapper { | ||
.visualization-renderer > .visualization-renderer-wrapper { | ||
overflow: auto; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { VisualizationType } from '@/visualizations'; | ||
import { VisualizationName } from '@/visualizations/VisualizationName'; | ||
|
||
function QueryLink({ query, visualization, readOnly }) { | ||
const getUrl = () => { | ||
let hash = null; | ||
if (visualization) { | ||
if (visualization.type === 'TABLE') { | ||
// link to hard-coded table tab instead of the (hidden) visualization tab | ||
hash = 'table'; | ||
} else { | ||
hash = visualization.id; | ||
} | ||
} | ||
|
||
return query.getUrl(false, hash); | ||
}; | ||
|
||
return ( | ||
<a href={readOnly ? null : getUrl()} className="query-link"> | ||
<VisualizationName visualization={visualization} />{' '} | ||
<span>{query.name}</span> | ||
</a> | ||
); | ||
} | ||
|
||
QueryLink.propTypes = { | ||
query: PropTypes.object.isRequired, // eslint-disable-line react/forbid-prop-types | ||
visualization: VisualizationType, | ||
readOnly: PropTypes.bool, | ||
}; | ||
|
||
QueryLink.defaultProps = { | ||
visualization: null, | ||
readOnly: false, | ||
}; | ||
|
||
export default QueryLink; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import Button from 'antd/lib/button'; | ||
import Modal from 'antd/lib/modal'; | ||
import { VisualizationRenderer } from '@/visualizations/VisualizationRenderer'; | ||
import { wrap as wrapDialog, DialogPropType } from '@/components/DialogWrapper'; | ||
import { VisualizationName } from '@/visualizations/VisualizationName'; | ||
|
||
function ExpandedWidgetDialog({ dialog, widget }) { | ||
return ( | ||
<Modal | ||
{...dialog.props} | ||
title={( | ||
<> | ||
<VisualizationName visualization={widget.visualization} />{' '} | ||
<span>{widget.getQuery().name}</span> | ||
</> | ||
)} | ||
width="95%" | ||
footer={(<Button onClick={dialog.dismiss}>Close</Button>)} | ||
> | ||
<VisualizationRenderer | ||
visualization={widget.visualization} | ||
queryResult={widget.getQueryResult()} | ||
context="widget" | ||
/> | ||
</Modal> | ||
); | ||
} | ||
|
||
ExpandedWidgetDialog.propTypes = { | ||
dialog: DialogPropType.isRequired, | ||
widget: PropTypes.object.isRequired, // eslint-disable-line react/forbid-prop-types | ||
}; | ||
|
||
export default wrapDialog(ExpandedWidgetDialog); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
client/app/components/dashboards/dashboard-widget/RestrictedWidget.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import React from 'react'; | ||
import Widget from './Widget'; | ||
|
||
function RestrictedWidget(props) { | ||
return ( | ||
<Widget {...props} className="d-flex justify-content-center align-items-center widget-restricted"> | ||
<div className="t-body scrollbox"> | ||
<div className="text-center"> | ||
<h1><span className="zmdi zmdi-lock" /></h1> | ||
<p className="text-muted"> | ||
This widget requires access to a data source you don't have access to. | ||
</p> | ||
</div> | ||
</div> | ||
</Widget> | ||
); | ||
} | ||
|
||
export default RestrictedWidget; |
50 changes: 50 additions & 0 deletions
50
client/app/components/dashboards/dashboard-widget/TextboxWidget.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import React, { useState } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { markdown } from 'markdown'; | ||
import Menu from 'antd/lib/menu'; | ||
import HtmlContent from '@/components/HtmlContent'; | ||
import TextboxDialog from '@/components/dashboards/TextboxDialog'; | ||
import Widget from './Widget'; | ||
|
||
function TextboxWidget(props) { | ||
const { widget, canEdit } = props; | ||
const [text, setText] = useState(widget.text); | ||
|
||
const editTextBox = () => { | ||
TextboxDialog.showModal({ | ||
text: widget.text, | ||
onConfirm: (newText) => { | ||
widget.text = newText; | ||
setText(newText); | ||
return widget.save(); | ||
}, | ||
}); | ||
}; | ||
|
||
const TextboxMenuOptions = [ | ||
<Menu.Item key="edit" onClick={editTextBox}>Edit</Menu.Item>, | ||
]; | ||
|
||
if (!widget.width) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<Widget {...props} menuOptions={canEdit ? TextboxMenuOptions : null} className="widget-text"> | ||
<HtmlContent className="body-row-auto scrollbox t-body p-15 markdown"> | ||
{markdown.toHTML(text || '')} | ||
</HtmlContent> | ||
</Widget> | ||
); | ||
} | ||
|
||
TextboxWidget.propTypes = { | ||
widget: PropTypes.object.isRequired, // eslint-disable-line react/forbid-prop-types | ||
canEdit: PropTypes.bool, | ||
}; | ||
|
||
TextboxWidget.defaultProps = { | ||
canEdit: false, | ||
}; | ||
|
||
export default TextboxWidget; |
Oops, something went wrong.