Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/develop' into fix/hot-reload
Browse files Browse the repository at this point in the history
# Conflicts:
#	package-lock.json
#	package.json
  • Loading branch information
lindapaiste committed Aug 2, 2023
2 parents c2b23e5 + 2da277c commit ce73fa0
Show file tree
Hide file tree
Showing 56 changed files with 40,605 additions and 24,501 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": ["airbnb", "prettier"],
"extends": ["airbnb", "prettier", "plugin:storybook/recommended"],
"parser": "@babel/eslint-parser",
"env": {
"browser": true,
Expand Down
44 changes: 25 additions & 19 deletions .storybook/main.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,35 @@
const path = require('path');

module.exports = {
/** @type { import('@storybook/react-webpack5').StorybookConfig } */
const config = {
stories: ['../client/**/*.stories.(jsx|mdx)'],
addons: [
'@storybook/addon-actions',
'@storybook/addon-docs',
'@storybook/addon-knobs',
'@storybook/addon-links',
'storybook-addon-theme-playground/dist/register'
'@storybook/addon-essentials',
'@storybook/addon-interactions'
],
webpackFinal: async config => {
// do mutation to the config

const rules = config.module.rules;

// modify storybook's file-loader rule to avoid conflicts with svgr
const fileLoaderRule = rules.find(rule => rule.test.test('.svg'));
fileLoaderRule.exclude = path.resolve(__dirname, '../client');
framework: {
name: '@storybook/react-webpack5',
options: {}
},
docs: {
autodocs: 'tag'
},
async webpackFinal(config) {
// https://storybook.js.org/docs/react/builders/webpack
// this modifies the existing image rule to exclude .svg files
// since we want to handle those files with @svgr/webpack
const imageRule = config.module.rules.find(rule => rule.test.test('.svg'))
imageRule.exclude = /\.svg$/

// use svgr for svg files
rules.push({
// configure .svg files to be loaded with @svgr/webpack
config.module.rules.push({
test: /\.svg$/,
use: ["@svgr/webpack"],
use: ['@svgr/webpack']
})

return config;
return config
},
};

export default config;


41 changes: 16 additions & 25 deletions .storybook/preview.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,22 @@
import React from 'react';
import { addDecorator, addParameters } from '@storybook/react';
import { withKnobs } from "@storybook/addon-knobs";
import { withThemePlayground } from 'storybook-addon-theme-playground';
import { ThemeProvider } from "styled-components";
import { Provider } from 'react-redux';

import theme, { Theme } from '../client/theme';
import ThemeProvider from '../client/modules/App/components/ThemeProvider';
import configureStore from '../client/store';
import '../client/i18n-test';
import '../client/styles/build/css/main.css'

addDecorator(withKnobs);
const initialState = window.__INITIAL_STATE__;

const themeConfigs = Object.values(Theme).map(
name => {
return { name, theme: theme[name] };
}
);
const store = configureStore(initialState);

addDecorator(withThemePlayground({
theme: themeConfigs,
provider: ThemeProvider
}));
export const decorators = [
(Story) => (
<Provider store={store}>
<ThemeProvider>
<Story />
</ThemeProvider>
</Provider>
),
]

addParameters({
options: {
/**
* display the top-level grouping as a "root" in the sidebar
*/
showRoots: true,
},
})

// addDecorator(storyFn => <ThemeProvider theme={theme}>{storyFn()}</ThemeProvider>);
5 changes: 5 additions & 0 deletions client/browserHistory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { createBrowserHistory } from 'history';

const browserHistory = createBrowserHistory();

export default browserHistory;
2 changes: 1 addition & 1 deletion client/common/Button.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import styled from 'styled-components';
import { Link } from 'react-router';
import { Link } from 'react-router-dom';

import { remSize, prop } from '../theme';

Expand Down
18 changes: 9 additions & 9 deletions client/common/Button.stories.jsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import React from 'react';
import { action } from '@storybook/addon-actions';
import { boolean, text } from '@storybook/addon-knobs';

import Button from './Button';
import { GithubIcon, DropdownArrowIcon, PlusIcon } from './icons';

export default {
title: 'Common/Button',
component: Button
component: Button,
args: {
children: 'this is the button',
label: 'submit',
disabled: false
}
};

export const AllFeatures = () => (
<Button
disabled={boolean('disabled', false)}
type="submit"
label={text('label', 'submit')}
>
{text('children', 'this is the button')}
export const AllFeatures = (args) => (
<Button disabled={args.disabled} type="submit" label={args.label}>
{args.children}
</Button>
);

Expand Down
2 changes: 1 addition & 1 deletion client/common/ButtonOrLink.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { Link } from 'react-router';
import { Link } from 'react-router-dom';
import PropTypes from 'prop-types';

/**
Expand Down
16 changes: 10 additions & 6 deletions client/common/icons.stories.jsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import React from 'react';
import { select } from '@storybook/addon-knobs';

import * as icons from './icons';

export default {
title: 'Common/Icons',
component: icons
component: icons,
argTypes: {
variant: {
options: Object.keys(icons),
control: { type: 'select' },
default: icons.CircleFolderIcon
}
}
};

export const AllIcons = () => {
const names = Object.keys(icons);

const SelectedIcon = icons[select('name', names, names[0])];
export const Icons = (args) => {
const SelectedIcon = icons[args.variant || 'CircleInfoIcon'];
return <SelectedIcon />;
};
22 changes: 7 additions & 15 deletions client/components/Nav.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
import React from 'react';
import { withTranslation } from 'react-i18next';
import { connect } from 'react-redux';
import { Link, withRouter } from 'react-router';
import { Link } from 'react-router-dom';
import { availableLanguages, languageKeyToLabel } from '../i18n';
import * as IDEActions from '../modules/IDE/actions/ide';
import * as toastActions from '../modules/IDE/actions/toast';
Expand Down Expand Up @@ -37,12 +37,12 @@ class Nav extends React.PureComponent {
}

handleNew() {
const { unsavedChanges, warnIfUnsavedChanges } = this.props;
const { unsavedChanges } = this.props;
if (!unsavedChanges) {
this.props.showToast(1500);
this.props.setToastText('Toast.OpenedNewSketch');
this.props.newProject();
} else if (warnIfUnsavedChanges && warnIfUnsavedChanges()) {
} else if (window.confirm(this.props.t('Nav.WarningUnsavedChanges'))) {
this.props.showToast(1500);
this.props.setToastText('Toast.OpenedNewSketch');
this.props.newProject();
Expand Down Expand Up @@ -73,11 +73,10 @@ class Nav extends React.PureComponent {
}

handleShare() {
const { username } = this.props.params;
this.props.showShareModal(
this.props.project.id,
this.props.project.name,
username
this.props.project.owner.username
);
}

Expand Down Expand Up @@ -351,14 +350,14 @@ Nav.propTypes = {
id: PropTypes.string,
name: PropTypes.string,
owner: PropTypes.shape({
id: PropTypes.string
id: PropTypes.string,
username: PropTypes.string
})
}),
logoutUser: PropTypes.func.isRequired,
showShareModal: PropTypes.func.isRequired,
showErrorModal: PropTypes.func.isRequired,
unsavedChanges: PropTypes.bool.isRequired,
warnIfUnsavedChanges: PropTypes.func,
showKeyboardShortcutModal: PropTypes.func.isRequired,
cmController: PropTypes.shape({
tidyCode: PropTypes.func,
Expand All @@ -374,9 +373,6 @@ Nav.propTypes = {
rootFile: PropTypes.shape({
id: PropTypes.string.isRequired
}).isRequired,
params: PropTypes.shape({
username: PropTypes.string
}),
t: PropTypes.func.isRequired,
setLanguage: PropTypes.func.isRequired,
language: PropTypes.string.isRequired,
Expand All @@ -391,10 +387,6 @@ Nav.defaultProps = {
},
cmController: {},
layout: 'project',
warnIfUnsavedChanges: undefined,
params: {
username: undefined
},
editorLink: '/'
};

Expand All @@ -420,6 +412,6 @@ const mapDispatchToProps = {
};

export default withTranslation()(
withRouter(connect(mapStateToProps, mapDispatchToProps)(Nav))
connect(mapStateToProps, mapDispatchToProps)(Nav)
);
export { Nav as NavComponent };
2 changes: 1 addition & 1 deletion client/components/PreviewNav.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import PropTypes from 'prop-types';
import React from 'react';
import { Link } from 'react-router';
import { Link } from 'react-router-dom';
import { useTranslation } from 'react-i18next';

import LogoIcon from '../images/p5js-logo-small.svg';
Expand Down
13 changes: 10 additions & 3 deletions client/components/__snapshots__/Nav.unit.test.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ exports[`Nav renders correctly 1`] = `
<li
class="nav__dropdown-item"
>
<a />
<a
href="/new-user/sketches"
/>
</li>
</ul>
</li>
Expand Down Expand Up @@ -195,7 +197,9 @@ exports[`Nav renders correctly 1`] = `
<li
class="nav__dropdown-item"
>
<a />
<a
href="/about"
/>
</li>
</ul>
</li>
Expand Down Expand Up @@ -229,6 +233,7 @@ exports[`Nav renders dashboard version 1`] = `
>
<a
class="nav__back-link"
href="/"
>
<test-file-stub
aria-hidden="true"
Expand Down Expand Up @@ -447,7 +452,9 @@ exports[`Nav renders editor version 1`] = `
<li
class="nav__dropdown-item"
>
<a>
<a
href="/about"
>
About
</a>
</li>
Expand Down
2 changes: 1 addition & 1 deletion client/components/createRedirectWithUsername.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { connect } from 'react-redux';
import { browserHistory } from 'react-router';
import browserHistory from '../browserHistory';

const RedirectToUser = ({ username, url = '/:username/sketches' }) => {
React.useEffect(() => {
Expand Down
2 changes: 1 addition & 1 deletion client/components/mobile/Tab.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import styled from 'styled-components';
import { Link } from 'react-router';
import { Link } from 'react-router-dom';
import { prop, remSize } from '../../theme';

export default styled(Link)`
Expand Down
7 changes: 2 additions & 5 deletions client/index.integration.test.jsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import { setupServer } from 'msw/node';
import { rest } from 'msw';
import React from 'react';
import { Router, browserHistory } from 'react-router';
import Routing from './routes';

import { reduxRender, act, waitFor, screen, within } from './test-utils';
import configureStore from './store';
import routes from './routes';
import * as Actions from './modules/User/actions';
import { userResponse } from './testData/testServerResponses';

// setup for the app
const history = browserHistory;
const initialState = window.__INITIAL_STATE__;
const store = configureStore(initialState);

Expand Down Expand Up @@ -56,8 +54,7 @@ document.createRange = () => {
// start testing
describe('index.jsx integration', () => {
// the subject under test
const subject = () =>
reduxRender(<Router history={history} routes={routes(store)} />, { store });
const subject = () => reduxRender(<Routing />, { store });

// spy on this function and wait for it to be called before making assertions
const spy = jest.spyOn(Actions, 'getUser');
Expand Down
10 changes: 6 additions & 4 deletions client/index.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import React, { Suspense } from 'react';
import { render } from 'react-dom';
import { Provider } from 'react-redux';
import { Router, browserHistory } from 'react-router';
import { Router } from 'react-router-dom';

import browserHistory from './browserHistory';
import configureStore from './store';
import routes from './routes';
import Routing from './routes';
import ThemeProvider from './modules/App/components/ThemeProvider';
import Loader from './modules/App/components/loader';
import './i18n';
Expand All @@ -14,15 +15,16 @@ require('./styles/main.scss');
// Load the p5 png logo, so that webpack will use it
require('./images/p5js-square-logo.png');

const history = browserHistory;
const initialState = window.__INITIAL_STATE__;

const store = configureStore(initialState);

const App = () => (
<Provider store={store}>
<ThemeProvider>
<Router history={history} routes={routes(store)} />
<Router history={browserHistory}>
<Routing />
</Router>
</ThemeProvider>
</Provider>
);
Expand Down
Loading

0 comments on commit ce73fa0

Please sign in to comment.