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

Effective Volto 2023 #793

Merged
merged 47 commits into from
Oct 1, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
5e4b699
Update getting started
sneridagh Sep 9, 2023
1beaba5
Add dataAdapter pattern
sneridagh Sep 10, 2023
b909010
Blocks layout and blocks styling updates
sneridagh Sep 10, 2023
b12dc17
theme addons
sneridagh Sep 10, 2023
1fde2ac
Update addons testing
sneridagh Sep 10, 2023
315e5fa
Update bypass cors local dev
sneridagh Sep 10, 2023
503eeb3
Fixed dataAdapter pattern
sneridagh Sep 10, 2023
7001254
Asyncconnect chapter
tiberiuichim Sep 11, 2023
fcb5999
Block styling chapter
tiberiuichim Sep 11, 2023
b66b813
BlockDataForm chapter
tiberiuichim Sep 11, 2023
5eafc38
Addon dependencies chapter
tiberiuichim Sep 11, 2023
1443ac6
How an addon works chapter
tiberiuichim Sep 11, 2023
4ebb3f1
i18n chapter
tiberiuichim Sep 11, 2023
3f438cf
Pipeline chapter
tiberiuichim Sep 11, 2023
7b61429
SemanticUI chapter
tiberiuichim Sep 11, 2023
01f9866
Use Released addons chapter
tiberiuichim Sep 11, 2023
daf6a71
View and use-repo-addon chapter
tiberiuichim Sep 12, 2023
ec04603
Webpack chapter
tiberiuichim Sep 12, 2023
e1af3f5
Babel and webpack
tiberiuichim Sep 12, 2023
293f83a
Blocks chapter
tiberiuichim Sep 12, 2023
1e57f64
Bootstrap chapter
tiberiuichim Sep 12, 2023
b7603f5
Configuration chapter
tiberiuichim Sep 18, 2023
8bc77f5
Add some info in CORS
tiberiuichim Sep 18, 2023
8c8ea3c
Multilingual and razzle
tiberiuichim Sep 18, 2023
fe86dfc
Redux chapter
tiberiuichim Sep 18, 2023
fbe0901
More docs
tiberiuichim Sep 18, 2023
35fdd67
More docs on backend
tiberiuichim Sep 19, 2023
caa5505
Info on storybook
tiberiuichim Sep 20, 2023
8ae8d5e
Fixes to jest.md
tiberiuichim Sep 21, 2023
beb7c3b
Merge branch 'main' into effectiveVolto2023
tiberiuichim Sep 27, 2023
c50ffd0
Add text to the seamless mode chapter
tiberiuichim Sep 29, 2023
adb59a9
Shuffle configuration in seamless
tiberiuichim Sep 29, 2023
cda43dc
Tweaks to component-registry and debugging
tiberiuichim Sep 29, 2023
9e6a0ff
Tweak environmentvariables.md
tiberiuichim Sep 29, 2023
004af08
Add details in icons.md
tiberiuichim Sep 29, 2023
5e8115c
Small tweaks to lazyloading
tiberiuichim Sep 29, 2023
f59be22
More tweaks
tiberiuichim Sep 29, 2023
07b73a6
Add info about the @URL value type
tiberiuichim Sep 29, 2023
c2eaf9c
Tweaks to seamlessmode chapter
tiberiuichim Sep 29, 2023
3905037
Tweaks to testing
tiberiuichim Sep 29, 2023
17f8dc8
Tweaks
tiberiuichim Sep 29, 2023
3e964b1
Update intro page
tiberiuichim Sep 29, 2023
990e152
Update intro page
tiberiuichim Sep 29, 2023
463ecec
Update intro page
tiberiuichim Sep 29, 2023
bc2da38
Some minor typos and fixes
sneridagh Sep 30, 2023
097f6f5
last amendments
sneridagh Oct 1, 2023
99e4a21
Merge branch 'main' into effectiveVolto2023
sneridagh Oct 1, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/effective-volto/about_effective_volto.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Tiberiu Ichim

Víctor Fernández de Alba

: Víctor is CTO at kitconcept GmbH, a Plone solution provider from Bonn, Germany. Member of the Plone Community since 2006, author of a Plone book, co-author of Plone 5’s multilingual feature and its default theme Barceloneta. He is the Plone 6 Volto Release Manager, member of the Volto Team and Plone REST API contributor. He was also organizer of the Barcelona Plone Conference in 2017, sprints and other Plone events in Barcelona and Bonn and he is deeply involved in several Plone Community Teams including the Plone Foundation Board of directors.
: Víctor is CTO at kitconcept GmbH, a Plone solution provider from Bonn, Germany. Member of the Plone Community since 2006, currently he's the Release Manager of Plone Volto and Volto Team leader.Author of a Plone book, co-author of Plone 5’s multilingual feature and its default theme Barceloneta. He is the Plone 6 Volto Release Manager, member of the Volto Team and Plone REST API contributor. He was also organizer of the Barcelona Plone Conference in 2017, sprints and other Plone events in Barcelona and Bonn and he is deeply involved in several Plone Community Teams.

## License

Expand Down
63 changes: 61 additions & 2 deletions docs/effective-volto/addons/blockdataform.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ The BlockDataForm renders an form fully integrated with a block's extension
mechanisms: variations and block styles. To use it, instantiate the schema and
pass it down to the component. A full Volto block edit component could be like:

```
```jsx
export const MyBlockSchema = ({data, intl}) => {
return {
title: "My block",
Expand Down Expand Up @@ -62,6 +62,9 @@ export const MyBlockEdit = (props) => {
});
}}
formData={data}
onChangeBlock={onChangeBlock}
block={block}
blocksConfig={blocksConfig}
/>
</SidebarPortal>
</>
Expand All @@ -76,7 +79,7 @@ If there's any registered variations for this block, they will be displayed as
a Select control for the active variation, in the sidebar.


```
```js
myblock: {
id: 'myblock',
title: 'My Block',
Expand Down Expand Up @@ -112,3 +115,59 @@ a Select control for the active variation, in the sidebar.
Note: you can assign the schema to `blockSchema` in the block configuration. It
is used only to extract the block default values. This integration will be
improved, in the future.

## Using a dataAdapter pattern

Sometimes is useful to adapt the incoming data to other data format, structure or type.
You can use the dataAdapter pattern in `BlockDataForm` as this:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pattern will cause confusion.

Why is the BlockDataForm looking for a dataAdapter for a certain block? (it's not explained that the BlockDataForm is used internally by the teaser block).

It's not explained how to register the data adapter (although this would be obvious, in theory). The data adapter function uses CamelCase naming, usually reserved for components.

I think it's dangerous to have the data adapter directly call onChangeBlock. I think it's better if the purity of the data operations is kept. No side-effects. If the data adapter is called too late in the data "fixing" chain, then we need to figure out a solution to call it sooner, at the top of the chain, at the level of the "big form".

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tiberiuichim I completed the docs to make them more consistent and understandable.

Regarding the purity... we are already calling it virtually everywhere, since the default pattern is:

          onChangeField={(id, value) => {
            onChangeBlock(block, {
              ...data,
              [id]: value,
            });
          }}

in all places. So calling it inside the dataAdapter is "legit", right? Granted, it could be handled better, but as a general improvement of the BlockDataForm.


```jsx
const schema = blocksConfig[data['@type']].blockSchema({ intl });
const dataAdapter = blocksConfig[data['@type']].dataAdapter;

<BlockDataForm
schema={schema}
title={schema.title}
onChangeField={(id, value) => {
dataAdapter({
block,
data,
id,
onChangeBlock,
value,
});
}}
onChangeBlock={onChangeBlock}
formData={data}
block={block}
blocksConfig={blocksConfig}
/>
```

and define `dataAdapter` as this:

```js
import { isEmpty } from 'lodash';

export const TeaserBlockDataAdapter = ({
block,
data,
id,
onChangeBlock,
value,
}) => {
let dataSaved = {
...data,
[id]: value,
};
if (id === 'href' && !isEmpty(value) && !data.title && !data.description) {
dataSaved = {
...dataSaved,
title: value[0].Title,
description: value[0].Description,
head_title: value[0].head_title,
};
}
onChangeBlock(block, dataSaved);
};
```
145 changes: 98 additions & 47 deletions docs/effective-volto/getting-started/add-on.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ they point the `main` key of their `package.json` to a module that exports, as
a default function that acts as a Volto configuration loader.

Although you could simply use `npm init` to generate an addon initial code,
we now have a nice
we have a
[Yeoman-based generator](https://github.com/plone/generator-volto) that you can use:

```shell
Expand All @@ -32,90 +32,141 @@ use the final ones from the very beginning. This means that you can use imports
such as `import { Something } from '@plone/my-volto-addon'` without any extra
configuration.

## Developing in isolation with a vanilla Volto project
## Developing in isolation using a full dockerized project approach

You can develop an add-on in isolation using the `@plone/scripts` `addon` command line.
This script creates and configures a vanilla project using the Volto generator.
You can develop an add-on in isolation using the boilerplate already provided by the add-on generator.
The project is configured to have the current add-on installed and ready to work with.
This script is useful to bootstrap an isolated environment that can be used to quickly develop the add-on or for demo purposes.
This is useful to bootstrap an isolated environment that can be used to quickly develop the add-on or for demo purposes.
It's also useful when testing an add-on in a CI environment.

```{note}
It's quite similar when you develop a Plone backend add-on in the Python side, and embed a ready to use Plone build (using buildout or pip) in order to develop and test the package.
```

Unfortunately, the NodeJS tooling does not work well with symlinks or outside the root of the project.
This script proceeds in the following way:
The dockerized approach performs all these actions in a custom built docker environment:

1. Generates a vanilla project using the official Volto Yo Generator (@plone/generator-volto)
2. Configures it to use the add-on with the name stated in the `package.json`
3. Copies over the root of the add-on (`src` and essential files) inside the created project
3. Links the root of the add-on inside the created project

After this, you can change directory to the created project, by default `addon-testing-project`.
The name of the created project is parameterizable.
After that you can use the inner dockerized project, and run any standard Volto command for linting, acceptance test or unit tests using Makefile commands provided for your convenience.

After that you can use the full fledged project, and run any standard Volto command for linting, acceptance test or unit tests.
### Setup the environment

### clone (git)
Run once

Given the add-on remote git repository, it pulls and configures it into the vanilla project generated by the script.
```shell
make dev
```

which will build and launch the backend and frontend containers.
There's no need to build them again after doing it the first time unless something has changed from the container setup.

In order to make the local IDE play well with this setup, is it required to run once `yarn` to install locally the required packages (ESlint, Prettier, Stylelint).

Run

```shell
yarn
```

### Build the containers manually

Run

```shell
make build-backend
make build-addon
```

### Run the containers

Run

```shell
make start-dev
```

This will start both the frontend and backend containers.

### Stop Backend (Docker)

After developing, in order to stop the running backend, don't forget to run:

Run

`npx -p @plone/scripts addon clone [options] <source> [destination]`
```shell
make stop-backend
```

### Linting

Run

```shell
make lint
```

### Formatting

Run

```shell
make format
```

```console
Usage: addon clone [options] <source> [destination]
### i18n

clone a repository into a newly created directory
Run

Options:
-p, --private set if the repo is private, then GITHUB_TOKEN is used
-b, --branch <branch> set the repo branch, defaults to main
-c, --canary downloads latest Volto canary (alpha) version
-h, --help display help for command
```shell
make i18n
```

This next command downloads the `volto-blocks-grid` add-on from its git repository's `main` branch, and will generate a project with the latest Volto canary (alpha) version.
### Unit tests

Run

```shell
npx -p @plone/scripts addon clone https://github.com/kitconcept/volto-blocks-grid.git --branch main --canary
make test
```

This will create a directory named `addon-testing-project`, and will bootstrap a new project using Volto's standard project generator.
It will adjust the configuration of this project to setup the add-on in the project using `mrs-developer`, and the git URL given to fetch the add-on contents.
You can specify the branch to be used, if the project should use the latest alpha available.
For private repositories, it uses the `GITHUB_TOKEN` present in your environment variables to fetch it.
### Acceptance tests

After this, as a developer you can use the usual project commands to run tests (unit, linting, acceptance) inside the generated `addon-testing-project`.
You can configure the CI of your choice for automated testing, you can take a look at how it's done in: https://github.com/kitconcept/volto-blocks-grid/tree/main/.github/workflows
Run once

The idea is to issue commands inside the generated `addon-testing-project` project and do your checks.
Take special care on how to pass down to the `npx` command the current pull request branch.
Depending on your CI system, this might be different.
```shell
make install-acceptance
```

### clone local
For starting the servers

You can also clone the local add-on using:
Run

```shell
npx -p @plone/scripts addon clone .
make start-test-acceptance-server
```

This only works if you execute the command from the root of your add-on directory.
The frontend is run in dev mode, so development while writing tests is possible.

### consolidate
Run

While developing, you might have done changes inside the generated project, and you most probably want to consolidate them, back into the root of the repository.
By running this script, it copies over from `addon-testing-project/src/addons/<my-addon>` to the root of your repository.
```shell
make test-acceptance
```

It should be run at the root of the add-on, and it gets an optional `source` argument in case you have specified a directory other than `addon-testing-project`.
To run Cypress tests afterwards.

`npx -p @plone/scripts addon consolidate --help`
When finished, don't forget to shutdown the backend server.

```console
Usage: addon consolidate [options] [source]
```shell
make stop-test-acceptance-server
```

Consolidate a cloned project
### Release

Options:
-h, --help display help for command
Run

```shell
make release
```
10 changes: 2 additions & 8 deletions docs/effective-volto/getting-started/project.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ myst:

# Bootstrapping a full Plone 6 project

We can use the new [cookiecutter-plone-starter](https://github.com/collective/cookiecutter-plone-starter) repository.
We will use the official [cookiecutter-plone-starter](https://github.com/collective/cookiecutter-plone-starter) repository.

```{note}
The introduction of more tools are in store in order to ease the creation of the boilerplate for a full Plone 6 project, but they might revolve around this cookiecutter template.
Expand All @@ -35,12 +35,10 @@ After that, install Yeoman according to the [Plone documentation](https://6.docs

Finally, install `yarn` according to the [Plone documentation](https://6.docs.plone.org/volto/getting-started/install.html#yarn-nodejs-package-manager).


### Docker (optional)
### Docker (optional, but recommended)

Install `Docker` according to the [official documentation](https://docs.docker.com/get-docker/).


Generate a new Plone 6 Project:

```shell
Expand Down Expand Up @@ -79,18 +77,14 @@ make build

and restart backend and frontend by stopping and re-running


```shell
make start-backend
```


```shell
make start-frontend
```



## Project Generation Options

These are all the template options that will be prompted by the [Cookiecutter CLI](https://github.com/cookiecutter/cookiecutter) prior to generating your project.
Expand Down