Skip to content
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

WIP Feature/smart form #31

Merged
merged 79 commits into from
Jun 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
bee3bb0
copied code from Vulcan for the components
eric-burel Apr 7, 2021
e239bb0
started to write stories for Form
eric-burel Apr 7, 2021
17b4c31
add i18n
eric-burel Apr 7, 2021
2cb6cc1
regenerated yarn.lock and updated to fix https://github.com/yarnpkg/y…
eric-burel Apr 7, 2021
13acbea
export callbacks to be reusable
eric-burel Apr 7, 2021
861f41e
fixed build issues after adding lodash typings
eric-burel Apr 7, 2021
5a5c74b
first version of the Form with no TS error
eric-burel Apr 7, 2021
b50fd8c
ported multiple FormComponent to TS
eric-burel Apr 16, 2021
4ee999b
moved all components to TSX except FormWrapper
eric-burel Apr 16, 2021
1ad2bbf
fix build after moving permissions
eric-burel Apr 16, 2021
788a8e3
moved FormWrapper to tsx
eric-burel Apr 21, 2021
d5a0801
fix storybook build, convert schema_utils to ts
eric-burel Apr 21, 2021
dc0aee3
update storybook version
eric-burel Apr 21, 2021
dc5c43e
create unified VulcanComponentsContext
eric-burel Apr 23, 2021
172ddbb
use default values for Form components, pass intl context
eric-burel Apr 23, 2021
f463b19
Merge branch 'devel' into feature/smart-form
eric-burel Apr 28, 2021
20bfe3d
create default form components
eric-burel Apr 28, 2021
e2131b3
setup storybook chrome debugging, can display the form shell
eric-burel Apr 28, 2021
02b3444
ok
eric-burel Apr 28, 2021
10c12fd
make FormGroup a functionnal component
eric-burel Apr 28, 2021
eabee3a
can render FormGroup
eric-burel Apr 28, 2021
7980d8f
can render 4 inputs
eric-burel Apr 28, 2021
f0eff26
create story for basic form
eric-burel Apr 30, 2021
f50afb9
copied bootstrap components to reuse them
eric-burel Apr 30, 2021
02ef3a8
moved FormComponent to a functionnal component
eric-burel Apr 30, 2021
8d03588
get the right components
eric-burel Apr 30, 2021
71149b5
remove tmp bootstrap components
eric-burel May 11, 2021
0639a30
use new context API for intl provider and move formComponetInner to s…
eric-burel May 11, 2021
6769e25
loaded context with new API in Form
eric-burel May 11, 2021
1d89708
fix typings of vulcan/schema that were not correctly exported
eric-burel May 11, 2021
f293776
update all components to use context provided by the top Form component
eric-burel May 11, 2021
32e3264
fix errors filtering
eric-burel May 11, 2021
b6a7dbd
extract getFields away from the stateful form
eric-burel May 19, 2021
f83c827
remove getFormType function
eric-burel May 19, 2021
dcce559
moved form props in their own function, using context
eric-burel May 19, 2021
f8dc288
remove isChanged method
eric-burel May 19, 2021
c12fb4d
split form into multiple files
eric-burel May 19, 2021
a73f3c5
move field creation into a separate file
eric-burel May 19, 2021
7b6b055
remove get document
eric-burel May 19, 2021
be3d571
start to extract the form leaving logic
eric-burel May 19, 2021
59ffa1c
set better API for form leaving, independant from router implementation
eric-burel May 21, 2021
bb2c0e5
fix basic inputs, added typings
eric-burel May 21, 2021
59282f6
move warnUnsaved
eric-burel May 21, 2021
4998793
can block/unblock on state transition
eric-burel May 21, 2021
b6fd83c
fix useWarnOnUnsaved
eric-burel May 21, 2021
c51386a
prevent jest projects duplication
eric-burel May 25, 2021
ee9078c
move unblocktransition to its own hook
eric-burel May 25, 2021
85e415e
unit tested useBlockTransition
eric-burel May 25, 2021
0b03d1c
move Form to stateless function
eric-burel May 28, 2021
a8cba33
react-components => react-ui
eric-burel May 28, 2021
701efa4
use storybook template syntax
eric-burel Jun 1, 2021
546c68d
setup form test, building but not yet passing
eric-burel Jun 1, 2021
e5e90c6
skipped tests so Jest works ok
eric-burel Jun 1, 2021
2dd2444
start to reenable array in form
eric-burel Jun 1, 2021
4c88eea
improve the readme for the first install
eric-burel Jun 4, 2021
9b19be9
Merge remote-tracking branch 'upstream/feature/smart-form' into featu…
Timi-Duban Jun 4, 2021
49be0d4
setup stories for the smartForm
eric-burel Jun 4, 2021
6037e52
circular dependency in form...
eric-burel Jun 4, 2021
1416088
fix typing issue
eric-burel Jun 4, 2021
aabc8f8
split context to avoid circular deps
eric-burel Jun 4, 2021
20576a2
update fragment test, fix types
eric-burel Jun 4, 2021
bbe7741
Merge remote-tracking branch 'upstream/feature/smart-form' into featu…
Timi-Duban Jun 7, 2021
ff4626b
fix storybook testing react config (#31)
Timi-Duban Jun 7, 2021
f3124f8
fix typescript issues
Timi-Duban Jun 7, 2021
df7a75f
fix react import issue
Timi-Duban Jun 7, 2021
8a7afdd
improve setup and typings to test apollo queries from the form
eric-burel Jun 7, 2021
341d1cd
rollbacked mandatory default fragment, stays optional
eric-burel Jun 7, 2021
4698e86
Merge branch 'feature/smart-form' of https://github.com/Timi-Duban/vu…
eric-burel Jun 7, 2021
8a12874
formatting
eric-burel Jun 8, 2021
060f256
reenable formatted message
eric-burel Jun 8, 2021
44e3ed9
improve typings for the form creatipn callback
eric-burel Jun 8, 2021
cd2bea1
move graphql outside of the form for creation cb
eric-burel Jun 8, 2021
60198f8
add mock for create
eric-burel Jun 8, 2021
68bbabe
multiQueryUpdater throwing clearer error when shape of returned data …
eric-burel Jun 8, 2021
d0e2107
correctly stop event propagation in Form
eric-burel Jun 8, 2021
90d2006
fix fragments generated by the form
eric-burel Jun 8, 2021
dc082bd
can create data
eric-burel Jun 8, 2021
bb3a583
Merge branch 'devel' into feature/smart-form
eric-burel Jun 8, 2021
12b8159
update docs, cleanup
eric-burel Jun 8, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -27,3 +27,6 @@ coverage/
coverage-unit/
dist
package-lock.json

#vscode extension
.vscode/snipsnap.code-snippets
11 changes: 11 additions & 0 deletions .storybook/main.js
@@ -0,0 +1,11 @@
module.exports = {
stories: [
"../stories/**/*.stories.mdx",
"../stories/**/*.stories.@(js|jsx|ts|tsx)",
// specifying packages folder is important to avoid rebuilding on cache change
// @see https://github.com/storybookjs/storybook/issues/14342
"../packages/**/*.stories.mdx",
"../packages/**/*.stories.@(js|jsx|ts|tsx)",
],
addons: ["@storybook/addon-links", "@storybook/addon-essentials"],
};
26 changes: 26 additions & 0 deletions .storybook/preview.jsx
@@ -0,0 +1,26 @@
import React from "react";
import { IntlProvider } from "../packages/i18n";

export const parameters = {
actions: { argTypesRegex: "^on[A-Z].*" },
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/,
},
},
};

export const decorators = [
(Story) => (
<IntlProvider locale="fr">
<Story />
</IntlProvider>
),
];

// Those events are triggered by the form when you activate
// warn on unsaved changes
// The end-user app should listen to those events to set route blocking
window.addEventListener("blocktransition", console.log);
window.addEventListener("unblocktransition", console.log);
15 changes: 15 additions & 0 deletions .vscode/launch.json
Expand Up @@ -2,6 +2,21 @@
"version": "0.2.0",
"nodeVersionHint": 10,
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "Storybook Debug",
"breakOnLoad": true,
"url": "http://localhost:6006",
"sourceMaps": true,
"webRoot": "${workspaceFolder}",
"sourceMapPathOverrides": {
"webpack:///*": "${webRoot}/*",
"webpack:///./*": "${webRoot}/*",
"webpack:///src/*": "${webRoot}/*",
"webpack:///./~/*": "${webRoot}/node_modules/*"
}
},
{
"type": "node",
"request": "launch",
Expand Down
49 changes: 49 additions & 0 deletions .vscode/ui-snippets.code-snippets
@@ -0,0 +1,49 @@
{
// Place your vulcan-npm workspace snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and
// description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope
// is left empty or omitted, the snippet gets applied to all languages. The prefix is what is
// used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders.
// Placeholders with the same ids are connected.
// Example:
// 'Print to console': {
// 'scope': 'javascript,typescript',
// 'prefix': 'log',
// 'body': [
// 'console.log("$1");',
// '$2'
// ],
// 'description': 'Log output to console'
// }
"Storybook story": {
"scope": "typescriptreact",
"prefix": "story",
"body": [
"import React from 'react'",
"import { Story, Meta } from '@storybook/react'",
"import { $1, $1Props } from '../$1'",
"export default {",
" component: $1,",
" title: '$1',",
" decorators: [",
" (Story) => (",
" <div>",
" <Story />",
" </div>",
" ),",
" ],",
" args: {",
" },",
" parameters: { actions: { argTypesRegex: '^.*Callback$' } },",
"} as Meta<$1Props>;",
"",
"const $1Template: Story<$1Props> = (args) => <$1 {...args} />",
"export const Default$1 = $1Template.bind({});",
],
"description": "New storybook story",
}




}
43 changes: 36 additions & 7 deletions README.md
@@ -1,21 +1,50 @@
# Vulcan NPM

## Contribute

For faster development, you may instead want to contribute to [Vulcan Next Starter](https://github.com/VulcanJS/vulcan-next-starter/issues/1). NPM packages will be published in this repo when they reach sufficient maturity.

### Install
After you've read the README, also check `./docs/contribute.md` for more information about contributions.

Install Lerna
## Install Vulcan NPM and start coding

Please use [Yarn](https://yarnpkg.com/)

```sh
yarn # will install + bootstrap learn
yarn run build # build all packages
```
npm i -g lerna
```

### Develop
Now you can either run Storybook `yarn run storybook` or unit tests `yarn run test` and start working.

## Plug to another local application

If you want to connect your local Vulcan NPM install to an existing application, please check [Vulcan Next documentation](https://github.com/VulcanJS/vulcan-next/blob/devel/src/content/docs/contributing.md).

It's a 2 step process:

- you publish the packages locally using Yalc `yarn run local-publish`
- you install them, using Yalc, in your app.

We use Yalc and not `yarn link` because linking is not sufficient, it raises a lot of issues with locally installed packages.

Now `@vulcanjs/xxx` will be available in your own application.

## Tips

### Dependency from a local package to another local package

Install packages using `lerna bootstrap`.

To use Vulcan NPM local install in Vulcan Next, see Vulcan Next contribution doc.
To add a dependency between 2 local Vulcan packages:

```sh
yarn lerna add @vulcanjs/<your-dependency> --scope=@vulcanjs/<the-parent-package>
```

You need this command because the package won't exist yet on NPMJS, so you need Lerna to manage the dependency.
You can run it from anywhere, and the `--scope` part is mandatory (otherwise the package get added everywhere).

## Resources

- [Babel monorepo](https://github.com/babel/babel), a great example of Lerna project
- [Babel monorepo](https://github.com/babel/babel), a great example of Lerna project
58 changes: 7 additions & 51 deletions docs/contribute.md
@@ -1,31 +1,10 @@
## Lerna

### Install

```sh
# Will install all NPM packages
# It uses yarn workspaces to avoid redundancy
lerna bootstrap
```

#### Use in another local package

In `vulcan-npm`, link all your packages:
# Contributing

```sh
# This is automatically done after an install
yarn link
```
## Read the Readme

In your app, link packages:
Start by reading the Readme for basic install information.

```sh
# USE YARN, it won't work with npm
yarn link @vulcanjs/model
yarn link @vulcanjs/schema
...
# NOTE: we don't yet have a way to link everything
```
## Lerna

### Yarn workspaces

Expand Down Expand Up @@ -65,6 +44,8 @@ If you write a test for package "React Hooks", and discover and fix a bug in pac
Define Peer Dependencies correctly. Many packages have side effects that are problematic if you duplicate them. Those packages should be
peer-dependencies in the relevant `package.json`. You may add them at the root of the project too in development.

Also, use Yalc to install local version of Vulcan NPM within another local app, see the README for more information.

##### Example with Mongoose

###### Make it a peer dependency
Expand All @@ -84,29 +65,4 @@ In `./package.json`:
devDependencies: {
"mongoose": "^5.10.16"
}
```

###### Setup for local install

This install `mongoose` as a global dev dependency so we can write unit tests for instance.

And now enable local development:
In `scripts/link-duplicates`:

```
cd ./node_modules/@apollo/client && yarn link && cd ../..
```

When you link the packages for local development, the `mongoose` from `vulcan-npm` will be used. This prevents potential conflicts.

In your app:

```
yarn link mongoose
```

It forces your app to use the `mongoose` install from `vulcan-npm`.

This guarantees that you use one and only one version of Mongoose.

Note: we'd like to simplify this process in the future, maybe by detecting peer dependencies automatically.
```
4 changes: 2 additions & 2 deletions jest.config.js
Expand Up @@ -113,7 +113,7 @@ module.exports = {
// preset: undefined,

// Run tests from one or more projects
projects: ["<rootDir>/packages/*"],
// projects: ["<rootDir>/packages/*"],

// Use this configuration option to add custom reporters to Jest
// reporters: undefined,
Expand Down Expand Up @@ -143,7 +143,7 @@ module.exports = {
// runner: "jest-runner",

// The paths to modules that run some code to configure or set up the testing environment before each test
// setupFiles: [],
setupFiles: ["./jest/setup.js"],

// A list of paths to modules that run some code to configure or set up the testing framework before each test
// setupFilesAfterEnv: [],
Expand Down
6 changes: 6 additions & 0 deletions jest/setup.js
@@ -0,0 +1,6 @@
// setupFile.js <-- this will run before the tests in jest.
// STORYBOOK global decorators
import { setGlobalConfig } from "@storybook/testing-react";
import * as globalStorybookConfig from "../.storybook/preview"; // path of your preview.js file

setGlobalConfig(globalStorybookConfig);
30 changes: 25 additions & 5 deletions package.json
Expand Up @@ -9,15 +9,25 @@
"unlink-yarn-legacy": "lerna exec yarn unlink",
"clean": "rm -Rf ./node_modules ./packages/*/dist ./packages/*/node_modules",
"test": "jest",
"coverage": "jest --coverage"
"coverage": "jest --coverage",
"storybook": "start-storybook -p 6006",
"build-storybook": "build-storybook"
},
"devDependencies": {
"@apollo/client": "3.2.5",
"@apollo/client": "^3.3.19",
"@babel/core": "^7.11.6",
"@babel/plugin-transform-runtime": "^7.11.5",
"@babel/preset-env": "^7.11.5",
"@babel/preset-react": "^7.10.4",
"@babel/preset-typescript": "^7.10.4",
"@mdx-js/react": "^1.6.22",
"@storybook/addon-actions": "^6.2.9",
"@storybook/addon-docs": "^6.2.9",
"@storybook/addon-essentials": "^6.2.9",
"@storybook/addon-links": "^6.2.9",
"@storybook/react": "^6.2.9",
"@storybook/testing-react": "^0.0.17",
"@testing-library/react": "^11.2.7",
"@types/jest": "^26.0.14",
"@types/node": "^13.7.6",
"@types/react": "^16.9.23",
Expand All @@ -28,6 +38,7 @@
"jest": "^26.4.2",
"lerna": "^3.22.1",
"mongoose": "^5.10.16",
"operation-name-mock-link": "^0.0.6",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"typescript": "^3.8.2",
Expand All @@ -40,7 +51,16 @@
"publishConfig": {
"access": "public"
},
"workspaces": [
"packages/*"
]
"workspaces": {
"packages": [
"packages/*"
],
"nohoist": [
"@storybook",
"@storybook/addon-docs",
"**/@storybook",
"**/@storybook/**"
]
},
"dependencies": {}
}
File renamed without changes.