#455 Remove config option in edit mode for widgets without options
Merged 6 years ago by abompard. Opened 6 years ago by ryanlerch.
ryanlerch/fedora-hubs no-options-no-config  into  develop

@@ -2,7 +2,7 @@ 

  import PropTypes from 'prop-types';

  import { connect } from 'react-redux';

  import { SortableHandle } from 'react-sortable-hoc';

- import { openConfigDialog } from "../core/actions/widget";

+ import { openConfigDialog, deleteWidget } from "../core/actions/widget";

  import "./WidgetChrome.css";

  

  
@@ -24,6 +24,7 @@ 

    constructor(props) {

      super(props);

      this.handleEditButtonClicked = this.handleEditButtonClicked.bind(this)

+     this.handleWidgetDeleted = this.handleWidgetDeleted.bind(this);    

    }

  

    handleEditButtonClicked(e) {
@@ -31,6 +32,11 @@ 

      this.props.onEdit(this.props.widget.idx);

    }

  

+   handleWidgetDeleted(e) {

+     e.preventDefault();

+     this.props.onDelete(this.props.widget.idx);

+   }

+ 

    render() {

      // Make sure there's always a title in edit mode

      const title = (this.props.editMode && !this.props.widget.title) ? this.props.widget.label : this.props.widget.title;
@@ -45,11 +51,19 @@ 

            <DragHandle />

            {title}

            <a href="#"

+             className="float-right text-danger pl-2"

+             onClick={this.handleWidgetDeleted}

+             >

+             <i className="fa fa-trash" aria-hidden="true" title="Delete this widget"></i>

+           </a> 

+           { this.props.widget.params.length > 0 &&

+           <a href="#"

              className="float-right text-dark"

              onClick={this.handleEditButtonClicked}

              >

              <i className="fa fa-cog" aria-hidden="true"></i>

            </a>

+           }

          </div>

        );

      } else if (title) {
@@ -86,7 +100,9 @@ 

  };

  const mapDispatchToProps = dispatch => {

    return {

-     onEdit: (widgetId) => { dispatch(openConfigDialog(widgetId)); }

+     onEdit: (widgetId) => { dispatch(openConfigDialog(widgetId)); },

+     onDelete: (widgetId) => { dispatch(deleteWidget(widgetId)); }

+     

    }

  }

  

@@ -3,7 +3,6 @@ 

  import { connect } from 'react-redux';

  import {

    saveConfig,

-   deleteWidget,

    closeConfigDialog,

    } from "../core/actions/widget";

  import { makeLoadable } from '../core/utils';
@@ -35,7 +34,6 @@ 

      };

      this.handleClose = this.handleClose.bind(this);

      this.handleWidgetEdited = this.handleWidgetEdited.bind(this);

-     this.handleWidgetDeleted = this.handleWidgetDeleted.bind(this);

      this.setWidgetConfig = this.setWidgetConfig.bind(this);

    }

  
@@ -61,11 +59,6 @@ 

      this.props.dispatch(saveConfig(this.props.widget.idx, this.state.widgetConfig));

    }

  

-   handleWidgetDeleted(e) {

-     e.preventDefault();

-     this.props.dispatch(deleteWidget(this.props.widget.idx));

-   }

- 

    handleClose(e) {

      this.props.dispatch(closeConfigDialog());

    }
@@ -96,13 +89,6 @@ 

        <div className="d-flex justify-content-end w-100">

          <button

            type="button"

-           className="btn btn-danger mr-auto"

-           onClick={this.handleWidgetDeleted}

-           >

-           Remove this widget

-         </button>

-         <button

-           type="button"

            className="btn btn-secondary ml-3"

            onClick={this.handleClose}

            >

In the edit mode, if a widget does not have config options, the
cog icon is not displayed anymore. As the ability to delete a widget
was previously in the config dialog, this is now moved to the widget
titlebar itself.

Signed-off-by: Ryan Lerch rlerch@redhat.com

Pull-Request has been merged by abompard

6 years ago