Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: replace react-portal with react-use-portal #5383

Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
"react-dom": "18.2.0",
"react-dropzone": "14.2.3",
"react-ga4": "2.1.0",
"react-portal": "4.2.2",
"react-redux": "8.0.5",
"react-router-dom": "6.22.3",
"react-storage-hooks": "4.0.1",
Expand Down Expand Up @@ -111,7 +110,6 @@
"@types/pluralize": "0.0.33",
"@types/react": "18.2.73",
"@types/react-dom": "18.2.23",
"@types/react-portal": "4.0.7",
Jay-Topher marked this conversation as resolved.
Show resolved Hide resolved
"@types/react-redux": "7.1.33",
"@types/react-router": "5.1.20",
"@types/react-router-dom": "5.3.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { useState } from "react";

import { Col, Modal, Row, Textarea } from "@canonical/react-components";
import { useFormikContext } from "formik";
import { Portal } from "react-portal";
import { useSelector } from "react-redux";
import usePortal from "react-useportal";
import * as Yup from "yup";
import type { SchemaOf } from "yup";

Expand Down Expand Up @@ -31,11 +31,11 @@ export const NodeConfigurationSchema: SchemaOf<NodeConfigurationValues> =
.defined();

const NodeConfigurationFields = (): JSX.Element => {
const { openPortal, closePortal, isOpen, Portal } = usePortal();
const { setFieldValue, values } = useFormikContext<NodeConfigurationValues>();
const selectedTags = useSelector((state: RootState) =>
tagSelectors.getByIDs(state, values.tags)
);
const [isOpen, setIsOpen] = useState(false);
const [newTagName, setNewTagName] = useState<string | null>(null);
const manualTags = useSelector(tagSelectors.getManual);

Expand All @@ -55,9 +55,9 @@ const NodeConfigurationFields = (): JSX.Element => {
)}
externalSelectedTags={selectedTags}
name="tags"
onAddNewTag={(name) => {
onAddNewTag={(name) => (event) => {
setNewTagName(name);
setIsOpen(true);
openPortal(event);
}}
placeholder="Create or remove tags"
tagList={manualTags}
Expand All @@ -68,7 +68,7 @@ const NodeConfigurationFields = (): JSX.Element => {
<Portal>
<Modal
className="tag-form__modal"
close={() => setIsOpen(false)}
close={() => closePortal()}
Jay-Topher marked this conversation as resolved.
Show resolved Hide resolved
title={Label.AddTag}
>
<AddTagForm
Expand All @@ -81,7 +81,7 @@ const NodeConfigurationFields = (): JSX.Element => {
onTagCreated={(tag) => {
setFieldValue("tags", values.tags.concat([tag.id]));
setNewTagName(null);
setIsOpen(false);
closePortal();
}}
/>
</Modal>
Expand Down
8 changes: 4 additions & 4 deletions src/app/base/components/TagSelector/TagSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export type Props = {
help?: string;
initialSelected?: Tag[];
label?: string | null;
onAddNewTag?: (name: string) => void;
onAddNewTag?: (name: string) => (event: React.SyntheticEvent) => void;
onTagsUpdate?: (tags: Tag[]) => void;
placeholder?: string;
required?: boolean;
Expand Down Expand Up @@ -91,10 +91,10 @@ const generateDropdownItems = ({
appearance="base"
className="tag-selector__dropdown-button u-break-word"
data-testid="new-tag"
onClick={() => {
onClick={(e) => {
const cleanedFilter = sanitiseFilter(filter);
if (onAddNewTag) {
onAddNewTag(cleanedFilter.name);
onAddNewTag(cleanedFilter.name)?.(e);
setFilter("");
} else {
updateTags([...selectedTags, cleanedFilter]);
Expand Down Expand Up @@ -272,7 +272,7 @@ export const TagSelector = ({
if (allowNewTags) {
const cleanedFilter = sanitiseFilter(filter);
if (onAddNewTag) {
onAddNewTag(cleanedFilter.name);
onAddNewTag(cleanedFilter.name)?.(e);
setFilter("");
} else {
updateTags([...selectedTags, cleanedFilter]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export const TagFormFields = ({
}
label={Label.TagInput}
name="added"
onAddNewTag={(name) => {
onAddNewTag={(name) => (_) => {
setNewTagName(name);
setSecondaryContent("addTag");
}}
Expand Down
16 changes: 1 addition & 15 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4801,13 +4801,6 @@
dependencies:
"@types/react" "*"

"@types/react-portal@4.0.7":
version "4.0.7"
resolved "https://registry.yarnpkg.com/@types/react-portal/-/react-portal-4.0.7.tgz#c7436c5039e74ec80d488fbe5c98dbcc6469bf44"
integrity sha512-3zQJL6Pqcq7d73+cakVkZDqAYGFBo37XXPfahjhdScr9EdYPlf9evYilL38Fpzs1YGWz7F2SkPtN6+ygTO7ymg==
dependencies:
"@types/react" "*"

"@types/react-redux@7.1.33":
version "7.1.33"
resolved "https://registry.yarnpkg.com/@types/react-redux/-/react-redux-7.1.33.tgz#53c5564f03f1ded90904e3c90f77e4bd4dc20b15"
Expand Down Expand Up @@ -11214,7 +11207,7 @@ prompts@^2.4.0:
kleur "^3.0.3"
sisteransi "^1.0.5"

prop-types@15.8.1, prop-types@^15.5.8, prop-types@^15.7.2, prop-types@^15.8.1:
prop-types@15.8.1, prop-types@^15.7.2, prop-types@^15.8.1:
version "15.8.1"
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.8.1.tgz#67d87bf1a694f48435cf332c24af10214a3140b5"
integrity sha512-oj87CgZICdulUohogVAR7AjlC0327U4el4L6eAvOqCeudMDVU0NThNaV+b9Df4dXgSP1gXMTnPdhfe/2qDH5cg==
Expand Down Expand Up @@ -11476,13 +11469,6 @@ react-is@^18.0.0:
resolved "https://registry.yarnpkg.com/react-is/-/react-is-18.2.0.tgz#199431eeaaa2e09f86427efbb4f1473edb47609b"
integrity sha512-xWGDIW6x921xtzPkhiULtthJHoJvBbF3q26fzloPCK0hsvxtPVelvftw3zjbHWSkR2km9Z+4uxbDDK/6Zw9B8w==

react-portal@4.2.2:
version "4.2.2"
resolved "https://registry.yarnpkg.com/react-portal/-/react-portal-4.2.2.tgz#bff1e024147d6041ba8c530ffc99d4c8248f49fa"
integrity sha512-vS18idTmevQxyQpnde0Td6ZcUlv+pD8GTyR42n3CHUQq9OHi1C4jDE4ZWEbEsrbrLRhSECYiao58cvocwMtP7Q==
dependencies:
prop-types "^15.5.8"

react-redux@8.0.5:
version "8.0.5"
resolved "https://registry.yarnpkg.com/react-redux/-/react-redux-8.0.5.tgz#e5fb8331993a019b8aaf2e167a93d10af469c7bd"
Expand Down
Loading