forked from opensearch-project/dashboards-observability
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/visualization (opensearch-project#83)
* resloved conflicts for rebasing * added overall layout and render fields * added two types of charts * added config panel for vis * removed unused files and for a quick demo * add intial redux setup * added initial reducer * refactorings for redux * minor code cleanup * adjusted chart styling, added timespan selector * added timestamp flag and checking for charts * fixed sidebar field icon issue * code cleanup * license and minor changes * changes for code review * removed few comments
- Loading branch information
1 parent
e9f1aed
commit 2442f53
Showing
80 changed files
with
4,159 additions
and
397 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
37 changes: 37 additions & 0 deletions
37
public/components/common/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,37 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
* | ||
* Modifications Copyright OpenSearch Contributors. See | ||
* GitHub history for details. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { mountWithIntl as mount } from 'test_utils/enzyme_helpers'; | ||
import { debouncedComponent } from './debounced_component'; | ||
import { act } from 'react-dom/test-utils'; | ||
|
||
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 act(async () => { | ||
await new Promise((r) => setTimeout(r, 1)); | ||
}); | ||
expect(component.text()).toEqual('yall'); | ||
}); | ||
}); |
33 changes: 33 additions & 0 deletions
33
public/components/common/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,33 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
* | ||
* Modifications Copyright OpenSearch Contributors. See | ||
* GitHub history for details. | ||
*/ | ||
|
||
import React, { useState, useMemo, useEffect, 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 debouncePropsChange = useMemo(() => debounce(setCachedProps, delay), [setCachedProps]); | ||
|
||
// cancel debounced prop change if component has been unmounted in the meantime | ||
useEffect(() => () => debouncePropsChange.cancel(), [debouncePropsChange]); | ||
debouncePropsChange(props); | ||
|
||
return React.createElement(MemoizedComponent, cachedProps); | ||
}; | ||
} |
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,12 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
* | ||
* Modifications Copyright OpenSearch Contributors. See | ||
* GitHub history for details. | ||
*/ | ||
|
||
export * from './debounced_component'; |
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.