|
|
|
@ -7,8 +7,18 @@ import { deleteTask, getStaticFile, getTasks, queryApi } from '../../../services
|
|
|
|
|
import { getDashboardByUid, getDatasources } from '../../../services/grafana_backend_service'; |
|
|
|
|
|
|
|
|
|
import { contextSrv } from 'grafana/app/core/core'; |
|
|
|
|
import { css } from '@emotion/css'; |
|
|
|
|
|
|
|
|
|
import { Table, Button, HorizontalGroup, Modal, LoadingPlaceholder } from '@grafana/ui'; |
|
|
|
|
import { |
|
|
|
|
Table, |
|
|
|
|
Button, |
|
|
|
|
HorizontalGroup, |
|
|
|
|
VerticalGroup, |
|
|
|
|
Modal, |
|
|
|
|
LoadingPlaceholder, |
|
|
|
|
TimeRangeInput, |
|
|
|
|
useStyles2, |
|
|
|
|
} from '@grafana/ui'; |
|
|
|
|
import { |
|
|
|
|
PanelProps, |
|
|
|
|
toDataFrame, |
|
|
|
@ -20,6 +30,7 @@ import {
|
|
|
|
|
PanelModel, |
|
|
|
|
DataQuery, |
|
|
|
|
DataSourceSettings, |
|
|
|
|
TimeRange, |
|
|
|
|
} from '@grafana/data'; |
|
|
|
|
import { RefreshEvent } from '@grafana/runtime'; |
|
|
|
|
|
|
|
|
@ -41,6 +52,8 @@ export function Panel({ width, height, timeRange, eventBus }: Props) {
|
|
|
|
|
|
|
|
|
|
const [isModalOpen, setModalVisibility] = useState<boolean>(false); |
|
|
|
|
|
|
|
|
|
const [selectedTimeRange, setTimeRange] = useState<TimeRange>(timeRange); |
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
async function getCurrentDashboard(): Promise<any> { |
|
|
|
|
const currentDashboardUid = getDashboardUid(window.location.toString()); |
|
|
|
@ -143,9 +156,8 @@ export function Panel({ width, height, timeRange, eventBus }: Props) {
|
|
|
|
|
|
|
|
|
|
async function onAddTaskClick(): Promise<void> { |
|
|
|
|
const selectedQueries = _.filter(queries, (query: QueryTableRowConfig) => query.selected); |
|
|
|
|
|
|
|
|
|
// TODO: timerange picker
|
|
|
|
|
const timerange: [number, number] = [timeRange.from.unix(), timeRange.to.unix()]; |
|
|
|
|
const timerange: [number, number] = [selectedTimeRange.from.unix(), selectedTimeRange.to.unix()]; |
|
|
|
|
// TODO: move this function to API Service
|
|
|
|
|
await queryApi('/task', { |
|
|
|
|
method: 'POST', |
|
|
|
@ -350,6 +362,8 @@ export function Panel({ width, height, timeRange, eventBus }: Props) {
|
|
|
|
|
setQueries(updatedQueries); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const styles = useStyles2(getStyles); |
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
|
<div> |
|
|
|
|
{tasksDataFrame === null ? ( |
|
|
|
@ -368,25 +382,39 @@ export function Panel({ width, height, timeRange, eventBus }: Props) {
|
|
|
|
|
> |
|
|
|
|
Add Task |
|
|
|
|
</Button> |
|
|
|
|
<Modal title="Select Queries" isOpen={isModalOpen} onDismiss={onCloseModal}> |
|
|
|
|
<Modal |
|
|
|
|
title="Select Queries" |
|
|
|
|
isOpen={isModalOpen} |
|
|
|
|
onDismiss={onCloseModal} |
|
|
|
|
className={styles.calendarModal} |
|
|
|
|
> |
|
|
|
|
{queriesDataFrame === null ? ( |
|
|
|
|
// TODO: if datasource responds with error, display the error
|
|
|
|
|
<LoadingPlaceholder text="Loading..."></LoadingPlaceholder> |
|
|
|
|
) : ( |
|
|
|
|
<div> |
|
|
|
|
<Table width={width / 2 - 20} height={height - 40} data={queriesDataFrame} /> |
|
|
|
|
<HorizontalGroup justify="flex-end"> |
|
|
|
|
<Button |
|
|
|
|
variant="primary" |
|
|
|
|
aria-label="Add task button" |
|
|
|
|
style={{ marginTop: '8px' }} |
|
|
|
|
onClick={onAddTaskClick} |
|
|
|
|
// TODO: move to function
|
|
|
|
|
disabled={!queries?.filter((query: QueryTableRowConfig) => query.selected)?.length} |
|
|
|
|
> |
|
|
|
|
Add Task |
|
|
|
|
</Button> |
|
|
|
|
</HorizontalGroup> |
|
|
|
|
<VerticalGroup spacing="xs"> |
|
|
|
|
<HorizontalGroup justify="flex-start" spacing="md"> |
|
|
|
|
<TimeRangeInput |
|
|
|
|
value={selectedTimeRange} |
|
|
|
|
onChange={(newTimeRange) => { |
|
|
|
|
setTimeRange(newTimeRange); |
|
|
|
|
}} |
|
|
|
|
/> |
|
|
|
|
</HorizontalGroup> |
|
|
|
|
<Table width={width / 2 - 20} height={height - 40} data={queriesDataFrame} /> |
|
|
|
|
<HorizontalGroup justify="flex-end" spacing="md"> |
|
|
|
|
<Button |
|
|
|
|
variant="primary" |
|
|
|
|
aria-label="Add task button" |
|
|
|
|
onClick={onAddTaskClick} |
|
|
|
|
// TODO: move to function
|
|
|
|
|
disabled={!queries?.filter((query: QueryTableRowConfig) => query.selected)?.length} |
|
|
|
|
> |
|
|
|
|
Add Task |
|
|
|
|
</Button> |
|
|
|
|
</HorizontalGroup> |
|
|
|
|
</VerticalGroup> |
|
|
|
|
</div> |
|
|
|
|
)} |
|
|
|
|
</Modal> |
|
|
|
@ -396,3 +424,13 @@ export function Panel({ width, height, timeRange, eventBus }: Props) {
|
|
|
|
|
</div> |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const getStyles = () => ({ |
|
|
|
|
calendarModal: css` |
|
|
|
|
section { |
|
|
|
|
position: fixed; |
|
|
|
|
top: 20%; |
|
|
|
|
z-index: 1061; |
|
|
|
|
} |
|
|
|
|
`,
|
|
|
|
|
}); |
|
|
|
|