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

(feat):App extras exceptions #5621

Merged
merged 26 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
854153f
Update AppExtras.jsx
dobri1408 Jan 14, 2024
6633a07
Update AppExtras.jsx
dobri1408 Jan 14, 2024
bbf02a2
Create 5621.feature
dobri1408 Jan 14, 2024
160d4ae
update snapshot
dobri1408 Jan 14, 2024
5ebc3e9
fix default value
dobri1408 Jan 14, 2024
c48386d
update tests
dobri1408 Jan 14, 2024
11d16e6
change tests
dobri1408 Jan 15, 2024
1bb5034
Merge branch 'main' into app-extras-exceptions
dobri1408 Jan 26, 2024
3391086
Update packages/volto/src/components/theme/AppExtras/AppExtras.test.jsx
dobri1408 Jan 26, 2024
ec55158
update tests
dobri1408 Jan 26, 2024
af675fd
Merge branch 'main' into app-extras-exceptions
dobri1408 Jan 26, 2024
94dfcff
Merge branch 'main' into app-extras-exceptions
dobri1408 Jan 29, 2024
f149526
update docs for appextras
dobri1408 Jan 29, 2024
6474186
Merge branch 'app-extras-exceptions' of https://github.com/plone/volt…
dobri1408 Jan 29, 2024
48ccb04
Update docs/source/recipes/appextras.md
dobri1408 Jan 29, 2024
6694c4e
Update docs/source/recipes/appextras.md
dobri1408 Jan 29, 2024
8243ef9
Apply suggestions from code review
dobri1408 Jan 29, 2024
988870c
Update docs/source/recipes/appextras.md
dobri1408 Jan 29, 2024
10ab335
Update docs/source/recipes/appextras.md
dobri1408 Jan 29, 2024
5c30c8a
Update docs/source/recipes/appextras.md
dobri1408 Jan 29, 2024
304d363
Update docs/source/recipes/appextras.md
dobri1408 Jan 29, 2024
d2a496a
Update docs/source/recipes/appextras.md
dobri1408 Jan 29, 2024
8e3b79b
Update packages/volto/news/5621.feature
dobri1408 Jan 29, 2024
14111c1
Update appextras.md
dobri1408 Jan 29, 2024
45eb170
Update docs/source/recipes/appextras.md
dobri1408 Jan 29, 2024
896f036
Merge branch 'main' into app-extras-exceptions
dobri1408 Feb 3, 2024
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
35 changes: 27 additions & 8 deletions docs/source/recipes/appextras.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ myst:

# AppExtras component

```{versionchanged} 17.11.6
Added the `ignore` property.
```

```{versionchanged} 16.30.3
Added the `ignore` property.
```

The `AppExtras` component is a general use insertion point for things like
analytics, general purpose code spanning the whole application or third party
services code. AppExtras component inserts will be rendered by the `App`
Expand All @@ -22,15 +30,15 @@ a custom `src/customizations/components/theme/AppExtras/AppExtras.jsx`...
Or you can use the new key of `config.settings`, the `appExtras`. This is
a list of registrations, each registration is an object with:

- `match`: The `match` key is for objects compatible with [react-router's
matchPath](https://v5.reactrouter.com/web/api/matchPath), so it can be either
a simple string or a match object.
- `match`: The `match` key is for objects compatible with [react-router's `matchPath`](https://v5.reactrouter.com/web/api/matchPath). It can be either a string or a [`match`](https://v5.reactrouter.com/web/api/match) object.
- `ignore`: The `ignore` key is for routes compatible with the [react-router's `matchPath`](https://v5.reactrouter.com/web/api/matchPath) property, and ignores all the results in the `ignore` rule.
It can be either a string or a [`match`](https://v5.reactrouter.com/web/api/match) object.
- `component`. Use the `component` to link the component to be used.
- `props`: Extra props to be inject to the actual component used.
- `props`: Extra props to be injected into the actual component used.

For example:

``` jsx
```jsx
import { settings as defaultSettings } from '@plone/volto/config'

export settings = {
Expand All @@ -54,10 +62,21 @@ export settings = {
{
path: '/blog/**/edit',
component: ExtraToolbarButton,
}
},
{
match: {
match: '/frontpage',
ignore: '/frontpage/images',
},
component: FrontPage
},
]
}
```

You can use this to render, for example, `<Portal>` components to be inserted
somewhere in the website.
The above example will apply the rules to their respective routes.

- Insert a Google Analytics tag everywhere.
- Insert the `WordClouds` component to the `/blogs` route.
- Insert the `ExtraToolbarButton` component when editing objects under the path `/blog/**/edit`.
- Insert the `FrontPage` component to the `frontpage` route, except under `/frontpage/images`.
1 change: 1 addition & 0 deletions packages/volto/news/5621.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added the `ignore` property to allow exceptions to rules that are applied to all routes. @dobri1408
2 changes: 2 additions & 0 deletions packages/volto/src/components/theme/AppExtras/AppExtras.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const AppExtras = (props) => {
const { pathname } = props;
const active = appExtras
.map((reg) => {
const ignored = matchPath(pathname, reg.ignore);
if (ignored) return null;
const match = matchPath(pathname, reg.match);
return match ? { reg, match } : null;
})
Expand Down
20 changes: 20 additions & 0 deletions packages/volto/src/components/theme/AppExtras/AppExtras.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ beforeAll(() => {
<div className="something">{JSON.stringify(props.match)}</div>
)),
},
{
match: '/frontpage',
ignore: '/frontpage/images',
component: jest.fn((props) => (
<div className="frontpage-content">{JSON.stringify(props.match)}</div>
)),
},
];
});

Expand Down Expand Up @@ -85,4 +92,17 @@ describe('AppExtras', () => {
const json = component.toJSON();
expect(json).toMatchSnapshot();
});
it('ignore property works', () => {
const componentView = renderer.create(
<AppExtras pathname="/frontpage"></AppExtras>,
);
const componentEdit = renderer.create(
<AppExtras pathname="/frontpage/images"></AppExtras>,
);

const jsonView = componentView.toJSON();
expect(jsonView).toMatchSnapshot();
const jsonEdit = componentEdit.toJSON();
expect(jsonEdit).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,29 @@ Array [
]
`;

exports[`AppExtras ignore property works 1`] = `
Array [
<div
className="everywhere"
>
/frontpage
</div>,
<div
className="frontpage-content"
>
{"path":"/frontpage","url":"/frontpage","isExact":true,"params":{}}
</div>,
]
`;

exports[`AppExtras ignore property works 2`] = `
<div
className="everywhere"
>
/frontpage/images
</div>
`;

exports[`AppExtras renders 2 app extras on specific path /blog/edit 1`] = `
Array [
<div
Expand Down
Loading