-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
feat(slo): SLO grouping values selector #202364
Merged
Merged
Changes from 13 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
f321de8
Update get SLO instances service
kdelemme 9aa59c8
Use settings to exclude stale
kdelemme 9283607
Use slo.groupBy instead of slo.groupings
kdelemme 986381f
Add copy button
kdelemme a414e4c
Redirect to new instance id
kdelemme 84866c0
Allow changing only from the main page
kdelemme ed53da2
Handle remote SLO
kdelemme 7ef2068
Fix tests
kdelemme 5165c30
fix type
kdelemme 6d04e55
Simplify conditional checks and move instance selector above
kdelemme 4a57b7c
Merge branch 'main' into slo/instance-selector
kdelemme 61c64f0
Fix storybook
kdelemme 4f45e83
Make sure the returned values are valid based on the other grouping f…
kdelemme 64c452d
Merge branch 'main' into slo/instance-selector
kdelemme 6a3a8ce
Add missing route spec
kdelemme 145d04a
adjust width a bit
shahzad31 a7911b6
Adding Instance title and changing order
kdelemme 09626b0
Fix layout
kdelemme 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
22 changes: 0 additions & 22 deletions
22
x-pack/packages/kbn-slo-schema/src/rest_specs/routes/get_instances.ts
This file was deleted.
Oops, something went wrong.
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
139 changes: 139 additions & 0 deletions
139
...olution/slo/public/pages/slo_details/components/groupings/slo_grouping_value_selector.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,139 @@ | ||
/* | ||
* 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; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { EuiButtonIcon, EuiComboBox, EuiComboBoxOptionOption, EuiCopy } from '@elastic/eui'; | ||
import { css } from '@emotion/react'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { ALL_VALUE, SLOWithSummaryResponse } from '@kbn/slo-schema'; | ||
import React, { useEffect, useState } from 'react'; | ||
import { useHistory, useLocation } from 'react-router-dom'; | ||
import useDebounce from 'react-use/lib/useDebounce'; | ||
import { SLOS_BASE_PATH } from '../../../../../common/locators/paths'; | ||
import { useFetchSloGroupings } from '../../hooks/use_fetch_slo_instances'; | ||
import { useGetQueryParams } from '../../hooks/use_get_query_params'; | ||
|
||
interface Props { | ||
slo: SLOWithSummaryResponse; | ||
groupingKey: string; | ||
value?: string; | ||
} | ||
|
||
interface Field { | ||
label: string; | ||
value: string; | ||
} | ||
|
||
export function SLOGroupingValueSelector({ slo, groupingKey, value }: Props) { | ||
const isAvailable = window.location.pathname.includes(SLOS_BASE_PATH); | ||
const { search: searchParams } = useLocation(); | ||
const history = useHistory(); | ||
const { remoteName } = useGetQueryParams(); | ||
|
||
const [currentValue, setCurrentValue] = useState<string | undefined>(value); | ||
const [options, setOptions] = useState<Field[]>([]); | ||
const [search, setSearch] = useState<string | undefined>(undefined); | ||
const [debouncedSearch, setDebouncedSearch] = useState<string | undefined>(undefined); | ||
useDebounce(() => setDebouncedSearch(search), 500, [search]); | ||
|
||
const { isLoading, isError, data } = useFetchSloGroupings({ | ||
sloId: slo.id, | ||
groupingKey, | ||
instanceId: slo.instanceId ?? ALL_VALUE, | ||
search: debouncedSearch, | ||
remoteName, | ||
}); | ||
|
||
useEffect(() => { | ||
if (data) { | ||
setSearch(undefined); | ||
setDebouncedSearch(undefined); | ||
setOptions(data.values.map(toField)); | ||
} | ||
}, [data]); | ||
|
||
const onChange = (selected: Array<EuiComboBoxOptionOption<string>>) => { | ||
const newValue = selected[0].value; | ||
if (!newValue) return; | ||
setCurrentValue(newValue); | ||
|
||
const urlSearchParams = new URLSearchParams(searchParams); | ||
const newGroupings = { ...slo.groupings, [groupingKey]: newValue }; | ||
urlSearchParams.set('instanceId', toInstanceId(newGroupings, slo.groupBy)); | ||
history.replace({ | ||
search: urlSearchParams.toString(), | ||
}); | ||
}; | ||
|
||
return ( | ||
<EuiComboBox<string> | ||
fullWidth={false} | ||
css={css` | ||
max-width: fit-content; | ||
`} | ||
isClearable={false} | ||
compressed | ||
prepend={groupingKey} | ||
append={ | ||
currentValue ? ( | ||
<EuiCopy textToCopy={currentValue}> | ||
{(copy) => ( | ||
<EuiButtonIcon | ||
data-test-subj="sloSLOGroupingValueSelectorButton" | ||
color="text" | ||
iconType="copyClipboard" | ||
onClick={copy} | ||
aria-label={i18n.translate('xpack.slo.sLOGroupingValueSelector.copyButton.label', { | ||
defaultMessage: 'Copy value to clipboard', | ||
})} | ||
/> | ||
)} | ||
</EuiCopy> | ||
) : ( | ||
<EuiButtonIcon | ||
data-test-subj="sloSLOGroupingValueSelectorButton" | ||
color="text" | ||
disabled={true} | ||
iconType="copyClipboard" | ||
aria-label={i18n.translate( | ||
'xpack.slo.sLOGroupingValueSelector.copyButton.noValueLabel', | ||
{ defaultMessage: 'Select a value before' } | ||
)} | ||
/> | ||
) | ||
} | ||
singleSelection={{ asPlainText: true }} | ||
options={options} | ||
isLoading={isLoading} | ||
isDisabled={isError || !isAvailable} | ||
placeholder={i18n.translate('xpack.slo.sLOGroupingValueSelector.placeholder', { | ||
defaultMessage: 'Select a group value', | ||
})} | ||
selectedOptions={currentValue ? [toField(currentValue)] : []} | ||
onChange={onChange} | ||
truncationProps={{ | ||
truncation: 'end', | ||
}} | ||
onSearchChange={(searchValue: string) => { | ||
if (searchValue !== '') { | ||
setSearch(searchValue); | ||
} | ||
}} | ||
/> | ||
); | ||
} | ||
|
||
function toField(value: string): Field { | ||
return { label: value, value }; | ||
} | ||
|
||
function toInstanceId( | ||
groupings: Record<string, string | number>, | ||
groupBy: string | string[] | ||
): string { | ||
const groups = [groupBy].flat(); | ||
return groups.map((group) => groupings[group]).join(','); | ||
} |
34 changes: 34 additions & 0 deletions
34
...bservability_solution/slo/public/pages/slo_details/components/groupings/slo_groupings.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,34 @@ | ||
/* | ||
* 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; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { EuiFlexGroup } from '@elastic/eui'; | ||
import { SLOWithSummaryResponse } from '@kbn/slo-schema'; | ||
import React from 'react'; | ||
import { SLOGroupingValueSelector } from './slo_grouping_value_selector'; | ||
|
||
export function SLOGroupings({ slo }: { slo: SLOWithSummaryResponse }) { | ||
const groupings = Object.entries(slo.groupings ?? {}); | ||
|
||
if (!groupings.length) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<EuiFlexGroup direction="row" gutterSize="s"> | ||
{groupings.map(([groupingKey, groupingValue]) => { | ||
return ( | ||
<SLOGroupingValueSelector | ||
key={groupingKey} | ||
slo={slo} | ||
groupingKey={groupingKey} | ||
value={String(groupingValue)} | ||
/> | ||
); | ||
})} | ||
</EuiFlexGroup> | ||
); | ||
} |
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.
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.
💬 This page can be displayed from the dashboard flyout, it's a little bit tricky to handle correctly so I've decided to disable the selection in this case.