From a0a77002d20820e78562cbf2787c538d97e52575 Mon Sep 17 00:00:00 2001 From: sunilyadav840 Date: Tue, 7 Sep 2021 16:17:48 +0530 Subject: [PATCH] Fixed eslint issue of InputTypeaheadComponent.tsx NotebookTerminalComponent.tsx NotebookViewerComponent.tsx LeftPaneComponent.tsx NodePropertiesComponent.tsx files --- .eslintignore | 16 ++-- package.json | 2 +- .../InputTypeaheadComponent.tsx | 3 +- .../NotebookViewerComponent.tsx | 2 +- .../GraphExplorerComponent/GraphExplorer.tsx | 74 +++++++++---------- .../LeftPaneComponent.tsx | 2 +- .../NodePropertiesComponent.test.tsx | 34 +++++---- .../NodePropertiesComponent.tsx | 25 ++++--- .../Tables/DataTable/DataTableBuilder.ts | 4 +- 9 files changed, 86 insertions(+), 76 deletions(-) diff --git a/.eslintignore b/.eslintignore index 3de1fdee0..9f9fedf52 100644 --- a/.eslintignore +++ b/.eslintignore @@ -137,18 +137,18 @@ src/Terminal/NotebookAppContracts.d.ts src/applyExplorerBindings.ts src/global.d.ts src/setupTests.ts -src/Explorer/Controls/InputTypeahead/InputTypeaheadComponent.tsx -src/Explorer/Controls/Notebook/NotebookTerminalComponent.test.tsx -src/Explorer/Controls/Notebook/NotebookTerminalComponent.tsx -src/Explorer/Controls/NotebookViewer/NotebookViewerComponent.tsx +; src/Explorer/Controls/InputTypeahead/InputTypeaheadComponent.tsx +; src/Explorer/Controls/Notebook/NotebookTerminalComponent.test.tsx +; src/Explorer/Controls/Notebook/NotebookTerminalComponent.tsx +; src/Explorer/Controls/NotebookViewer/NotebookViewerComponent.tsx src/Explorer/Controls/TreeComponent/TreeComponent.tsx src/Explorer/Graph/GraphExplorerComponent/GraphExplorer.test.tsx src/Explorer/Graph/GraphExplorerComponent/GraphExplorer.tsx src/Explorer/Graph/GraphExplorerComponent/GraphVizComponent.tsx -src/Explorer/Graph/GraphExplorerComponent/LeftPaneComponent.tsx -src/Explorer/Graph/GraphExplorerComponent/MiddlePaneComponent.tsx -src/Explorer/Graph/GraphExplorerComponent/NodePropertiesComponent.test.tsx -src/Explorer/Graph/GraphExplorerComponent/NodePropertiesComponent.tsx +; src/Explorer/Graph/GraphExplorerComponent/LeftPaneComponent.tsx +; src/Explorer/Graph/GraphExplorerComponent/MiddlePaneComponent.tsx +; src/Explorer/Graph/GraphExplorerComponent/NodePropertiesComponent.test.tsx +; src/Explorer/Graph/GraphExplorerComponent/NodePropertiesComponent.tsx src/Explorer/Graph/GraphExplorerComponent/ReadOnlyNodePropertiesComponent.test.tsx src/Explorer/Graph/GraphExplorerComponent/ReadOnlyNodePropertiesComponent.tsx src/Explorer/Menus/CommandBar/CommandBarUtil.tsx diff --git a/package.json b/package.json index 762d9c9ce..02bfb1387 100644 --- a/package.json +++ b/package.json @@ -230,4 +230,4 @@ "prettier": { "printWidth": 120 } -} +} \ No newline at end of file diff --git a/src/Explorer/Controls/InputTypeahead/InputTypeaheadComponent.tsx b/src/Explorer/Controls/InputTypeahead/InputTypeaheadComponent.tsx index 2e9a2d104..66e9b70df 100644 --- a/src/Explorer/Controls/InputTypeahead/InputTypeaheadComponent.tsx +++ b/src/Explorer/Controls/InputTypeahead/InputTypeaheadComponent.tsx @@ -50,7 +50,7 @@ export interface InputTypeaheadComponentProps { * Override default jquery-typeahead options * WARNING: do not override input, source or callback to avoid breaking the components behavior. */ - typeaheadOverrideOptions?: any; + typeaheadOverrideOptions?: { dynamic: boolean }; /** * This function gets called when pressing ENTER on the input box @@ -132,6 +132,7 @@ export class InputTypeaheadComponent extends React.Component< private filterChoiceByValue = (choices: Item[], searchKeyword: string): Item[] => { return choices.filter((choice) => + // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore Object.keys(choice).some((key) => choice[key].toLowerCase().includes(searchKeyword.toLowerCase())) ); diff --git a/src/Explorer/Controls/NotebookViewer/NotebookViewerComponent.tsx b/src/Explorer/Controls/NotebookViewer/NotebookViewerComponent.tsx index 3bbc6a538..4930ae8ab 100644 --- a/src/Explorer/Controls/NotebookViewer/NotebookViewerComponent.tsx +++ b/src/Explorer/Controls/NotebookViewer/NotebookViewerComponent.tsx @@ -264,6 +264,6 @@ export class NotebookViewerComponent }; private reportAbuse = (): void => { - GalleryUtils.reportAbuse(this.props.junoClient, this.state.galleryItem, this, () => {}); + GalleryUtils.reportAbuse(this.props.junoClient, this.state.galleryItem, this, () => ({})); }; } diff --git a/src/Explorer/Graph/GraphExplorerComponent/GraphExplorer.tsx b/src/Explorer/Graph/GraphExplorerComponent/GraphExplorer.tsx index cf2fbbb3a..1b10f1d44 100644 --- a/src/Explorer/Graph/GraphExplorerComponent/GraphExplorer.tsx +++ b/src/Explorer/Graph/GraphExplorerComponent/GraphExplorer.tsx @@ -330,10 +330,10 @@ export class GraphExplorer extends React.Component { @@ -473,7 +473,7 @@ export class GraphExplorer extends React.Component { return this.submitToBackend(`g.E('${GraphUtil.escapeSingleQuotes(edgeId)}').drop()`).then( () => { - let graphData = this.originalGraphData; + const graphData = this.originalGraphData; graphData.removeEdge(edgeId, false); this.updateGraphData(graphData, this.state.igraphConfig); }, @@ -826,9 +826,9 @@ export class GraphExplorer extends React.Component 0) { - let v0 = vertices[0]; + const v0 = vertices[0]; if (!v0.hasOwnProperty("id") || !v0.hasOwnProperty("type") || v0.type !== "vertex") { return false; } @@ -933,7 +933,7 @@ export class GraphExplorer extends React.Component void) { - let errorDataStr: string = ""; + let errorDataStr = ""; if (errorData && errorData.length > 0) { console.error(msg, errorData); errorDataStr = ": " + JSON.stringify(errorData); @@ -1224,7 +1224,7 @@ export class GraphExplorer extends React.Component { - let result = GraphData.GraphData.getNodePropValue(value, key); + const result = GraphData.GraphData.getNodePropValue(value, key); return { caption: result !== undefined ? result : value.id, id: value.id, @@ -1388,7 +1388,7 @@ export class GraphExplorer extends React.Component { - let possibleVertices = [] as PossibleVertex[]; + const possibleVertices = [] as PossibleVertex[]; $.each(documents, (index: number, item: any) => { if (highlightedNodeId && item.id === highlightedNodeId) { // Exclude highlighed node in the list @@ -1463,16 +1463,16 @@ export class GraphExplorer extends React.Component { - let promises = []; + const promises = []; // Drop edges for (let i = 0; i < editedEdges.droppedIds.length; i++) { - let id = editedEdges.droppedIds[i]; + const id = editedEdges.droppedIds[i]; promises.push(this.removeEdge(id)); } // Add edges for (let i = 0; i < editedEdges.addedEdges.length; i++) { - let e = editedEdges.addedEdges[i]; + const e = editedEdges.addedEdges[i]; promises.push( this.createNewEdge(e).then(() => { // Reload neighbors in case we linked to a vertex that isn't loaded in the graph @@ -1533,7 +1533,7 @@ export class GraphExplorer extends React.Component { - for (var p in item) { + for (const p in item) { // DocDB: Exclude type because it's always 'vertex' if (p !== "type" && typeof (item as any)[p] === "string") { props[p] = true; @@ -1543,7 +1543,7 @@ export class GraphExplorer extends React.Component gremlinProperty.value); } // update neighbors - let sources: NeighborVertexBasicInfo[] = []; - let targets: NeighborVertexBasicInfo[] = []; + const sources: NeighborVertexBasicInfo[] = []; + const targets: NeighborVertexBasicInfo[] = []; this.props.onResetDefaultGraphConfigValues(); - let nodeCaption = this.state.igraphConfigUiData.nodeCaptionChoice; + const nodeCaption = this.state.igraphConfigUiData.nodeCaptionChoice; this.updateSelectedNodeNeighbors(data.id, nodeCaption, sources, targets); - let sData: GraphHighlightedNodeData = { + const sData: GraphHighlightedNodeData = { id: data.id, label: data.label, properties: props, @@ -1611,16 +1611,16 @@ export class GraphExplorer extends React.Component { @@ -1629,7 +1629,7 @@ export class GraphExplorer extends React.Component { @@ -1648,7 +1648,7 @@ export class GraphExplorer extends React.Component { className={className} as="tr" aria-label={node.caption} - onActivated={(e) => this.props.onRootNodeSelected(node.id)} + onActivated={() => this.props.onRootNodeSelected(node.id)} key={node.id} > diff --git a/src/Explorer/Graph/GraphExplorerComponent/NodePropertiesComponent.test.tsx b/src/Explorer/Graph/GraphExplorerComponent/NodePropertiesComponent.test.tsx index bd894129f..6cda8d3a2 100644 --- a/src/Explorer/Graph/GraphExplorerComponent/NodePropertiesComponent.test.tsx +++ b/src/Explorer/Graph/GraphExplorerComponent/NodePropertiesComponent.test.tsx @@ -1,8 +1,8 @@ -import React from "react"; import { mount, ReactWrapper } from "enzyme"; import * as Q from "q"; -import { NodePropertiesComponent, NodePropertiesComponentProps, Mode } from "./NodePropertiesComponent"; -import { GraphHighlightedNodeData, EditedProperties, EditedEdges, PossibleVertex } from "./GraphExplorer"; +import React from "react"; +import { GraphHighlightedNodeData, PossibleVertex } from "./GraphExplorer"; +import { Mode, NodePropertiesComponent, NodePropertiesComponentProps } from "./NodePropertiesComponent"; describe("Property pane", () => { const title = "My Title"; @@ -37,17 +37,25 @@ describe("Property pane", () => { return { expandedTitle: title, isCollapsed: false, - onCollapsedChanged: (newValue: boolean): void => {}, + onCollapsedChanged: (): void => { + (""); + }, node: highlightedNode, - getPkIdFromNodeData: (v: GraphHighlightedNodeData): string => null, - collectionPartitionKeyProperty: null, - updateVertexProperties: (editedProperties: EditedProperties): Q.Promise => Q.resolve(), - selectNode: (id: string): void => {}, - updatePossibleVertices: (): Q.Promise => Q.resolve(null), - possibleEdgeLabels: null, - editGraphEdges: (editedEdges: EditedEdges): Q.Promise => Q.resolve(), - deleteHighlightedNode: (): void => {}, - onModeChanged: (newMode: Mode): void => {}, + getPkIdFromNodeData: (): string => undefined, + collectionPartitionKeyProperty: undefined, + updateVertexProperties: (): Q.Promise => Q.resolve(), + selectNode: (): void => { + (""); + }, + updatePossibleVertices: (): Q.Promise => Q.resolve(undefined), + possibleEdgeLabels: undefined, + editGraphEdges: (): Q.Promise => Q.resolve(), + deleteHighlightedNode: (): void => { + (""); + }, + onModeChanged: (): void => { + (""); + }, viewMode: Mode.READONLY_PROP, }; }; diff --git a/src/Explorer/Graph/GraphExplorerComponent/NodePropertiesComponent.tsx b/src/Explorer/Graph/GraphExplorerComponent/NodePropertiesComponent.tsx index 55f641a30..80dc417bd 100644 --- a/src/Explorer/Graph/GraphExplorerComponent/NodePropertiesComponent.tsx +++ b/src/Explorer/Graph/GraphExplorerComponent/NodePropertiesComponent.tsx @@ -45,7 +45,7 @@ export interface NodePropertiesComponentProps { selectNode: (id: string) => void; updatePossibleVertices: () => Q.Promise; possibleEdgeLabels: Item[]; - editGraphEdges: (editedEdges: EditedEdges) => Q.Promise; + editGraphEdges: (editedEdges: EditedEdges) => Q.Promise; deleteHighlightedNode: () => void; onModeChanged: (newMode: Mode) => void; viewMode: Mode; // If viewMode is specified in parent, keep state in sync with it @@ -72,7 +72,7 @@ export class NodePropertiesComponent extends React.Component< super(props); this.state = { editedProperties: { - pkId: null, + pkId: undefined, readOnlyProperties: [], existingProperties: [], addedProperties: [], @@ -98,15 +98,12 @@ export class NodePropertiesComponent extends React.Component< }; } - public static getDerivedStateFromProps( - props: NodePropertiesComponentProps, - state: NodePropertiesComponentState - ): Partial { + public static getDerivedStateFromProps(props: NodePropertiesComponentProps): Partial { if (props.viewMode !== Mode.READONLY_PROP) { return { isDeleteConfirm: false }; } - return null; + return undefined; } public render(): JSX.Element { @@ -137,11 +134,14 @@ export class NodePropertiesComponent extends React.Component< * Get type option. Limit to string, number or boolean * @param value */ - private static getTypeOption(value: any): ViewModels.InputPropertyValueTypeString { - if (value == null) { + private static getTypeOption( + value: null | string | number | undefined | boolean + ): ViewModels.InputPropertyValueTypeString { + // eslint-disable-next-line no-null/no-null + if (value === null) { return "null"; } - let type = typeof value; + const type = typeof value; switch (type) { case "number": case "boolean": @@ -173,9 +173,10 @@ export class NodePropertiesComponent extends React.Component< const existingProps: ViewModels.InputProperty[] = []; + // eslint-disable-next-line no-prototype-builtins if (this.props.node.hasOwnProperty("properties")) { const hProps = this.props.node["properties"]; - for (let p in hProps) { + for (const p in hProps) { const propValues = hProps[p]; (p === partitionKeyProperty ? readOnlyProps : existingProps).push({ key: p, @@ -437,7 +438,7 @@ export class NodePropertiesComponent extends React.Component< ); } else { - return null; + return undefined; } } diff --git a/src/Explorer/Tables/DataTable/DataTableBuilder.ts b/src/Explorer/Tables/DataTable/DataTableBuilder.ts index 2fc3000ba..5d8ad849c 100644 --- a/src/Explorer/Tables/DataTable/DataTableBuilder.ts +++ b/src/Explorer/Tables/DataTable/DataTableBuilder.ts @@ -19,7 +19,7 @@ export function createDataTable($dataTableElem: JQuery, settings: any): DataTabl * @return The given settings with all columns having a rendering function */ function applyDefaultRendering(settings: any): DataTables.SettingsLegacy { - var tableColumns: DataTables.ColumnLegacy[] = null; + let tableColumns: DataTables.ColumnLegacy[] = null; if (settings.aoColumns) { tableColumns = settings.aoColumns; @@ -34,7 +34,7 @@ function applyDefaultRendering(settings: any): DataTables.SettingsLegacy { return settings; } - for (var i = 0; i < tableColumns.length; i++) { + for (let i = 0; i < tableColumns.length; i++) { // the column does not have a render function if (!tableColumns[i].mRender) { tableColumns[i].mRender = defaultDataRender;