DeepLinking onClick does not scroll or open Operation. #3958
Comments
Hey @travispamaral! Unfortunately, this is intended behavior. The deep linking feature runs once, on page load - we don't (currently) have a router that's keeping an eye on the URL hash and mediating layout state changes. This was mostly done for compatibility with our previous version, so we'd be happy to accept a PR for this! Switching this over to a |
Quoting myself from #3963, since it's relevant here:
|
@shockey got it! Thanks for the info! Is this feature in the road map? |
@travispamaral, unfortunately I have no ETA for this |
Hey guys! I wanna take this ticket, but I'm running into a problem: I don't know where's the code responsible for expanding and scrolling to an operation in response to clicking a deeplink. I know the expand and scroll behavior is implemented via updateResolved() in deep-link/spec-wrap-actions.js, but in which file is this function used to respond to the clicking of a deeplink? |
Thanks @srpalomino! I'm sure @shockey would love to point you in the right direction. |
Hi @srpalomino! Most of the action is here: https://github.com/swagger-api/swagger-ui/tree/master/src/core/plugins/deep-linking The layout action wrappers listen to layout state changes and set the URL hash when it changes, and the spec action wrappers trigger the scrolling when the spec we're displaying is loaded or changes. |
@shockey Thanks for the info! Unfortunately I'm still a little bit confused. In what file/files does:
I appreciate all the help!!! |
@srpalomino - most of the wiring comes from the plugin system. To start, I'd suggest reading this and this in our documentation, as it provides some context. Let me step back a bit... The deep linking feature handles two pieces of work: updating the URL hash when tags/operations are expanded/collapsed and reading the URL hash when the API definition is rendered after page load. Updating the URL hashThe The deepLinking plugin wants to know when something is expanded or collapsed, because when something is expanded we want to update the URL hash to link to that thing, and when something is collapsed, we want to clear out the URL hash. To this end, the deepLinking plugin uses the Wrap-Action plugin interface in order to listen in on the layout plugin's At runtime, Swagger-UI's plugin system binds this Wrap-Action on top of the layout plugin's When the Parsing the hash when the application startsIn a similar fashion to the above, we're going to wrap another plugin's action in order to know what's going on. One thing to note is that we only do this once. We create a We're wrapping the spec plugin's The spec actions Once Operations and tags have HTML element IDs set on them (here and here), so we find the DOM element that matches here and use the zen scroll library to scroll the page down to it. Wow, this is a bit longer than I thought it would be I think the best way forward is to modify the URL hash parsing code to also use I hope this helped! You have my email, so if you get stuck on something, feel free to reach out either here or over email. |
@shockey This is exactly the amount of depth I was looking for in an
explanation!
Thanks again, and I'll definitely reach out if I have more questions :)
|
@shockey Can you please list concretely all the layout state changes related to what you said earlier??
|
@srpalomino, the layout state changes are the calls to the |
Hi there, while waiting for some kind soul to implement this; is there anything I can do in the meantime to force the page to re-render? With the 2.0 UI I was able to do:
This was probably an evil hack, but it worked; it caused the open operation to close and then the target operation to open. Is there anything similar in the 3.0 UI? Thanks! |
If anyone wants dynamic linking this is my current implementation using typescript and SwaggerUi v3.17.5. const CustomInfoPlugin = () => {
return {
wrapComponents: {
info: () => () => null,
schemes: () => () => null,
operations: (Original: React.ComponentClass, system: any) => (props: any) => {
return (
<CustomOperationContainer originalOpContainer={<Original {...props} />} system={system} />
);
}
}
};
};
export default CustomInfoPlugin;
export class CustomOperationContainer extends React.Component<CustomOpProps, CustomOpState> {
// Opens and scrolls to selected link
choosePath = (path: string) => {
const scrollId; // Operation's div id
const operationId; // Name of operation
const tag; // The tag of the operation
const previousPath = this.state.previousPath;
const layoutActions = this.props.system.layoutActions;
// Closes the previously opened path
if (previousPath !== null && previousPath.operationId !== operationId) {
layoutActions.show(['operations', previousPath.tag, previousPath.operationId], false);
}
// Opens the operation container
layoutActions.show(['operations', tag, operationId], true);
this.delay(500).then(() => this.scrollTo(scrollId));
}
scrollTo = (scrollId: string) => {
let element = document.getElementById(scrollId);
if (element) {
element.scrollIntoView();
}
}
/*...*/
} A sidebar uses choosePath as a callback function and sends the desired link. layoutActions.show opens the chosen link and scrollTo will scroll the view to that link. Because it takes some time for the link to open I used a delay. While I understand using |
@wongJonathan I'm a newbie in SwaggerUI Plugins. |
@zurmuehl, can you share how you're using Swagger UI? |
Shure. |
As of the MDN documentation described, the Some of the i18n fragments, eg: the tag is |
…(via #4953) * add tests for operation lacking an operationId * add deep linking tests for tags/operationIds with underscores * migrate from `_` to `%20` for deeplink hash whitespace escaping * add backwards compatibility for `_` whitespace escaping * update util unit tests
* ref #3958, support utf16 fragments on the deeplink plugin * put -> head for UTF16 operation this is a temporary fix, eventually we will run out of methods and need to use a new targeting strategy * drop obsolete %20 decoder * add full test suite for UTF16 operation * use encodeURIComponent when setting hash * drop obsolete test cases
Hi |
Any news on this? I have also tried to add |
Hi there! I see that an issue #2884 deeplinking was integrated to 3.x however if I have a hyperlink with a hash to the operationID nothing happens on click. If I reload the page the UI scrolls to the open panel as expected. Is there something I am missing here? My url looks as follows and I am using the 3.0 dist repo installed via npm.
Again when clicked the URL address is updated but nothing happens until the page is refreshed manually. Any suggestions?
<a href="#/pet/deletePet">Deletes a pet</a>
The text was updated successfully, but these errors were encountered: