Skip to content

Commit

Permalink
Fix any warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
asimonok committed Feb 1, 2024
1 parent 6b2e425 commit 03b0304
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"overrides": [
{
"files": ["**/*.test.tsx", "**/*.test.ts"],
"files": ["**/*.test.tsx", "**/*.test.ts", "src/__testUtils__/**/*", "**/__mocks__/**/*"],
"rules": {
"@typescript-eslint/no-explicit-any": "off"
}
Expand Down
16 changes: 16 additions & 0 deletions src/@types/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* Extend window interface
*/
interface Window {
/**
* Gaode Maps
*/
// eslint-disable-next-line @typescript-eslint/naming-convention
AMap?: unknown;

/**
* Baidu Maps
*/
// eslint-disable-next-line @typescript-eslint/naming-convention
BMap?: unknown;
}
32 changes: 27 additions & 5 deletions src/components/EchartsPanel/EchartsPanel.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -348,10 +348,15 @@ describe('Panel', () => {
* Error handling section
*/
describe('Error handling', () => {
const error = {
message: 'some error',
stack: 'some stack',
};
class CustomError extends Error {
constructor(
public name: string,
public stack: string
) {
super(name);
}
}
const error = new CustomError('some error', 'stack');

beforeEach(() => {
jest.mocked(registerMaps).mockImplementationOnce(() => {
Expand All @@ -360,11 +365,28 @@ describe('Panel', () => {
});

it('Should show errors if unable to register maps', () => {
render(getComponent({ options: { map: Map.JSON } }));
jest.mocked(registerMaps).mockImplementationOnce(() => {
throw error;
});

render(
getComponent({
options: {
map: Map.JSON,
getOption: `return {
series: []
}`,
},
})
);
expect(screen.getByText(error.message)).toBeInTheDocument();
});

it('Should show stack if unable to register maps', () => {
jest.mocked(registerMaps).mockImplementationOnce(() => {
throw error;
});

render(getComponent({ options: { map: Map.JSON } }));
expect(screen.getByText(error.stack)).toBeInTheDocument();
});
Expand Down
10 changes: 5 additions & 5 deletions src/components/EchartsPanel/EchartsPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const EchartsPanel: React.FC<Props> = ({ options, data, width, height, re
/**
* Transformations
*/
const ecStat: any = echartsStat;
const ecStat = echartsStat;

/**
* Initialize Chart
Expand Down Expand Up @@ -92,8 +92,8 @@ export const EchartsPanel: React.FC<Props> = ({ options, data, width, height, re
const themeConfig = JSON.parse(options.themeEditor.config);
echartsTheme = Theme.CUSTOM;
echarts.registerTheme(echartsTheme, themeConfig);
} catch (e: any) {
setThemeError(e);
} catch (e: unknown) {
setThemeError(e instanceof Error ? e : new Error(`${e}`));
}
}

Expand Down Expand Up @@ -244,7 +244,7 @@ export const EchartsPanel: React.FC<Props> = ({ options, data, width, height, re
/**
* Chart option
*/
let chartOption = {};
let chartOption;

/**
* Default Option Config with merge disabled
Expand Down Expand Up @@ -290,7 +290,7 @@ export const EchartsPanel: React.FC<Props> = ({ options, data, width, height, re
chartOptionConfig
);
} catch (err) {
setError(err as any);
setError(err instanceof Error ? err : new Error(`${err}`));
}

return unsubscribeFn;
Expand Down
2 changes: 1 addition & 1 deletion src/components/SeriesEditor/SeriesEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export const SeriesEditor: React.FC<Props> = ({ value, onChange, dataset }) => {
*/
const onAddNewItem = useCallback(() => {
setNewItem('');
const addedItem = getSeriesWithNewType({ id: newItem, name: '', uid: getSeriesUniqueId() } as any, SeriesType.LINE);
const addedItem = getSeriesWithNewType({ id: newItem, name: '', uid: getSeriesUniqueId() }, SeriesType.LINE);
onChangeItems(items.concat(addedItem));
onToggleItem(addedItem);
}, [items, newItem, onChangeItems, onToggleItem]);
Expand Down
4 changes: 2 additions & 2 deletions src/maps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const registerMaps = () => {
* Load Baidu Maps
*/
export const loadBaidu = (options: BaiduOptions) => {
if ((window as any).BMap) {
if (window.BMap) {
return;
}

Expand All @@ -37,7 +37,7 @@ export const loadBaidu = (options: BaiduOptions) => {
* Load Gaode Maps
*/
export const loadGaode = (options: GaodeOptions) => {
if ((window as any).AMap) {
if (window.AMap) {
return;
}

Expand Down
6 changes: 3 additions & 3 deletions src/utils/visual-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const getDatasetItemUniqueName = (item: DatasetItem) => {
* @param items
*/
export const getDatasetSource = (frames: DataFrame[], items: DatasetItem[]): [string[], ...unknown[]] => {
const itemValuesMap = items.reduce((acc: Map<string, any[]>, item) => {
const itemValuesMap = items.reduce((acc: Map<string, unknown[]>, item) => {
const frame = frames.find((frame) =>
item.source ? frame.refId === item.source : frame.fields.some((field) => field.name === item.name)
);
Expand Down Expand Up @@ -62,8 +62,8 @@ export const getDatasetSource = (frames: DataFrame[], items: DatasetItem[]): [st
* @param item
* @param newType
*/
export const getSeriesWithNewType = (
item: SeriesItem,
export const getSeriesWithNewType = <TItem extends Pick<SeriesItem, 'id' | 'name' | 'uid'>>(
item: TItem,
newType: SeriesType
): SeriesByType<SeriesItem, typeof newType> => {
const commonValues = {
Expand Down

0 comments on commit 03b0304

Please sign in to comment.