Browse Source

lint:fix

pull/5/head
rozetko 2 years ago
parent
commit
e1f8b071ed
  1. 31
      src/panels/corpglory-dataexporter-panel/components/Panel.tsx
  2. 2
      src/panels/corpglory-dataexporter-panel/types.ts
  3. 2
      src/services/grafana_backend_service.ts
  4. 2
      src/utils/index.ts

31
src/panels/corpglory-dataexporter-panel/components/Panel.tsx

@ -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 {

2
src/panels/corpglory-dataexporter-panel/types.ts

@ -1,4 +1,4 @@
import { DataQuery, DataSourceRef, DataSourceSettings, PanelModel } from "@grafana/data"; import { DataQuery, DataSourceRef, DataSourceSettings, PanelModel } from '@grafana/data';
export interface PanelOptions {} export interface PanelOptions {}

2
src/services/grafana_backend_service.ts

@ -1,4 +1,4 @@
import { getBackendSrv } from "@grafana/runtime"; import { getBackendSrv } from '@grafana/runtime';
export async function getDatasources() { export async function getDatasources() {
const backendSrv = getBackendSrv(); const backendSrv = getBackendSrv();

2
src/utils/index.ts

@ -13,7 +13,7 @@ export function getDashboardUid(url: string): string {
} else { } else {
return matches[1]; return matches[1];
} }
}; }
export function convertTimestampToDate(timestamp: number): string { export function convertTimestampToDate(timestamp: number): string {
const options: Intl.DateTimeFormatOptions = { const options: Intl.DateTimeFormatOptions = {

Loading…
Cancel
Save