Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 2 additions & 0 deletions packages/decap-cms-core/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ declare module 'decap-cms-core' {
default?: any;

allow_add?: boolean;
allow_remove?: boolean;
allow_reorder?: boolean;
collapsed?: boolean;
summary?: string;
minimize_collapsed?: boolean;
Expand Down
2 changes: 2 additions & 0 deletions packages/decap-cms-core/src/types/redux.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ export interface CmsFieldList {
default?: unknown;

allow_add?: boolean;
allow_remove?: boolean;
allow_reorder?: boolean;
collapsed?: boolean;
summary?: string;
minimize_collapsed?: boolean;
Expand Down
21 changes: 17 additions & 4 deletions packages/decap-cms-ui-default/src/ListItemTopBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,31 @@ function DragHandle({ Wrapper, id }) {
}

function ListItemTopBar(props) {
const { className, collapsed, onCollapseToggle, onRemove, dragHandle, id } = props;
const {
className,
collapsed,
onCollapseToggle,
onRemove,
allowRemove,
dragHandle,
allowReorder,
id,
} = props;
return (
<TopBar className={className}>
{onCollapseToggle ? (
<TopBarButton onClick={onCollapseToggle}>
<Icon type="chevron" size="small" direction={collapsed ? 'right' : 'down'} />
</TopBarButton>
) : null}
{dragHandle ? <DragHandle Wrapper={dragHandle} id={id} /> : null}
{onRemove ? (
{dragHandle && allowReorder ? <DragHandle Wrapper={dragHandle} id={id} /> : <span></span>}
{onRemove && allowRemove ? (
<TopBarButton onClick={onRemove}>
<Icon type="close" size="small" />
</TopBarButton>
) : null}
) : (
<span></span>
Comment thread
martinjagodic marked this conversation as resolved.
Comment thread
martinjagodic marked this conversation as resolved.
)}
</TopBar>
);
}
Expand All @@ -69,6 +80,8 @@ ListItemTopBar.propTypes = {
collapsed: PropTypes.bool,
onCollapseToggle: PropTypes.func,
onRemove: PropTypes.func,
allowRemove: PropTypes.bool,
allowReorder: PropTypes.bool,
};

const StyledListItemTopBar = styled(ListItemTopBar)`
Expand Down
2 changes: 2 additions & 0 deletions packages/decap-cms-widget-list/src/ListControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,8 @@ export default class ListControl extends React.Component {
onCollapseToggle={partial(this.handleItemCollapseToggle, index)}
dragHandle={DragHandle}
id={key}
allowRemove={field.get('allow_remove', true)}
allowReorder={field.get('allow_reorder', true)}
onRemove={partial(this.handleRemove, index)}
data-testid={`styled-list-item-top-bar-${key}`}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ exports[`ListControl should add to list when add button is clicked 1`] = `
class="emotion-15 emotion-16"
>
<mock-list-item-top-bar
allowremove=""
allowreorder=""
class="emotion-17 emotion-18"
data-testid="styled-list-item-top-bar-0"
id="0"
Expand Down Expand Up @@ -454,6 +456,8 @@ exports[`ListControl should remove from list when remove button is clicked 1`] =
class="emotion-15 emotion-16"
>
<mock-list-item-top-bar
allowremove=""
allowreorder=""
class="emotion-17 emotion-18"
data-testid="styled-list-item-top-bar-0"
id="0"
Expand Down Expand Up @@ -482,6 +486,8 @@ exports[`ListControl should remove from list when remove button is clicked 1`] =
class="emotion-15 emotion-16"
>
<mock-list-item-top-bar
allowremove=""
allowreorder=""
class="emotion-17 emotion-18"
data-testid="styled-list-item-top-bar-1"
id="1"
Expand Down Expand Up @@ -732,6 +738,8 @@ exports[`ListControl should remove from list when remove button is clicked 2`] =
class="emotion-15 emotion-16"
>
<mock-list-item-top-bar
allowremove=""
allowreorder=""
class="emotion-17 emotion-18"
collapsed=""
data-testid="styled-list-item-top-bar-1"
Expand Down Expand Up @@ -995,6 +1003,8 @@ exports[`ListControl should render list with fields with collapse = "false" and
class="emotion-15 emotion-16"
>
<mock-list-item-top-bar
allowremove=""
allowreorder=""
class="emotion-17 emotion-18"
data-testid="styled-list-item-top-bar-0"
id="0"
Expand Down Expand Up @@ -1023,6 +1033,8 @@ exports[`ListControl should render list with fields with collapse = "false" and
class="emotion-15 emotion-16"
>
<mock-list-item-top-bar
allowremove=""
allowreorder=""
class="emotion-17 emotion-18"
data-testid="styled-list-item-top-bar-1"
id="1"
Expand Down Expand Up @@ -1273,6 +1285,8 @@ exports[`ListControl should render list with fields with collapse = "false" and
class="emotion-15 emotion-16"
>
<mock-list-item-top-bar
allowremove=""
allowreorder=""
class="emotion-17 emotion-18"
data-testid="styled-list-item-top-bar-0"
id="0"
Expand Down Expand Up @@ -1301,6 +1315,8 @@ exports[`ListControl should render list with fields with collapse = "false" and
class="emotion-15 emotion-16"
>
<mock-list-item-top-bar
allowremove=""
allowreorder=""
class="emotion-17 emotion-18"
data-testid="styled-list-item-top-bar-1"
id="1"
Expand Down Expand Up @@ -1551,6 +1567,8 @@ exports[`ListControl should render list with fields with default collapse ("true
class="emotion-15 emotion-16"
>
<mock-list-item-top-bar
allowremove=""
allowreorder=""
class="emotion-17 emotion-18"
collapsed=""
data-testid="styled-list-item-top-bar-0"
Expand Down Expand Up @@ -1581,6 +1599,8 @@ exports[`ListControl should render list with fields with default collapse ("true
class="emotion-15 emotion-16"
>
<mock-list-item-top-bar
allowremove=""
allowreorder=""
class="emotion-17 emotion-18"
collapsed=""
data-testid="styled-list-item-top-bar-1"
Expand Down Expand Up @@ -2015,6 +2035,8 @@ exports[`ListControl should render list with nested object 1`] = `
class="emotion-15 emotion-16"
>
<mock-list-item-top-bar
allowremove=""
allowreorder=""
class="emotion-17 emotion-18"
collapsed=""
data-testid="styled-list-item-top-bar-0"
Expand Down Expand Up @@ -2045,6 +2067,8 @@ exports[`ListControl should render list with nested object 1`] = `
class="emotion-15 emotion-16"
>
<mock-list-item-top-bar
allowremove=""
allowreorder=""
class="emotion-17 emotion-18"
collapsed=""
data-testid="styled-list-item-top-bar-1"
Expand Down Expand Up @@ -2297,6 +2321,8 @@ exports[`ListControl should render list with nested object with collapse = false
class="emotion-15 emotion-16"
>
<mock-list-item-top-bar
allowremove=""
allowreorder=""
class="emotion-17 emotion-18"
data-testid="styled-list-item-top-bar-0"
id="0"
Expand Down Expand Up @@ -2325,6 +2351,8 @@ exports[`ListControl should render list with nested object with collapse = false
class="emotion-15 emotion-16"
>
<mock-list-item-top-bar
allowremove=""
allowreorder=""
class="emotion-17 emotion-18"
data-testid="styled-list-item-top-bar-1"
id="1"
Expand Down
2 changes: 2 additions & 0 deletions packages/decap-cms-widget-list/src/schema.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
export default {
properties: {
allow_add: { type: 'boolean' },
allow_remove: { type: 'boolean' },
allow_reorder: { type: 'boolean' },
collapsed: { type: 'boolean' },
summary: { type: 'string' },
minimize_collapsed: { type: 'boolean' },
Expand Down
Loading