From 5ebcd270a2af900a41fc71849681ec114915b399 Mon Sep 17 00:00:00 2001 From: Dave Roberts Date: Wed, 11 Dec 2024 14:23:59 +0000 Subject: [PATCH] Cleaned up unnecessary code --- .../button/lib/create-report-button.test.ts | 3 ++- .../components/button/lib/submit-field-button.ts | 1 - src/frontend/components/dashboard/lib/react/App.tsx | 4 +--- .../components/dashboard/lib/react/api/index.ts | 2 -- src/frontend/components/data-table/lib/component.js | 2 -- .../components/form-group/filter/lib/component.js | 2 +- .../components/form-group/input/lib/fileComponent.ts | 2 +- .../components/timeline/lib/print/timeline.js | 4 ++-- src/frontend/js/lib/util/common.test.ts | 1 - src/frontend/js/lib/util/common.ts | 4 ++-- src/frontend/js/lib/util/formatters/markdown.ts | 2 +- src/frontend/js/lib/util/upload/UploadControl.test.ts | 11 +++++------ src/frontend/js/lib/util/upload/UploadControl.ts | 6 +++--- 13 files changed, 18 insertions(+), 26 deletions(-) diff --git a/src/frontend/components/button/lib/create-report-button.test.ts b/src/frontend/components/button/lib/create-report-button.test.ts index 88f9fc910..1dfca942c 100644 --- a/src/frontend/components/button/lib/create-report-button.test.ts +++ b/src/frontend/components/button/lib/create-report-button.test.ts @@ -1,6 +1,7 @@ import "../../../testing/globals.definitions"; import {validateRequiredFields} from 'validation'; import CreateReportButtonComponent from "./create-report-button"; +import {describe, it, jest, expect} from "@jest/globals"; describe('create-report-button', () => { it('does not submit form if no checkboxes are checked', () => { @@ -54,7 +55,7 @@ describe('create-report-button', () => { `; - let $submit = $('#submit'); + const $submit = $('#submit'); new CreateReportButtonComponent($submit); const submitSpy = jest.fn((ev) => { ev.preventDefault(); diff --git a/src/frontend/components/button/lib/submit-field-button.ts b/src/frontend/components/button/lib/submit-field-button.ts index bf52328c1..6e8a994e0 100644 --- a/src/frontend/components/button/lib/submit-field-button.ts +++ b/src/frontend/components/button/lib/submit-field-button.ts @@ -91,7 +91,6 @@ export default class SubmitFieldButton { url: this.getURL(data), data: {data: mytext, csrf_token: data.csrfToken} }).done(() => { - // eslint-disable-next-line no-alert alert('Tree has been updated') }); } diff --git a/src/frontend/components/dashboard/lib/react/App.tsx b/src/frontend/components/dashboard/lib/react/App.tsx index 23e4199b8..8439f6869 100644 --- a/src/frontend/components/dashboard/lib/react/App.tsx +++ b/src/frontend/components/dashboard/lib/react/App.tsx @@ -40,10 +40,8 @@ export default function App(state: AppState) { const [editHtml, setEditHtml] = React.useState(""); const [modalOpen, setModalOpen] = React.useState(false); const [activeItem, setActiveItem] = React.useState(""); - // eslint-disable-next-line const [loading, setLoading] = React.useState(false); - // eslint-disable-next-line - + useEffect(() => { sidebarObservable.addSubscriber(()=> { window.dispatchEvent(new Event('resize')); diff --git a/src/frontend/components/dashboard/lib/react/api/index.ts b/src/frontend/components/dashboard/lib/react/api/index.ts index 45c506cd9..44c97a156 100644 --- a/src/frontend/components/dashboard/lib/react/api/index.ts +++ b/src/frontend/components/dashboard/lib/react/api/index.ts @@ -1,6 +1,4 @@ -// I wonder if this could be used as a "better" version of the UploadClient class with only minor modifications import {Layout} from "react-grid-layout"; -import {WidgetData} from "../interfaces/interfaces"; export default class ApiClient { private readonly baseUrl: string; diff --git a/src/frontend/components/data-table/lib/component.js b/src/frontend/components/data-table/lib/component.js index 8c83d888f..813b6e8bf 100644 --- a/src/frontend/components/data-table/lib/component.js +++ b/src/frontend/components/data-table/lib/component.js @@ -8,7 +8,6 @@ import 'datatables.net-rowreorder-bs4' import { setupDisclosureWidgets, onDisclosureClick } from 'components/more-less/lib/disclosure-widgets' import { moreLess } from 'components/more-less/lib/more-less' import { bindToggleTableClickHandlers } from './toggle-table' -import TypeaheadBuilder from 'util/typeahead' const MORE_LESS_TRESHOLD = 50 @@ -715,7 +714,6 @@ class DataTableComponent extends Component { I have tried manually changing the DOM, as well as the methods already present in the code, and I currently believe there is a bug within the DataTables button code that is meaning that this won't change (although I am open to the fact that I am being a little slow and missing something glaringly obvious). */ - // eslint-disable-next-line @typescript-eslint/no-unused-vars toggleFullScreenMode(buttonElement) { const table = document.querySelector("table.data-table"); const currentTable = $(table); diff --git a/src/frontend/components/form-group/filter/lib/component.js b/src/frontend/components/form-group/filter/lib/component.js index ff91155fa..2d4fad1ce 100644 --- a/src/frontend/components/form-group/filter/lib/component.js +++ b/src/frontend/components/form-group/filter/lib/component.js @@ -186,7 +186,7 @@ class FilterComponent extends Component { // Ensure that no blank rules by default, otherwise view cannot be submitted $builderEl.queryBuilder('setRules', {rules:[]}) } - } catch (error) { + } catch { logging.log('Incorrect data object passed to queryBuilder') } } diff --git a/src/frontend/components/form-group/input/lib/fileComponent.ts b/src/frontend/components/form-group/input/lib/fileComponent.ts index 89fa37492..541bde993 100644 --- a/src/frontend/components/form-group/input/lib/fileComponent.ts +++ b/src/frontend/components/form-group/input/lib/fileComponent.ts @@ -22,7 +22,7 @@ class FileComponent { const dropTarget = this.el.closest('.file-upload'); if (dropTarget) { const dragOptions = { allowMultiple: false }; - (dropTarget as any).filedrag(dragOptions).on('onFileDrop', (ev, file) => { // eslint-disable-line @typescript-eslint/no-explicit-any + (dropTarget as any).filedrag(dragOptions).on('onFileDrop', (ev, file) => { this.handleFormUpload(file); }); } else { diff --git a/src/frontend/components/timeline/lib/print/timeline.js b/src/frontend/components/timeline/lib/print/timeline.js index 388f439be..3826cbaba 100644 --- a/src/frontend/components/timeline/lib/print/timeline.js +++ b/src/frontend/components/timeline/lib/print/timeline.js @@ -514,13 +514,13 @@ const injectContrastingColor = function(dataset) { const setupTimeline = function(container, options_in) { const records_base64 = container.data("records"); - const json = base64.decode(records_base64); + const json = atob(records_base64); const dataset = JSON.parse(json); injectContrastingColor(dataset); const items = new vis.DataSet(dataset); let groups = container.data("groups"); - const json_group = base64.decode(groups); + const json_group = atob(groups); groups = JSON.parse(json_group); const is_dashboard = !!container.data("dashboard"); const layout_identifier = $("body").data("layout-identifier"); diff --git a/src/frontend/js/lib/util/common.test.ts b/src/frontend/js/lib/util/common.test.ts index 6e0832712..6dc17e10f 100644 --- a/src/frontend/js/lib/util/common.test.ts +++ b/src/frontend/js/lib/util/common.test.ts @@ -1,6 +1,5 @@ import "../../../testing/globals.definitions"; import { describe, beforeEach, afterEach, jest, it, expect } from "@jest/globals"; -import { DefaultElementLike, ElementLike } from "../../../testing/globals.definitions"; import { compare, fromJson, hideElement, showElement } from "./common"; describe('common functions', () => { diff --git a/src/frontend/js/lib/util/common.ts b/src/frontend/js/lib/util/common.ts index 0eda32598..1e8d0a270 100644 --- a/src/frontend/js/lib/util/common.ts +++ b/src/frontend/js/lib/util/common.ts @@ -18,7 +18,7 @@ export const showElement = (element: HTMLElement | ElementLike |JQuery (json: String | object): T | object => { +export const fromJson = (json: string | object): T | object => { try { if (!json || json === '') return {}; if (typeof json === 'string') { @@ -26,7 +26,7 @@ export const fromJson = (json: String | object): T | object => { return result as T ?? result; } return json as T ?? json; - } catch (e) { + } catch { return {}; } } diff --git a/src/frontend/js/lib/util/formatters/markdown.ts b/src/frontend/js/lib/util/formatters/markdown.ts index a565dff3d..f78e90d3c 100644 --- a/src/frontend/js/lib/util/formatters/markdown.ts +++ b/src/frontend/js/lib/util/formatters/markdown.ts @@ -14,7 +14,7 @@ function MarkDown(strings: TemplateStringsArray, ...values:(stringLike| string|n } } str = str.replace(/\\n/g, '\n\n'); - return (marked(str) as String).trim(); + return (marked(str) as string).trim(); } export {MarkdownCode, MarkDown}; diff --git a/src/frontend/js/lib/util/upload/UploadControl.test.ts b/src/frontend/js/lib/util/upload/UploadControl.test.ts index 51d6faec0..2fbb89db1 100644 --- a/src/frontend/js/lib/util/upload/UploadControl.test.ts +++ b/src/frontend/js/lib/util/upload/UploadControl.test.ts @@ -1,5 +1,4 @@ -/* eslint-disable @typescript-eslint/no-unused-vars */ -import { describe, it, expect } from '@jest/globals'; +import { describe, it, expect, beforeEach, afterEach, jest } from '@jest/globals'; import { Uploader, XmlHttpRequestLike } from './UploadControl'; import { initGlobals, MockXhr } from '../../../../testing/globals.definitions'; @@ -11,12 +10,12 @@ describe('UploadControl', () => { initGlobals(); mockXhr = new MockXhr(); - oldXMLHttpRequest = window.XMLHttpRequest; // eslint-disable-line @typescript-eslint/no-explicit-any - window.XMLHttpRequest = (jest.fn(() => mockXhr)); // eslint-disable-line @typescript-eslint/no-explicit-any + oldXMLHttpRequest = window.XMLHttpRequest; + window.XMLHttpRequest = (jest.fn(() => mockXhr)); }); afterEach(() => { - window.XMLHttpRequest = oldXMLHttpRequest; // eslint-disable-line @typescript-eslint/no-explicit-any + window.XMLHttpRequest = oldXMLHttpRequest; mockXhr = null; }); @@ -73,7 +72,7 @@ describe('UploadControl', () => { const ev: ProgressEvent = { loaded: 1, total: 2, - } as any; // eslint-disable-line @typescript-eslint/no-explicit-any + } as any; setTimeout(() => { localMock.onprogress && localMock.onprogress(ev); }, 500); diff --git a/src/frontend/js/lib/util/upload/UploadControl.ts b/src/frontend/js/lib/util/upload/UploadControl.ts index d883deb54..dfb5c71d0 100644 --- a/src/frontend/js/lib/util/upload/UploadControl.ts +++ b/src/frontend/js/lib/util/upload/UploadControl.ts @@ -12,10 +12,10 @@ type RequestMethod = "PUT"|"POST"|"GET"|"DELETE"|"PATCH"; */ type XmlHttpRequestLike = { open: (method: string, url: string) => void, - onabort?: ((this: XMLHttpRequest, ev: ProgressEvent) => any) | null, // eslint-disable-line @typescript-eslint/no-explicit-any - onerror?: ((this: XMLHttpRequest, ev: ProgressEvent) => any) | null, // eslint-disable-line @typescript-eslint/no-explicit-any + onabort?: ((this: XMLHttpRequest, ev: ProgressEvent) => any) | null, + onerror?: ((this: XMLHttpRequest, ev: ProgressEvent) => any) | null, onprogress?: ((e: ProgressEvent) => void) | null, - onreadystatechange: ((this: XMLHttpRequest, ev: Event) => any) | null, // eslint-disable-line @typescript-eslint/no-explicit-any + onreadystatechange: ((this: XMLHttpRequest, ev: Event) => any) | null, send: (data?: Document | XMLHttpRequestBodyInit | null | undefined) => void, setRequestHeader: (header: string, value: string) => void, readyState: number,