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
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ class APIDefinition extends React.Component {
linterSelectedSeverity: null,
linterSelectedLine: null,
isImporting: false,
closeImportDialog: null,
};
this.handleNo = this.handleNo.bind(this);
this.handleSave = this.handleSave.bind(this);
Expand All @@ -187,6 +188,7 @@ class APIDefinition extends React.Component {
this.updateSwaggerDefinition = this.updateSwaggerDefinition.bind(this);
this.updateAsyncAPIDefinitionAndDeploy = this.updateAsyncAPIDefinitionAndDeploy.bind(this);
this.onChangeSwaggerContent = this.onChangeSwaggerContent.bind(this);
this.setImportDialogClose = this.setImportDialogClose.bind(this);
this.updateAsyncAPIDefinition = this.updateAsyncAPIDefinition.bind(this);
this.onChangeAsyncAPIContent = this.onChangeAsyncAPIContent.bind(this);
this.setErrors = this.setErrors.bind(this);
Expand Down Expand Up @@ -521,6 +523,14 @@ class APIDefinition extends React.Component {
}
}

/**
* Stores the function to close the import dialog from child component.
* @param {function} closeFn Function to close the import dialog
* */
setImportDialogClose(closeFn) {
this.setState({ closeImportDialog: closeFn });
}

/**
* Handles the transition of the drawer.
* @param {object} props list of props
Expand Down Expand Up @@ -597,6 +607,14 @@ class APIDefinition extends React.Component {
*/
updateAPI();
this.setState({ isUpdating: false });

// Close editor and import dialog after successful import
if (this.state.isImporting) {
this.setState({ openEditor: false, isImporting: false });
if (this.state.closeImportDialog) {
this.state.closeImportDialog();
}
}
})
.catch((err) => {
console.log(err);
Expand Down Expand Up @@ -850,8 +868,9 @@ class APIDefinition extends React.Component {
)
)}
{(!api.initiatedFromGateway && !isApiProduct) && (
<ImportDefinition setSchemaDefinition={this.setSchemaDefinition}
editAndImport={this.openEditorToImport}/>
<ImportDefinition setSchemaDefinition={this.setSchemaDefinition}
editAndImport={this.openEditorToImport}
onImportDialogClose={this.setImportDialogClose}/>
)}
{(api.serviceInfo && api.serviceInfo.outdated && api.type !== 'SOAP') && (
<DefinitionOutdated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* specific language governing permissions and limitations
* under the License.
*/
import React, { useReducer, useState } from 'react';
import React, { useReducer, useState, useEffect } from 'react';
import { styled } from '@mui/material/styles';
import PropTypes from 'prop-types';
import Button from '@mui/material/Button';
Expand Down Expand Up @@ -63,7 +63,7 @@ const Root = styled('div')(() => ({
* @returns
*/
export default function ImportDefinition(props) {
const { setSchemaDefinition, editAndImport } = props;
const { setSchemaDefinition, editAndImport, onImportDialogClose } = props;
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Add PropTypes validation for the new prop.

The onImportDialogClose prop is missing from the PropTypes definition at lines 503-505. Add validation to document the expected function signature.

Add this to the PropTypes definition:

 ImportDefinition.propTypes = {
     setSchemaDefinition: PropTypes.func.isRequired,
+    editAndImport: PropTypes.func,
+    onImportDialogClose: PropTypes.func,
 };
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const { setSchemaDefinition, editAndImport, onImportDialogClose } = props;
ImportDefinition.propTypes = {
setSchemaDefinition: PropTypes.func.isRequired,
editAndImport: PropTypes.func,
onImportDialogClose: PropTypes.func,
};
🤖 Prompt for AI Agents
In
portals/publisher/src/main/webapp/source/src/app/components/Apis/Details/APIDefinition/ImportDefinition.jsx
around line 66 and update the PropTypes block at lines 503-505: the new prop
onImportDialogClose is used but not declared in PropTypes; add a PropTypes entry
for onImportDialogClose (e.g., PropTypes.func or PropTypes.func.isRequired
depending on whether it must always be provided) and include a short comment
describing the expected function signature (no args or a callback with an
event/object) to document usage.

const { settings } = useAppContext();
const [openAPIDefinitionImport, setOpenAPIDefinitionImport] = useState(false);
const [isImporting, setIsImporting] = useState(false);
Expand Down Expand Up @@ -117,6 +117,15 @@ export default function ImportDefinition(props) {
// isWebSocket || isWebSub ? setAsyncAPIDefinitionImport(false) : setOpenAPIDefinitionImport(false);
};

// Expose close dialog function to parent component
useEffect(() => {
if (onImportDialogClose) {
onImportDialogClose(() => {
handleAPIDefinitionImportCancel();
});
}
}, [onImportDialogClose]);

const handleAPIDefinitionEditAndImport = () => {
const {
importingContent,
Expand Down
Loading