Fix: reverted back to import * as module instead of using namespaces (#23069)

* Removed namespace declaration to prevent issues with external plugins.

* fixed imports and tests.
This commit is contained in:
Marcus Andersson 2020-03-25 17:01:43 +01:00 committed by GitHub
parent c4693378dd
commit f75387bd14
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 427 additions and 438 deletions

View File

@ -1,7 +1,7 @@
import sinon, { SinonFakeTimers } from 'sinon'; import sinon, { SinonFakeTimers } from 'sinon';
import each from 'lodash/each'; import each from 'lodash/each';
import { dateMath } from './datemath'; import * as dateMath from './datemath';
import { dateTime, DurationUnit, DateTime } from './moment_wrapper'; import { dateTime, DurationUnit, DateTime } from './moment_wrapper';
describe('DateMath', () => { describe('DateMath', () => {

View File

@ -5,8 +5,6 @@ import { TimeZone } from '../types/index';
const units: DurationUnit[] = ['y', 'M', 'w', 'd', 'h', 'm', 's']; const units: DurationUnit[] = ['y', 'M', 'w', 'd', 'h', 'm', 's'];
// eslint-disable-next-line @typescript-eslint/no-namespace
export namespace dateMath {
export function isMathString(text: string | DateTime | Date): boolean { export function isMathString(text: string | DateTime | Date): boolean {
if (!text) { if (!text) {
return false; return false;
@ -162,4 +160,3 @@ export namespace dateMath {
} }
return dateTime; return dateTime;
} }
}

View File

@ -1,6 +1,7 @@
// Names are too general to export globally // Names are too general to export globally
export { dateMath } from './datemath'; import * as dateMath from './datemath';
export { rangeUtil } from './rangeutil'; import * as rangeUtil from './rangeutil';
export * from './moment_wrapper'; export * from './moment_wrapper';
export * from './timezones'; export * from './timezones';
export * from './formats'; export * from './formats';
export { dateMath, rangeUtil };

View File

@ -3,11 +3,9 @@ import groupBy from 'lodash/groupBy';
import { RawTimeRange } from '../types/time'; import { RawTimeRange } from '../types/time';
import { dateMath } from './datemath'; import * as dateMath from './datemath';
import { isDateTime, DateTime } from './moment_wrapper'; import { isDateTime, DateTime } from './moment_wrapper';
// eslint-disable-next-line @typescript-eslint/no-namespace
export namespace rangeUtil {
const spans: { [key: string]: { display: string; section?: number } } = { const spans: { [key: string]: { display: string; section?: number } } = {
s: { display: 'second' }, s: { display: 'second' },
m: { display: 'minute' }, m: { display: 'minute' },
@ -182,4 +180,3 @@ export namespace rangeUtil {
const info = describeTextRange(value); const info = describeTextRange(value);
return info.invalid !== true; return info.invalid !== true;
}; };
}

View File

@ -5,11 +5,8 @@ export interface AppEvent<T> {
payload?: T; payload?: T;
} }
// eslint-disable-next-line @typescript-eslint/no-namespace
export namespace AppEvents {
export type AlertPayload = [string, string?]; export type AlertPayload = [string, string?];
export const alertSuccess = eventFactory<AlertPayload>('alert-success'); export const alertSuccess = eventFactory<AlertPayload>('alert-success');
export const alertWarning = eventFactory<AlertPayload>('alert-warning'); export const alertWarning = eventFactory<AlertPayload>('alert-warning');
export const alertError = eventFactory<AlertPayload>('alert-error'); export const alertError = eventFactory<AlertPayload>('alert-error');
}

View File

@ -24,5 +24,9 @@ export * from './theme';
export * from './orgs'; export * from './orgs';
export * from './flot'; export * from './flot';
export { AppEvent, AppEvents } from './appEvents'; import * as AppEvents from './appEvents';
export { PanelEvents } from './panelEvents'; import { AppEvent } from './appEvents';
export { AppEvent, AppEvents };
import * as PanelEvents from './panelEvents';
export { PanelEvents };

View File

@ -2,8 +2,6 @@ import { eventFactory } from './utils';
import { DataQueryError, DataQueryResponseData } from './datasource'; import { DataQueryError, DataQueryResponseData } from './datasource';
import { AngularPanelMenuItem } from './panel'; import { AngularPanelMenuItem } from './panel';
// eslint-disable-next-line @typescript-eslint/no-namespace
export namespace PanelEvents {
/** Payloads */ /** Payloads */
export interface PanelChangeViewPayload { export interface PanelChangeViewPayload {
fullscreen?: boolean; fullscreen?: boolean;
@ -26,4 +24,3 @@ export namespace PanelEvents {
export const panelTeardown = eventFactory('panel-teardown'); export const panelTeardown = eventFactory('panel-teardown');
export const render = eventFactory<any>('render'); export const render = eventFactory<any>('render');
export const viewModeChanged = eventFactory('view-mode-changed'); export const viewModeChanged = eventFactory('view-mode-changed');
}

View File

@ -2,7 +2,7 @@ import React, { ChangeEvent } from 'react';
import { HorizontalGroup } from '../Layout/Layout'; import { HorizontalGroup } from '../Layout/Layout';
import Forms from '../Forms'; import Forms from '../Forms';
import { MappingType, RangeMap, ValueMap, ValueMapping } from '@grafana/data'; import { MappingType, RangeMap, ValueMap, ValueMapping } from '@grafana/data';
import { styleMixins } from '../../themes/mixins'; import * as styleMixins from '../../themes/mixins';
import { useTheme } from '../../themes'; import { useTheme } from '../../themes';
import { FieldConfigItemHeaderTitle } from '../FieldConfigs/FieldConfigItemHeaderTitle'; import { FieldConfigItemHeaderTitle } from '../FieldConfigs/FieldConfigItemHeaderTitle';

View File

@ -3,4 +3,6 @@ import { getTheme, mockTheme } from './getTheme';
import { selectThemeVariant } from './selectThemeVariant'; import { selectThemeVariant } from './selectThemeVariant';
export { stylesFactory } from './stylesFactory'; export { stylesFactory } from './stylesFactory';
export { ThemeContext, withTheme, mockTheme, getTheme, selectThemeVariant, useTheme, mockThemeContext }; export { ThemeContext, withTheme, mockTheme, getTheme, selectThemeVariant, useTheme, mockThemeContext };
export { styleMixins } from './mixins';
import * as styleMixins from './mixins';
export { styleMixins };

View File

@ -3,8 +3,6 @@ import { selectThemeVariant } from './selectThemeVariant';
import { css } from 'emotion'; import { css } from 'emotion';
import { stylesFactory } from './stylesFactory'; import { stylesFactory } from './stylesFactory';
// eslint-disable-next-line @typescript-eslint/no-namespace
export namespace styleMixins {
export function cardChrome(theme: GrafanaTheme): string { export function cardChrome(theme: GrafanaTheme): string {
if (theme.isDark) { if (theme.isDark) {
return ` return `
@ -98,4 +96,3 @@ export namespace styleMixins {
`, `,
}; };
}); });
}

View File

@ -1,5 +1,3 @@
// eslint-disable-next-line @typescript-eslint/no-namespace
export namespace DOMUtil {
// Node.closest() polyfill // Node.closest() polyfill
if ('Element' in window && !Element.prototype.closest) { if ('Element' in window && !Element.prototype.closest) {
Element.prototype.closest = function(this: any, s: string) { Element.prototype.closest = function(this: any, s: string) {
@ -41,4 +39,3 @@ export namespace DOMUtil {
const offset = range.startOffset; const offset = range.startOffset;
return text!.substr(offset, 1); return text!.substr(offset, 1);
} }
}

View File

@ -6,5 +6,5 @@ export * from './tags';
export * from './measureText'; export * from './measureText';
export { default as ansicolor } from './ansicolor'; export { default as ansicolor } from './ansicolor';
// Export with a namespace import * as DOMUtil from './dom'; // includes Element.closest polyfil
export { DOMUtil } from './dom'; // includes Element.closest polyfil export { DOMUtil };