Skip to content

Commit

Permalink
Set dashboard title and description with React (Graylog2#4730)
Browse files Browse the repository at this point in the history
Handle editing of dashboard title and description through React and
Reflux, avoiding the use of jquery and specially `.html`
  • Loading branch information
edmundoa authored and dennisoelkers committed Apr 19, 2018
1 parent 0617c62 commit 5fbb7d3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 17 deletions.
4 changes: 2 additions & 2 deletions graylog2-web-interface/src/components/dashboard/Dashboard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ const Dashboard = createReactClass({
return (
<li className="stream">
<h2>
<Link to={Routes.dashboard_show(this.props.dashboard.id)}><span ref="dashboardTitle">{this.props.dashboard.title}</span></Link>
<Link to={Routes.dashboard_show(this.props.dashboard.id)}>{this.props.dashboard.title}</Link>
</h2>

<div className="stream-data">
{this._getDashboardActions()}
<div className="stream-description">
{createdFromContentPack}
<span ref="dashboardDescription">{this.props.dashboard.description}</span>
{this.props.dashboard.description}
</div>
</div>
</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,6 @@ const EditDashboardModal = createReactClass({
promise.then(() => {
this.close();

const idSelector = `[data-dashboard-id="${this.state.id}"]`;
const $title = $(`${idSelector}.dashboard-title`);
if ($title.length > 0) {
$title.html(this.state.title);
}

const $description = $(`${idSelector}.dashboard-description`);
if ($description.length > 0) {
$description.html(this.state.description);
}

if (typeof this.props.onSaved === 'function') {
this.props.onSaved(this.state.id);
}
Expand Down
16 changes: 12 additions & 4 deletions graylog2-web-interface/src/pages/ShowDashboardPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,10 @@ const ShowDashboardPage = createReactClass({
UserNotification.success(`Graphs will be updated ${forceUpdate ? 'even' : 'only'} when the browser is in the ${forceUpdate ? 'background' : 'foreground'}`, '');
},

_handleDashboardUpdate() {
this.loadData();
},

render() {
if (!this.state.dashboard) {
return <Spinner />;
Expand Down Expand Up @@ -259,13 +263,17 @@ const ShowDashboardPage = createReactClass({
}

const editDashboardTrigger = !this.state.locked && !this._dashboardIsEmpty(dashboard) ?
(<EditDashboardModalTrigger id={dashboard.id} action="edit" title={dashboard.title}
description={dashboard.description} buttonClass="btn-info btn-xs">
(<EditDashboardModalTrigger id={dashboard.id}
action="edit"
title={dashboard.title}
description={dashboard.description}
onSaved={this._handleDashboardUpdate}
buttonClass="btn-info btn-xs">
<i className="fa fa-pencil" />
</EditDashboardModalTrigger>) : null;
const dashboardTitle = (
<span>
<span data-dashboard-id={dashboard.id} className="dashboard-title">{dashboard.title}</span>
{dashboard.title}
&nbsp;
{editDashboardTrigger}
</span>
Expand All @@ -274,7 +282,7 @@ const ShowDashboardPage = createReactClass({
<DocumentTitle title={`Dashboard ${dashboard.title}`}>
<span>
<PageHeader title={dashboardTitle}>
<span data-dashboard-id={dashboard.id} className="dashboard-description">{dashboard.description}</span>
{dashboard.description}
{supportText}
{actions}
</PageHeader>
Expand Down

0 comments on commit 5fbb7d3

Please sign in to comment.