Skip to content

Commit

Permalink
Removed volto-addons
Browse files Browse the repository at this point in the history
  • Loading branch information
razvanMiu committed Oct 14, 2021
1 parent fbae9e6 commit a92a389
Show file tree
Hide file tree
Showing 23 changed files with 36,278 additions and 108 deletions.
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
"@eeacms/volto-grid-block",
"@eeacms/volto-datablocks",
"@eeacms/volto-embed",
"volto-addons",
"@eeacms/volto-openlayers-map",
"@eeacms/volto-tableau",
"@eeacms/volto-matomo"
Expand All @@ -63,8 +62,7 @@
"react-iframe": "^1.8.0",
"react-tooltip": "^4.2.9",
"react-visibility-sensor": "^5.1.1",
"tableau-api-js": "github:eea/tableau-api-js#1.1.0",
"volto-addons": "github:eea/volto-addons#master"
"tableau-api-js": "github:eea/tableau-api-js#1.1.0"
},
"devDependencies": {
"eslint-plugin-prettier": "3.1.3",
Expand Down
50 changes: 50 additions & 0 deletions src/components/manage/Blocks/ExpendableList/Edit.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import React, { useState, useEffect } from 'react';
import { connect } from 'react-redux';
import { compose } from 'redux';
import _uniqueId from 'lodash/uniqueId';
import InlineForm from '@plone/volto/components/manage/Form/InlineForm';
import { SidebarPortal } from '@plone/volto/components';
import View from './ViewEdit';
import config from '@plone/volto/registry';
import { makeSchema } from './schema';

const Edit = (props) => {
const [state, setState] = useState({
schema: makeSchema({ ...props, providerUrl: config.settings.providerUrl }),
id: _uniqueId('block_'),
});
useEffect(() => {
setState({
...state,
schema: makeSchema({
...props,
}),
});
/* eslint-disable-next-line */
}, [props.data.isExpandable]);
return (
<div>
<SidebarPortal selected={props.selected}>
<InlineForm
schema={state.schema}
title={state.schema.title}
onChangeField={(field, data) => {
props.onChangeBlock(props.block, {
...(props.data || {}),
[field]: data,
});
}}
formData={props.data || {}}
block={props.block}
/>
</SidebarPortal>
<View {...props} id={state.id} mode="edit" />
</div>
);
};

export default compose(
connect((state, props) => ({
pathname: state.router.location.pathname,
})),
)(Edit);
73 changes: 73 additions & 0 deletions src/components/manage/Blocks/ExpendableList/View.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/* REACT */
import React, { useState } from 'react';
import { compose } from 'redux';
import { connect } from 'react-redux';
import { Icon } from '@plone/volto/components';
import DOMPurify from 'dompurify';
import move from 'lodash-move';
import cx from 'classnames';
import dragSVG from '@plone/volto/icons/drag.svg';
import './style.css';
const View = ({ content, ...props }) => {
const [state, setState] = useState({
activeItem: '',
});
const isExpandable = props.data?.isExpandable;
const listItemTitleClassname = props.data?.listItemTitleClassname;
const listItemDescriptionClassname = props.data?.listItemDescriptionClassname;
const listClassname = props.data?.listClassname;
const items = props.data?.items || [];
const ordered = props.data?.ordered;

return (
<div className={cx('expandable-list', listClassname)}>
{props.mode === 'edit' && !items.length ? <p>Expandable list</p> : ''}
{items
? Object.entries(items).map(([key, value], index) => (
<div className="list-item" key={`list-item-${key}`}>
<button
className={cx(
'list-item-title',
listItemTitleClassname ? listItemTitleClassname : '',
isExpandable ? 'expandable' : 'no-expandable',
)}
onClick={() => {
if (isExpandable && state.activeItem === key) {
setState({ ...state, activeItem: '' });
} else if (isExpandable) {
setState({ ...state, activeItem: key });
}
}}
>
<span className="count">{ordered ? `${index + 1}. ` : ''}</span>
<span>{value.title}</span>
</button>
<div
className={cx(
'list-item-description',
listItemDescriptionClassname
? listItemDescriptionClassname
: '',
isExpandable
? state.activeItem === key
? 'show'
: 'hide'
: '',
)}
dangerouslySetInnerHTML={{
__html: DOMPurify.sanitize(value.description),
}}
/>
</div>
))
: ''}
</div>
);
};

export default compose(
connect((state, props) => ({
content:
state.prefetch?.[state.router.location.pathname] || state.content.data,
})),
)(View);
133 changes: 133 additions & 0 deletions src/components/manage/Blocks/ExpendableList/ViewEdit.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/* REACT */
import React, { useState } from 'react';
import { compose } from 'redux';
import { connect } from 'react-redux';
import { Icon } from '@plone/volto/components';
import { DragDropContext, Droppable, Draggable } from 'react-beautiful-dnd';
import DOMPurify from 'dompurify';
import move from 'lodash-move';
import cx from 'classnames';
import dragSVG from '@plone/volto/icons/drag.svg';
import './style.css';
const View = ({ content, ...props }) => {
const [state, setState] = useState({
activeItem: '',
});
const isExpandable = props.data?.isExpandable;
const listItemTitleClassname = props.data?.listItemTitleClassname;
const listItemDescriptionClassname = props.data?.listItemDescriptionClassname;
const listClassname = props.data?.listClassname;
const items = props.data?.items || [];
const ordered = props.data?.ordered;

const onDragEnd = (result) => {
const { source, destination } = result;
if (!destination) {
return;
}
if (source.droppableId === destination.droppableId) {
props.onChangeBlock(props.block, {
...props.data,
items: move(props.data.items, source.index, destination.index),
});
} else {
// WIP
}
};

return (
<div className={cx('expandable-list', listClassname)}>
{props.mode === 'edit' && !items.length ? <p>Expandable list</p> : ''}
{items ? (
<DragDropContext onDragEnd={onDragEnd}>
<Droppable droppableId="list-item">
{(providedDroppable) => (
<>
<div ref={providedDroppable.innerRef}>
{Object.entries(items).map(([key, value], index) => (
<Draggable key={key} draggableId={key} index={index}>
{(providedItem) => (
<div
ref={providedItem.innerRef}
{...providedItem.draggableProps}
>
<div
style={{
position: 'relative',
height: '100%',
}}
>
<div
style={{
visibility: 'visible',
display: 'inline-block',
}}
{...providedItem.dragHandleProps}
className="drag handle wrapper"
>
<Icon name={dragSVG} size="18px" />
</div>
<div className="list-item" key={`list-item-${key}`}>
<button
className={cx(
'list-item-title',
listItemTitleClassname
? listItemTitleClassname
: '',
isExpandable ? 'expandable' : 'no-expandable',
)}
onClick={() => {
if (
isExpandable &&
state.activeItem === key
) {
setState({ ...state, activeItem: '' });
} else if (isExpandable) {
setState({ ...state, activeItem: key });
}
}}
>
{ordered ? `${index + 1}. ` : ''}
{value.title}
</button>
<div
className={cx(
'list-item-description',
listItemDescriptionClassname
? listItemDescriptionClassname
: '',
isExpandable
? state.activeItem === key
? 'show'
: 'hide'
: '',
)}
dangerouslySetInnerHTML={{
__html: DOMPurify.sanitize(value.description),
}}
/>
</div>
</div>
</div>
)}
</Draggable>
))}
</div>
{providedDroppable.placeholder}
</>
)}
</Droppable>
</DragDropContext>
) : (
''
)}
</div>
);
};

export default compose(
connect((state, props) => ({
content:
state.prefetch?.[state.router.location.pathname] || state.content.data,
})),
)(View);
80 changes: 80 additions & 0 deletions src/components/manage/Blocks/ExpendableList/schema.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
const getListSchema = (props) => {
return {
title: 'List item',
fieldsets: [
{
id: 'default',
title: 'Default',
fields: ['title', 'description'],
},
],
properties: {
title: {
title: 'Title',
widget: 'text',
},
description: {
title: 'Description',
widget: 'textarea',
},
},
required: [],
};
};

export const makeSchema = (props) => {
return {
title: props.schemaTitle || 'Title',
fieldsets: [
{
id: 'default',
title: 'Default',
fields: [],
},
{
id: 'list-items',
title: 'List items',
fields: ['items'],
},
{
id: 'settings',
title: 'Settings',
fields: [
'ordered',
'isExpandable',
'listClassname',
'listItemTitleClassname',
'listItemDescriptionClassname',
],
},
],
properties: {
items: {
title: 'List items',
widget: 'object_list',
schema: getListSchema(),
},
ordered: {
title: 'Ordered',
type: 'boolean',
},
isExpandable: {
title: 'Is expandable',
type: 'boolean',
},
listClassname: {
title: 'List classname',
type: 'text',
},
listItemTitleClassname: {
title: 'Title class name',
type: 'text',
},
listItemDescriptionClassname: {
title: 'Description class name',
type: 'text',
},
},
required: [],
};
};
Loading

0 comments on commit a92a389

Please sign in to comment.