|
|
@ -28,7 +28,6 @@ import * as _ from 'lodash'; |
|
|
|
interface Props extends PanelProps<PanelOptions> {} |
|
|
|
interface Props extends PanelProps<PanelOptions> {} |
|
|
|
|
|
|
|
|
|
|
|
export function Panel({ width, height, timeRange }: Props) { |
|
|
|
export function Panel({ width, height, timeRange }: 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); |
|
|
@ -45,8 +44,6 @@ export function Panel({ width, height, timeRange }: Props) { |
|
|
|
async function getCurrentDashboard(): Promise<any> { |
|
|
|
async function getCurrentDashboard(): Promise<any> { |
|
|
|
const currentDashboardUid = getDashboardUid(window.location.toString()); |
|
|
|
const currentDashboardUid = getDashboardUid(window.location.toString()); |
|
|
|
|
|
|
|
|
|
|
|
console.log(currentDashboardUid) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return getDashboardByUid(currentDashboardUid); |
|
|
|
return getDashboardByUid(currentDashboardUid); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -78,22 +75,17 @@ export function Panel({ width, height, timeRange }: Props) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
console.log(panel) |
|
|
|
panel.targets?.forEach((target: DataQuery) => { |
|
|
|
|
|
|
|
console.log('uid', target.datasource?.uid); |
|
|
|
panel.targets?.forEach( |
|
|
|
const datasource = getDatasourceByUid(target.datasource?.uid); |
|
|
|
(target: DataQuery) => { |
|
|
|
if (!datasource) { |
|
|
|
console.log('uid',target.datasource?.uid) |
|
|
|
return; |
|
|
|
const datasource = getDatasourceByUid(target.datasource?.uid); |
|
|
|
|
|
|
|
if (!datasource) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
queries.push({ ...target, selected: false, panel, datasource }); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
); |
|
|
|
queries.push({ ...target, selected: false, panel, datasource }); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
console.log('q', queries) |
|
|
|
|
|
|
|
setQueries(queries); |
|
|
|
setQueries(queries); |
|
|
|
}) |
|
|
|
}); |
|
|
|
}, [dashboard, datasources]); |
|
|
|
}, [dashboard, datasources]); |
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
useEffect(() => { |
|
|
@ -116,13 +108,12 @@ export function Panel({ width, height, timeRange }: Props) { |
|
|
|
}, []); |
|
|
|
}, []); |
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
useEffect(() => { |
|
|
|
if(queries === null) { |
|
|
|
if (queries === null) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
setQueriesDataFrame(getDataFrameForQueriesTable(queries)); |
|
|
|
setQueriesDataFrame(getDataFrameForQueriesTable(queries)); |
|
|
|
}, [queries]); |
|
|
|
}, [queries]); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getDatasourceByUid(uid?: string): DataSourceSettings | undefined { |
|
|
|
function getDatasourceByUid(uid?: string): DataSourceSettings | undefined { |
|
|
|
if (_.isNil(uid)) { |
|
|
|
if (_.isNil(uid)) { |
|
|
|
console.warn(`uid is required to get datasource`); |
|
|
|
console.warn(`uid is required to get datasource`); |
|
|
@ -170,9 +161,7 @@ export function Panel({ width, height, timeRange }: Props) { |
|
|
|
if (queries === null) { |
|
|
|
if (queries === null) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
setQueries(queries.map( |
|
|
|
setQueries(queries.map((query: QueryTableRowConfig) => ({ ...query, selected: false }))); |
|
|
|
(query: QueryTableRowConfig) => ({ ...query, selected: false }) |
|
|
|
|
|
|
|
)); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function openDatasourceModal(): void { |
|
|
|
function openDatasourceModal(): void { |
|
|
|