Skip to content

Commit ff961f4

Browse files
feat: add allow_remove and allow_reorder flags (#7573)
* feat: add allow_remove and allow_reorder flags * fix: update snapshots
1 parent 9a75cfc commit ff961f4

File tree

6 files changed

+53
-4
lines changed

6 files changed

+53
-4
lines changed

packages/decap-cms-core/index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ declare module 'decap-cms-core' {
133133
default?: any;
134134

135135
allow_add?: boolean;
136+
allow_remove?: boolean;
137+
allow_reorder?: boolean;
136138
collapsed?: boolean;
137139
summary?: string;
138140
minimize_collapsed?: boolean;

packages/decap-cms-core/src/types/redux.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ export interface CmsFieldList {
148148
default?: unknown;
149149

150150
allow_add?: boolean;
151+
allow_remove?: boolean;
152+
allow_reorder?: boolean;
151153
collapsed?: boolean;
152154
summary?: string;
153155
minimize_collapsed?: boolean;

packages/decap-cms-ui-default/src/ListItemTopBar.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,20 +46,31 @@ function DragHandle({ Wrapper, id }) {
4646
}
4747

4848
function ListItemTopBar(props) {
49-
const { className, collapsed, onCollapseToggle, onRemove, dragHandle, id } = props;
49+
const {
50+
className,
51+
collapsed,
52+
onCollapseToggle,
53+
onRemove,
54+
allowRemove,
55+
dragHandle,
56+
allowReorder,
57+
id,
58+
} = props;
5059
return (
5160
<TopBar className={className}>
5261
{onCollapseToggle ? (
5362
<TopBarButton onClick={onCollapseToggle}>
5463
<Icon type="chevron" size="small" direction={collapsed ? 'right' : 'down'} />
5564
</TopBarButton>
5665
) : null}
57-
{dragHandle ? <DragHandle Wrapper={dragHandle} id={id} /> : null}
58-
{onRemove ? (
66+
{dragHandle && allowReorder ? <DragHandle Wrapper={dragHandle} id={id} /> : <span></span>}
67+
{onRemove && allowRemove ? (
5968
<TopBarButton onClick={onRemove}>
6069
<Icon type="close" size="small" />
6170
</TopBarButton>
62-
) : null}
71+
) : (
72+
<span></span>
73+
)}
6374
</TopBar>
6475
);
6576
}
@@ -69,6 +80,8 @@ ListItemTopBar.propTypes = {
6980
collapsed: PropTypes.bool,
7081
onCollapseToggle: PropTypes.func,
7182
onRemove: PropTypes.func,
83+
allowRemove: PropTypes.bool,
84+
allowReorder: PropTypes.bool,
7285
};
7386

7487
const StyledListItemTopBar = styled(ListItemTopBar)`

packages/decap-cms-widget-list/src/ListControl.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,8 @@ export default class ListControl extends React.Component {
682682
onCollapseToggle={partial(this.handleItemCollapseToggle, index)}
683683
dragHandle={DragHandle}
684684
id={key}
685+
allowRemove={field.get('allow_remove', true)}
686+
allowReorder={field.get('allow_reorder', true)}
685687
onRemove={partial(this.handleRemove, index)}
686688
data-testid={`styled-list-item-top-bar-${key}`}
687689
/>

packages/decap-cms-widget-list/src/__tests__/__snapshots__/ListControl.spec.js.snap

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,8 @@ exports[`ListControl should add to list when add button is clicked 1`] = `
204204
class="emotion-15 emotion-16"
205205
>
206206
<mock-list-item-top-bar
207+
allowremove=""
208+
allowreorder=""
207209
class="emotion-17 emotion-18"
208210
data-testid="styled-list-item-top-bar-0"
209211
id="0"
@@ -454,6 +456,8 @@ exports[`ListControl should remove from list when remove button is clicked 1`] =
454456
class="emotion-15 emotion-16"
455457
>
456458
<mock-list-item-top-bar
459+
allowremove=""
460+
allowreorder=""
457461
class="emotion-17 emotion-18"
458462
data-testid="styled-list-item-top-bar-0"
459463
id="0"
@@ -482,6 +486,8 @@ exports[`ListControl should remove from list when remove button is clicked 1`] =
482486
class="emotion-15 emotion-16"
483487
>
484488
<mock-list-item-top-bar
489+
allowremove=""
490+
allowreorder=""
485491
class="emotion-17 emotion-18"
486492
data-testid="styled-list-item-top-bar-1"
487493
id="1"
@@ -732,6 +738,8 @@ exports[`ListControl should remove from list when remove button is clicked 2`] =
732738
class="emotion-15 emotion-16"
733739
>
734740
<mock-list-item-top-bar
741+
allowremove=""
742+
allowreorder=""
735743
class="emotion-17 emotion-18"
736744
collapsed=""
737745
data-testid="styled-list-item-top-bar-1"
@@ -995,6 +1003,8 @@ exports[`ListControl should render list with fields with collapse = "false" and
9951003
class="emotion-15 emotion-16"
9961004
>
9971005
<mock-list-item-top-bar
1006+
allowremove=""
1007+
allowreorder=""
9981008
class="emotion-17 emotion-18"
9991009
data-testid="styled-list-item-top-bar-0"
10001010
id="0"
@@ -1023,6 +1033,8 @@ exports[`ListControl should render list with fields with collapse = "false" and
10231033
class="emotion-15 emotion-16"
10241034
>
10251035
<mock-list-item-top-bar
1036+
allowremove=""
1037+
allowreorder=""
10261038
class="emotion-17 emotion-18"
10271039
data-testid="styled-list-item-top-bar-1"
10281040
id="1"
@@ -1273,6 +1285,8 @@ exports[`ListControl should render list with fields with collapse = "false" and
12731285
class="emotion-15 emotion-16"
12741286
>
12751287
<mock-list-item-top-bar
1288+
allowremove=""
1289+
allowreorder=""
12761290
class="emotion-17 emotion-18"
12771291
data-testid="styled-list-item-top-bar-0"
12781292
id="0"
@@ -1301,6 +1315,8 @@ exports[`ListControl should render list with fields with collapse = "false" and
13011315
class="emotion-15 emotion-16"
13021316
>
13031317
<mock-list-item-top-bar
1318+
allowremove=""
1319+
allowreorder=""
13041320
class="emotion-17 emotion-18"
13051321
data-testid="styled-list-item-top-bar-1"
13061322
id="1"
@@ -1551,6 +1567,8 @@ exports[`ListControl should render list with fields with default collapse ("true
15511567
class="emotion-15 emotion-16"
15521568
>
15531569
<mock-list-item-top-bar
1570+
allowremove=""
1571+
allowreorder=""
15541572
class="emotion-17 emotion-18"
15551573
collapsed=""
15561574
data-testid="styled-list-item-top-bar-0"
@@ -1581,6 +1599,8 @@ exports[`ListControl should render list with fields with default collapse ("true
15811599
class="emotion-15 emotion-16"
15821600
>
15831601
<mock-list-item-top-bar
1602+
allowremove=""
1603+
allowreorder=""
15841604
class="emotion-17 emotion-18"
15851605
collapsed=""
15861606
data-testid="styled-list-item-top-bar-1"
@@ -2015,6 +2035,8 @@ exports[`ListControl should render list with nested object 1`] = `
20152035
class="emotion-15 emotion-16"
20162036
>
20172037
<mock-list-item-top-bar
2038+
allowremove=""
2039+
allowreorder=""
20182040
class="emotion-17 emotion-18"
20192041
collapsed=""
20202042
data-testid="styled-list-item-top-bar-0"
@@ -2045,6 +2067,8 @@ exports[`ListControl should render list with nested object 1`] = `
20452067
class="emotion-15 emotion-16"
20462068
>
20472069
<mock-list-item-top-bar
2070+
allowremove=""
2071+
allowreorder=""
20482072
class="emotion-17 emotion-18"
20492073
collapsed=""
20502074
data-testid="styled-list-item-top-bar-1"
@@ -2297,6 +2321,8 @@ exports[`ListControl should render list with nested object with collapse = false
22972321
class="emotion-15 emotion-16"
22982322
>
22992323
<mock-list-item-top-bar
2324+
allowremove=""
2325+
allowreorder=""
23002326
class="emotion-17 emotion-18"
23012327
data-testid="styled-list-item-top-bar-0"
23022328
id="0"
@@ -2325,6 +2351,8 @@ exports[`ListControl should render list with nested object with collapse = false
23252351
class="emotion-15 emotion-16"
23262352
>
23272353
<mock-list-item-top-bar
2354+
allowremove=""
2355+
allowreorder=""
23282356
class="emotion-17 emotion-18"
23292357
data-testid="styled-list-item-top-bar-1"
23302358
id="1"

packages/decap-cms-widget-list/src/schema.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
export default {
22
properties: {
33
allow_add: { type: 'boolean' },
4+
allow_remove: { type: 'boolean' },
5+
allow_reorder: { type: 'boolean' },
46
collapsed: { type: 'boolean' },
57
summary: { type: 'string' },
68
minimize_collapsed: { type: 'boolean' },

0 commit comments

Comments
 (0)