-
Notifications
You must be signed in to change notification settings - Fork 9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(oas31): simplify Webhooks component by utilizing selectors
Refs #8474
- Loading branch information
Showing
11 changed files
with
126 additions
and
74 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
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 |
---|---|---|
@@ -1,59 +1,45 @@ | ||
/** | ||
* @prettier | ||
*/ | ||
import React from "react" | ||
import PropTypes from "prop-types" | ||
import { fromJS } from "immutable" | ||
import ImPropTypes from "react-immutable-proptypes" | ||
|
||
// Todo: nice to have: similar to operation-tags, could have an expand/collapse button | ||
// to show/hide all webhook items | ||
const Webhooks = (props) => { | ||
const { specSelectors, getComponent, specPath } = props | ||
const Webhooks = ({ specSelectors, getComponent }) => { | ||
const operationDTOs = specSelectors.selectWebhooksOperations() | ||
const pathItemNames = Object.keys(operationDTOs) | ||
|
||
const webhooksPathItems = specSelectors.webhooks() | ||
if (!webhooksPathItems || webhooksPathItems?.size < 1) { | ||
return null | ||
} | ||
const OperationContainer = getComponent("OperationContainer", true) | ||
|
||
const pathItemsElements = webhooksPathItems.entrySeq().map(([pathItemName, pathItem], i) => { | ||
const operationsElements = pathItem.entrySeq().map(([operationMethod, operation], j) => { | ||
const op = fromJS({ | ||
operation | ||
}) | ||
// using defaultProps for `specPath`; may want to remove from props | ||
// and/or if extract to separate PathItem component, allow for use | ||
// with both OAS3.1 "webhooks" and "components.pathItems" features | ||
return <OperationContainer | ||
{...props} | ||
op={op} | ||
key={`${pathItemName}--${operationMethod}--${j}`} | ||
tag={""} | ||
method={operationMethod} | ||
path={pathItemName} | ||
specPath={specPath.push("webhooks", pathItemName, operationMethod)} | ||
allowTryItOut={false} | ||
/> | ||
}) | ||
return <div key={`${pathItemName}-${i}`}> | ||
{operationsElements} | ||
</div> | ||
}) | ||
if (pathItemNames.length === 0) return null | ||
|
||
return ( | ||
<div className="webhooks"> | ||
<h2>Webhooks</h2> | ||
{pathItemsElements} | ||
|
||
{pathItemNames.map((pathItemName) => ( | ||
<div key={`${pathItemName}-webhook`}> | ||
{operationDTOs[pathItemName].map((operationDTO) => ( | ||
<OperationContainer | ||
key={`${pathItemName}-${operationDTO.method}-webhook`} | ||
op={operationDTO.operation} | ||
tag="" | ||
method={operationDTO.method} | ||
path={pathItemName} | ||
specPath={operationDTO.specPath} | ||
allowTryItOut={false} | ||
/> | ||
))} | ||
</div> | ||
))} | ||
</div> | ||
) | ||
} | ||
|
||
Webhooks.propTypes = { | ||
specSelectors: PropTypes.object.isRequired, | ||
specSelectors: PropTypes.shape({ | ||
selectWebhooksOperations: PropTypes.func.isRequired, | ||
}).isRequired, | ||
getComponent: PropTypes.func.isRequired, | ||
specPath: ImPropTypes.list, | ||
} | ||
|
||
Webhooks.defaultProps = { | ||
specPath: fromJS([]) | ||
} | ||
|
||
export default Webhooks |
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 |
---|---|---|
@@ -1,19 +1,15 @@ | ||
/** | ||
* @prettier | ||
*/ | ||
import { onlyOAS31Wrap } from "../helpers" | ||
|
||
export const isOAS3 = | ||
(oriSelector, system) => | ||
(state, ...args) => { | ||
const isOAS31 = system.specSelectors.isOAS31() | ||
return isOAS31 || oriSelector(...args) | ||
} | ||
|
||
export const selectLicenseUrl = | ||
(oriSelector, system) => | ||
(state, ...args) => { | ||
if (system.specSelectors.isOAS31()) { | ||
return system.oas31Selectors.selectLicenseUrl() | ||
} | ||
|
||
return oriSelector(...args) | ||
} | ||
export const selectLicenseUrl = onlyOAS31Wrap(() => (system) => { | ||
return system.oas31Selectors.selectLicenseUrl() | ||
}) |
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