generated from eea/volto-addon-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #267 from eea/develop
Release
- Loading branch information
Showing
27 changed files
with
1,264 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/components/manage/Blocks/ContextNavigation/ContextNavigationEdit.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import React from 'react'; | ||
import { EditSchema } from './schema'; | ||
import { SidebarPortal } from '@plone/volto/components'; | ||
import BlockDataForm from '@plone/volto/components/manage/Form/BlockDataForm'; | ||
|
||
import ContextNavigationView from './ContextNavigationView'; | ||
|
||
const ContextNavigationFillEdit = (props) => { | ||
const contentTypes = props.properties?.['@components']?.types; | ||
const availableTypes = React.useMemo( | ||
() => contentTypes?.map((type) => [type.id, type.title || type.name]), | ||
[contentTypes], | ||
); | ||
|
||
const schema = React.useMemo( | ||
() => EditSchema({ availableTypes }), | ||
[availableTypes], | ||
); | ||
|
||
return ( | ||
<> | ||
<h3>Context navigation</h3> | ||
<ContextNavigationView {...props} mode="edit" />{' '} | ||
<SidebarPortal selected={props.selected}> | ||
<BlockDataForm | ||
schema={schema} | ||
title={schema.title} | ||
onChangeField={(id, value) => { | ||
props.onChangeBlock(props.block, { | ||
...props.data, | ||
[id]: value, | ||
}); | ||
}} | ||
onChangeBlock={props.onChangeBlock} | ||
formData={props.data} | ||
block={props.block} | ||
navRoot={props.navRoot} | ||
contentType={props.contentType} | ||
/> | ||
</SidebarPortal> | ||
</> | ||
); | ||
}; | ||
|
||
export default ContextNavigationFillEdit; |
88 changes: 88 additions & 0 deletions
88
src/components/manage/Blocks/ContextNavigation/ContextNavigationEdit.test.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import React from 'react'; | ||
import { render, fireEvent } from '@testing-library/react'; | ||
import ContextNavigationEdit from './ContextNavigationEdit'; | ||
import { Router } from 'react-router-dom'; | ||
import { Provider } from 'react-intl-redux'; | ||
import configureStore from 'redux-mock-store'; | ||
import { createMemoryHistory } from 'history'; | ||
import '@testing-library/jest-dom/extend-expect'; | ||
|
||
jest.mock('@plone/volto/components', () => ({ | ||
InlineForm: ({ onChangeField }) => ( | ||
<div> | ||
<p>InlineForm</p> | ||
<input id="test" onChange={onChangeField} /> | ||
</div> | ||
), | ||
SidebarPortal: ({ children, selected }) => | ||
selected ? ( | ||
<div> | ||
<div>SidebarPortal</div> | ||
{children} | ||
</div> | ||
) : null, | ||
})); | ||
|
||
jest.mock('@plone/volto/components/theme/Navigation/ContextNavigation', () => { | ||
return { | ||
__esModule: true, | ||
default: ({ params }) => { | ||
return <div>ConnectedContextNavigation {params.root_path}</div>; | ||
}, | ||
}; | ||
}); | ||
|
||
jest.mock('@plone/volto/helpers', () => ({ | ||
withBlockExtensions: jest.fn((Component) => Component), | ||
emptyBlocksForm: jest.fn(), | ||
getBlocksLayoutFieldname: () => 'blocks_layout', | ||
withVariationSchemaEnhancer: jest.fn((Component) => Component), | ||
})); | ||
|
||
const mockStore = configureStore(); | ||
const store = mockStore({ | ||
intl: { | ||
locale: 'en', | ||
messages: {}, | ||
}, | ||
}); | ||
|
||
describe('ContextNavigationEdit', () => { | ||
it('renders corectly', () => { | ||
const history = createMemoryHistory(); | ||
const { getByText, queryByText } = render( | ||
<Provider store={store}> | ||
<Router history={history}> | ||
<ContextNavigationEdit selected={false} /> | ||
</Router> | ||
, | ||
</Provider>, | ||
); | ||
|
||
expect(getByText('Context navigation')).toBeInTheDocument(); | ||
expect(getByText('ConnectedContextNavigation')).toBeInTheDocument(); | ||
expect(queryByText('InlineForm')).toBeNull(); | ||
expect(queryByText('SidebarPortal')).toBeNull(); | ||
}); | ||
|
||
it('renders corectly', () => { | ||
const history = createMemoryHistory(); | ||
const { container, getByText } = render( | ||
<Provider store={store}> | ||
<Router history={history}> | ||
<ContextNavigationEdit selected={true} onChangeBlock={() => {}} /> | ||
</Router> | ||
, | ||
</Provider>, | ||
); | ||
|
||
expect(getByText('Context navigation')).toBeInTheDocument(); | ||
expect(getByText('ConnectedContextNavigation')).toBeInTheDocument(); | ||
expect(getByText('InlineForm')).toBeInTheDocument(); | ||
expect(getByText('SidebarPortal')).toBeInTheDocument(); | ||
|
||
fireEvent.change(container.querySelector('#test'), { | ||
target: { value: 'test' }, | ||
}); | ||
}); | ||
}); |
14 changes: 14 additions & 0 deletions
14
src/components/manage/Blocks/ContextNavigation/ContextNavigationView.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import React from 'react'; | ||
import { flattenToAppURL, withBlockExtensions } from '@plone/volto/helpers'; | ||
import DefaultTemplate from './variations/Default'; | ||
|
||
const ContextNavigationView = (props = {}) => { | ||
const { variation, data = {} } = props; | ||
const navProps = { ...data }; | ||
const root_path = data?.root_node?.[0]?.['@id']; | ||
if (root_path) navProps['root_path'] = flattenToAppURL(root_path); | ||
const Renderer = variation?.view ?? DefaultTemplate; | ||
return <Renderer params={navProps} mode={props.mode} />; | ||
}; | ||
|
||
export default withBlockExtensions(ContextNavigationView); |
71 changes: 71 additions & 0 deletions
71
src/components/manage/Blocks/ContextNavigation/ContextNavigationView.test.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import ContextNavigationView from './ContextNavigationView'; | ||
import { Router } from 'react-router-dom'; | ||
import { Provider } from 'react-intl-redux'; | ||
import configureStore from 'redux-mock-store'; | ||
import { createMemoryHistory } from 'history'; | ||
import '@testing-library/jest-dom/extend-expect'; | ||
|
||
jest.mock('@plone/volto/components/theme/Navigation/ContextNavigation', () => { | ||
return { | ||
__esModule: true, | ||
default: ({ params }) => { | ||
return <div>ConnectedContextNavigation {params.root_path}</div>; | ||
}, | ||
}; | ||
}); | ||
|
||
jest.mock('@plone/volto/helpers', () => ({ | ||
withBlockExtensions: jest.fn((Component) => Component), | ||
emptyBlocksForm: jest.fn(), | ||
getBlocksLayoutFieldname: () => 'blocks_layout', | ||
flattenToAppURL: () => '', | ||
})); | ||
|
||
const mockStore = configureStore(); | ||
const store = mockStore({ | ||
intl: { | ||
locale: 'en', | ||
messages: {}, | ||
}, | ||
}); | ||
|
||
describe('ContextNavigationView', () => { | ||
let history; | ||
beforeEach(() => { | ||
history = createMemoryHistory(); | ||
}); | ||
|
||
it('renders corectly', () => { | ||
const { container } = render( | ||
<Provider store={store}> | ||
<Router history={history}> | ||
<ContextNavigationView /> | ||
</Router> | ||
</Provider>, | ||
); | ||
|
||
expect(container.firstChild).toHaveTextContent( | ||
'ConnectedContextNavigation', | ||
); | ||
}); | ||
|
||
it('renders corectly', () => { | ||
const { container } = render( | ||
<Provider store={store}> | ||
<Router history={history}> | ||
<ContextNavigationView | ||
data={{ | ||
navProps: { root_path: 'https://localhost:3000/test' }, | ||
root_node: [{ '@id': 'root_node' }], | ||
}} | ||
/> | ||
</Router> | ||
</Provider>, | ||
); | ||
expect(container.firstChild).toHaveTextContent( | ||
'ConnectedContextNavigation', | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import codeSVG from '@plone/volto/icons/code.svg'; | ||
import ContextNavigationEdit from './ContextNavigationEdit'; | ||
import ContextNavigationView from './ContextNavigationView'; | ||
import BlockSettingsSchema from '@plone/volto/components/manage/Blocks/Block/Schema'; | ||
import variations from './variations'; | ||
|
||
const applyConfig = (config) => { | ||
config.blocks.blocksConfig.contextNavigation = { | ||
id: 'contextNavigation', | ||
title: 'Navigation', | ||
icon: codeSVG, | ||
group: 'common', | ||
view: ContextNavigationView, | ||
edit: ContextNavigationEdit, | ||
schema: BlockSettingsSchema, | ||
restricted: false, | ||
variations, | ||
mostUsed: false, | ||
blockHasOwnFocusManagement: true, | ||
sidebarTab: 1, | ||
security: { | ||
addPermission: [], | ||
view: [], | ||
}, | ||
}; | ||
|
||
return config; | ||
}; | ||
|
||
export default applyConfig; |
Oops, something went wrong.