-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EPMRPP-90318 || Remote plugins support
- Loading branch information
Showing
24 changed files
with
419 additions
and
157 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
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
52 changes: 52 additions & 0 deletions
52
app/src/components/extensionLoader/federatedExtensionLoader/federatedExtensionLoader.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,52 @@ | ||
/* | ||
* Copyright 2024 EPAM Systems | ||
* | ||
* 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 { BubblesLoader } from '@reportportal/ui-kit'; | ||
import { createImportProps } from 'controllers/plugins/uiExtensions/createImportProps'; | ||
import { getExtensionUrl } from '../utils'; | ||
import { useFederatedComponent } from '../hooks'; | ||
import { extensionType } from '../extensionTypes'; | ||
|
||
export function FederatedExtensionLoader({ extension, withPreloader, ...componentProps }) { | ||
const { moduleName, scope, pluginName } = extension; | ||
const url = getExtensionUrl(extension); | ||
|
||
const { failed, Component } = useFederatedComponent(scope, moduleName, url); | ||
|
||
// TODO: replace with proper failed state | ||
if (failed) { | ||
return <h2>Failed to load extension: {moduleName}</h2>; | ||
} | ||
|
||
// TODO: Provide extensionImportProps via React Context | ||
const extensionImportProps = createImportProps(pluginName); | ||
|
||
return ( | ||
<React.Suspense fallback={withPreloader ? <BubblesLoader /> : null}> | ||
{Component ? <Component {...extensionImportProps} {...componentProps} /> : null} | ||
</React.Suspense> | ||
); | ||
} | ||
FederatedExtensionLoader.propTypes = { | ||
extension: extensionType, | ||
withPreloader: PropTypes.bool, | ||
}; | ||
FederatedExtensionLoader.defaultProps = { | ||
extension: {}, | ||
withPreloader: false, | ||
}; |
17 changes: 17 additions & 0 deletions
17
app/src/components/extensionLoader/federatedExtensionLoader/index.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,17 @@ | ||
/* | ||
* Copyright 2024 EPAM Systems | ||
* | ||
* 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. | ||
*/ | ||
|
||
export { FederatedExtensionLoader } from './federatedExtensionLoader'; |
17 changes: 17 additions & 0 deletions
17
app/src/components/extensionLoader/standaloneExtensionLoader/index.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,17 @@ | ||
/* | ||
* Copyright 2024 EPAM Systems | ||
* | ||
* 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. | ||
*/ | ||
|
||
export { StandaloneExtensionLoader } from './standaloneExtensionLoader'; |
78 changes: 78 additions & 0 deletions
78
app/src/components/extensionLoader/standaloneExtensionLoader/standaloneExtensionLoader.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,78 @@ | ||
/* | ||
* Copyright 2024 EPAM Systems | ||
* | ||
* 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, { useRef, useEffect, useState } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { connect } from 'react-redux'; | ||
import { userInfoSelector } from 'controllers/user'; | ||
import { projectInfoSelector } from 'controllers/project'; | ||
import { extensionType } from '../extensionTypes'; | ||
|
||
// http://localhost:3000/#superadmin_personal/plugin/BrowserKube | ||
// TODO: add loader while loading the iframe | ||
// TODO: configure sandbox for iframe | ||
function StandaloneExtensionLoader({ extension, userInfo, projectInfo }) { | ||
const [loaded, setLoaded] = useState(false); | ||
const ref = useRef(); | ||
|
||
const onLoad = () => { | ||
setLoaded(true); | ||
}; | ||
|
||
const sendRpContext = () => { | ||
const consumerOrigin = new URL(extension.url).origin; | ||
const data = { | ||
user: userInfo, | ||
project: projectInfo, | ||
}; | ||
ref?.current?.contentWindow.postMessage(data, consumerOrigin); | ||
}; | ||
|
||
useEffect(() => { | ||
if (loaded) { | ||
sendRpContext(); | ||
} | ||
}, [loaded, userInfo, projectInfo]); | ||
Check warning on line 48 in app/src/components/extensionLoader/standaloneExtensionLoader/standaloneExtensionLoader.jsx
|
||
|
||
return ( | ||
<iframe | ||
ref={ref} | ||
name={extension.pluginName} | ||
title={extension.pluginName} | ||
src={extension.url} | ||
style={{ width: '100%', height: '100%' }} | ||
onLoad={onLoad} | ||
seamless | ||
/> | ||
); | ||
} | ||
StandaloneExtensionLoader.propTypes = { | ||
extension: extensionType, | ||
userInfo: PropTypes.object.isRequired, | ||
projectInfo: PropTypes.object.isRequired, | ||
}; | ||
StandaloneExtensionLoader.defaultProps = { | ||
extension: {}, | ||
}; | ||
|
||
const withConnect = connect((state) => ({ | ||
userInfo: userInfoSelector(state), | ||
projectInfo: projectInfoSelector(state), | ||
})); | ||
|
||
const ConnectedStandaloneExtensionLoader = withConnect(StandaloneExtensionLoader); | ||
|
||
export { ConnectedStandaloneExtensionLoader as StandaloneExtensionLoader }; |
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
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,15 @@ | ||
import React from 'react'; | ||
import { useSelector } from 'react-redux'; | ||
import { pluginPageSelector } from 'controllers/pages'; | ||
|
||
export const useActivePluginPageExtension = (extensionsSelector) => { | ||
const extensions = useSelector(extensionsSelector); | ||
const activePluginPage = useSelector(pluginPageSelector); | ||
|
||
const extension = React.useMemo( | ||
() => extensions.find((ex) => ex.internalRoute === activePluginPage), | ||
[extensions, activePluginPage], | ||
); | ||
|
||
return extension; | ||
}; |
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.