-
Notifications
You must be signed in to change notification settings - Fork 8.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Dashboard] [Controls] Refactor options list to align with new code standards #138336
Merged
Heenawter
merged 11 commits into
elastic:main
from
Heenawter:refactor-options-list_2022-08-08
Aug 12, 2022
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
4b12df8
Refactor public folder structure
Heenawter 0a37b38
Refactor common folder structure
Heenawter b542bf4
Refactor server folder structure
Heenawter 58e5d15
Stub out Jest tests and stories
Heenawter b60af68
Add popover jest tests
Heenawter 4756944
Fix strings + imports
Heenawter 0720d1b
Remove comments and unused strings
Heenawter 9a891a0
Fix jest tests
Heenawter 2d1944c
Clean imports
Heenawter 54282cc
Merge branch 'main' into refactor-options-list_2022-08-08
Heenawter 2340f62
Merge branch 'main' into refactor-options-list_2022-08-08
Heenawter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 { getDefaultControlGroupInput } from '..'; | ||
import { ControlGroupInput } from './types'; | ||
|
||
export const mockControlGroupInput = (partial?: Partial<ControlGroupInput>): ControlGroupInput => ({ | ||
id: 'mocked_control_group', | ||
...getDefaultControlGroupInput(), | ||
...{ | ||
panels: { | ||
control1: { | ||
order: 0, | ||
width: 'medium', | ||
grow: true, | ||
type: 'mockedOptionsList', | ||
explicitInput: { | ||
id: 'control1', | ||
}, | ||
}, | ||
control2: { | ||
order: 1, | ||
width: 'large', | ||
grow: true, | ||
type: 'mockedRangeSlider', | ||
explicitInput: { | ||
id: 'control2', | ||
}, | ||
}, | ||
control3: { | ||
order: 2, | ||
width: 'small', | ||
grow: true, | ||
type: 'mockedOptionsList', | ||
explicitInput: { | ||
id: 'control3', | ||
}, | ||
}, | ||
}, | ||
}, | ||
...(partial ?? {}), | ||
}); |
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,63 @@ | ||
/* | ||
* 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 { ReduxEmbeddableContext } from '@kbn/presentation-util-plugin/public/redux_embeddables/types'; | ||
import { ControlOutput } from '../../public/types'; | ||
import { | ||
OptionsListComponentState, | ||
OptionsListEmbeddableInput, | ||
OptionsListReduxState, | ||
} from '../../public/options_list/types'; | ||
import { optionsListReducers } from '../../public/options_list/options_list_reducers'; | ||
|
||
const mockOptionsListComponentState = { | ||
field: undefined, | ||
totalCardinality: 0, | ||
availableOptions: ['woof', 'bark', 'meow', 'quack', 'moo'], | ||
invalidSelections: [], | ||
validSelections: [], | ||
searchString: '', | ||
} as OptionsListComponentState; | ||
|
||
const mockOptionsListEmbeddableInput = { | ||
id: 'sample options list', | ||
fieldName: 'sample field', | ||
dataViewId: 'sample id', | ||
selectedOptions: [], | ||
runPastTimeout: false, | ||
singleSelect: false, | ||
} as OptionsListEmbeddableInput; | ||
|
||
const mockOptionsListOutput = { | ||
loading: false, | ||
} as ControlOutput; | ||
|
||
export const mockOptionsListContext = ( | ||
partialState?: Partial<OptionsListReduxState> | ||
): ReduxEmbeddableContext<OptionsListReduxState, typeof optionsListReducers> => { | ||
const mockReduxState = { | ||
componentState: { | ||
...mockOptionsListComponentState, | ||
...partialState?.componentState, | ||
}, | ||
explicitInput: { | ||
...mockOptionsListEmbeddableInput, | ||
...partialState?.explicitInput, | ||
}, | ||
output: { | ||
...mockOptionsListOutput, | ||
...partialState?.output, | ||
}, | ||
} as OptionsListReduxState; | ||
|
||
return { | ||
actions: {}, | ||
useEmbeddableDispatch: () => {}, | ||
useEmbeddableSelector: (selector: any) => selector(mockReduxState), | ||
} as unknown as ReduxEmbeddableContext<OptionsListReduxState, typeof optionsListReducers>; | ||
}; |
File renamed without changes.
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 |
---|---|---|
|
@@ -6,5 +6,4 @@ | |
* Side Public License, v 1. | ||
*/ | ||
|
||
export * from './options_list'; | ||
export * from './range_slider'; |
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
File renamed without changes.
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
104 changes: 104 additions & 0 deletions
104
src/plugins/controls/public/options_list/components/options_list_popover.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,104 @@ | ||
/* | ||
* 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 from 'react'; | ||
import { ReactWrapper } from 'enzyme'; | ||
|
||
import { mountWithIntl } from '@kbn/test-jest-helpers'; | ||
import { findTestSubject } from '@elastic/eui/lib/test'; | ||
import { EmbeddableReduxContext } from '@kbn/presentation-util-plugin/public/redux_embeddables/use_redux_embeddable_context'; | ||
|
||
import { OptionsListPopover, OptionsListPopoverProps } from './options_list_popover'; | ||
import { | ||
OptionsListComponentState, | ||
OptionsListEmbeddableInput, | ||
OptionsListReduxState, | ||
} from '../types'; | ||
import { ControlOutput } from '../..'; | ||
import { mockOptionsListContext } from '../../../common/mocks'; | ||
|
||
describe('Options list popover', () => { | ||
const defaultProps = { | ||
width: 500, | ||
updateSearchString: jest.fn(), | ||
}; | ||
|
||
interface MountOptions { | ||
componentState: Partial<OptionsListComponentState>; | ||
explicitInput: Partial<OptionsListEmbeddableInput>; | ||
output: Partial<ControlOutput>; | ||
popoverProps: Partial<OptionsListPopoverProps>; | ||
} | ||
|
||
function mountComponent(options?: Partial<MountOptions>) { | ||
const compProps = { ...defaultProps, ...(options?.popoverProps ?? {}) }; | ||
const context = mockOptionsListContext({ | ||
componentState: options?.componentState ?? {}, | ||
explicitInput: options?.explicitInput ?? {}, | ||
output: options?.output ?? {}, | ||
} as Partial<OptionsListReduxState>); | ||
|
||
return mountWithIntl( | ||
<EmbeddableReduxContext.Provider value={context}> | ||
<OptionsListPopover {...compProps} /> | ||
</EmbeddableReduxContext.Provider> | ||
); | ||
} | ||
|
||
const clickShowOnlySelections = (popover: ReactWrapper) => { | ||
const showOnlySelectedButton = findTestSubject( | ||
popover, | ||
'optionsList-control-show-only-selected' | ||
); | ||
showOnlySelectedButton.simulate('click'); | ||
}; | ||
|
||
test('available options list width responds to container size', () => { | ||
let popover = mountComponent({ popoverProps: { width: 301 } }); | ||
let availableOptionsDiv = findTestSubject(popover, 'optionsList-control-available-options'); | ||
expect(availableOptionsDiv.getDOMNode().getAttribute('style')).toBe('width: 301px;'); | ||
|
||
// the div cannot be smaller than 301 pixels wide | ||
popover = mountComponent({ popoverProps: { width: 300 } }); | ||
availableOptionsDiv = findTestSubject(popover, 'optionsList-control-available-options'); | ||
expect(availableOptionsDiv.getDOMNode().getAttribute('style')).toBe(null); | ||
}); | ||
|
||
test('no available options', () => { | ||
const popover = mountComponent({ componentState: { availableOptions: [] } }); | ||
const availableOptionsDiv = findTestSubject(popover, 'optionsList-control-available-options'); | ||
const noOptionsDiv = findTestSubject( | ||
availableOptionsDiv, | ||
'optionsList-control-noSelectionsMessage' | ||
); | ||
expect(noOptionsDiv.exists()).toBeTruthy(); | ||
}); | ||
|
||
test('display error message when the show only selected toggle is true but there are no selections', () => { | ||
const popover = mountComponent(); | ||
clickShowOnlySelections(popover); | ||
const availableOptionsDiv = findTestSubject(popover, 'optionsList-control-available-options'); | ||
const noSelectionsDiv = findTestSubject( | ||
availableOptionsDiv, | ||
'optionsList-control-selectionsEmptyMessage' | ||
); | ||
expect(noSelectionsDiv.exists()).toBeTruthy(); | ||
}); | ||
|
||
test('show only selected options', () => { | ||
const selections = ['woof', 'bark']; | ||
const popover = mountComponent({ | ||
explicitInput: { selectedOptions: selections }, | ||
}); | ||
clickShowOnlySelections(popover); | ||
const availableOptionsDiv = findTestSubject(popover, 'optionsList-control-available-options'); | ||
availableOptionsDiv.children().forEach((child, i) => { | ||
expect(child.text()).toBe(selections[i]); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LOL why is time slider using the options list persistable state? Definitely something to fix in the time slider refactor @cqliu1 @ThomThomson 😆