diff --git a/.yarn/patches/@react-md-autocomplete-npm-2.9.1-0914f23b5c.patch b/.yarn/patches/@react-md-autocomplete-npm-2.9.1-0914f23b5c.patch new file mode 100644 index 00000000..3768d78a --- /dev/null +++ b/.yarn/patches/@react-md-autocomplete-npm-2.9.1-0914f23b5c.patch @@ -0,0 +1,44 @@ +diff --git a/es/useAutoComplete.js b/es/useAutoComplete.js +index 371a36548135141002e014180c831f74cee15e06..6f78c77c662763aae9eb73d20a129def7c35a468 100644 +--- a/es/useAutoComplete.js ++++ b/es/useAutoComplete.js +@@ -203,6 +203,7 @@ export function useAutoComplete(_a) { + break; + case "Enter": + if (visible && focusedIndex >= 0) { ++ event.preventDefault(); + event.stopPropagation(); + handleAutoComplete(focusedIndex); + hide(); +diff --git a/es/useAutoComplete.js.map b/es/useAutoComplete.js.map +index afa51cb523b2dcaf50cad2fe77d060f81e28cc18..144e38c3e8ce7baa68a895be97546f79f50a9260 100644 +--- a/es/useAutoComplete.js.map ++++ b/es/useAutoComplete.js.map +@@ -1 +1 @@ +-{"version":3,"file":"useAutoComplete.js","sourceRoot":"","sources":["../src/useAutoComplete.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,EASL,WAAW,EACX,SAAS,EACT,MAAM,EACN,QAAQ,GACT,MAAM,OAAO,CAAC;AAEf,OAAO,EAAmB,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC5E,OAAO,EAEL,eAAe,EACf,cAAc,EACd,2BAA2B,EAC3B,sBAAsB,EACtB,aAAa,EACb,wBAAwB,EACxB,SAAS,GACV,MAAM,iBAAiB,CAAC;AAOzB,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AA0D5C;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,EAmCV;;QAlCpB,aAAa,mBAAA,EACb,IAAI,UAAA,EACJ,SAAS,eAAA,EACT,oBAAiB,EAAjB,YAAY,mBAAG,EAAE,KAAA,EACT,QAAQ,YAAA,EAChB,aAAa,mBAA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eAAA,EAAE,QAAQ,cAAA,EAAE,WAAW,iBAmBhE,CAAC;IAEL,SAAS,CAAC;QACR,IAAI,CAAC,OAAO,CAAC,OAAO,IAAI,aAAa,CAAC,OAAO,EAAE;YAC7C,OAAO;SACR;QAED,IAAI,YAAY,CAAC,MAAM,IAAI,CAAC,OAAO,IAAI,KAAK,CAAC,MAAM,IAAI,kBAAkB,EAAE;YACzE,IAAI,EAAE,CAAC;SACR;aAAM,IAAI,CAAC,YAAY,CAAC,MAAM,IAAI,OAAO,EAAE;YAC1C,IAAI,EAAE,CAAC;SACR;QAED,0EAA0E;QAC1E,oCAAoC;QACpC,uDAAuD;IACzD,CAAC,EAAE,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC,CAAC;IAE1B,SAAS,CAAC;QACR,IAAI,CAAC,OAAO,EAAE;YACZ,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC;YACpB,OAAO;SACR;QAED,WAAW,EAAE,CAAC;QAEd,4EAA4E;QAC5E,UAAU;QACV,uDAAuD;IACzD,CAAC,EAAE,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC;IAE5B,OAAO;QACL,GAAG,EAAE,UAAU;QACf,KAAK,OAAA;QACL,KAAK,OAAA;QACL,OAAO,SAAA;QACP,QAAQ,UAAA;QACR,QAAQ,UAAA;QACR,YAAY,cAAA;QACZ,UAAU,wBAAO,KAAK,GAAK,YAAY,CAAE;QACzC,eAAe,EAAE;YACf,OAAO,SAAA;YACP,UAAU,YAAA;YACV,SAAS,WAAA;YACT,QAAQ,UAAA;SACT;QACD,UAAU,YAAA;QACV,UAAU,YAAA;QACV,WAAW,aAAA;QACX,WAAW,aAAA;QACX,YAAY,cAAA;QACZ,aAAa,eAAA;QACb,kBAAkB,oBAAA;KACnB,CAAC;AACJ,CAAC"} +\ No newline at end of file ++{"version":3,"file":"useAutoComplete.js","sourceRoot":"","sources":["../src/useAutoComplete.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,EASL,WA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L,GAAG,EAAE,UAAU;QACf,KAAK,OAAA;QACL,KAAK,OAAA;QACL,OAAO,SAAA;QACP,QAAQ,UAAA;QACR,QAAQ,UAAA;QACR,YAAY,cAAA;QACZ,UAAU,wBAAO,KAAK,GAAK,YAAY,CAAE;QACzC,eAAe,EAAE;YACf,OAAO,SAAA;YACP,UAAU,YAAA;YACV,SAAS,WAAA;YACT,QAAQ,UAAA;SACT;QACD,UAAU,YAAA;QACV,UAAU,YAAA;QACV,WAAW,aAAA;QACX,WAAW,aAAA;QACX,YAAY,cAAA;QACZ,aAAa,eAAA;QACb,kBAAkB,oBAAA;KACnB,CAAC;AACJ,CAAC"} +diff --git a/lib/useAutoComplete.js b/lib/useAutoComplete.js +index 74d8c8424cd1680419e712d1467a26c928087762..5a93146353691afdbc6fe02f41b6c7a7baf08313 100644 +--- a/lib/useAutoComplete.js ++++ b/lib/useAutoComplete.js +@@ -206,6 +206,7 @@ function useAutoComplete(_a) { + break; + case "Enter": + if (visible && focusedIndex >= 0) { ++ event.preventDefault(); + event.stopPropagation(); + handleAutoComplete(focusedIndex); + hide(); +diff --git a/src/useAutoComplete.ts b/src/useAutoComplete.ts +index 16f5e2762e29626d4bb58faf433fb7919899dc51..9951829c80cd9ecc13fd356847abc164dbc8325f 100644 +--- a/src/useAutoComplete.ts ++++ b/src/useAutoComplete.ts +@@ -393,6 +393,7 @@ export function useAutoComplete({ + break; + case "Enter": + if (visible && focusedIndex >= 0) { ++ event.preventDefault(); + event.stopPropagation(); + handleAutoComplete(focusedIndex); + hide(); diff --git a/package.json b/package.json index 7778dce6..e3b2b865 100644 --- a/package.json +++ b/package.json @@ -84,6 +84,7 @@ }, "packageManager": "yarn@3.3.1", "resolutions": { - "react-native@^0.66": "patch:react-native@npm%3A0.66.5#./.yarn/patches/react-native-npm-0.66.5-22e5dd8ec5.patch" + "react-native@^0.66": "patch:react-native@npm%3A0.66.5#./.yarn/patches/react-native-npm-0.66.5-22e5dd8ec5.patch", + "@react-md/autocomplete@^2": "patch:@react-md/autocomplete@npm%3A2.9.1#./.yarn/patches/@react-md-autocomplete-npm-2.9.1-0914f23b5c.patch" } } diff --git a/premiser-ui/README.md b/premiser-ui/README.md index bae08e65..50962795 100644 --- a/premiser-ui/README.md +++ b/premiser-ui/README.md @@ -1,11 +1,6 @@ -# Debugging Tests +# Howdju web app (`premiser-ui`) -``` -yarn test:debug -``` - -Then open Chrome at `chrome://inspect` and select the node instance. -[Details](https://jestjs.io/docs/en/troubleshooting#tests-are-failing-and-you-don-t-know-why) +This is the yarn workspace for Howdju's web app. ## Hot module reload @@ -31,3 +26,11 @@ I did: But then I discovered that iframe.onLoad wasn't working in local development (used by extension), and I suspected the hot loaders interaction with react-dom, so I just switched to `yarn add 'react-dom@^16.2.0'` + +## react-md + +This workspace currently depends on a patch of @react-md/autocomplete@2.9.1 that adds +`event.preventDefault()` when the user presses enter to autocomplete. This change prevents +submitting a form when the user is autocompleting. + +PR for that change is here: https://github.com/mlaursen/react-md/pull/1439 diff --git a/premiser-ui/src/ApiAutoComplete.tsx b/premiser-ui/src/ApiAutoComplete.tsx index 2f333872..ce9569cb 100644 --- a/premiser-ui/src/ApiAutoComplete.tsx +++ b/premiser-ui/src/ApiAutoComplete.tsx @@ -39,7 +39,8 @@ export interface Props > { id: ComponentId; name: string; - autocompleteThrottleMs?: number; + /** The number of milliseconds after typing to wait before fetching suggestions. */ + autocompleteDebounceMs?: number; fetchSuggestions: FetchSuggestionsActionCreator; cancelSuggestions: CancelSuggestionsActionCreator; /** Whether the input should be constrained to a single line. */ @@ -61,7 +62,7 @@ export interface Props export default function ApiAutoComplete({ id, name, - autocompleteThrottleMs = 250, + autocompleteDebounceMs = 250, fetchSuggestions, cancelSuggestions, singleLine = true, @@ -79,7 +80,7 @@ export default function ApiAutoComplete({ const dispatch = useAppDispatch(); const debouncedFetchSuggestions = useDebouncedCallback((value: string) => { dispatch(fetchSuggestions(value, suggestionsKey)); - }, autocompleteThrottleMs); + }, autocompleteDebounceMs); function onChange(event: ChangeEvent) { const name = event.target.name; diff --git a/premiser-ui/src/CreatePropositionPage.tsx b/premiser-ui/src/CreatePropositionPage.tsx index 0b4de588..c38bc90d 100644 --- a/premiser-ui/src/CreatePropositionPage.tsx +++ b/premiser-ui/src/CreatePropositionPage.tsx @@ -491,7 +491,6 @@ class CreatePropositionPage extends Component { suggestionsKey={combineSuggestionsKeys(id, tagsName)} onTag={this.onTagProposition} onUnTag={this.onUnTagProposition} - onSubmit={onSubmit} /> diff --git a/premiser-ui/src/TagsControl.test.tsx b/premiser-ui/src/TagsControl.test.tsx index 0e28cb74..aca38f20 100644 --- a/premiser-ui/src/TagsControl.test.tsx +++ b/premiser-ui/src/TagsControl.test.tsx @@ -1,17 +1,26 @@ import React from "react"; -import { screen } from "@testing-library/react"; +import { fireEvent, screen } from "@testing-library/react"; import TagsControl from "./TagsControl"; import { renderWithProviders, setupUserEvent, withFakeTimers, + withMockServer, } from "./testUtils"; -import { CreatePropositionInput, Tag, TagVote } from "howdju-common"; +import { + CreatePropositionInput, + httpStatusCodes, + Tag, + TagVote, +} from "howdju-common"; +import { InferResponseBody, serviceRoutes } from "howdju-service-routes"; +import { rest } from "msw"; withFakeTimers(); +const server = withMockServer(); describe("TagsControl", () => { - test("pressing enter with non-empty tag name adds tag", async () => { + test("pressing enter with non-empty tag name adds tag and doesn't submit enclosing form", async () => { const onSubmit = jest.fn(); const onTag = jest.fn(); const onUnTag = jest.fn(); @@ -42,33 +51,32 @@ describe("TagsControl", () => { expect(onUnTag).not.toHaveBeenCalled(); }); - test("pressing enter with empty tag name submits", async () => { - const onSubmit = jest.fn(); + test("pressing enter with empty tag name collapses input", async () => { const onTag = jest.fn(); const onUnTag = jest.fn(); renderWithProviders( -
- - + ); const user = setupUserEvent(); // Act + await user.click(screen.getByRole("button", { description: /add tag/i })); await user.type(screen.getByLabelText(/tag/i), "{Enter}"); // Assert - // Ensure we didn't submit for both form and TagsControl. - expect(onSubmit).toHaveBeenCalledOnce(); + expect( + screen.queryByRole("input", { name: "tagName" }) + ).not.toBeInTheDocument(); }); test("downvoting tag calls untag", async () => { @@ -101,5 +109,53 @@ describe("TagsControl", () => { // Assert expect(onUnTag).toHaveBeenCalled(); }); - // TODO(222): add more coverage + + test("autocompleting with partial input tags only the autocompleted tag.", async () => { + const user = setupUserEvent(); + const onTag = jest.fn(); + const onUnTag = jest.fn(); + + server.use( + rest.get(`http://localhost/search-tags`, (_req, res, ctx) => { + const response: InferResponseBody = { + tags: [ + { id: "1", name: "Politics" }, + { id: "2", name: "Political" }, + ], + }; + return res(ctx.status(httpStatusCodes.OK), ctx.json(response)); + }) + ); + + renderWithProviders( + + ); + + // Act + + const input = screen.getByLabelText(/tag/i); + + await user.type(input, "Poli"); + fireEvent.keyDown(input, { key: "ArrowDown" }); + await user.type(input, "{Enter}"); + + // Assert + + // Ensure we didn't tag both "Poli" (the text entry) and "Politics" (the first tag, selected + // using down-arrow.) + expect(onTag).toHaveBeenCalledOnceWith({ id: "1", name: "Politics" }); + }); + test.todo("initially shows tags with votes"); + test.todo("initially hides tags lacking votes"); + test.todo("shows tags lacking votes after clicking show all"); + test.todo("shows recommended tags initially"); + test.todo("hides recommended tags after downvoting them"); }); diff --git a/premiser-ui/src/TagsControl.tsx b/premiser-ui/src/TagsControl.tsx index 5f2194d8..e2c66333 100644 --- a/premiser-ui/src/TagsControl.tsx +++ b/premiser-ui/src/TagsControl.tsx @@ -1,4 +1,4 @@ -import React, { useState } from "react"; +import React, { FormEvent, useState } from "react"; import find from "lodash/find"; import get from "lodash/get"; import includes from "lodash/includes"; @@ -19,7 +19,6 @@ import TagsViewer from "./TagsViewer"; import { Keys } from "./keyCodes"; import { ComponentId, - OnEventCallback, OnKeyDownCallback, OnPropertyChangeCallback, SuggestionsKey, @@ -61,17 +60,16 @@ export interface Props { /** Enable collapsing the tag name input */ inputCollapsable?: boolean; addTitle?: string; - onSubmit?: OnEventCallback; + /** The autocomplete suggestion fetch debounce milliseconds. */ + autocompleteDebounceMs?: number; } -const upDownArrowKeys = [Keys.ARROW_UP, Keys.ARROW_DOWN]; - export default function TagsControl(props: Props) { const { tags, votes, recommendedTags, - commitChipKeys = [Keys.ENTER, Keys.COMMA], + commitChipKeys = [Keys.COMMA], id, suggestionsKey, votePolarity = { @@ -84,45 +82,31 @@ export default function TagsControl(props: Props) { onUnTag, onAntiTag, addTitle = "Add tag", - onSubmit, + autocompleteDebounceMs, ...rest } = props; const [tagName, setTagName] = useState(""); const [isInputCollapsed, setIsInputCollapsed] = useState(true); - // Whether the user has highlighted the autocomplete dropdown. - // - // react-md's AutoComplete leaves the focus in the text box, so that pressing enter - // both triggers an autocomplete and triggers an Enter keydown in the text input - // (which we would also like to use to create a tag.) To avoid both an autocomplete - // and submitting a partial tag name, we try to keep track of whether the dropdown is - // highlighted and skip the text input Enter behavior if so. - const [isDropdownHighlighted, setIsDropdownHighlighted] = useState(false); - const onTagNameKeyDown: OnKeyDownCallback = (event) => { - if (includes(upDownArrowKeys, event.key)) { - setIsDropdownHighlighted(true); + function submitTagName(event: FormEvent) { + // Stop it from submitting an enclosing form + event.preventDefault(); + // Stop it from propagating to an enclosing form + event.stopPropagation(); + + addTag(tagName); + setTagName(""); + if (inputCollapsable) { + setIsInputCollapsed(true); } + } - if ( - !isDropdownHighlighted && - includes(commitChipKeys, event.key) && - tagName - ) { - // Stops ApiAutocomplete from proceeding to call onSubmit callbacks + const onTagNameKeyDown: OnKeyDownCallback = (event) => { + if (includes(commitChipKeys, event.key) && tagName) { event.preventDefault(); - if (event.key === Keys.ENTER) { - // Stops the form from submitting via native user agent behavior - event.stopPropagation(); - } addTag(tagName); setTagName(""); - setIsDropdownHighlighted(false); - } - - if (inputCollapsable && event.key === Keys.ENTER) { - setIsInputCollapsed(true); - setIsDropdownHighlighted(false); } }; @@ -133,7 +117,6 @@ export default function TagsControl(props: Props) { const onTagNameAutocomplete = (tag: Tag) => { onTag(tag); setTagName(""); - setIsDropdownHighlighted(false); }; const onClickTag = (tagName: string) => { @@ -195,7 +178,6 @@ export default function TagsControl(props: Props) { addTag(tagName); } setTagName(""); - setIsDropdownHighlighted(false); setIsInputCollapsed(true); }; @@ -203,25 +185,33 @@ export default function TagsControl(props: Props) { const extraChildren = []; if (!inputCollapsable || !isInputCollapsed) { extraChildren.push( - closeInput()}> - done - - ) : undefined - } - onSubmit={onSubmit} - /> + // This form makes it easier to receive a submit only when the autocomplete listbox is closed. + // But it also makes it possible for us to nest forms, which is tecnically invalid HTML. + // Other solutions include updating AutoComplete to call onKeyDown after it has + // preventedDefault so that our onKeyDown could inspect that and do nothing. Or to define a + // custom onKeyDown that passes information about the current AutoComplete state, like whether + // the listbox is visible. +
+ closeInput()}> + done + + ) : undefined + } + autocompleteDebounceMs={autocompleteDebounceMs} + /> + ); } if (inputCollapsable && isInputCollapsed) { diff --git a/premiser-ui/src/__snapshots__/CreatePropositionPage.test.tsx.snap b/premiser-ui/src/__snapshots__/CreatePropositionPage.test.tsx.snap index 1c48b1fb..f5a746cb 100644 --- a/premiser-ui/src/__snapshots__/CreatePropositionPage.test.tsx.snap +++ b/premiser-ui/src/__snapshots__/CreatePropositionPage.test.tsx.snap @@ -114,38 +114,40 @@ exports[`CreatePropositionPage can add URL while editing a WritQuote-based justi
-
+
-
+
-
+
-
+
= 15.6" + peerDependencies: + react: ">= 16.8" + dependenciesMeta: + prop-types: + optional: true + checksum: 92f565c5de36053b0179c9528d1b0da8c90b139f9e2b1cd2b8fd8c959ac2eba51b2161fc6f073769655596d0ce23ebf97ffd9e4ce60cf5638b06278b81d789b1 + languageName: node + linkType: hard + "@react-md/avatar@npm:^2.9.1": version: 2.9.1 resolution: "@react-md/avatar@npm:2.9.1" @@ -10244,7 +10267,14 @@ __metadata: languageName: node linkType: hard -"classnames@npm:^2.2.5, classnames@npm:^2.2.6, classnames@npm:^2.3.1": +"classnames@npm:^2.2.5": + version: 2.3.2 + resolution: "classnames@npm:2.3.2" + checksum: 2c62199789618d95545c872787137262e741f9db13328e216b093eea91c85ef2bfb152c1f9e63027204e2559a006a92eb74147d46c800a9f96297ae1d9f96f4e + languageName: node + linkType: hard + +"classnames@npm:^2.2.6, classnames@npm:^2.3.1": version: 2.3.1 resolution: "classnames@npm:2.3.1" checksum: 14db8889d56c267a591f08b0834989fe542d47fac659af5a539e110cc4266694e8de86e4e3bbd271157dbd831361310a8293e0167141e80b0f03a0f175c80960 @@ -13767,7 +13797,7 @@ __metadata: languageName: node linkType: hard -"fbjs@npm:^0.8.12, fbjs@npm:^0.8.16, fbjs@npm:^0.8.4": +"fbjs@npm:^0.8.12": version: 0.8.17 resolution: "fbjs@npm:0.8.17" dependencies: @@ -13782,6 +13812,21 @@ __metadata: languageName: node linkType: hard +"fbjs@npm:^0.8.16, fbjs@npm:^0.8.4": + version: 0.8.18 + resolution: "fbjs@npm:0.8.18" + dependencies: + core-js: ^1.0.0 + isomorphic-fetch: ^2.1.1 + loose-envify: ^1.0.0 + object-assign: ^4.1.0 + promise: ^7.1.1 + setimmediate: ^1.0.5 + ua-parser-js: ^0.7.30 + checksum: 668731b946a765908c9cbe51d5160f973abb78004b3d122587c3e930e3e1ddcc0ce2b17f2a8637dc9d733e149aa580f8d3035a35cc2d3bc78b78f1b19aab90e2 + languageName: node + linkType: hard + "figures@npm:^3.0.0": version: 3.2.0 resolution: "figures@npm:3.2.0" @@ -18194,9 +18239,9 @@ __metadata: linkType: soft "keycode@npm:^2.1.7": - version: 2.2.0 - resolution: "keycode@npm:2.2.0" - checksum: cb91c2940a892f1444a41fc08339b8831445a6b095af9103e3061ea7d4bdbfc420135dcb5d9257020e35c374468bb7d4495ea9fcea54e5760196daff3c874fa4 + version: 2.2.1 + resolution: "keycode@npm:2.2.1" + checksum: 7a5c775b2410a3b6d9c07a415ecb70639187a965be239d2c11c71079cb1ca2f9dede94b86426f3ece475dc8ae3debf2367531bbcafc0af8c82f157d9a4f7e6cb languageName: node linkType: hard @@ -22512,7 +22557,7 @@ __metadata: languageName: node linkType: hard -"prop-types@npm:>= 15.6": +"prop-types@npm:>= 15.6, prop-types@npm:^15.5.4, prop-types@npm:^15.5.6, prop-types@npm:^15.5.8, prop-types@npm:^15.6.0": version: 15.8.1 resolution: "prop-types@npm:15.8.1" dependencies: @@ -22523,7 +22568,7 @@ __metadata: languageName: node linkType: hard -"prop-types@npm:^15.5.10, prop-types@npm:^15.5.4, prop-types@npm:^15.5.6, prop-types@npm:^15.5.8, prop-types@npm:^15.6.0, prop-types@npm:^15.6.1, prop-types@npm:^15.6.2, prop-types@npm:^15.7.2": +"prop-types@npm:^15.5.10, prop-types@npm:^15.6.1, prop-types@npm:^15.6.2, prop-types@npm:^15.7.2": version: 15.7.2 resolution: "prop-types@npm:15.7.2" dependencies: @@ -26592,6 +26637,13 @@ resolve@^2.0.0-next.3: languageName: node linkType: hard +"ua-parser-js@npm:^0.7.30": + version: 0.7.35 + resolution: "ua-parser-js@npm:0.7.35" + checksum: 0a332e8d72d277e62f29ecb3a33843b274de93eb9378350b746ea0f89ef05ee09c94f2c1fdab8001373ad5e95a48beb0a94f39dc1670c908db9fc9b8f0876204 + languageName: node + linkType: hard + "uglify-es@npm:^3.1.9": version: 3.3.10 resolution: "uglify-es@npm:3.3.10"