-
Notifications
You must be signed in to change notification settings - Fork 839
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[EuiDataGrid] improve height calculation (#5447)
* Calculate the grid's height based on all known values * Add cypress test to verify switching from default single row height to auto fit will expand the grid * remove comment * Compute the grid's unconstrained height when a row's height changes * Simplify setRenderPass logic * Added useForceRender hook, refactored data grid row height updating to use the new hook * Created a hook to better organize and document how the unconstrained height is calculated * Update src/services/hooks/useForceRender.ts Co-authored-by: Constance <constancecchen@users.noreply.github.com> Co-authored-by: Constance Chen <constance.chen.3@gmail.com> Co-authored-by: Constance <constancecchen@users.noreply.github.com>
- Loading branch information
1 parent
cedee33
commit 9d816bf
Showing
9 changed files
with
186 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import React, { useImperativeHandle, createRef, forwardRef } from 'react'; | ||
import { act } from 'react-dom/test-utils'; | ||
import { mount } from 'enzyme'; | ||
import { useForceRender } from './useForceRender'; | ||
|
||
interface MockRefShape { | ||
render: () => void; | ||
} | ||
|
||
describe('useForceRender', () => { | ||
const renderTracker = jest.fn(); | ||
|
||
// eslint-disable-next-line local/forward-ref | ||
const MockComponent = forwardRef<MockRefShape>((props, ref) => { | ||
const render = useForceRender(); | ||
|
||
renderTracker(); | ||
|
||
// expose the render function on the component's ref | ||
useImperativeHandle(ref, () => ({ render }), [render]); | ||
|
||
return null; | ||
}); | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('causes the component to re-render', () => { | ||
const ref = createRef<MockRefShape>(); | ||
mount(<MockComponent ref={ref} />); | ||
|
||
expect(renderTracker).toHaveBeenCalledTimes(1); | ||
act(() => { | ||
ref.current!.render(); | ||
}); | ||
expect(renderTracker).toHaveBeenCalledTimes(2); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { useState, useCallback } from 'react'; | ||
|
||
export const useForceRender = () => { | ||
const [, setRenderCount] = useState(0); | ||
return useCallback(() => { | ||
setRenderCount((x) => x + 1); | ||
}, []); | ||
}; |