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

fix(web): ensure the argument of runes function are string #1340

Merged
merged 3 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 1 addition & 2 deletions web/src/components/atoms/Input/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { runes } from "runes2";
export type { SearchProps } from "antd/lib/input";

type Props = {
value?: string;
isError?: boolean;
} & InputProps;

Expand All @@ -15,7 +14,7 @@ const Input = forwardRef<InputRef, Props>(
if (
isError ||
(required && !value) ||
(maxLength && value && runes(value).length > maxLength)
(maxLength && typeof value === "string" && value && runes(value).length > maxLength)
caichi-t marked this conversation as resolved.
Show resolved Hide resolved
) {
return "error";
}
Expand Down
5 changes: 2 additions & 3 deletions web/src/components/atoms/Markdown/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { runes } from "runes2";
import TextArea, { TextAreaProps } from "@reearth-cms/components/atoms/TextArea";

type Props = {
value?: string;
onChange?: (value: string) => void;
isError?: boolean;
} & TextAreaProps;
Expand All @@ -17,7 +16,7 @@ const MarkdownInput: React.FC<Props> = ({ value, onChange, ...props }) => {
const isError = useMemo(() => {
if (props.isError || (props.required && !value)) {
return true;
} else if (props.maxLength && value) {
} else if (props.maxLength && typeof value === "string" && value) {
return runes(value).length > props.maxLength;
} else {
return false;
Expand Down Expand Up @@ -52,7 +51,7 @@ const MarkdownInput: React.FC<Props> = ({ value, onChange, ...props }) => {
showCount
/>
<StyledMD disabled={props.disabled} isError={isError} hidden={!showMD} onClick={handleClick}>
<ReactMarkdown>{value}</ReactMarkdown>
<ReactMarkdown>{typeof value === "string" ? value : undefined}</ReactMarkdown>
</StyledMD>
</MarkdownWrapper>
);
Expand Down
3 changes: 1 addition & 2 deletions web/src/components/atoms/TextArea/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { forwardRef, useMemo } from "react";
import { runes } from "runes2";

type Props = {
value?: string;
isError?: boolean;
} & TextAreaProps;

Expand All @@ -13,7 +12,7 @@ const TextArea = forwardRef<HTMLInputElement, Props>(
if (
isError ||
(required && !value) ||
(maxLength && value && runes(value).length > maxLength)
(maxLength && typeof value === "string" && value && runes(value).length > maxLength)
) {
return "error";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ const DefaultField: React.FC<DefaultFieldProps> = ({
validator: (_, value) => {
if (value && maxLength) {
if (Array.isArray(value)) {
if (value.some(v => maxLength < runes(v).length)) {
if (value.some(v => typeof v === "string" && maxLength < runes(v).length)) {
return Promise.reject();
}
} else if (maxLength < runes(value).length) {
} else if (typeof value === "string" && maxLength < runes(value).length) {
return Promise.reject();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ const MarkdownField: React.FC<DefaultFieldProps> = ({ field, itemGroupId, disabl
validator: (_, value) => {
if (value && maxLength) {
if (Array.isArray(value)) {
if (value.some(v => maxLength < runes(v).length)) {
if (value.some(v => typeof v === "string" && maxLength < runes(v).length)) {
return Promise.reject();
}
} else if (maxLength < runes(value).length) {
} else if (typeof value === "string" && maxLength < runes(value).length) {
return Promise.reject();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ const TextareaField: React.FC<DefaultFieldProps> = ({ field, itemGroupId, disabl
validator: (_, value) => {
if (value && maxLength) {
if (Array.isArray(value)) {
if (value.some(v => maxLength < runes(v).length)) {
if (value.some(v => typeof v === "string" && maxLength < runes(v).length)) {
return Promise.reject();
}
} else if (maxLength < runes(value).length) {
} else if (typeof value === "string" && maxLength < runes(value).length) {
caichi-t marked this conversation as resolved.
Show resolved Hide resolved
return Promise.reject();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ const MarkdownField: React.FC<Props> = ({ multiple, maxLength }) => {
validator: (_, value) => {
if (value && maxLength) {
if (Array.isArray(value)) {
if (value.some(v => maxLength < runes(v).length)) {
if (value.some(v => typeof v === "string" && maxLength < runes(v).length)) {
return Promise.reject();
}
} else if (maxLength < runes(value).length) {
} else if (typeof value === "string" && maxLength < runes(value).length) {
return Promise.reject();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ const TextAreaField: React.FC<Props> = ({ multiple, maxLength }) => {
validator: (_, value) => {
if (value && maxLength) {
if (Array.isArray(value)) {
if (value.some(v => maxLength < runes(v).length)) {
if (value.some(v => typeof v === "string" && maxLength < runes(v).length)) {
return Promise.reject();
}
} else if (maxLength < runes(value).length) {
} else if (typeof value === "string" && maxLength < runes(value).length) {
return Promise.reject();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ const TextField: React.FC<Props> = ({ multiple, maxLength }) => {
validator: (_, value) => {
if (value && maxLength) {
if (Array.isArray(value)) {
if (value.some(v => maxLength < runes(v).length)) {
if (value.some(v => typeof v === "string" && maxLength < runes(v).length)) {
return Promise.reject();
}
} else if (maxLength < runes(value).length) {
} else if (typeof value === "string" && maxLength < runes(value).length) {
return Promise.reject();
caichi-t marked this conversation as resolved.
Show resolved Hide resolved
}
}
Expand Down
Loading