forked from elastic/kibana
-
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.
[Dataset quality] Filters for timeRange, integrations and datasetQuery (
elastic#176611) Closes elastic#170242 --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
- Loading branch information
Showing
37 changed files
with
784 additions
and
107 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# @kbn/timerange | ||
|
||
This package shares a set of utilities for working with timeranges. | ||
|
||
## Utils | ||
|
||
### getDateRange | ||
|
||
This function return a timestamp for `startDate` and `endDate` of a given date range. | ||
|
||
```tsx | ||
import { getDateRange } from '@kbn/timerange'; | ||
|
||
const { startDate, endDate } = getDateRange({ from: 'now-24h', to: 'now' }); | ||
``` | ||
|
||
### getDateISORange | ||
|
||
This function return an ISO string for `startDate` and `endDate` of a given date range. | ||
|
||
```tsx | ||
import { getDateRange } from '@kbn/timerange'; | ||
|
||
const { startDate, endDate } = getDateISORange({ from: 'now-24h', to: 'now' }); | ||
``` |
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,9 @@ | ||
/* | ||
* 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 { getDateRange, getDateISORange } from './src'; |
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. | ||
*/ | ||
|
||
module.exports = { | ||
preset: '@kbn/test', | ||
rootDir: '../..', | ||
roots: ['<rootDir>/packages/kbn-timerange'], | ||
}; |
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,5 @@ | ||
{ | ||
"type": "shared-common", | ||
"id": "@kbn/timerange", | ||
"owner": "@elastic/obs-ux-logs-team" | ||
} |
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,6 @@ | ||
{ | ||
"name": "@kbn/timerange", | ||
"private": true, | ||
"version": "1.0.0", | ||
"license": "SSPL-1.0 OR Elastic License 2.0" | ||
} |
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,53 @@ | ||
/* | ||
* 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 datemath from '@kbn/datemath'; | ||
|
||
function getParsedDate(rawDate?: string, options = {}) { | ||
if (rawDate) { | ||
const parsed = datemath.parse(rawDate, options); | ||
if (parsed && parsed.isValid()) { | ||
return parsed.toDate(); | ||
} | ||
} | ||
} | ||
|
||
function getRanges({ from, to }: { from: string; to: string }) { | ||
const start = getParsedDate(from); | ||
const end = getParsedDate(to, { roundUp: true }); | ||
|
||
if (!start || !end || start > end) { | ||
throw new Error(`Invalid Dates: from: ${from}, to: ${to}`); | ||
} | ||
|
||
const startDate = start.toISOString(); | ||
const endDate = end.toISOString(); | ||
|
||
return { | ||
startDate, | ||
endDate, | ||
}; | ||
} | ||
|
||
export function getDateRange({ from, to }: { from: string; to: string }) { | ||
const { startDate, endDate } = getRanges({ from, to }); | ||
|
||
return { | ||
startDate: new Date(startDate).getTime(), | ||
endDate: new Date(endDate).getTime(), | ||
}; | ||
} | ||
|
||
export function getDateISORange({ from, to }: { from: string; to: string }) { | ||
const { startDate, endDate } = getRanges({ from, to }); | ||
|
||
return { | ||
startDate, | ||
endDate, | ||
}; | ||
} |
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,21 @@ | ||
{ | ||
"extends": "../../tsconfig.base.json", | ||
"compilerOptions": { | ||
"outDir": "target/types", | ||
"types": [ | ||
"jest", | ||
"node", | ||
"react" | ||
] | ||
}, | ||
"include": [ | ||
"**/*.ts", | ||
"**/*.tsx", | ||
], | ||
"exclude": [ | ||
"target/**/*" | ||
], | ||
"kbn_references": [ | ||
"@kbn/datemath", | ||
] | ||
} |
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
39 changes: 39 additions & 0 deletions
39
x-pack/plugins/dataset_quality/public/components/dataset_quality/filters/filter_bar.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,39 @@ | ||
/* | ||
* 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 React, { ChangeEvent, useCallback } from 'react'; | ||
import { EuiFieldSearch } from '@elastic/eui'; | ||
import { i18n } from '@kbn/i18n'; | ||
|
||
const placeholder = i18n.translate('xpack.datasetQuality.filterBar.placeholder', { | ||
defaultMessage: 'Filter datasets', | ||
}); | ||
|
||
export interface FilterBarComponentProps { | ||
query?: string; | ||
onQueryChange: (query: string) => void; | ||
} | ||
|
||
export const FilterBar = ({ query, onQueryChange }: FilterBarComponentProps) => { | ||
const onChange = useCallback( | ||
(event: ChangeEvent<HTMLInputElement>) => { | ||
onQueryChange(event.target.value); | ||
}, | ||
[onQueryChange] | ||
); | ||
|
||
return ( | ||
<EuiFieldSearch | ||
fullWidth | ||
placeholder={placeholder} | ||
value={query ?? ''} | ||
onChange={onChange} | ||
isClearable={true} | ||
aria-label={placeholder} | ||
/> | ||
); | ||
}; |
78 changes: 78 additions & 0 deletions
78
x-pack/plugins/dataset_quality/public/components/dataset_quality/filters/filters.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,78 @@ | ||
/* | ||
* 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, EuiFlexItem } from '@elastic/eui'; | ||
import { EuiSuperDatePicker } from '@elastic/eui'; | ||
import { UI_SETTINGS } from '@kbn/data-service'; | ||
import { TimePickerQuickRange } from '@kbn/observability-shared-plugin/public/hooks/use_quick_time_ranges'; | ||
import React, { useMemo } from 'react'; | ||
import { useDatasetQualityFilters } from '../../../hooks/use_dataset_quality_filters'; | ||
import { useKibanaContextForPlugin } from '../../../utils/use_kibana'; | ||
import { FilterBar } from './filter_bar'; | ||
import { IntegrationsSelector } from './integrations_selector'; | ||
|
||
// Allow for lazy loading | ||
// eslint-disable-next-line import/no-default-export | ||
export default function Filters() { | ||
const { | ||
timeRange, | ||
onTimeChange, | ||
onRefresh, | ||
onRefreshChange, | ||
isLoading, | ||
integrations, | ||
onIntegrationsChange, | ||
selectedQuery, | ||
onQueryChange, | ||
} = useDatasetQualityFilters(); | ||
|
||
const { | ||
services: { uiSettings }, | ||
} = useKibanaContextForPlugin(); | ||
|
||
const timePickerQuickRanges = uiSettings.get<TimePickerQuickRange[]>( | ||
UI_SETTINGS.TIMEPICKER_QUICK_RANGES | ||
); | ||
|
||
const commonlyUsedRanges = useMemo( | ||
() => | ||
timePickerQuickRanges.map(({ from, to, display }) => ({ | ||
start: from, | ||
end: to, | ||
label: display, | ||
})), | ||
[timePickerQuickRanges] | ||
); | ||
|
||
return ( | ||
<EuiFlexGroup gutterSize="s"> | ||
<EuiFlexItem> | ||
<FilterBar query={selectedQuery} onQueryChange={onQueryChange} /> | ||
</EuiFlexItem> | ||
<EuiFlexItem grow={false}> | ||
<IntegrationsSelector | ||
isLoading={isLoading} | ||
integrations={integrations} | ||
onIntegrationsChange={onIntegrationsChange} | ||
/> | ||
</EuiFlexItem> | ||
<EuiFlexItem grow={false}> | ||
<EuiSuperDatePicker | ||
start={timeRange.from} | ||
end={timeRange.to} | ||
onTimeChange={onTimeChange} | ||
onRefresh={onRefresh} | ||
onRefreshChange={onRefreshChange} | ||
commonlyUsedRanges={commonlyUsedRanges} | ||
showUpdateButton={true} | ||
isPaused={timeRange.refresh.isPaused} | ||
refreshInterval={timeRange.refresh.interval} | ||
/> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
); | ||
} |
Oops, something went wrong.