-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
153 additions
and
53 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
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'; |
51 changes: 51 additions & 0 deletions
51
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,51 @@ | ||
/* | ||
* 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 } from 'react'; | ||
import { extensionType } from '../extensionTypes'; | ||
|
||
export function StandaloneExtensionLoader({ extension }) { | ||
const ref = useRef(); | ||
|
||
const onLoad = () => { | ||
// TODO: whitelist the necessary origin | ||
ref?.current?.contentWindow.postMessage('Hello from ReportPortal', '*'); | ||
console.log('iFrame loaded, send data to it'); | ||
}; | ||
|
||
useEffect(() => { | ||
setTimeout(() => { | ||
onLoad(); | ||
}, 5000); | ||
}); | ||
|
||
return ( | ||
<iframe | ||
ref={ref} | ||
name={extension.pluginName} | ||
title={extension.pluginName} | ||
src={extension.url} | ||
style={{ width: '100%', height: '100%' }} | ||
onLoad={onLoad} | ||
/> | ||
); | ||
} | ||
StandaloneExtensionLoader.propTypes = { | ||
extension: extensionType, | ||
}; | ||
StandaloneExtensionLoader.defaultProps = { | ||
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
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