Skip to content

Commit

Permalink
Cleaned up unnecessary code
Browse files Browse the repository at this point in the history
  • Loading branch information
droberts-ctrlo committed Dec 11, 2024
1 parent ca1332c commit 5ebcd27
Show file tree
Hide file tree
Showing 13 changed files with 18 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down Expand Up @@ -54,7 +55,7 @@ describe('create-report-button', () => {
</form>
`;

let $submit = $('#submit');
const $submit = $('#submit');
new CreateReportButtonComponent($submit);
const submitSpy = jest.fn((ev) => {
ev.preventDefault();
Expand Down
1 change: 0 additions & 1 deletion src/frontend/components/button/lib/submit-field-button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
});
}
Expand Down
4 changes: 1 addition & 3 deletions src/frontend/components/dashboard/lib/react/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,8 @@ export default function App(state: AppState) {
const [editHtml, setEditHtml] = React.useState<string>("");
const [modalOpen, setModalOpen] = React.useState(false);
const [activeItem, setActiveItem] = React.useState<string>("");
// eslint-disable-next-line
const [loading, setLoading] = React.useState(false);
// eslint-disable-next-line


useEffect(() => {
sidebarObservable.addSubscriber(()=> {
window.dispatchEvent(new Event('resize'));
Expand Down
2 changes: 0 additions & 2 deletions src/frontend/components/dashboard/lib/react/api/index.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 0 additions & 2 deletions src/frontend/components/data-table/lib/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/components/form-group/filter/lib/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions src/frontend/components/timeline/lib/print/timeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
1 change: 0 additions & 1 deletion src/frontend/js/lib/util/common.test.ts
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down
4 changes: 2 additions & 2 deletions src/frontend/js/lib/util/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ export const showElement = (element: HTMLElement | ElementLike |JQuery<HTMLEleme
$el.removeAttr('style');
};

export const fromJson = <T> (json: String | object): T | object => {
export const fromJson = <T> (json: string | object): T | object => {
try {
if (!json || json === '') return {};
if (typeof json === 'string') {
const result = JSON.parse(json);
return result as T ?? result;
}
return json as T ?? json;
} catch (e) {
} catch {
return {};
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/js/lib/util/formatters/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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};
11 changes: 5 additions & 6 deletions src/frontend/js/lib/util/upload/UploadControl.test.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -11,12 +10,12 @@ describe('UploadControl', () => {
initGlobals();

mockXhr = new MockXhr();
oldXMLHttpRequest = <any>window.XMLHttpRequest; // eslint-disable-line @typescript-eslint/no-explicit-any
window.XMLHttpRequest = <any>(jest.fn(() => mockXhr)); // eslint-disable-line @typescript-eslint/no-explicit-any
oldXMLHttpRequest = <any>window.XMLHttpRequest;
window.XMLHttpRequest = <any>(jest.fn(() => mockXhr));
});

afterEach(() => {
window.XMLHttpRequest = <any>oldXMLHttpRequest; // eslint-disable-line @typescript-eslint/no-explicit-any
window.XMLHttpRequest = <any>oldXMLHttpRequest;
mockXhr = null;
});

Expand Down Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/frontend/js/lib/util/upload/UploadControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ type RequestMethod = "PUT"|"POST"|"GET"|"DELETE"|"PATCH";
*/
type XmlHttpRequestLike = {
open: (method: string, url: string) => void,
onabort?: ((this: XMLHttpRequest, ev: ProgressEvent<EventTarget>) => any) | null, // eslint-disable-line @typescript-eslint/no-explicit-any
onerror?: ((this: XMLHttpRequest, ev: ProgressEvent<EventTarget>) => any) | null, // eslint-disable-line @typescript-eslint/no-explicit-any
onabort?: ((this: XMLHttpRequest, ev: ProgressEvent<EventTarget>) => any) | null,
onerror?: ((this: XMLHttpRequest, ev: ProgressEvent<EventTarget>) => 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,
Expand Down

0 comments on commit 5ebcd27

Please sign in to comment.