-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Lens] Data panel styling and optimizations (#40787)
Style the data panel (mostly Joe Reuter's doing). Optimize a bunch of the Lens stack.
- Loading branch information
1 parent
dd49f8a
commit 9202916
Showing
26 changed files
with
1,039 additions
and
250 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
x-pack/legacy/plugins/lens/public/debounced_component/debounced_component.test.tsx
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,29 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { mountWithIntl as mount } from 'test_utils/enzyme_helpers'; | ||
import { debouncedComponent } from './debounced_component'; | ||
|
||
describe('debouncedComponent', () => { | ||
test('immediately renders', () => { | ||
const TestComponent = debouncedComponent(({ title }: { title: string }) => { | ||
return <h1>{title}</h1>; | ||
}); | ||
expect(mount(<TestComponent title="hoi" />).html()).toMatchInlineSnapshot(`"<h1>hoi</h1>"`); | ||
}); | ||
|
||
test('debounces changes', async () => { | ||
const TestComponent = debouncedComponent(({ title }: { title: string }) => { | ||
return <h1>{title}</h1>; | ||
}, 1); | ||
const component = mount(<TestComponent title="there" />); | ||
component.setProps({ title: 'yall' }); | ||
expect(component.text()).toEqual('there'); | ||
await new Promise(r => setTimeout(r, 1)); | ||
expect(component.text()).toEqual('yall'); | ||
}); | ||
}); |
26 changes: 26 additions & 0 deletions
26
x-pack/legacy/plugins/lens/public/debounced_component/debounced_component.tsx
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,26 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import React, { useState, useMemo, memo, FunctionComponent } from 'react'; | ||
import { debounce } from 'lodash'; | ||
|
||
/** | ||
* debouncedComponent wraps the specified React component, returning a component which | ||
* only renders once there is a pause in props changes for at least `delay` milliseconds. | ||
* During the debounce phase, it will return the previously rendered value. | ||
*/ | ||
export function debouncedComponent<TProps>(component: FunctionComponent<TProps>, delay = 256) { | ||
const MemoizedComponent = (memo(component) as unknown) as FunctionComponent<TProps>; | ||
|
||
return (props: TProps) => { | ||
const [cachedProps, setCachedProps] = useState(props); | ||
const delayRender = useMemo(() => debounce(setCachedProps, delay), []); | ||
|
||
delayRender(props); | ||
|
||
return React.createElement(MemoizedComponent, cachedProps); | ||
}; | ||
} |
7 changes: 7 additions & 0 deletions
7
x-pack/legacy/plugins/lens/public/debounced_component/index.ts
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,7 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
export * from './debounced_component'; |
40 changes: 40 additions & 0 deletions
40
x-pack/legacy/plugins/lens/public/drag_drop/providers.test.tsx
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,40 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import React, { useContext } from 'react'; | ||
import { mount } from 'enzyme'; | ||
import { RootDragDropProvider, DragContext } from './providers'; | ||
|
||
jest.useFakeTimers(); | ||
|
||
describe('RootDragDropProvider', () => { | ||
test('reuses contexts for each render', () => { | ||
const contexts: any[] = []; | ||
const TestComponent = ({ name }: { name: string }) => { | ||
const context = useContext(DragContext); | ||
contexts.push(context); | ||
return ( | ||
<div data-test-subj="test-component"> | ||
{name} {!!context.dragging} | ||
</div> | ||
); | ||
}; | ||
|
||
const RootComponent = ({ name }: { name: string }) => ( | ||
<RootDragDropProvider> | ||
<TestComponent name={name} /> | ||
</RootDragDropProvider> | ||
); | ||
|
||
const component = mount(<RootComponent name="aaaa" />); | ||
|
||
component.setProps({ name: 'bbbb' }); | ||
|
||
expect(component.find('[data-test-subj="test-component"]').text()).toContain('bbb'); | ||
expect(contexts.length).toEqual(2); | ||
expect(contexts[0]).toStrictEqual(contexts[1]); | ||
}); | ||
}); |
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
Oops, something went wrong.