Skip to content
This repository was archived by the owner on Aug 4, 2025. It is now read-only.

Commit 11fbb34

Browse files
authored
Only show select/deselect-all when selectItems fn is provided (#79)
1 parent 85e268b commit 11fbb34

7 files changed

Lines changed: 141 additions & 37 deletions

File tree

src/ObjectList.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,8 @@ class ObjectList extends Component {
167167
loadFavourite={loadFavourite}
168168

169169
selection={selection}
170-
selectAll={this.selectAll}
171-
deselectAll={this.deselectAll}
170+
selectAll={selectItems && this.selectAll}
171+
deselectAll={selectItems && this.deselectAll}
172172
numSelected={numSelected}
173173
customActions={customActions}
174174
/>

src/ObjectList.stories.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ storiesOf('object-list', module)
135135
searchKey="search"
136136
removeFilter={action('removeFilter')}
137137
customActions={[downloadSomething, aButton]}
138+
selectItems={action('selecting items')}
138139
/>)
139140
})
140141
.add('has error', () => (

src/__snapshots__/ObjectList.stories.storyshot

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4165,6 +4165,17 @@ exports[`Storyshots object-list has everything 1`] = `
41654165
className=""
41664166
>
41674167
<tr>
4168+
<th
4169+
className="objectlist-table__th objectlist-table__th--border-bottom objectlist-table__th--selector"
4170+
rowSpan={1}
4171+
>
4172+
<input
4173+
checked={true}
4174+
className="objectlist-table__checkbox"
4175+
onChange={[Function]}
4176+
type="checkbox"
4177+
/>
4178+
</th>
41684179
<th
41694180
className="objectlist-table__th objectlist-table__th--border-bottom "
41704181
colSpan={undefined}
@@ -4228,6 +4239,16 @@ exports[`Storyshots object-list has everything 1`] = `
42284239
className="objectlist-table__row"
42294240
onClick={null}
42304241
>
4242+
<td
4243+
className="objectlist-table__td"
4244+
>
4245+
<input
4246+
checked={true}
4247+
className="objectlist-table__checkbox"
4248+
onChange={[Function]}
4249+
type="checkbox"
4250+
/>
4251+
</td>
42314252
<td
42324253
className="objectlist-table__td"
42334254
>
@@ -4248,6 +4269,16 @@ exports[`Storyshots object-list has everything 1`] = `
42484269
className="objectlist-table__row"
42494270
onClick={null}
42504271
>
4272+
<td
4273+
className="objectlist-table__td"
4274+
>
4275+
<input
4276+
checked={true}
4277+
className="objectlist-table__checkbox"
4278+
onChange={[Function]}
4279+
type="checkbox"
4280+
/>
4281+
</td>
42514282
<td
42524283
className="objectlist-table__td"
42534284
>
@@ -4268,6 +4299,16 @@ exports[`Storyshots object-list has everything 1`] = `
42684299
className="objectlist-table__row"
42694300
onClick={null}
42704301
>
4302+
<td
4303+
className="objectlist-table__td"
4304+
>
4305+
<input
4306+
checked={true}
4307+
className="objectlist-table__checkbox"
4308+
onChange={[Function]}
4309+
type="checkbox"
4310+
/>
4311+
</td>
42714312
<td
42724313
className="objectlist-table__td"
42734314
>
@@ -4288,6 +4329,16 @@ exports[`Storyshots object-list has everything 1`] = `
42884329
className="objectlist-table__row"
42894330
onClick={null}
42904331
>
4332+
<td
4333+
className="objectlist-table__td"
4334+
>
4335+
<input
4336+
checked={true}
4337+
className="objectlist-table__checkbox"
4338+
onChange={[Function]}
4339+
type="checkbox"
4340+
/>
4341+
</td>
42914342
<td
42924343
className="objectlist-table__td"
42934344
>
@@ -4308,6 +4359,16 @@ exports[`Storyshots object-list has everything 1`] = `
43084359
className="objectlist-table__row"
43094360
onClick={null}
43104361
>
4362+
<td
4363+
className="objectlist-table__td"
4364+
>
4365+
<input
4366+
checked={true}
4367+
className="objectlist-table__checkbox"
4368+
onChange={[Function]}
4369+
type="checkbox"
4370+
/>
4371+
</td>
43114372
<td
43124373
className="objectlist-table__td"
43134374
>
@@ -4328,6 +4389,16 @@ exports[`Storyshots object-list has everything 1`] = `
43284389
className="objectlist-table__row"
43294390
onClick={null}
43304391
>
4392+
<td
4393+
className="objectlist-table__td"
4394+
>
4395+
<input
4396+
checked={true}
4397+
className="objectlist-table__checkbox"
4398+
onChange={[Function]}
4399+
type="checkbox"
4400+
/>
4401+
</td>
43314402
<td
43324403
className="objectlist-table__td"
43334404
>
@@ -4348,6 +4419,16 @@ exports[`Storyshots object-list has everything 1`] = `
43484419
className="objectlist-table__row"
43494420
onClick={null}
43504421
>
4422+
<td
4423+
className="objectlist-table__td"
4424+
>
4425+
<input
4426+
checked={true}
4427+
className="objectlist-table__checkbox"
4428+
onChange={[Function]}
4429+
type="checkbox"
4430+
/>
4431+
</td>
43514432
<td
43524433
className="objectlist-table__td"
43534434
>
@@ -4368,6 +4449,16 @@ exports[`Storyshots object-list has everything 1`] = `
43684449
className="objectlist-table__row"
43694450
onClick={null}
43704451
>
4452+
<td
4453+
className="objectlist-table__td"
4454+
>
4455+
<input
4456+
checked={true}
4457+
className="objectlist-table__checkbox"
4458+
onChange={[Function]}
4459+
type="checkbox"
4460+
/>
4461+
</td>
43714462
<td
43724463
className="objectlist-table__td"
43734464
>
@@ -4388,6 +4479,16 @@ exports[`Storyshots object-list has everything 1`] = `
43884479
className="objectlist-table__row"
43894480
onClick={null}
43904481
>
4482+
<td
4483+
className="objectlist-table__td"
4484+
>
4485+
<input
4486+
checked={true}
4487+
className="objectlist-table__checkbox"
4488+
onChange={[Function]}
4489+
type="checkbox"
4490+
/>
4491+
</td>
43914492
<td
43924493
className="objectlist-table__td"
43934494
>
@@ -4408,6 +4509,16 @@ exports[`Storyshots object-list has everything 1`] = `
44084509
className="objectlist-table__row"
44094510
onClick={null}
44104511
>
4512+
<td
4513+
className="objectlist-table__td"
4514+
>
4515+
<input
4516+
checked={true}
4517+
className="objectlist-table__checkbox"
4518+
onChange={[Function]}
4519+
type="checkbox"
4520+
/>
4521+
</td>
44114522
<td
44124523
className="objectlist-table__td"
44134524
>
@@ -4428,6 +4539,16 @@ exports[`Storyshots object-list has everything 1`] = `
44284539
className="objectlist-table__row"
44294540
onClick={null}
44304541
>
4542+
<td
4543+
className="objectlist-table__td"
4544+
>
4545+
<input
4546+
checked={true}
4547+
className="objectlist-table__checkbox"
4548+
onChange={[Function]}
4549+
type="checkbox"
4550+
/>
4551+
</td>
44314552
<td
44324553
className="objectlist-table__td"
44334554
>
@@ -4448,6 +4569,16 @@ exports[`Storyshots object-list has everything 1`] = `
44484569
className="objectlist-table__row"
44494570
onClick={null}
44504571
>
4572+
<td
4573+
className="objectlist-table__td"
4574+
>
4575+
<input
4576+
checked={true}
4577+
className="objectlist-table__checkbox"
4578+
onChange={[Function]}
4579+
type="checkbox"
4580+
/>
4581+
</td>
44514582
<td
44524583
className="objectlist-table__td"
44534584
>

src/actions-filters/ActionsFiltersContainer.stories.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ storiesOf('object-list/ActionsFiltersContainer', module)
7070
updateFilter={action('Update filter')}
7171
removeFilter={action('Remove filter')}
7272
customActions={[downloadSomething, aButton]}
73+
deselectAll={action('Select all items')}
7374
/>
7475
)
7576
}).add('has search', () => {

src/actions-filters/SelectAllAction.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class SelectAllAction extends Component {
2828
}
2929

3030
render() {
31-
const {selectAll, count, numSelected, itemPluralName, itemCount} = this.props
31+
const {selectAll, count, numSelected, itemPluralName, itemCount, deselectAll} = this.props
3232
let selectAllLink
3333
if (selectAll && count > 0 && numSelected < count && numSelected >= itemCount) {
3434
selectAllLink = (
@@ -42,7 +42,7 @@ class SelectAllAction extends Component {
4242
)
4343
}
4444
let deselectLink
45-
if (numSelected > 0) {
45+
if (deselectAll && numSelected > 0) {
4646
deselectLink = (
4747
<a
4848
className="objectlist-link"

src/actions-filters/__snapshots__/ActionsFiltersContainer.stories.storyshot

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -910,17 +910,6 @@ exports[`Storyshots object-list/ActionsFiltersContainer default view 1`] = `
910910
>
911911
573,489 octopi found
912912
</span>
913-
<div
914-
className="objectlist-row"
915-
>
916-
<a
917-
className="objectlist-link"
918-
href="#"
919-
onClick={[Function]}
920-
>
921-
Clear selection
922-
</a>
923-
</div>
924913
</div>
925914
<div
926915
className="objectlist-column"
@@ -2898,17 +2887,6 @@ exports[`Storyshots object-list/ActionsFiltersContainer has search 1`] = `
28982887
>
28992888
573,489 dogs found
29002889
</span>
2901-
<div
2902-
className="objectlist-row"
2903-
>
2904-
<a
2905-
className="objectlist-link"
2906-
href="#"
2907-
onClick={[Function]}
2908-
>
2909-
Clear selection
2910-
</a>
2911-
</div>
29122890
</div>
29132891
<div
29142892
className="objectlist-column"
@@ -3831,17 +3809,6 @@ exports[`Storyshots object-list/ActionsFiltersContainer has search with value 1`
38313809
>
38323810
573,489 mouses found
38333811
</span>
3834-
<div
3835-
className="objectlist-row"
3836-
>
3837-
<a
3838-
className="objectlist-link"
3839-
href="#"
3840-
onClick={[Function]}
3841-
>
3842-
Clear selection
3843-
</a>
3844-
</div>
38453812
</div>
38463813
<div
38473814
className="objectlist-column"

src/actions-filters/__tests__/SelectAllAction.test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ describe('<SelectAllAction />', () => {
1414
count: 5,
1515
numSelected: 3,
1616
itemCount: 3,
17+
deselectAll: jest.fn(),
1718
}
1819
snapshotTest(<SelectAllAction {...props} />)
1920
})
@@ -22,6 +23,7 @@ describe('<SelectAllAction />', () => {
2223
count: 5,
2324
numSelected: 2,
2425
itemCount: 3,
26+
deselectAll: jest.fn(),
2527
}
2628
snapshotTest(<SelectAllAction {...props} />)
2729
})
@@ -30,6 +32,7 @@ describe('<SelectAllAction />', () => {
3032
count: 5,
3133
numSelected: 5,
3234
itemCount: 3,
35+
deselectAll: jest.fn(),
3336
}
3437
snapshotTest(<SelectAllAction {...props} />)
3538
})
@@ -40,6 +43,7 @@ describe('<SelectAllAction />', () => {
4043
numSelected: 3,
4144
itemCount: 3,
4245
itemPluralName: 'kitties',
46+
deselectAll: jest.fn(),
4347
}
4448
snapshotTest(<SelectAllAction {...props} />)
4549
})

0 commit comments

Comments
 (0)