Skip to content

Commit 6e52ee3

Browse files
authored
Merge pull request #1 from stackblitz/tomek/poc
Initial version, preparing for release
2 parents f2b30a2 + a98c1f9 commit 6e52ee3

19 files changed

+15779
-9178
lines changed

package-lock.json

Lines changed: 15676 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
"version": "0.0.0",
44
"description": "Create a one-click Pull Request environment right from your component",
55
"keywords": [
6-
"stackblitz", "pull-request", "ide", "code", "storybook-addons"
6+
"stackblitz",
7+
"pull-request",
8+
"ide",
9+
"code",
10+
"storybook-addons"
711
],
812
"repository": {
913
"type": "git",
@@ -64,6 +68,7 @@
6468
"auto": "^10.3.0",
6569
"boxen": "^5.0.1",
6670
"dedent": "^0.7.0",
71+
"ini": "^4.1.1",
6772
"npm-run-all": "^4.1.5",
6873
"prettier": "^2.3.1",
6974
"prompts": "^2.4.2",
@@ -102,7 +107,15 @@
102107
"storybook": {
103108
"displayName": "StackBlitz",
104109
"supportedFrameworks": [
105-
"react", "vue", "angular", "web-components", "ember", "html", "svelte", "preact", "react-native"
110+
"react",
111+
"vue",
112+
"angular",
113+
"web-components",
114+
"ember",
115+
"html",
116+
"svelte",
117+
"preact",
118+
"react-native"
106119
],
107120
"icon": "https://user-images.githubusercontent.com/321738/63501763-88dbf600-c4cc-11e9-96cd-94adadc2fd72.png"
108121
}

read-remote.mjs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import fs from 'fs';
2+
import ini from 'ini';
3+
4+
const config = ini.parse(fs.readFileSync('./.git/config', 'utf-8'))
5+
6+
const remoteOrigin = config['remote "origin"']
7+
8+
if (remoteOrigin) {
9+
const remoteUrl = config['remote "origin"'].url.replace('.git', '');
10+
const stackBlitzUrl = remoteUrl.replace('https://', 'https://pr.new/');
11+
} else {
12+
console.warn('no remote origin set');
13+
}

src/Panel.tsx

Lines changed: 0 additions & 36 deletions
This file was deleted.

src/Tab.tsx

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/Tool.tsx

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,50 @@
1-
import React, { memo, useCallback, useEffect } from "react";
2-
import { useGlobals, useStorybookApi } from "@storybook/manager-api";
3-
import { Icons, IconButton } from "@storybook/components";
4-
import { ADDON_ID, PARAM_KEY, TOOL_ID } from "./constants";
1+
import React, { useState, MouseEvent } from "react";
2+
import { useParameter, useStorybookApi } from "@storybook/manager-api";
3+
import { IconButton } from "@storybook/components";
4+
import { PARAM_KEY, TOOL_ID } from "./constants";
5+
import CodeflowLogo from "./components/CodeflowLogo";
6+
7+
export const Tool = function MyAddonSelector() {
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);
511

6-
export const Tool = memo(function MyAddonSelector() {
7-
const [globals, updateGlobals] = useGlobals();
812
const api = useStorybookApi();
13+
const [disabled, setDisabled] = useState(false)
14+
15+
const currentStory = api.getCurrentStoryData();
916

10-
const isActive = [true, "true"].includes(globals[PARAM_KEY]);
17+
if (!currentStory) {
18+
return null;
19+
}
1120

12-
const toggleMyTool = useCallback(() => {
13-
updateGlobals({
14-
[PARAM_KEY]: !isActive,
15-
});
16-
}, [isActive]);
21+
if (!repositoryUrl && !disabled) {
22+
console.warn(`"${PARAM_KEY}" parameter not defined. Make sure to configure it in your story.`);
23+
setDisabled(true);
24+
} else if (repositoryUrl && disabled) {
25+
setDisabled(false);
26+
}
1727

18-
useEffect(() => {
19-
api.setAddonShortcut(ADDON_ID, {
20-
label: "Toggle Measure [O]",
21-
defaultShortcut: ["O"],
22-
actionName: "outline",
23-
showInMenu: false,
24-
action: toggleMyTool,
25-
});
26-
}, [toggleMyTool, api]);
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+
}
2737

2838
return (
2939
<IconButton
40+
disabled={disabled}
3041
key={TOOL_ID}
31-
active={isActive}
32-
title="Enable my addon"
33-
onClick={toggleMyTool}
42+
href={stackblitzUrl}
43+
onClick={(e: MouseEvent) => disabled && e.preventDefault()}
44+
target="_blank"
45+
title="Open in StackBlitz and make a pull request"
3446
>
35-
<Icons icon="lightning" />
47+
<CodeflowLogo style={{width: 18, margin: '0 -2px'}} />
3648
</IconButton>
3749
);
38-
});
50+
};

src/components/CodeflowLogo.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import * as React from "react"
2+
import { SVGProps } from "react"
3+
4+
const CodeflowLogo = (props: SVGProps<SVGSVGElement>) => (
5+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 24" {...props}>
6+
<path
7+
fill="#e246e5"
8+
d="M27.77 7.038A7.62 7.62 0 0 1 29.6 12a7.1 7.1 0 0 1-7.1 7.1c-1.419 0-2.82-.291-4.137-1.376-1.27-1.046-2.356-2.745-3.384-5.316-.972-2.429-1.886-3.73-2.74-4.434C11.43 7.31 10.58 7.1 9.5 7.1A4.9 4.9 0 0 0 4.6 12c0 1.38.522 2.628 1.295 3.524.783.906 1.75 1.376 2.605 1.376.127 0 .259-.008.392-.021l-.625-1.666a.4.4 0 0 1 .472-.528l4.732 1.183a.4.4 0 0 1 .244.597l-2.662 4.337a.4.4 0 0 1-.715-.068l-.655-1.746c-.37.065-.776.112-1.183.112-1.644 0-3.178-.873-4.27-2.139A7.62 7.62 0 0 1 2.4 12a7.1 7.1 0 0 1 7.1-7.1c1.419 0 2.82.291 4.137 1.376 1.27 1.046 2.356 2.745 3.384 5.316.972 2.429 1.886 3.73 2.74 4.434.809.665 1.658.874 2.739.874a4.9 4.9 0 0 0 4.9-4.9 5.42 5.42 0 0 0-1.295-3.524 4.553 4.553 0 0 0-.878-.79 3.602 3.602 0 0 1-7.077-.936 3.6 3.6 0 0 1 6.816-1.62c1.074.34 2.045 1.03 2.804 1.908ZM21.75 5.35a1.4 1.4 0 1 0 0 2.8 1.4 1.4 0 0 0 0-2.8Z"
9+
/>
10+
</svg>
11+
)
12+
export default CodeflowLogo

src/components/List.tsx

Lines changed: 0 additions & 95 deletions
This file was deleted.

src/components/PanelContent.tsx

Lines changed: 0 additions & 76 deletions
This file was deleted.

0 commit comments

Comments
 (0)