Chore: Improve some types (#64675)

* some type fixes

* few more

* more type fixes

* fix the majority of (window as any) calls

* don't make new variable for event

* few more

* MOAR
This commit is contained in:
Ashley Harrison
2023-03-14 09:51:44 +00:00
committed by GitHub
parent aade4b0bd2
commit 53186c14a4
73 changed files with 256 additions and 436 deletions

View File

@@ -43,16 +43,6 @@ function mockLocationHref(href: string) {
};
}
function setUTCTimeZone() {
(window as any).Intl.DateTimeFormat = () => {
return {
resolvedOptions: () => {
return { timeZone: 'UTC' };
},
};
};
}
const mockUid = 'abc123';
jest.mock('@grafana/runtime', () => {
const original = jest.requireActual('@grafana/runtime');
@@ -80,7 +70,13 @@ describe('ShareModal', () => {
beforeEach(() => {
const defaultTimeRange = getDefaultTimeRange();
setUTCTimeZone();
jest.spyOn(window.Intl, 'DateTimeFormat').mockImplementation(() => {
return {
resolvedOptions: () => {
return { timeZone: 'UTC' };
},
} as Intl.DateTimeFormat;
});
mockLocationHref('http://server/#!/test');
config.rendererAvailable = true;
config.bootData.user.orgId = 1;

View File

@@ -95,7 +95,7 @@ export class ShareModal extends React.Component<Props, State> {
reportInteraction('grafana_dashboards_share_modal_viewed');
}
onSelectTab = (t: any) => {
onSelectTab: React.ComponentProps<typeof ModalTabsHeader>['onChangeTab'] = (t) => {
this.setState((prevState) => ({ ...prevState, activeTab: t.value }));
};

View File

@@ -121,11 +121,11 @@ export function getLocalTimeZone() {
const utcOffset = '&tz=UTC' + encodeURIComponent(dateTime().format('Z'));
// Older browser does not the internationalization API
if (!(window as any).Intl) {
if (!window.Intl) {
return utcOffset;
}
const dateFormat = (window as any).Intl.DateTimeFormat();
const dateFormat = window.Intl.DateTimeFormat();
if (!dateFormat.resolvedOptions) {
return utcOffset;
}