This repository has been archived by the owner on Sep 11, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 833
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3341 from matrix-org/travis/tabbed-managers
Support multiple integration managers behind a labs flag
- Loading branch information
Showing
13 changed files
with
313 additions
and
21 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
62 changes: 62 additions & 0 deletions
62
res/css/views/dialogs/_TabbedIntegrationManagerDialog.scss
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,62 @@ | ||
/* | ||
Copyright 2019 The Matrix.org Foundation C.I.C. | ||
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. | ||
*/ | ||
|
||
.mx_TabbedIntegrationManagerDialog .mx_Dialog { | ||
width: 60%; | ||
height: 70%; | ||
overflow: hidden; | ||
padding: 0; | ||
max-width: initial; | ||
max-height: initial; | ||
position: relative; | ||
} | ||
|
||
.mx_TabbedIntegrationManagerDialog_container { | ||
// Full size of the dialog, whatever it is | ||
position: absolute; | ||
top: 0; | ||
bottom: 0; | ||
left: 0; | ||
right: 0; | ||
|
||
.mx_TabbedIntegrationManagerDialog_currentManager { | ||
width: 100%; | ||
height: 100%; | ||
border-top: 1px solid $accent-color; | ||
|
||
iframe { | ||
background-color: #fff; | ||
border: 0; | ||
width: 100%; | ||
height: 100%; | ||
} | ||
} | ||
} | ||
|
||
.mx_TabbedIntegrationManagerDialog_tab { | ||
display: inline-block; | ||
border: 1px solid $accent-color; | ||
border-bottom: 0; | ||
border-top-left-radius: 3px; | ||
border-top-right-radius: 3px; | ||
padding: 10px 8px; | ||
margin-right: 5px; | ||
} | ||
|
||
.mx_TabbedIntegrationManagerDialog_currentTab { | ||
background-color: $accent-color; | ||
color: $accent-fg-color; | ||
} |
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
172 changes: 172 additions & 0 deletions
172
src/components/views/dialogs/TabbedIntegrationManagerDialog.js
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,172 @@ | ||
/* | ||
Copyright 2019 The Matrix.org Foundation C.I.C. | ||
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 {IntegrationManagers} from "../../../integrations/IntegrationManagers"; | ||
import {Room} from "matrix-js-sdk"; | ||
import sdk from '../../../index'; | ||
import {dialogTermsInteractionCallback, TermsNotSignedError} from "../../../Terms"; | ||
import classNames from 'classnames'; | ||
import ScalarMessaging from "../../../ScalarMessaging"; | ||
|
||
export default class TabbedIntegrationManagerDialog extends React.Component { | ||
static propTypes = { | ||
/** | ||
* Called with: | ||
* * success {bool} True if the user accepted any douments, false if cancelled | ||
* * agreedUrls {string[]} List of agreed URLs | ||
*/ | ||
onFinished: PropTypes.func.isRequired, | ||
|
||
/** | ||
* Optional room where the integration manager should be open to | ||
*/ | ||
room: PropTypes.instanceOf(Room), | ||
|
||
/** | ||
* Optional screen to open on the integration manager | ||
*/ | ||
screen: PropTypes.string, | ||
|
||
/** | ||
* Optional integration ID to open in the integration manager | ||
*/ | ||
integrationId: PropTypes.string, | ||
}; | ||
|
||
constructor(props) { | ||
super(props); | ||
|
||
this.state = { | ||
managers: IntegrationManagers.sharedInstance().getOrderedManagers(), | ||
busy: true, | ||
currentIndex: 0, | ||
currentConnected: false, | ||
currentLoading: true, | ||
currentScalarClient: null, | ||
}; | ||
} | ||
|
||
componentDidMount(): void { | ||
this.openManager(0, true); | ||
} | ||
|
||
openManager = async (i: number, force = false) => { | ||
if (i === this.state.currentIndex && !force) return; | ||
|
||
const manager = this.state.managers[i]; | ||
const client = manager.getScalarClient(); | ||
this.setState({ | ||
busy: true, | ||
currentIndex: i, | ||
currentLoading: true, | ||
currentConnected: false, | ||
currentScalarClient: client, | ||
}); | ||
|
||
ScalarMessaging.setOpenManagerUrl(manager.uiUrl); | ||
|
||
client.setTermsInteractionCallback((policyInfo, agreedUrls) => { | ||
// To avoid visual glitching of two modals stacking briefly, we customise the | ||
// terms dialog sizing when it will appear for the integrations manager so that | ||
// it gets the same basic size as the IM's own modal. | ||
return dialogTermsInteractionCallback( | ||
policyInfo, agreedUrls, 'mx_TermsDialog_forIntegrationsManager', | ||
); | ||
}); | ||
|
||
try { | ||
await client.connect(); | ||
if (!client.hasCredentials()) { | ||
this.setState({ | ||
busy: false, | ||
currentLoading: false, | ||
currentConnected: false, | ||
}); | ||
} else { | ||
this.setState({ | ||
busy: false, | ||
currentLoading: false, | ||
currentConnected: true, | ||
}); | ||
} | ||
} catch (e) { | ||
if (e instanceof TermsNotSignedError) { | ||
return; | ||
} | ||
|
||
console.error(e); | ||
this.setState({ | ||
busy: false, | ||
currentLoading: false, | ||
currentConnected: false, | ||
}); | ||
} | ||
}; | ||
|
||
_renderTabs() { | ||
const AccessibleButton = sdk.getComponent("views.elements.AccessibleButton"); | ||
return this.state.managers.map((m, i) => { | ||
const classes = classNames({ | ||
'mx_TabbedIntegrationManagerDialog_tab': true, | ||
'mx_TabbedIntegrationManagerDialog_currentTab': this.state.currentIndex === i, | ||
}); | ||
return ( | ||
<AccessibleButton | ||
className={classes} | ||
onClick={() => this.openManager(i)} | ||
key={`tab_${i}`} | ||
disabled={this.state.busy} | ||
> | ||
{m.name} | ||
</AccessibleButton> | ||
); | ||
}); | ||
} | ||
|
||
_renderTab() { | ||
const IntegrationsManager = sdk.getComponent("views.settings.IntegrationsManager"); | ||
let uiUrl = null; | ||
if (this.state.currentScalarClient) { | ||
uiUrl = this.state.currentScalarClient.getScalarInterfaceUrlForRoom( | ||
this.props.room, | ||
this.props.screen, | ||
this.props.integrationId, | ||
); | ||
} | ||
return <IntegrationsManager | ||
configured={true} | ||
loading={this.state.currentLoading} | ||
connected={this.state.currentConnected} | ||
url={uiUrl} | ||
onFinished={() => {/* no-op */}} | ||
/>; | ||
} | ||
|
||
render() { | ||
return ( | ||
<div className='mx_TabbedIntegrationManagerDialog_container'> | ||
<div className='mx_TabbedIntegrationManagerDialog_tabs'> | ||
{this._renderTabs()} | ||
</div> | ||
<div className='mx_TabbedIntegrationManagerDialog_currentManager'> | ||
{this._renderTab()} | ||
</div> | ||
</div> | ||
); | ||
} | ||
} |
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
Oops, something went wrong.