Skip to content

Commit 25754b8

Browse files
jakobkolblevino
authored andcommitted
Add storybook and one default story
1 parent c639dbf commit 25754b8

File tree

10 files changed

+2370
-133
lines changed

10 files changed

+2370
-133
lines changed

frontend/.storybook/.babelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"plugins": ["@emotion"]
3+
}

frontend/.storybook/main.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
stories: ['../src/**/*.stories.(ts|tsx|js|jsx)'],
3+
addons: [
4+
'@storybook/preset-create-react-app',
5+
'@storybook/addon-actions',
6+
'@storybook/addon-links',
7+
],
8+
};

frontend/package.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
"heroku-postbuild": "yarn run build",
1717
"lint": "eslint --ext .ts --ext .tsx src/",
1818
"typecheck": "tsc -p tsconfig.json --noEmit",
19-
"serve": "ts-node mock-api/server"
19+
"serve": "ts-node mock-api/server",
20+
"storybook": "start-storybook -p 9009 -s public",
21+
"build-storybook": "build-storybook -s public"
2022
},
2123
"homepage": "/app/static",
2224
"dependencies": {
@@ -37,6 +39,7 @@
3739
"lodash.difference": "^4.5.0",
3840
"mustache": "^2.3.0",
3941
"node-sass": "^4.12.0",
42+
"ramda": "^0.27.0",
4043
"react": "^16.13.1",
4144
"react-animated-dots": "^1.0.0",
4245
"react-dnd": "^9.4.0",
@@ -68,6 +71,11 @@
6871
"redux-thunk": "^2.3.0"
6972
},
7073
"devDependencies": {
74+
"@storybook/addon-actions": "^5.3.19",
75+
"@storybook/addon-links": "^5.3.19",
76+
"@storybook/addons": "^5.3.19",
77+
"@storybook/preset-create-react-app": "^3.1.4",
78+
"@storybook/react": "^5.3.19",
7179
"@types/axios": "^0.14.0",
7280
"@types/body-parser": "^1.19.0",
7381
"@types/classnames": "^2.2.10",
@@ -82,6 +90,7 @@
8290
"@types/node-sass": "^4.11.1",
8391
"@types/papaparse": "^5.0.4",
8492
"@types/prettier": "^2.0.2",
93+
"@types/ramda": "^0.27.11",
8594
"@types/react": "^16.9.25",
8695
"@types/react-dnd-multi-backend": "^4.0.1",
8796
"@types/react-dom": "^16.9.5",

frontend/src/index.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,8 @@ const disableLogin = !!process.env.REACT_APP_DISABLE_LOGIN;
2020
const LANG = process.env.REACT_APP_LANG;
2121

2222
if (!LANG || LANG === "de") {
23-
//@ts-ignore
24-
2523
initializeLocalization("de", de, translationsDe);
2624
} else {
27-
//@ts-ignore
28-
2925
initializeLocalization("en", enGB, translationsEn);
3026
}
3127

@@ -45,5 +41,5 @@ const environment = {
4541
};
4642

4743
const tabs = [StandardQueryEditorTab, TimebasedQueryEditorTab, FormsTab];
48-
44+
console.log(tabs);
4945
conquery(environment, tabs, theme);

frontend/src/js/app/Content.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ type PropsType = {
6565
rightTabs: TabT[];
6666
};
6767

68-
const CustomHTML5toTouch = {
68+
export const CustomHTML5toTouch = {
6969
backends: [
7070
{
7171
backend: HTML5Backend

frontend/src/js/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ const renderRoot = (tabs: Record<string, any>, theme: Theme) => {
3333
basename: basename()
3434
});
3535
//@ts-ignore
36-
3736
store = store || makeStore(initialState, browserHistory, tabs);
37+
console.log(store.getState());
3838

3939
ReactDOM.render(
4040
<ThemeProvider theme={theme}>

frontend/src/js/localization/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import _T from "i18n-react";
2+
import { Locale } from "date-fns";
23

34
import { mergeDeep } from "../common/helpers";
45

@@ -7,11 +8,11 @@ export const T = _T;
78
type AvailableLocale = "en" | "de";
89

910
let i18nLocale: AvailableLocale | null = null;
10-
let dateFnsLocale: AvailableLocale | null = null;
11+
let dateFnsLocale: Locale | null = null;
1112

1213
export const initializeLocalization = (
1314
locale: AvailableLocale,
14-
dateLocale: AvailableLocale,
15+
dateLocale: Locale,
1516
// @ts-ignore
1617
...texts
1718
) => {
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import React from "react";
2+
import { QueryEditor } from "./QueryEditor";
3+
import { StoryWrapper } from "../../storybook";
4+
5+
export default {
6+
component: QueryEditor,
7+
title: "Query Editor"
8+
};
9+
10+
const dropAction = {
11+
type: "query-editor/DROP_AND_NODE",
12+
payload: {
13+
item: {
14+
width: 572.2000122070312,
15+
height: 20,
16+
ids: ["action_movies"],
17+
label: "Action Movies",
18+
19+
tree: "movie_appearances"
20+
}
21+
}
22+
};
23+
24+
export const Default = () => (
25+
<StoryWrapper actions={[dropAction]}>
26+
<QueryEditor selectedDatasetId={"blub"} />
27+
</StoryWrapper>
28+
);

frontend/src/storybook/index.tsx

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { createBrowserHistory } from "history";
2+
import React from "react";
3+
import { makeStore } from "../js/store";
4+
import { Provider } from "react-redux";
5+
import { ThemeProvider } from "@emotion/react";
6+
import { theme } from "../app-theme";
7+
import { DndProvider } from "react-dnd";
8+
import MultiBackend from "react-dnd-multi-backend";
9+
import { CustomHTML5toTouch } from "../js/app/Content";
10+
import StandardQueryEditorTab from "../js/standard-query-editor";
11+
import TimebasedQueryEditorTab from "../js/timebased-query-editor";
12+
import FormsTab from "../js/external-forms";
13+
import { initializeLocalization } from "../js/localization";
14+
import translationsDe from "../localization/de.json";
15+
import { de } from "date-fns/locale";
16+
import { AnyAction } from "redux";
17+
import * as R from "ramda";
18+
19+
initializeLocalization("de", de, translationsDe);
20+
21+
const browserHistory = createBrowserHistory();
22+
const tabs = [StandardQueryEditorTab, TimebasedQueryEditorTab, FormsTab];
23+
24+
type StoryWrapperProps = {
25+
actions?: ReadonlyArray<AnyAction>;
26+
};
27+
28+
export const StoryWrapper: React.FC<StoryWrapperProps> = ({
29+
children,
30+
actions = []
31+
}) => {
32+
const store = makeStore({}, browserHistory, tabs);
33+
R.forEach(store.dispatch, actions);
34+
return (
35+
<Provider store={store}>
36+
<ThemeProvider theme={theme}>
37+
<DndProvider backend={MultiBackend} options={CustomHTML5toTouch}>
38+
{children}
39+
</DndProvider>
40+
</ThemeProvider>
41+
</Provider>
42+
);
43+
};

0 commit comments

Comments
 (0)