Skip to content

Commit d4f1986

Browse files
authored
fix(next): group by boolean values (#13382)
When grouping by a checkbox field, boolean values are not translated, causing labels to render incorrectly, and falsey values to render without a heading. --- - To see the specific tasks where the Asana app for GitHub is being used, see below: - https://app.asana.com/0/0/1210979856538211
1 parent 5d8f8dc commit d4f1986

File tree

4 files changed

+65
-0
lines changed

4 files changed

+65
-0
lines changed

packages/next/src/views/List/handleGroupBy.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,16 @@ export const handleGroupBy = async ({
163163
})
164164
}
165165

166+
if (groupByField.type === 'checkbox') {
167+
if (valueOrRelationshipID === true) {
168+
heading = req.i18n.t('general:true')
169+
}
170+
171+
if (valueOrRelationshipID === false) {
172+
heading = req.i18n.t('general:false')
173+
}
174+
}
175+
166176
if (groupData.docs && groupData.docs.length > 0) {
167177
const { columnState: newColumnState, Table: NewTable } = renderTable({
168178
clientCollectionConfig,

test/group-by/collections/Posts/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ export const PostsCollection: CollectionConfig = {
2222
type: 'relationship',
2323
relationTo: categoriesSlug,
2424
},
25+
{
26+
name: 'checkbox',
27+
type: 'checkbox',
28+
},
2529
{
2630
name: 'date',
2731
type: 'date',

test/group-by/e2e.spec.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,55 @@ test.describe('Group By', () => {
265265
).toBeVisible()
266266
})
267267

268+
test('should group by boolean values', async () => {
269+
await Promise.all([
270+
await payload.create({
271+
collection: postsSlug,
272+
data: {
273+
title: 'Null Post',
274+
checkbox: null,
275+
},
276+
}),
277+
await payload.create({
278+
collection: postsSlug,
279+
data: {
280+
title: 'True Post',
281+
checkbox: true,
282+
},
283+
}),
284+
await payload.create({
285+
collection: postsSlug,
286+
data: {
287+
title: 'False Post',
288+
checkbox: false,
289+
},
290+
}),
291+
])
292+
293+
await page.goto(url.list)
294+
295+
await addGroupBy(page, {
296+
fieldLabel: 'Checkbox',
297+
fieldPath: 'checkbox',
298+
})
299+
300+
await expect(page.locator('.table-wrap')).toHaveCount(3)
301+
302+
await expect(page.locator('.group-by-header')).toHaveCount(3)
303+
304+
await expect(
305+
page.locator('.group-by-header__heading', { hasText: exactText('No value') }),
306+
).toBeVisible()
307+
308+
await expect(
309+
page.locator('.group-by-header__heading', { hasText: exactText('True') }),
310+
).toBeVisible()
311+
312+
await expect(
313+
page.locator('.group-by-header__heading', { hasText: exactText('False') }),
314+
).toBeVisible()
315+
})
316+
268317
test('should sort the group-by field globally', async () => {
269318
await page.goto(url.list)
270319

test/group-by/payload-types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ export interface Post {
125125
id: string;
126126
title?: string | null;
127127
category?: (string | null) | Category;
128+
checkbox?: boolean | null;
128129
date?: string | null;
129130
tab1Field?: string | null;
130131
updatedAt: string;
@@ -281,6 +282,7 @@ export interface PayloadMigration {
281282
export interface PostsSelect<T extends boolean = true> {
282283
title?: T;
283284
category?: T;
285+
checkbox?: T;
284286
date?: T;
285287
tab1Field?: T;
286288
updatedAt?: T;

0 commit comments

Comments
 (0)