|
|
@ -1,6 +1,6 @@ |
|
|
|
import { PanelOptions, ExportTask, DashboardQuery, DatasourceType, ExportStatus, PanelStatus } from '../types'; |
|
|
|
import { PanelOptions, ExportTask, DashboardQuery, DatasourceType, ExportStatus, PanelStatus } from '../types'; |
|
|
|
|
|
|
|
|
|
|
|
import { convertTimestampToDate, getDashboardUid } from '../../../utils'; |
|
|
|
import { convertTimestampToDate, convertTimeZoneTypeToName, getDashboardUid } from '../../../utils'; |
|
|
|
import { CLOSE_ICON_BASE_64, DOWNLOAD_ICON_BASE_64, SELECT_ICON_BASE_64, UNSELECT_ICON_BASE_64 } from '../../../icons'; |
|
|
|
import { CLOSE_ICON_BASE_64, DOWNLOAD_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'; |
|
|
@ -43,7 +43,7 @@ const APP_ID = 'corpglory-dataexporter-app'; |
|
|
|
|
|
|
|
|
|
|
|
interface Props extends PanelProps<PanelOptions> {} |
|
|
|
interface Props extends PanelProps<PanelOptions> {} |
|
|
|
|
|
|
|
|
|
|
|
export function Panel({ width, height, timeRange, eventBus }: Props) { |
|
|
|
export function Panel({ width, height, timeRange, eventBus, timeZone }: Props) { |
|
|
|
// TODO: Dashboard type
|
|
|
|
// TODO: Dashboard type
|
|
|
|
const [dashboard, setDashboard] = useState<any | null>(null); |
|
|
|
const [dashboard, setDashboard] = useState<any | null>(null); |
|
|
|
const [datasources, setDatasources] = useState<DataSourceSettings[] | null>(null); |
|
|
|
const [datasources, setDatasources] = useState<DataSourceSettings[] | null>(null); |
|
|
@ -60,6 +60,8 @@ export function Panel({ width, height, timeRange, eventBus }: Props) { |
|
|
|
|
|
|
|
|
|
|
|
const [panelStatus, setPanelStatus] = useState<PanelStatus>(PanelStatus.LOADING); |
|
|
|
const [panelStatus, setPanelStatus] = useState<PanelStatus>(PanelStatus.LOADING); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const timeZoneName = convertTimeZoneTypeToName(timeZone); |
|
|
|
|
|
|
|
|
|
|
|
if (contextSrv.user.orgRole !== OrgRole.Admin) { |
|
|
|
if (contextSrv.user.orgRole !== OrgRole.Admin) { |
|
|
|
// TODO: it shouldn't be overriten
|
|
|
|
// TODO: it shouldn't be overriten
|
|
|
|
setPanelStatus(PanelStatus.PERMISSION_ERROR); |
|
|
|
setPanelStatus(PanelStatus.PERMISSION_ERROR); |
|
|
@ -100,12 +102,11 @@ export function Panel({ width, height, timeRange, eventBus }: Props) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
panel.targets?.forEach((target: DataQuery) => { |
|
|
|
panel.targets?.forEach((target: DataQuery) => { |
|
|
|
console.log('uid', target.datasource?.uid); |
|
|
|
|
|
|
|
const datasource = getDatasourceByUid(target.datasource?.uid); |
|
|
|
const datasource = getDatasourceByUid(target.datasource?.uid); |
|
|
|
if (!datasource) { |
|
|
|
if (!datasource) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
queries.push({ ...target, selected: false, panel, datasource }); |
|
|
|
queries.push({ selected: false, target, panel, datasource }); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
setQueries(queries); |
|
|
|
setQueries(queries); |
|
|
@ -167,7 +168,7 @@ export function Panel({ width, height, timeRange, eventBus }: Props) { |
|
|
|
return datasource; |
|
|
|
return datasource; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async function onAddTaskClick(): Promise<void> { |
|
|
|
async function onAddTaskClick(timeZoneName: string): Promise<void> { |
|
|
|
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()]; |
|
|
|
|
|
|
|
|
|
|
@ -186,6 +187,7 @@ export function Panel({ width, height, timeRange, eventBus }: Props) { |
|
|
|
data: { |
|
|
|
data: { |
|
|
|
task, |
|
|
|
task, |
|
|
|
url: window.location.toString(), |
|
|
|
url: window.location.toString(), |
|
|
|
|
|
|
|
timeZoneName, |
|
|
|
}, |
|
|
|
}, |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
@ -246,7 +248,7 @@ export function Panel({ width, height, timeRange, eventBus }: Props) { |
|
|
|
{ |
|
|
|
{ |
|
|
|
name: 'RefId', |
|
|
|
name: 'RefId', |
|
|
|
type: FieldType.string, |
|
|
|
type: FieldType.string, |
|
|
|
values: _.map(queries, (query) => query.refId), |
|
|
|
values: _.map(queries, (query) => query.target.refId), |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ |
|
|
|
{ |
|
|
|
name: 'Datasource', |
|
|
|
name: 'Datasource', |
|
|
@ -438,7 +440,7 @@ export function Panel({ width, height, timeRange, eventBus }: Props) { |
|
|
|
<Button |
|
|
|
<Button |
|
|
|
variant="primary" |
|
|
|
variant="primary" |
|
|
|
aria-label="Add task button" |
|
|
|
aria-label="Add task button" |
|
|
|
onClick={onAddTaskClick} |
|
|
|
onClick={() => onAddTaskClick(timeZoneName)} |
|
|
|
// TODO: move to function
|
|
|
|
// TODO: move to function
|
|
|
|
disabled={!queries?.filter((query: DashboardQuery) => query.selected)?.length} |
|
|
|
disabled={!queries?.filter((query: DashboardQuery) => query.selected)?.length} |
|
|
|
> |
|
|
|
> |
|
|
|