Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 0 additions & 1 deletion web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@
"react-dom": "^19.3.1",
"react-draggable": "^4.7.2",
"react-dropzone": "^20.2.1",
"react-frame-component": "~5.3.2",
"react-leaflet": "^4.2.1",
"react-resize-detector": "^12.3.0",
"react-rnd": "^10.5.3",
Expand Down
7 changes: 4 additions & 3 deletions web/pgadmin/static/js/ToolView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ import { LAYOUT_EVENTS } from './helpers/Layout';
import { useApplicationState } from '../../settings/static/ApplicationStateProvider';


function ToolForm({actionUrl, params}) {
function ToolForm({actionUrl, params, target}) {
const formRef = useRef(null);

useLayoutEffect(()=>{
formRef.current?.submit();
}, []);

return (
<form ref={formRef} id="tool-form" action={actionUrl} method="post" hidden>
<form ref={formRef} id={target ? `tool-form-${target}` : 'tool-form'} action={actionUrl} method="post" target={target} hidden>
{Object.keys(params).map((k)=>{
return k ? <textarea key={k} name={k} defaultValue={params[k]} /> : <></>;
})}
Expand All @@ -36,6 +36,7 @@ function ToolForm({actionUrl, params}) {
ToolForm.propTypes = {
actionUrl: PropTypes.string,
params: PropTypes.object,
target: PropTypes.string,
};

export function getToolTabParams(panelId, toolUrl, formParams, tabParams, restore=false) {
Expand All @@ -48,7 +49,7 @@ export function getToolTabParams(panelId, toolUrl, formParams, tabParams, restor
title: panelId,
content: (
<LayoutIframeTab target={panelId} src={formParams ? undefined : toolUrl}>
{formParams && <ToolForm actionUrl={toolUrl} params={{...formParams, restore:restore, workSpace: tabParams?.workSpace }}/>}
{formParams && <ToolForm actionUrl={toolUrl} params={{...formParams, restore:restore, workSpace: tabParams?.workSpace }} target={panelId}/>}
</LayoutIframeTab>
),
closable: true,
Expand Down
20 changes: 10 additions & 10 deletions web/pgadmin/static/js/helpers/Layout/LayoutIframeTab.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
//////////////////////////////////////////////////////////////
import { Portal } from '@mui/material';
import { useEffect, useRef, useState } from 'react';
import Frame from 'react-frame-component';
import PropTypes from 'prop-types';
import CustomPropTypes from '../../custom_prop_types';

Expand Down Expand Up @@ -57,15 +56,16 @@ export default function LayoutIframeTab({target, src, children}) {

return (
<div ref={selfRef} data-target={target} style={{width: '100%', height: '100%'}}>
<Portal ref={(r)=>{
if(r) setIframeTarget(r.querySelector('#'+target));
}} container={document.querySelector('#layout-portal')}>
{src ?
<iframe src={src} title=" " id={target} style={{position: 'fixed', border: 0, zIndex: 1}} />:
<Frame src={src} id={target} style={{position: 'fixed', border: 0, zIndex: 1}}>
{children}
</Frame>
}
<Portal container={document.querySelector('#layout-portal')}>
<iframe
ref={setIframeTarget}
src={src}
name={target}
title=" "
id={target}
style={{position: 'fixed', border: 0, zIndex: 1}}
/>
{children}
</Portal>
</div>);
}
Expand Down
128 changes: 128 additions & 0 deletions web/regression/javascript/helpers/LayoutIframeTab.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
/////////////////////////////////////////////////////////////
//
// pgAdmin 4 - PostgreSQL Tools
//
// Copyright (C) 2013 - 2026, The pgAdmin Development Team
// This software is released under the PostgreSQL Licence
//
//////////////////////////////////////////////////////////////

import { render } from '@testing-library/react';
import LayoutIframeTab from '../../../pgadmin/static/js/helpers/Layout/LayoutIframeTab';
import { getToolTabParams } from '../../../pgadmin/static/js/ToolView';

describe('LayoutIframeTab', () => {
let portalContainer;
let tabHost;

beforeEach(() => {
portalContainer = document.createElement('div');
portalContainer.id = 'layout-portal';
document.body.appendChild(portalContainer);

tabHost = document.createElement('div');
tabHost.id = 'frm_sqleditor_101';
document.body.appendChild(tabHost);
});

afterEach(() => {
portalContainer.remove();
tabHost.remove();
});

it('renders a named iframe directly with src when no POST form children are used', () => {
render(
<LayoutIframeTab target="frm_sqleditor_101" src="/sqleditor/panel/101" />,
{ container: tabHost }
);

const iframe = portalContainer.querySelector('iframe#frm_sqleditor_101');
expect(iframe).not.toBeNull();
expect(iframe.getAttribute('name')).toBe('frm_sqleditor_101');
expect(iframe.getAttribute('src')).toBe('/sqleditor/panel/101');
});

it('targets POST tool forms at an initial about:blank iframe without srcdoc and unmounts cleanly', () => {
let submittedTarget = null;
let iframeExistedAtSubmit = false;

const submitSpy = jest
.spyOn(window.HTMLFormElement.prototype, 'submit')
.mockImplementation(function () {
submittedTarget = this.getAttribute('target');
const targetIframe = portalContainer.querySelector(`iframe[name="${submittedTarget}"]`);
iframeExistedAtSubmit = Boolean(targetIframe);
});

const tabParams = getToolTabParams(
'frm_sqleditor_101',
'/sqleditor/panel/101?is_query_tool=true',
{ title: 'postgres@localhost', query_url: '' },
{ title: 'postgres@localhost' }
);

const { rerender, unmount } = render(tabParams.content, { container: tabHost });

const iframe = portalContainer.querySelector('iframe#frm_sqleditor_101');
const form = portalContainer.querySelector('form#tool-form-frm_sqleditor_101');
expect(iframe).not.toBeNull();
expect(form).not.toBeNull();
expect(iframe.hasAttribute('src')).toBe(false);
expect(iframe.hasAttribute('srcdoc')).toBe(false);
expect(iframeExistedAtSubmit).toBe(true);
expect(submittedTarget).toBe('frm_sqleditor_101');
expect(form.getAttribute('action')).toBe('/sqleditor/panel/101?is_query_tool=true');
expect(form.getAttribute('method')).toBe('post');
expect(submitSpy).toHaveBeenCalledTimes(1);

const rerenderTabParams = getToolTabParams(
'frm_sqleditor_101',
'/sqleditor/panel/101?is_query_tool=true',
{ title: 'postgres@localhost', query_url: '' },
{ title: 'postgres@localhost' }
);
rerender(rerenderTabParams.content);
expect(submitSpy).toHaveBeenCalledTimes(1);

unmount();
expect(portalContainer.querySelector('iframe#frm_sqleditor_101')).toBeNull();

submitSpy.mockRestore();
});

it('isolates form IDs and targets when parent and spawned child Query Tool tabs are mounted together', () => {
const childHost = document.createElement('div');
childHost.id = 'frm_sqleditor_102';
document.body.appendChild(childHost);

const submittedTargets = [];
const submitSpy = jest
.spyOn(window.HTMLFormElement.prototype, 'submit')
.mockImplementation(function () {
submittedTargets.push(this.getAttribute('target'));
});

const parentParams = getToolTabParams(
'frm_sqleditor_101',
'/sqleditor/panel/101?is_query_tool=true',
{ title: 'parent' },
{ title: 'parent' }
);
const childParams = getToolTabParams(
'frm_sqleditor_102',
'/sqleditor/panel/102?is_query_tool=true',
{ title: 'child' },
{ title: 'child' }
);

render(parentParams.content, { container: tabHost });
render(childParams.content, { container: childHost });

expect(submittedTargets).toEqual(['frm_sqleditor_101', 'frm_sqleditor_102']);
expect(portalContainer.querySelector('#tool-form-frm_sqleditor_101')).not.toBeNull();
expect(portalContainer.querySelector('#tool-form-frm_sqleditor_102')).not.toBeNull();

submitSpy.mockRestore();
childHost.remove();
});
});
8 changes: 0 additions & 8 deletions web/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,6 @@ module.exports = [{
resolve: {
fullySpecified: false
},
},{
// react-frame-component 5.3 declares "type": "module" but maps its
// "require" export to a UMD build. Babel compiles our imports to
// require(), so webpack picks the UMD file and, honouring the package
// type, parses it as ESM, where the UMD wrapper finds no exports object
// and exports nothing. Parse it as CommonJS/auto so the UMD works.
test: /[\\/]node_modules[\\/]react-frame-component[\\/].*\.js$/,
type: 'javascript/auto',
},{
test: /\.tsx?$|\.ts?$|\.jsx?$/,
exclude: [/node_modules/, /vendor/],
Expand Down
12 changes: 0 additions & 12 deletions web/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12755,17 +12755,6 @@ __metadata:
languageName: node
linkType: hard

"react-frame-component@npm:~5.3.2":
version: 5.3.2
resolution: "react-frame-component@npm:5.3.2"
peerDependencies:
prop-types: ^15.8.1 || ^16.0.0 || ^17.0.0 || ^18.0.0
react: ">= 16.8 || ^17.0.0 || ^18.0.0 || ^19.0.0"
react-dom: ">= 16.8 || ^17.0.0 || ^18.0.0 || ^19.0.0"
checksum: 10c0/c158117f832c82ee4e17584b1a8a90ac2080d8fdf8bf9708c1fea5dc38052763e71f378cc09e1e82b8cf67715d9933dde64c011cf7331d2edc33b3383f711206
languageName: node
linkType: hard

"react-is@npm:^16.13.1, react-is@npm:^16.7.0":
version: 16.13.1
resolution: "react-is@npm:16.13.1"
Expand Down Expand Up @@ -13327,7 +13316,6 @@ __metadata:
react-dom: "npm:^19.3.1"
react-draggable: "npm:^4.7.2"
react-dropzone: "npm:^20.2.1"
react-frame-component: "npm:~5.3.2"
react-leaflet: "npm:^4.2.1"
react-resize-detector: "npm:^12.3.0"
react-rnd: "npm:^10.5.3"
Expand Down