Skip to content

Commit d372129

Browse files
authored
fix(Splitter): validate empty group silently (#2835)
* fix(Splitter): validate empty group silently * fix(Splitter): keep panel-count invariant when validating empty group --------- Co-authored-by: Lazizbek Ergashev <20501725+lazerg@users.noreply.github.com>
1 parent 85895b2 commit d372129

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { afterEach, describe, expect, it, vi } from 'vitest'
2+
import { validatePanelGroupLayout } from './validation'
3+
4+
afterEach(() => {
5+
vi.restoreAllMocks()
6+
})
7+
8+
describe('validatePanelGroupLayout', () => {
9+
it('should validate an empty group silently', () => {
10+
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {})
11+
const result = validatePanelGroupLayout({ layout: [], panelConstraints: [] })
12+
expect(result).toEqual([])
13+
expect(warn).not.toHaveBeenCalled()
14+
})
15+
16+
it('should throw when the layout length does not match the panel constraints', () => {
17+
expect(() =>
18+
validatePanelGroupLayout({ layout: [50, 50], panelConstraints: [] }),
19+
).toThrow('Invalid 0 panel layout')
20+
})
21+
})

‎packages/core/src/Splitter/utils/validation.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ export function validatePanelGroupLayout({
1212
panelConstraints: PanelConstraints[]
1313
}): number[] {
1414
const nextLayout = [...prevLayout]
15+
16+
// An empty group has no sizes to total, so 0 !== 100 here is not a misconfiguration
17+
if (nextLayout.length === 0 && panelConstraints.length === 0)
18+
return nextLayout
19+
1520
const nextLayoutTotalSize = nextLayout.reduce(
1621
(accumulated, current) => accumulated + current,
1722
0,

0 commit comments

Comments
 (0)