@@ -5,7 +5,10 @@ import { PARAM_KEY, TOOL_ID } from "./constants";
55import CodeflowLogo from "./components/CodeflowLogo" ;
66
77export const Tool = function MyAddonSelector ( ) {
8- const githubUrl = useParameter ( PARAM_KEY ) ;
8+ const repositoryUrl = useParameter < string > ( PARAM_KEY . REPO , null ) ;
9+ const branch = useParameter < string > ( PARAM_KEY . BRANCH , 'main' ) ;
10+ const filePath = useParameter < string > ( PARAM_KEY . FILE_PATH , null ) ;
11+
912 const api = useStorybookApi ( ) ;
1013 const [ disabled , setDisabled ] = useState ( false )
1114
@@ -15,14 +18,22 @@ export const Tool = function MyAddonSelector() {
1518 return null ;
1619 }
1720
18- if ( ! githubUrl && ! disabled ) {
21+ if ( ! repositoryUrl && ! disabled ) {
1922 console . warn ( `"${ PARAM_KEY } " parameter not defined. Make sure to configure it in your story.` ) ;
2023 setDisabled ( true ) ;
21- } else if ( githubUrl && disabled ) {
24+ } else if ( repositoryUrl && disabled ) {
2225 setDisabled ( false ) ;
2326 }
2427
25- const stackblitzUrl = `https://pr.new/${ githubUrl } ` ;
28+ let stackblitzUrl = `https://pr.new/${ repositoryUrl } ` ;
29+ if ( filePath ) {
30+ stackblitzUrl = `${ stackblitzUrl } /blob/${ branch } /${ filePath } ` ;
31+ /*
32+ * We've just addded `/` between all segments not caring if user already appended or prepanded them,
33+ * so let's remove any possible double `//` (not preceded by `:` so we don't mess up the `https://`)
34+ */
35+ stackblitzUrl = stackblitzUrl . replaceAll ( / (?< ! : ) \/ \/ / g, '/' )
36+ }
2637
2738 return (
2839 < IconButton
0 commit comments