Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Move manage integrations button from settings page to room header as a stand-alone component #1286

Merged
merged 22 commits into from
Aug 18, 2017
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
1973b2b
Switch app drawer icons
rxl881 Aug 4, 2017
a22e768
Move room settings button to RoomHeader
rxl881 Aug 6, 2017
308d932
CancelClick prop.
rxl881 Aug 6, 2017
18ae5fd
Send messages on widget addition and deletion
rxl881 Aug 6, 2017
9f8e8ae
Split timeline updates in to different PR.
rxl881 Aug 8, 2017
4bc25f1
Move manage integrations button in to stand-alone component
rxl881 Aug 9, 2017
185379b
Merge branch 'develop' of https://github.com/matrix-org/matrix-react-…
rxl881 Aug 9, 2017
0323151
Show a dialog if the maximum number of widgets allowed has been reached.
rxl881 Aug 10, 2017
454ec40
Merge branch 'develop' of https://github.com/matrix-org/matrix-react-…
rxl881 Aug 11, 2017
9111cb4
Merge pull request #1291 from matrix-org/rxl881/maxWidgets
rxl881 Aug 17, 2017
2c25639
Fix copyright header
rxl881 Aug 17, 2017
eb77dcc
Camel case variable name
rxl881 Aug 17, 2017
d1ee257
Pass roomId rather than whole room object.
rxl881 Aug 17, 2017
02edadb
Don't bubble cancel click to room header.
rxl881 Aug 17, 2017
0907fff
Merge branch 'develop' of https://github.com/matrix-org/matrix-react-…
rxl881 Aug 17, 2017
120a4f4
Check for valid roomId before renering manageIntegsButton.
rxl881 Aug 17, 2017
95d1c37
Kick travis
rxl881 Aug 17, 2017
96900e7
Move error logging to where it is first caught.
rxl881 Aug 18, 2017
84f5e5a
REmove unused onCancelClick
rxl881 Aug 18, 2017
857a8c9
Remove empty defaultProps.
rxl881 Aug 18, 2017
b7d46d9
Merge branch 'develop' of https://github.com/matrix-org/matrix-react-…
rxl881 Aug 18, 2017
1c36e47
Fix add widget link
rxl881 Aug 18, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 127 additions & 0 deletions src/components/views/elements/ManageIntegsButton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/*
Copyright 2017 Vector Creations Ltd
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not anymore!


Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import React from 'react';
import PropTypes from 'prop-types';
import sdk from '../../../index';
import SdkConfig from '../../../SdkConfig';
import ScalarAuthClient from '../../../ScalarAuthClient';
import ScalarMessaging from '../../../ScalarMessaging';
import Modal from "../../../Modal";
import { _t } from '../../../languageHandler';
import AccessibleButton from './AccessibleButton';
import TintableSvg from './TintableSvg';

export default class ManageIntegsButton extends React.Component {
constructor(props) {
super(props);

this.state = {
scalar_error: null,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be camelCase

showIntegrationsError: false,
};

this.onManageIntegrations = this.onManageIntegrations.bind(this);
this.onShowIntegrationsError = this.onShowIntegrationsError.bind(this);
}

componentWillMount() {
ScalarMessaging.startListening();
this.scalarClient = null;

if (SdkConfig.get().integrations_ui_url && SdkConfig.get().integrations_rest_url) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's strange that we don't pass these URLs into the auth client here, and have to check the config before creating a ScakarAuthClient.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not an argument against fixing it, but this is simply copied across from the existing code on the settings page -- https://github.com/matrix-org/matrix-react-sdk/pull/1286/files#diff-7810353d2ee5218b7242e81423030433L141.

Unless you think this is broken, I'm inclined to leave it. What do you reckon?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not broken, it's just a weird API that made sense when we only ever made one Scalar client. Feel free to leave it for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool. Cheers.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wrote this check to hide all instances of Manage Integrations/Scalar/Modular if there is are no integrations URLs defined in the config. i.e a way to hide the buttons.

This seems to have regressed from the original function: #816

this.scalarClient = new ScalarAuthClient();
this.scalarClient.connect().done(() => {
this.forceUpdate();
}, (err) => {
this.setState({ scalar_error: err});
});
}
}

componentWillUnmount() {
ScalarMessaging.stopListening();
}

onManageIntegrations(ev) {
ev.preventDefault();
const IntegrationsManager = sdk.getComponent("views.settings.IntegrationsManager");
Modal.createDialog(IntegrationsManager, {
src: (this.scalarClient !== null && this.scalarClient.hasCredentials()) ?
this.scalarClient.getScalarInterfaceUrlForRoom(this.props.room.roomId) :
null,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this not open an iFrame with a null src?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As with some of the previous comments, this has just been cargo-culted across from the existing room settings code (https://github.com/matrix-org/matrix-react-sdk/pull/1286/files#diff-7810353d2ee5218b7242e81423030433L520). As it is not currently considered broken, I'm inclined to leave it as is, for now.

onFinished: ()=>{
if (this.props.onCancelClick) {
this.props.onCancelClick(ev);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You probably don't want to be returning this ev here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As with one of the previous comments, this code is directly copied across from the existing settings page - https://github.com/matrix-org/matrix-react-sdk/pull/1286/files#diff-7810353d2ee5218b7242e81423030433L525.

I'm inclined to leave it, for fear of breaking existing expected behaviour.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for fear of breaking existing expected behaviour.

This property is never set - the entire if is redundant and we should absolutely avoid redundant, potentially confusing code.

This means that the behaviour has changed, given you've copied it. Oh! I guess this is the thing where if you close the integrations manager, you also close the room settings. Maybe that wasn't so bizarre after all?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed IRL, I've removed this all together from the ManageIntegsButton component, as it doesn't appear to be used at the moment.

}
},
}, "mx_IntegrationsManager");
}

onShowIntegrationsError(ev) {
ev.preventDefault();
this.setState({
showIntegrationsError: !this.state.showIntegrationsError,
});
}

render() {
let integrationsButton;
let integrationsError;
if (this.scalarClient !== null) {
if (this.state.showIntegrationsError && this.state.scalar_error) {
console.error(this.state.scalar_error);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be logged after line 50

integrationsError = (
<span className="mx_RoomSettings_integrationsButton_errorPopup">
{ _t('Could not connect to the integration server') }
</span>
);
}

if (this.scalarClient.hasCredentials()) {
integrationsButton = (
<AccessibleButton className="mx_RoomHeader_button" onClick={this.onManageIntegrations} title={ _t('Manage Integrations') }>
<TintableSvg src="img/icons-apps.svg" width="35" height="35"/>
</AccessibleButton>
);
} else if (this.state.scalar_error) {
integrationsButton = (
<div className="mx_RoomSettings_integrationsButton_error" onClick={ this.onShowIntegrationsError }>
<img src="img/warning.svg" title={_t('Integrations Error')} width="17"/>
{ integrationsError }
</div>
);
} else {
integrationsButton = (
<AccessibleButton className="mx_RoomHeader_button" onClick={this.onManageIntegrations} title={ _t('Manage Integrations') }>
<TintableSvg src="img/icons-apps.svg" width="35" height="35"/>
</AccessibleButton>
);
}
}

return integrationsButton;
}
}

ManageIntegsButton.propTypes = {
room: PropTypes.object.isRequired,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer a roomId going in here, ManageIntegsButton doesn't need the rest of room state.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

onCancelClick: PropTypes.func,
};

ManageIntegsButton.defaultProps = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty default props

onCancelClick: function() {},
};
4 changes: 2 additions & 2 deletions src/components/views/rooms/MessageComposer.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,12 +289,12 @@ export default class MessageComposer extends React.Component {
if (this.props.showApps) {
hideAppsButton =
<div key="controls_hide_apps" className="mx_MessageComposer_apps" onClick={this.onHideAppsClick} title={_t("Hide Apps")}>
<TintableSvg src="img/icons-apps-active.svg" width="35" height="35"/>
<TintableSvg src="img/icons-hide-apps.svg" width="35" height="35"/>
</div>;
} else {
showAppsButton =
<div key="show_apps" className="mx_MessageComposer_apps" onClick={this.onShowAppsClick} title={_t("Show Apps")}>
<TintableSvg src="img/icons-apps.svg" width="35" height="35"/>
<TintableSvg src="img/icons-show-apps.svg" width="35" height="35"/>
</div>;
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/components/views/rooms/RoomHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import * as linkify from 'linkifyjs';
import linkifyElement from 'linkifyjs/element';
import linkifyMatrix from '../../../linkify-matrix';
import AccessibleButton from '../elements/AccessibleButton';
import ManageIntegsButton from '../elements/ManageIntegsButton';
import {CancelButton} from './SimpleRoomHeader';

linkifyMatrix(linkify);
Expand All @@ -47,13 +48,15 @@ module.exports = React.createClass({
onSaveClick: React.PropTypes.func,
onSearchClick: React.PropTypes.func,
onLeaveClick: React.PropTypes.func,
onCancelClick: React.PropTypes.func,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

onCancelClick is not used by anything

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although it is not used by anything that I have added, this prop actually is used elsewhere in the code... https://github.com/matrix-org/matrix-react-sdk/pull/1286/files#diff-96b79748dd7ebec5d36339d2478e92cbR194

I was adding it in to the component props and default to make it clear to future people (like me) that this prop is passed in are available to be used by other components and to make sure that there is a sensible default if the function is not passed.

I can remove it if you want, but I think it makes more sense to leave it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My mistake, this looks to be necessary. I think I was confused by the fact that it wasn't in prop types previously.

},

getDefaultProps: function() {
return {
editing: false,
inRoom: false,
onSaveClick: function() {},
onCancelClick: function() {},
};
},

Expand Down Expand Up @@ -320,10 +323,15 @@ module.exports = React.createClass({
}

let rightRow;

if (!this.props.editing) {
rightRow =
<div className="mx_RoomHeader_rightRow">
{ settingsButton }
<ManageIntegsButton
onCancelClick={this.props.onCancelClick}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems quite bizarre to be bubbling the onCancelClick of the integrations manager to the onCancelClick of the room header. Stranger still that the onCancelClick that is passed to RoomView will close room settings, so this is definitely wrong.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for spotting that!

room={this.props.room}
/>
{ forgetButton }
{ searchButton }
{ rightPanelButtons }
Expand Down
79 changes: 0 additions & 79 deletions src/components/views/rooms/RoomSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ import sdk from '../../../index';
import Modal from '../../../Modal';
import ObjectUtils from '../../../ObjectUtils';
import dis from '../../../dispatcher';
import ScalarAuthClient from '../../../ScalarAuthClient';
import ScalarMessaging from '../../../ScalarMessaging';
import UserSettingsStore from '../../../UserSettingsStore';
import AccessibleButton from '../elements/AccessibleButton';

Expand Down Expand Up @@ -92,7 +90,6 @@ module.exports = React.createClass({
propTypes: {
room: React.PropTypes.object.isRequired,
onSaveClick: React.PropTypes.func,
onCancelClick: React.PropTypes.func,
},

getInitialState: function() {
Expand All @@ -118,14 +115,10 @@ module.exports = React.createClass({
// Default to false if it's undefined, otherwise react complains about changing
// components from uncontrolled to controlled
isRoomPublished: this._originalIsRoomPublished || false,
scalar_error: null,
showIntegrationsError: false,
};
},

componentWillMount: function() {
ScalarMessaging.startListening();

MatrixClientPeg.get().on("RoomMember.membership", this._onRoomMemberMembership);

MatrixClientPeg.get().getRoomDirectoryVisibility(
Expand All @@ -137,18 +130,6 @@ module.exports = React.createClass({
console.error("Failed to get room visibility: " + err);
});

this.scalarClient = null;
if (SdkConfig.get().integrations_ui_url && SdkConfig.get().integrations_rest_url) {
this.scalarClient = new ScalarAuthClient();
this.scalarClient.connect().done(() => {
this.forceUpdate();
}, (err) => {
this.setState({
scalar_error: err
});
});
}

dis.dispatch({
action: 'ui_opacity',
sideOpacity: 0.3,
Expand All @@ -157,8 +138,6 @@ module.exports = React.createClass({
},

componentWillUnmount: function() {
ScalarMessaging.stopListening();

const cli = MatrixClientPeg.get();
if (cli) {
cli.removeListener("RoomMember.membership", this._onRoomMemberMembership);
Expand Down Expand Up @@ -513,28 +492,6 @@ module.exports = React.createClass({
roomState.mayClientSendStateEvent("m.room.guest_access", cli));
},

onManageIntegrations(ev) {
ev.preventDefault();
var IntegrationsManager = sdk.getComponent("views.settings.IntegrationsManager");
Modal.createTrackedDialog('Integrations Manager', 'onManageIntegrations', IntegrationsManager, {
src: (this.scalarClient !== null && this.scalarClient.hasCredentials()) ?
this.scalarClient.getScalarInterfaceUrlForRoom(this.props.room.roomId) :
null,
onFinished: ()=>{
if (this._calcSavePromises().length === 0) {
this.props.onCancelClick(ev);
}
},
}, "mx_IntegrationsManager");
},

onShowIntegrationsError(ev) {
ev.preventDefault();
this.setState({
showIntegrationsError: !this.state.showIntegrationsError,
});
},

onLeaveClick() {
dis.dispatch({
action: 'leave_room',
Expand Down Expand Up @@ -796,46 +753,10 @@ module.exports = React.createClass({
</div>;
}

let integrationsButton;
let integrationsError;

if (this.scalarClient !== null) {
if (this.state.showIntegrationsError && this.state.scalar_error) {
console.error(this.state.scalar_error);
integrationsError = (
<span className="mx_RoomSettings_integrationsButton_errorPopup">
{ _t('Could not connect to the integration server') }
</span>
);
}

if (this.scalarClient.hasCredentials()) {
integrationsButton = (
<div className="mx_RoomSettings_integrationsButton" onClick={ this.onManageIntegrations }>
{ _t('Manage Integrations') }
</div>
);
} else if (this.state.scalar_error) {
integrationsButton = (
<div className="mx_RoomSettings_integrationsButton_error" onClick={ this.onShowIntegrationsError }>
Integrations Error <img src="img/warning.svg" width="17"/>
{ integrationsError }
</div>
);
} else {
integrationsButton = (
<div className="mx_RoomSettings_integrationsButton" style={{opacity: 0.5}}>
{ _t('Manage Integrations') }
</div>
);
}
}

return (
<div className="mx_RoomSettings">

{ leaveButton }
{ integrationsButton }

{ tagsSection }

Expand Down