-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Storybook: Add mechanism to redirect moved stories #59181
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<script> | ||
( function redirectIfStoryMoved() { | ||
const REDIRECTS = [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Seems like this could be declared a single time outside of the function (while still kept private from the global scope in a closure)? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Like in an additional wrapper function? Not exactly sure what you had in mind here. Though I do think we should extract this into a separate script file if things get more complicated, or if we want to put more JS in this template part file. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, an additional wrapper function. Fine to leave it as-is, this is quite a nitpick at this level. |
||
{ | ||
from: /\/components-deprecated-/, | ||
to: '/components-', | ||
Comment on lines
+5
to
+6
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Next step will be to add a |
||
}, | ||
]; | ||
|
||
const params = new URLSearchParams( window.location.search ); | ||
|
||
const matchedRedirect = REDIRECTS.find( ( { from } ) => | ||
from.test( params.get( 'path' ) ) | ||
); | ||
|
||
if ( ! matchedRedirect ) { | ||
return; | ||
} | ||
|
||
params.set( | ||
'path', | ||
params | ||
.get( 'path' ) | ||
.replace( matchedRedirect.from, matchedRedirect.to ) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need a check for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's fine at this scale. Maybe add some type checking if the list gets longer, but at this moment I only expect two or three entries. |
||
); | ||
|
||
const newUrl = | ||
window.location.origin + | ||
window.location.pathname + | ||
'?' + | ||
decodeURIComponent( params.toString() ); | ||
mirka marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
window.location.replace( newUrl ); | ||
} )(); | ||
</script> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The plan is to move all the "Components (Experimental)" components into the main "Components" grouping, while keeping the "Components (Deprecated)" grouping separate so outdated components don't clutter the list.
The
id
is for overriding the id that will be auto-generated from thetitle
. Although it's a hassle to have to manually set thisid
, I don't expect us having to do it often, because:id
s manually.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With #58518 adding the idea of
status-*
tags, it would be nice if we didn't have to do this at all. Ideally, both theid
andtitle
could be auto-generated by some build step, and we should rarely if ever have to do anything except set thecomponent
.id
is easy enough to generate from the package and component, andtitle
could equally be based on the package name, any relevant status tag, and the component name.