-
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.
* Adds range slider control Fix ts error Fix ref type error Extracted i18n strings Fixed number rounding Fixed missing i18n string Add loading state to range slider control output Remove unnecessary change Fix i18n errors Apply formatter to range slider tick labels * Apply comment updates from code review Co-authored-by: Devon Thomson <[email protected]> * Remove extra fetches * set min width for panel * Fix functional tests * Fixed controls page object Co-authored-by: Devon Thomson <[email protected]> Co-authored-by: andreadelrio <[email protected]> Co-authored-by: Kibana Machine <[email protected]>
- Loading branch information
1 parent
e67a782
commit ba6be79
Showing
30 changed files
with
1,497 additions
and
30 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
src/plugins/controls/common/control_types/range_slider/range_slider_persistable_state.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,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 { | ||
EmbeddableStateWithType, | ||
EmbeddablePersistableStateService, | ||
} from '../../../../embeddable/common'; | ||
import { RangeSliderEmbeddableInput } from './types'; | ||
import { SavedObjectReference } from '../../../../../core/types'; | ||
import { DATA_VIEW_SAVED_OBJECT_TYPE } from '../../../../data_views/common'; | ||
|
||
type RangeSliderInputWithType = Partial<RangeSliderEmbeddableInput> & { type: string }; | ||
const dataViewReferenceName = 'optionsListDataView'; | ||
|
||
export const createRangeSliderInject = (): EmbeddablePersistableStateService['inject'] => { | ||
return (state: EmbeddableStateWithType, references: SavedObjectReference[]) => { | ||
const workingState = { ...state } as EmbeddableStateWithType | RangeSliderInputWithType; | ||
references.forEach((reference) => { | ||
if (reference.name === dataViewReferenceName) { | ||
(workingState as RangeSliderInputWithType).dataViewId = reference.id; | ||
} | ||
}); | ||
return workingState as EmbeddableStateWithType; | ||
}; | ||
}; | ||
|
||
export const createRangeSliderExtract = (): EmbeddablePersistableStateService['extract'] => { | ||
return (state: EmbeddableStateWithType) => { | ||
const workingState = { ...state } as EmbeddableStateWithType | RangeSliderInputWithType; | ||
const references: SavedObjectReference[] = []; | ||
|
||
if ('dataViewId' in workingState) { | ||
references.push({ | ||
name: dataViewReferenceName, | ||
type: DATA_VIEW_SAVED_OBJECT_TYPE, | ||
id: workingState.dataViewId!, | ||
}); | ||
delete workingState.dataViewId; | ||
} | ||
return { state: workingState as EmbeddableStateWithType, references }; | ||
}; | ||
}; |
19 changes: 19 additions & 0 deletions
19
src/plugins/controls/common/control_types/range_slider/types.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,19 @@ | ||
/* | ||
* 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 { ControlInput } from '../../types'; | ||
|
||
export const RANGE_SLIDER_CONTROL = 'rangeSliderControl'; | ||
|
||
export type RangeValue = [string, string]; | ||
|
||
export interface RangeSliderEmbeddableInput extends ControlInput { | ||
fieldName: string; | ||
dataViewId: string; | ||
value: RangeValue; | ||
} |
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 |
---|---|---|
|
@@ -7,3 +7,4 @@ | |
*/ | ||
|
||
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
13 changes: 13 additions & 0 deletions
13
src/plugins/controls/public/control_types/range_slider/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,13 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
export { RANGE_SLIDER_CONTROL } from '../../../common/control_types/range_slider/types'; | ||
export { RangeSliderEmbeddableFactory } from './range_slider_embeddable_factory'; | ||
|
||
export type { RangeSliderEmbeddable } from './range_slider_embeddable'; | ||
export type { RangeSliderEmbeddableInput } from '../../../common/control_types/range_slider/types'; |
72 changes: 72 additions & 0 deletions
72
src/plugins/controls/public/control_types/range_slider/range_slider.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,72 @@ | ||
/* | ||
* 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, { FC, useCallback, useState } from 'react'; | ||
import { BehaviorSubject } from 'rxjs'; | ||
|
||
import { DataViewField } from '../../../../data_views/public'; | ||
import { useReduxEmbeddableContext } from '../../../../presentation_util/public'; | ||
import { useStateObservable } from '../../hooks/use_state_observable'; | ||
import { RangeSliderPopover } from './range_slider_popover'; | ||
import { rangeSliderReducers } from './range_slider_reducers'; | ||
import { RangeSliderEmbeddableInput, RangeValue } from './types'; | ||
|
||
import './range_slider.scss'; | ||
|
||
interface Props { | ||
componentStateSubject: BehaviorSubject<RangeSliderComponentState>; | ||
} | ||
// Availableoptions and loading state is controled by the embeddable, but is not considered embeddable input. | ||
export interface RangeSliderComponentState { | ||
field?: DataViewField; | ||
fieldFormatter: (value: string) => string; | ||
min: string; | ||
max: string; | ||
loading: boolean; | ||
} | ||
|
||
export const RangeSliderComponent: FC<Props> = ({ componentStateSubject }) => { | ||
// Redux embeddable Context to get state from Embeddable input | ||
const { | ||
useEmbeddableDispatch, | ||
useEmbeddableSelector, | ||
actions: { selectRange }, | ||
} = useReduxEmbeddableContext<RangeSliderEmbeddableInput, typeof rangeSliderReducers>(); | ||
const dispatch = useEmbeddableDispatch(); | ||
|
||
// useStateObservable to get component state from Embeddable | ||
const { loading, min, max, fieldFormatter } = useStateObservable<RangeSliderComponentState>( | ||
componentStateSubject, | ||
componentStateSubject.getValue() | ||
); | ||
|
||
const { value = ['', ''], id, title } = useEmbeddableSelector((state) => state); | ||
|
||
const [selectedValue, setSelectedValue] = useState<RangeValue>(value || ['', '']); | ||
|
||
const onChangeComplete = useCallback( | ||
(range: RangeValue) => { | ||
dispatch(selectRange(range)); | ||
setSelectedValue(range); | ||
}, | ||
[selectRange, setSelectedValue, dispatch] | ||
); | ||
|
||
return ( | ||
<RangeSliderPopover | ||
id={id} | ||
isLoading={loading} | ||
min={min} | ||
max={max} | ||
title={title} | ||
value={selectedValue} | ||
onChange={onChangeComplete} | ||
fieldFormatter={fieldFormatter} | ||
/> | ||
); | ||
}; |
57 changes: 57 additions & 0 deletions
57
src/plugins/controls/public/control_types/range_slider/range_slider.scss
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,57 @@ | ||
.rangeSlider__popoverOverride { | ||
height: 100%; | ||
max-width: 100%; | ||
width: 100%; | ||
} | ||
|
||
@include euiBreakpoint('m', 'l', 'xl') { | ||
.rangeSlider__panelOverride { | ||
min-width: $euiSizeXXL * 12; | ||
} | ||
} | ||
|
||
.rangeSlider__anchorOverride { | ||
>div { | ||
height: 100%; | ||
} | ||
} | ||
|
||
.rangeSliderAnchor__button { | ||
display: flex; | ||
align-items: center; | ||
width: 100%; | ||
height: 100%; | ||
justify-content: space-between; | ||
background-color: $euiFormBackgroundColor; | ||
@include euiFormControlSideBorderRadius($euiFormControlBorderRadius, $side: 'right', $internal: true); | ||
|
||
.euiToolTipAnchor { | ||
width: 100%; | ||
} | ||
|
||
.rangeSliderAnchor__delimiter { | ||
background-color: unset; | ||
} | ||
.rangeSliderAnchor__fieldNumber { | ||
font-weight: $euiFontWeightBold; | ||
box-shadow: none; | ||
text-align: center; | ||
background-color: unset; | ||
|
||
&::placeholder { | ||
font-weight: $euiFontWeightRegular; | ||
color: $euiColorMediumShade; | ||
text-decoration: none; | ||
} | ||
} | ||
|
||
.rangeSliderAnchor__fieldNumber--invalid { | ||
text-decoration: line-through; | ||
font-weight: $euiFontWeightRegular; | ||
color: $euiColorMediumShade; | ||
} | ||
|
||
.rangeSliderAnchor__spinner { | ||
padding-right: $euiSizeS; | ||
} | ||
} |
Oops, something went wrong.