From 6b5e2618dd8c324afb137be434124243b6f4e870 Mon Sep 17 00:00:00 2001 From: sunilyadav840 Date: Thu, 26 Aug 2021 16:02:29 +0530 Subject: [PATCH] fixed tsstrict of InputTypeHeadComponent.tsx --- .../InputTypeaheadComponent.test.tsx | 16 +++++++++++-- .../InputTypeaheadComponent.tsx | 24 +++++++++---------- tsconfig.strict.json | 4 +++- 3 files changed, 29 insertions(+), 15 deletions(-) diff --git a/src/Explorer/Controls/InputTypeahead/InputTypeaheadComponent.test.tsx b/src/Explorer/Controls/InputTypeahead/InputTypeaheadComponent.test.tsx index e06b28ade..a80e63830 100644 --- a/src/Explorer/Controls/InputTypeahead/InputTypeaheadComponent.test.tsx +++ b/src/Explorer/Controls/InputTypeahead/InputTypeaheadComponent.test.tsx @@ -1,7 +1,7 @@ -import React from "react"; import { shallow } from "enzyme"; -import { InputTypeaheadComponent, InputTypeaheadComponentProps } from "./InputTypeaheadComponent"; +import React from "react"; import "../../../../externals/jquery.typeahead.min.js"; +import { InputTypeaheadComponent, InputTypeaheadComponentProps } from "./InputTypeaheadComponent"; describe("inputTypeahead", () => { it("renders ", () => { @@ -12,6 +12,12 @@ describe("inputTypeahead", () => { ], placeholder: "placeholder", useTextarea: false, + onNewValue: () => { + (""); + }, + submitFct: () => { + (""); + }, }; const wrapper = shallow(); @@ -26,6 +32,12 @@ describe("inputTypeahead", () => { ], placeholder: "placeholder", useTextarea: true, + onNewValue: () => { + (""); + }, + submitFct: () => { + (""); + }, }; const wrapper = shallow(); diff --git a/src/Explorer/Controls/InputTypeahead/InputTypeaheadComponent.tsx b/src/Explorer/Controls/InputTypeahead/InputTypeaheadComponent.tsx index 2e9a2d104..3a65367c7 100644 --- a/src/Explorer/Controls/InputTypeahead/InputTypeaheadComponent.tsx +++ b/src/Explorer/Controls/InputTypeahead/InputTypeaheadComponent.tsx @@ -33,7 +33,7 @@ export interface InputTypeaheadComponentProps { /** * The current string value of */ - onNewValue?: (newValue: string) => void; + onNewValue: (newValue?: string) => void; // inputValue?:ko.Observable; /** @@ -55,7 +55,7 @@ export interface InputTypeaheadComponentProps { /** * This function gets called when pressing ENTER on the input box */ - submitFct?: (inputValue: string, selection: Item) => void; + submitFct?: (inputValue?: string, selection?: Item) => void; /** * Typehead comes with a Search button that we normally remove. @@ -76,7 +76,7 @@ export interface InputTypeaheadComponentProps { interface InputTypeaheadComponentState { isSuggestionVisible: boolean; - selectedChoice: Item; + selectedChoice?: Item; filteredChoices: Item[]; } @@ -96,21 +96,21 @@ export class InputTypeaheadComponent extends React.Component< }; } - private onRenderCell = (item: Item): JSX.Element => { + private onRenderCell = (item?: Item): JSX.Element => { return (
this.onChoiceClick(item)}> -

{item.caption}

- {item.value} +

{item?.caption}

+ {item?.value}
); }; - private onChoiceClick = (item: Item): void => { - this.props.onNewValue(item.caption); + private onChoiceClick = (item?: Item): void => { + this.props.onNewValue(item?.caption); this.setState({ isSuggestionVisible: false, selectedChoice: item }); }; - private handleChange = (value: string): void => { + private handleChange = (value?: string): void => { if (!value) { this.setState({ isSuggestionVisible: true }); } @@ -130,7 +130,7 @@ export class InputTypeaheadComponent extends React.Component< } }; - private filterChoiceByValue = (choices: Item[], searchKeyword: string): Item[] => { + private filterChoiceByValue = (choices: Item[], searchKeyword?: string): Item[] => { return choices.filter((choice) => // @ts-ignore Object.keys(choice).some((key) => choice[key].toLowerCase().includes(searchKeyword.toLowerCase())) @@ -138,7 +138,7 @@ export class InputTypeaheadComponent extends React.Component< }; public render(): JSX.Element { - const { defaultValue, useTextarea, placeholder, onNewValue } = this.props; + const { defaultValue, useTextarea, placeholder, onNewValue, submitFct } = this.props; const { isSuggestionVisible, selectedChoice, filteredChoices } = this.state; const theme = getTheme(); @@ -185,7 +185,7 @@ export class InputTypeaheadComponent extends React.Component< styles={iconButtonStyles} iconProps={searchIcon} ariaLabel="Search Button" - onClick={() => this.props.submitFct(defaultValue, selectedChoice)} + onClick={() => submitFct && submitFct(defaultValue, selectedChoice)} /> )} diff --git a/tsconfig.strict.json b/tsconfig.strict.json index ee037db87..0b6e8c05b 100644 --- a/tsconfig.strict.json +++ b/tsconfig.strict.json @@ -8,6 +8,8 @@ "noUnusedParameters": true }, "files": [ + "./src/Explorer/Controls/InputTypeahead/InputTypeaheadComponent.tsx", + "./src/Explorer/Controls/InputTypeahead/InputTypeaheadComponent.test.tsx", "./src/AuthType.ts", "./src/Bindings/ReactBindingHandler.ts", "./src/Common/ArrayHashMap.ts", @@ -165,4 +167,4 @@ "src/Terminal/**/*", "src/Utils/arm/**/*" ] -} +} \ No newline at end of file