Browse Source

pass timezone to the api

pull/10/head
rozetko 1 year ago
parent
commit
a9184050f4
  1. 11
      src/panels/corpglory-dataexporter-panel/components/Panel.tsx
  2. 13
      src/utils/index.ts

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

@ -1,6 +1,6 @@
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 { deleteTask, getStaticFile, getTasks, queryApi } from '../../../services/api_service';
@ -43,7 +43,7 @@ const APP_ID = 'corpglory-dataexporter-app';
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
const [dashboard, setDashboard] = useState<any | 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 timeZoneName = convertTimeZoneTypeToName(timeZone);
if (contextSrv.user.orgRole !== OrgRole.Admin) {
// TODO: it shouldn't be overriten
setPanelStatus(PanelStatus.PERMISSION_ERROR);
@ -166,7 +168,7 @@ export function Panel({ width, height, timeRange, eventBus }: Props) {
return datasource;
}
async function onAddTaskClick(): Promise<void> {
async function onAddTaskClick(timeZoneName: string): Promise<void> {
const selectedQueries = _.filter(queries, (query: DashboardQuery) => query.selected);
const timerange: [number, number] = [selectedTimeRange.from.unix(), selectedTimeRange.to.unix()];
@ -185,6 +187,7 @@ export function Panel({ width, height, timeRange, eventBus }: Props) {
data: {
task,
url: window.location.toString(),
timeZoneName,
},
});
@ -437,7 +440,7 @@ export function Panel({ width, height, timeRange, eventBus }: Props) {
<Button
variant="primary"
aria-label="Add task button"
onClick={onAddTaskClick}
onClick={() => onAddTaskClick(timeZoneName)}
// TODO: move to function
disabled={!queries?.filter((query: DashboardQuery) => query.selected)?.length}
>

13
src/utils/index.ts

@ -1,4 +1,4 @@
import { AppEvents } from '@grafana/data';
import { AppEvents, TimeZone } from '@grafana/data';
// @ts-ignore
import appEvents from 'grafana/app/core/app_events';
@ -28,3 +28,14 @@ export function convertTimestampToDate(timestamp?: number): string {
new Date(timestamp).toLocaleString('en-GB', options):
'-';
}
export function convertTimeZoneTypeToName(timeZone: TimeZone): string {
switch (timeZone) {
case 'utc':
return 'Etc/UTC';
case 'browser':
return Intl.DateTimeFormat().resolvedOptions().timeZone;
default:
return timeZone;
}
}

Loading…
Cancel
Save