|
|
@ -1,12 +1,20 @@ |
|
|
|
import { PanelOptions, ExportTask, DashboardQuery, DatasourceType, ExportStatus, PanelStatus } from '../types'; |
|
|
|
import { |
|
|
|
|
|
|
|
PanelOptions, |
|
|
|
import { convertTimestampToDate, convertTimeZoneTypeToName, getDashboardUid } from '../../../utils'; |
|
|
|
ExportTask, |
|
|
|
import { CLOSE_ICON_BASE_64, DOWNLOAD_ICON_BASE_64, SELECT_ICON_BASE_64, UNSELECT_ICON_BASE_64 } from '../../../icons'; |
|
|
|
DashboardQuery, |
|
|
|
|
|
|
|
DatasourceType, |
|
|
|
|
|
|
|
ExportStatus, |
|
|
|
|
|
|
|
PanelStatus, |
|
|
|
|
|
|
|
Dashboard, |
|
|
|
|
|
|
|
} from '../types'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import { convertTimestampToDate, convertTimeZoneTypeToName, getCurrentDashboardUid } from '../../../utils'; |
|
|
|
|
|
|
|
import { CLOSE_ICON_BASE_64, OPTIONS_ICON_BASE_64, SELECT_ICON_BASE_64, UNSELECT_ICON_BASE_64 } from '../../../icons'; |
|
|
|
|
|
|
|
|
|
|
|
import { deleteTask, getStaticFile, getTasks, queryApi } from '../../../services/api_service'; |
|
|
|
import { deleteTask, getStaticFile, getTasks, queryApi } from '../../../services/api_service'; |
|
|
|
import { getDashboardByUid, getDatasources } from '../../../services/grafana_backend_service'; |
|
|
|
import { getDashboardByUid, getDatasources } from '../../../services/grafana_backend_service'; |
|
|
|
|
|
|
|
|
|
|
|
import { contextSrv } from 'grafana/app/core/core'; |
|
|
|
import { appEvents, contextSrv } from 'grafana/app/core/core'; |
|
|
|
import { css } from '@emotion/css'; |
|
|
|
import { css } from '@emotion/css'; |
|
|
|
|
|
|
|
|
|
|
|
import { |
|
|
|
import { |
|
|
@ -32,6 +40,7 @@ import { |
|
|
|
DataSourceSettings, |
|
|
|
DataSourceSettings, |
|
|
|
TimeRange, |
|
|
|
TimeRange, |
|
|
|
OrgRole, |
|
|
|
OrgRole, |
|
|
|
|
|
|
|
AppEvents, |
|
|
|
} from '@grafana/data'; |
|
|
|
} from '@grafana/data'; |
|
|
|
import { RefreshEvent } from '@grafana/runtime'; |
|
|
|
import { RefreshEvent } from '@grafana/runtime'; |
|
|
|
|
|
|
|
|
|
|
@ -44,8 +53,7 @@ const APP_ID = 'corpglory-dataexporter-app'; |
|
|
|
interface Props extends PanelProps<PanelOptions> {} |
|
|
|
interface Props extends PanelProps<PanelOptions> {} |
|
|
|
|
|
|
|
|
|
|
|
export function Panel({ width, height, timeRange, eventBus, timeZone }: Props) { |
|
|
|
export function Panel({ width, height, timeRange, eventBus, timeZone }: Props) { |
|
|
|
// TODO: Dashboard type
|
|
|
|
const [dashboard, setDashboard] = useState<Dashboard | null>(null); |
|
|
|
const [dashboard, setDashboard] = useState<any | null>(null); |
|
|
|
|
|
|
|
const [datasources, setDatasources] = useState<DataSourceSettings[] | null>(null); |
|
|
|
const [datasources, setDatasources] = useState<DataSourceSettings[] | null>(null); |
|
|
|
|
|
|
|
|
|
|
|
const [tasks, setTasks] = useState<ExportTask[] | null>(null); |
|
|
|
const [tasks, setTasks] = useState<ExportTask[] | null>(null); |
|
|
@ -59,17 +67,24 @@ export function Panel({ width, height, timeRange, eventBus, timeZone }: Props) { |
|
|
|
const [selectedTimeRange, setTimeRange] = useState<TimeRange>(timeRange); |
|
|
|
const [selectedTimeRange, setTimeRange] = useState<TimeRange>(timeRange); |
|
|
|
|
|
|
|
|
|
|
|
const [panelStatus, setPanelStatus] = useState<PanelStatus>(PanelStatus.LOADING); |
|
|
|
const [panelStatus, setPanelStatus] = useState<PanelStatus>(PanelStatus.LOADING); |
|
|
|
|
|
|
|
function setPanelStatusWithValidate(status: PanelStatus): void { |
|
|
|
|
|
|
|
if (panelStatus === PanelStatus.PERMISSION_ERROR) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return setPanelStatus(status); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const [errorMessage, setErrorMessage] = useState<string | null>(null); |
|
|
|
|
|
|
|
|
|
|
|
const timeZoneName = convertTimeZoneTypeToName(timeZone); |
|
|
|
const timeZoneName = convertTimeZoneTypeToName(timeZone); |
|
|
|
|
|
|
|
|
|
|
|
if (contextSrv.user.orgRole !== OrgRole.Admin) { |
|
|
|
if (contextSrv.user.orgRole !== OrgRole.Admin) { |
|
|
|
// TODO: it shouldn't be overriten
|
|
|
|
setPanelStatusWithValidate(PanelStatus.PERMISSION_ERROR); |
|
|
|
setPanelStatus(PanelStatus.PERMISSION_ERROR); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
useEffect(() => { |
|
|
|
async function getCurrentDashboard(): Promise<any> { |
|
|
|
async function getCurrentDashboard(): Promise<any> { |
|
|
|
const currentDashboardUid = getDashboardUid(window.location.toString()); |
|
|
|
const currentDashboardUid = getCurrentDashboardUid(); |
|
|
|
|
|
|
|
|
|
|
|
return getDashboardByUid(currentDashboardUid); |
|
|
|
return getDashboardByUid(currentDashboardUid); |
|
|
|
} |
|
|
|
} |
|
|
@ -86,12 +101,30 @@ export function Panel({ width, height, timeRange, eventBus, timeZone }: Props) { |
|
|
|
}, []); |
|
|
|
}, []); |
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
useEffect(() => { |
|
|
|
|
|
|
|
if (tasks === null) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
const dataFrame = getDataFrameForTaskTable(tasks); |
|
|
|
|
|
|
|
setTasksDataFrame(dataFrame); |
|
|
|
|
|
|
|
}, [tasks]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(fetchTasks, []); // eslint-disable-line react-hooks/exhaustive-deps
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
|
|
|
if (queries === null) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
setQueriesDataFrame(getDataFrameForQueriesTable(queries)); |
|
|
|
|
|
|
|
}, [queries]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function updateQueries(): Promise<void> { |
|
|
|
if (!dashboard || !datasources) { |
|
|
|
if (!dashboard || !datasources) { |
|
|
|
|
|
|
|
console.warn(`Can't update queries if there is no dashboard or datasources`); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
dashboard.panels.forEach((panel: PanelModel) => { |
|
|
|
|
|
|
|
const queries: DashboardQuery[] = []; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const queries: DashboardQuery[] = []; |
|
|
|
|
|
|
|
dashboard.panels?.forEach((panel: PanelModel) => { |
|
|
|
// @ts-ignore
|
|
|
|
// @ts-ignore
|
|
|
|
if (panel.type === PANEL_ID) { |
|
|
|
if (panel.type === PANEL_ID) { |
|
|
|
return; |
|
|
|
return; |
|
|
@ -108,47 +141,32 @@ export function Panel({ width, height, timeRange, eventBus, timeZone }: Props) { |
|
|
|
} |
|
|
|
} |
|
|
|
queries.push({ selected: false, target, panel, datasource }); |
|
|
|
queries.push({ selected: false, target, panel, datasource }); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
setQueries(queries); |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
}, [dashboard, datasources]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
|
|
setQueries(queries); |
|
|
|
|
|
|
|
} |
|
|
|
useEffect(() => { |
|
|
|
|
|
|
|
if (tasks === null) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
const dataFrame = getDataFrameForTaskTable(tasks); |
|
|
|
|
|
|
|
setTasksDataFrame(dataFrame); |
|
|
|
|
|
|
|
}, [tasks]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(refresh, []); // eslint-disable-line react-hooks/exhaustive-deps
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
function fetchTasks(): void { |
|
|
|
if (queries === null) { |
|
|
|
const dashboardUid = getCurrentDashboardUid(); |
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
setQueriesDataFrame(getDataFrameForQueriesTable(queries)); |
|
|
|
|
|
|
|
}, [queries]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function refresh(): void { |
|
|
|
getTasks(dashboardUid) |
|
|
|
getTasks() |
|
|
|
|
|
|
|
.then((tasks) => { |
|
|
|
.then((tasks) => { |
|
|
|
setTasks(tasks); |
|
|
|
setTasks(tasks); |
|
|
|
setPanelStatus(PanelStatus.OK); |
|
|
|
setPanelStatusWithValidate(PanelStatus.OK); |
|
|
|
for (let task of tasks) { |
|
|
|
for (let task of tasks) { |
|
|
|
if (task.progress?.status === ExportStatus.EXPORTING) { |
|
|
|
if (task.progress?.status === ExportStatus.EXPORTING) { |
|
|
|
setTimeout(refresh, 1000); |
|
|
|
setTimeout(fetchTasks, 1000); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
.catch((err) => { |
|
|
|
.catch((err) => { |
|
|
|
setPanelStatus(PanelStatus.DATASOURCE_ERROR); |
|
|
|
setPanelStatusWithValidate(PanelStatus.DATASOURCE_ERROR); |
|
|
|
console.error('some error', err); |
|
|
|
console.error('some error', err); |
|
|
|
|
|
|
|
setErrorMessage(`${err.name}: ${err.message}`); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
eventBus.subscribe(RefreshEvent, refresh); |
|
|
|
eventBus.subscribe(RefreshEvent, fetchTasks); |
|
|
|
|
|
|
|
|
|
|
|
function getDatasourceByUid(uid?: string): DataSourceSettings | undefined { |
|
|
|
function getDatasourceByUid(uid?: string): DataSourceSettings | undefined { |
|
|
|
if (_.isNil(uid)) { |
|
|
|
if (_.isNil(uid)) { |
|
|
@ -172,7 +190,10 @@ export function Panel({ width, height, timeRange, eventBus, timeZone }: Props) { |
|
|
|
const selectedQueries = _.filter(queries, (query: DashboardQuery) => query.selected); |
|
|
|
const selectedQueries = _.filter(queries, (query: DashboardQuery) => query.selected); |
|
|
|
const timerange: [number, number] = [selectedTimeRange.from.unix(), selectedTimeRange.to.unix()]; |
|
|
|
const timerange: [number, number] = [selectedTimeRange.from.unix(), selectedTimeRange.to.unix()]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const dashboardUid = getCurrentDashboardUid(); |
|
|
|
|
|
|
|
|
|
|
|
const task: ExportTask = { |
|
|
|
const task: ExportTask = { |
|
|
|
|
|
|
|
dashboardUid, |
|
|
|
// @ts-ignore
|
|
|
|
// @ts-ignore
|
|
|
|
username: contextSrv.user.name, |
|
|
|
username: contextSrv.user.name, |
|
|
|
timeRange: { |
|
|
|
timeRange: { |
|
|
@ -191,7 +212,7 @@ export function Panel({ width, height, timeRange, eventBus, timeZone }: Props) { |
|
|
|
}, |
|
|
|
}, |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
refresh(); |
|
|
|
fetchTasks(); |
|
|
|
|
|
|
|
|
|
|
|
onCloseModal(); |
|
|
|
onCloseModal(); |
|
|
|
unselectAllQueries(); |
|
|
|
unselectAllQueries(); |
|
|
@ -205,6 +226,7 @@ export function Panel({ width, height, timeRange, eventBus, timeZone }: Props) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function openDatasourceModal(): void { |
|
|
|
function openDatasourceModal(): void { |
|
|
|
|
|
|
|
updateQueries(); |
|
|
|
setTimeRange(timeRange); |
|
|
|
setTimeRange(timeRange); |
|
|
|
setModalVisibility(true); |
|
|
|
setModalVisibility(true); |
|
|
|
} |
|
|
|
} |
|
|
@ -271,80 +293,75 @@ export function Panel({ width, height, timeRange, eventBus, timeZone }: Props) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function getDataFrameForTaskTable(tasks: ExportTask[]): DataFrame { |
|
|
|
function getDataFrameForTaskTable(tasks: ExportTask[]): DataFrame { |
|
|
|
|
|
|
|
const sortedTasks = _.orderBy(tasks, (task) => task.progress?.time, 'desc'); |
|
|
|
const dataFrame = toDataFrame({ |
|
|
|
const dataFrame = toDataFrame({ |
|
|
|
name: 'A', |
|
|
|
name: 'A', |
|
|
|
fields: [ |
|
|
|
fields: [ |
|
|
|
{ |
|
|
|
{ |
|
|
|
name: 'Time', |
|
|
|
name: 'Status Updated At', |
|
|
|
type: FieldType.number, |
|
|
|
type: FieldType.number, |
|
|
|
values: _.map(tasks, (task) => convertTimestampToDate(task.progress?.time)), |
|
|
|
values: _.map(sortedTasks, (task) => convertTimestampToDate(task.progress?.time)), |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
name: 'From', |
|
|
|
|
|
|
|
type: FieldType.number, |
|
|
|
|
|
|
|
values: _.map(sortedTasks, (task) => convertTimestampToDate(task.timeRange.from)), |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
name: 'To', |
|
|
|
|
|
|
|
type: FieldType.number, |
|
|
|
|
|
|
|
values: _.map(sortedTasks, (task) => convertTimestampToDate(task.timeRange.to)), |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ |
|
|
|
{ |
|
|
|
name: 'User', |
|
|
|
name: 'User', |
|
|
|
type: FieldType.string, |
|
|
|
type: FieldType.string, |
|
|
|
values: _.map(tasks, (task) => task.username), |
|
|
|
values: _.map(sortedTasks, (task) => task.username), |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ |
|
|
|
{ |
|
|
|
name: 'Datasource', |
|
|
|
name: 'Datasource', |
|
|
|
type: FieldType.string, |
|
|
|
type: FieldType.string, |
|
|
|
values: _.map(tasks, (task) => task.queries.map((query) => query.datasource?.name).join(',')), |
|
|
|
values: _.map(sortedTasks, (task) => task.queries.map((query) => query.datasource?.name).join(',')), |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ |
|
|
|
{ |
|
|
|
name: 'Exported Rows', |
|
|
|
name: 'Exported Rows', |
|
|
|
type: FieldType.number, |
|
|
|
type: FieldType.number, |
|
|
|
values: _.map(tasks, (task) => task.progress?.exportedRowsCount), |
|
|
|
values: _.map(sortedTasks, (task) => task.progress?.exportedRowsCount), |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ |
|
|
|
{ |
|
|
|
name: 'Progress', |
|
|
|
name: 'Progress', |
|
|
|
type: FieldType.string, |
|
|
|
type: FieldType.string, |
|
|
|
values: _.map(tasks, (task) => `${((task.progress?.progress || 0) * 100).toFixed(0)}%`), |
|
|
|
values: _.map(sortedTasks, (task) => `${((task.progress?.progress || 0) * 100).toFixed(0)}%`), |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ |
|
|
|
{ |
|
|
|
name: 'Status', |
|
|
|
name: 'Status', |
|
|
|
type: FieldType.string, |
|
|
|
type: FieldType.string, |
|
|
|
values: _.map(tasks, (task) => task.progress?.status), |
|
|
|
values: _.map(sortedTasks, (task) => task.progress?.status), |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ |
|
|
|
{ |
|
|
|
name: 'Error', |
|
|
|
name: 'Error', |
|
|
|
type: FieldType.string, |
|
|
|
type: FieldType.string, |
|
|
|
values: _.map(tasks, (task) => task.progress?.errorMessage || '-'), |
|
|
|
values: _.map(sortedTasks, (task) => task.progress?.errorMessage || '-'), |
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
name: 'Download CSV', |
|
|
|
|
|
|
|
type: FieldType.string, |
|
|
|
|
|
|
|
values: _.map(tasks, () => `data:image/png;base64,${DOWNLOAD_ICON_BASE_64}`), |
|
|
|
|
|
|
|
config: { |
|
|
|
|
|
|
|
custom: { |
|
|
|
|
|
|
|
filterable: false, |
|
|
|
|
|
|
|
displayMode: 'image', |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
links: [ |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
targetBlank: false, |
|
|
|
|
|
|
|
title: 'Download', |
|
|
|
|
|
|
|
url: '#', |
|
|
|
|
|
|
|
onClick: (event: DataLinkClickEvent) => onDownloadClick(event), |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
}, |
|
|
|
}, |
|
|
|
{ |
|
|
|
{ |
|
|
|
name: 'Delete task', |
|
|
|
name: 'Actions', |
|
|
|
type: FieldType.string, |
|
|
|
type: FieldType.string, |
|
|
|
values: _.map(tasks, () => `data:image/png;base64,${CLOSE_ICON_BASE_64}`), |
|
|
|
values: _.map(sortedTasks, (task) => { |
|
|
|
|
|
|
|
switch (task.progress?.status) { |
|
|
|
|
|
|
|
case ExportStatus.FINISHED: |
|
|
|
|
|
|
|
return `data:image/png;base64,${OPTIONS_ICON_BASE_64}`; |
|
|
|
|
|
|
|
case ExportStatus.ERROR: |
|
|
|
|
|
|
|
return `data:image/png;base64,${CLOSE_ICON_BASE_64}`; |
|
|
|
|
|
|
|
case ExportStatus.EXPORTING: |
|
|
|
|
|
|
|
return ``; |
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
throw new Error(`Unknown exporting status: ${task.progress?.status}`); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}), |
|
|
|
config: { |
|
|
|
config: { |
|
|
|
custom: { |
|
|
|
custom: { |
|
|
|
filterable: false, |
|
|
|
filterable: false, |
|
|
|
displayMode: 'image', |
|
|
|
displayMode: 'image', |
|
|
|
}, |
|
|
|
}, |
|
|
|
links: [ |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
targetBlank: false, |
|
|
|
|
|
|
|
title: 'Delete', |
|
|
|
|
|
|
|
url: '#', |
|
|
|
|
|
|
|
onClick: (event: DataLinkClickEvent) => onDeleteClick(event), |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
], |
|
|
|
], |
|
|
@ -359,22 +376,57 @@ export function Panel({ width, height, timeRange, eventBus, timeZone }: Props) { |
|
|
|
theme: createTheme(), |
|
|
|
theme: createTheme(), |
|
|
|
replaceVariables: (value: string) => value, |
|
|
|
replaceVariables: (value: string) => value, |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// @ts-expect-error
|
|
|
|
|
|
|
|
dataFrames[0].fields[9].getLinks = (cell: { valueRowIndex: number }) => { |
|
|
|
|
|
|
|
const rowIndex = cell.valueRowIndex; |
|
|
|
|
|
|
|
const task = _.find(sortedTasks, (task, idx) => idx === rowIndex); |
|
|
|
|
|
|
|
if (!task) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
switch (task.progress?.status) { |
|
|
|
|
|
|
|
case ExportStatus.FINISHED: |
|
|
|
|
|
|
|
return [ |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
targetBlank: false, |
|
|
|
|
|
|
|
title: 'Download', |
|
|
|
|
|
|
|
url: '#', |
|
|
|
|
|
|
|
onClick: () => onDownloadClick(task), |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
targetBlank: false, |
|
|
|
|
|
|
|
title: 'Delete', |
|
|
|
|
|
|
|
url: '#', |
|
|
|
|
|
|
|
onClick: () => onDeleteClick(task), |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
]; |
|
|
|
|
|
|
|
case ExportStatus.ERROR: |
|
|
|
|
|
|
|
return [ |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
targetBlank: false, |
|
|
|
|
|
|
|
title: 'Delete', |
|
|
|
|
|
|
|
url: '#', |
|
|
|
|
|
|
|
onClick: () => onDeleteClick(task), |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
]; |
|
|
|
|
|
|
|
case ExportStatus.EXPORTING: |
|
|
|
|
|
|
|
return []; |
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
throw new Error(`Unknown exporting status: ${task.progress?.status}`); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
return dataFrames[0]; |
|
|
|
return dataFrames[0]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async function onDeleteClick(e: DataLinkClickEvent): Promise<void> { |
|
|
|
async function onDeleteClick(taskToDelete: ExportTask): Promise<void> { |
|
|
|
const rowIndex = e.origin.rowIndex; |
|
|
|
await deleteTask(taskToDelete?.id); |
|
|
|
|
|
|
|
|
|
|
|
const task = _.find(tasks, (task, idx) => idx === rowIndex); |
|
|
|
|
|
|
|
await deleteTask(task?.id); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const filteredTasks = _.filter(tasks, (task, idx) => idx !== rowIndex); |
|
|
|
const filteredTasks = _.filter(tasks, (task) => task.id !== taskToDelete.id); |
|
|
|
setTasks(filteredTasks); |
|
|
|
setTasks(filteredTasks); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function onDownloadClick(e: DataLinkClickEvent): void { |
|
|
|
function onDownloadClick(task: ExportTask): void { |
|
|
|
const rowIndex = e.origin.rowIndex; |
|
|
|
appEvents.emit(AppEvents.alertSuccess, ['CSV has started downloading...']); |
|
|
|
const task = _.find(tasks, (task, idx) => idx === rowIndex); |
|
|
|
|
|
|
|
getStaticFile(task?.id); |
|
|
|
getStaticFile(task?.id); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -396,34 +448,33 @@ export function Panel({ width, height, timeRange, eventBus, timeZone }: Props) { |
|
|
|
<div> |
|
|
|
<div> |
|
|
|
<p>Datasource is unavailable.</p> |
|
|
|
<p>Datasource is unavailable.</p> |
|
|
|
<div> |
|
|
|
<div> |
|
|
|
Click <a href={`/plugins/${APP_ID}`}>here</a> to configure DataExporter. |
|
|
|
If you have not setup the plugin click |
|
|
|
|
|
|
|
<a className={styles.customLink} href={`/plugins/${APP_ID}`}> |
|
|
|
|
|
|
|
here |
|
|
|
|
|
|
|
</a> |
|
|
|
|
|
|
|
to configure DataExporter. |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
{/* TODO: display error message? */} |
|
|
|
<p style={{ marginTop: '16px' }}>{errorMessage}</p> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
); |
|
|
|
); |
|
|
|
const permissionErrorDiv = ( |
|
|
|
const permissionErrorDiv = ( |
|
|
|
<div> |
|
|
|
<div> |
|
|
|
<p>Permission Error.</p> |
|
|
|
<p> Permission Error. </p> |
|
|
|
<div> DataExporter panel availabel only for Admins </div> |
|
|
|
<div> DataExporter panel available only for Admins. </div> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
); |
|
|
|
); |
|
|
|
const mainDiv = ( |
|
|
|
const mainDiv = ( |
|
|
|
<div> |
|
|
|
<div> |
|
|
|
<Table width={width} height={height - 40} data={tasksDataFrame as DataFrame} /> |
|
|
|
<Table width={width} height={height - 40} data={tasksDataFrame as DataFrame} /> |
|
|
|
<HorizontalGroup justify="flex-end"> |
|
|
|
<HorizontalGroup justify="flex-end"> |
|
|
|
<Button |
|
|
|
<Button variant="primary" icon="plus" style={{ marginTop: '8px' }} onClick={openDatasourceModal}> |
|
|
|
variant="primary" |
|
|
|
|
|
|
|
aria-label="Rich history button" |
|
|
|
|
|
|
|
icon="plus" |
|
|
|
|
|
|
|
style={{ marginTop: '8px' }} |
|
|
|
|
|
|
|
onClick={openDatasourceModal} |
|
|
|
|
|
|
|
> |
|
|
|
|
|
|
|
Add Task |
|
|
|
Add Task |
|
|
|
</Button> |
|
|
|
</Button> |
|
|
|
<Modal title="Select Queries" isOpen={isModalOpen} onDismiss={onCloseModal} className={styles.calendarModal}> |
|
|
|
<Modal title="Select Queries" isOpen={isModalOpen} onDismiss={onCloseModal} className={styles.calendarModal}> |
|
|
|
{queriesDataFrame === null ? ( |
|
|
|
{queriesDataFrame === null ? ( |
|
|
|
// TODO: if datasource responds with error, display the error
|
|
|
|
<div> |
|
|
|
<LoadingPlaceholder text="Loading..."></LoadingPlaceholder> |
|
|
|
<p>There are no queries to export.</p> |
|
|
|
|
|
|
|
</div> |
|
|
|
) : ( |
|
|
|
) : ( |
|
|
|
<div> |
|
|
|
<div> |
|
|
|
<VerticalGroup spacing="xs"> |
|
|
|
<VerticalGroup spacing="xs"> |
|
|
@ -480,4 +531,11 @@ const getStyles = () => ({ |
|
|
|
z-index: 1061; |
|
|
|
z-index: 1061; |
|
|
|
} |
|
|
|
} |
|
|
|
`,
|
|
|
|
`,
|
|
|
|
|
|
|
|
customLink: css` |
|
|
|
|
|
|
|
color: #6e9fff; |
|
|
|
|
|
|
|
margin: 0 4px; |
|
|
|
|
|
|
|
&:hover { |
|
|
|
|
|
|
|
text-decoration: underline; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
`,
|
|
|
|
}); |
|
|
|
}); |
|
|
|