Skip to content

Commit

Permalink
🐛Should always use IStr in ISelectField
Browse files Browse the repository at this point in the history
  • Loading branch information
carefree0910 committed May 20, 2023
1 parent 11fb5de commit 607fef4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
11 changes: 6 additions & 5 deletions cfdraw/.web/src/plugins/components/Fields/SelectField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Box, Flex } from "@chakra-ui/react";

import { getHash } from "@carefree0910/core";

import type { IStr } from "@/schema/misc";
import type { IField } from "@/schema/plugins";
import type { ISelectField } from "@/schema/fields";
import { getBaseURL, titleCaseWord } from "@/utils/misc";
Expand All @@ -16,13 +17,13 @@ import { CFLabel } from "@/components/CFText";
import { CFSrollableSelect } from "@/components/CFSelect";
import { useDefaultFieldValue } from "./utils";

function SelectField({ definition, ...fieldKeys }: IField<ISelectField<string>>) {
function SelectField({ definition, ...fieldKeys }: IField<ISelectField>) {
useDefaultFieldValue({ definition, ...fieldKeys });
const userId = userStore.userId;
const label = parseIStr(definition.label ?? titleCaseWord(fieldKeys.field));
const tooltip = parseIStr(definition.tooltip ?? "");
const [value, setValue] = useState(getMetaField(fieldKeys) ?? definition.default);
const [options, setOptions] = useState(definition.values as string[]);
const [options, setOptions] = useState(definition.values as IStr[]);
const onMenuOpen = useCallback(() => {
if (definition.localProperties) {
const extraData = definition.localProperties;
Expand Down Expand Up @@ -50,16 +51,16 @@ function SelectField({ definition, ...fieldKeys }: IField<ISelectField<string>>)
}
}, [definition.localProperties]);

const selected = { value, label: value };
const selectOptions = options.map((value) => ({ value, label: value }));
const selected = { value, label: parseIStr(value) };
const selectOptions = options.map((value) => ({ value, label: parseIStr(value) }));

return (
<Flex w="100%" h="100%" align="center" {...definition.props}>
<CFTooltip label={tooltip}>
<CFLabel label={label} />
</CFTooltip>
<Box w="8px" />
<CFSrollableSelect<string, false>
<CFSrollableSelect<IStr, false>
height="40px"
boxProps={{ flex: 1 }}
value={selected}
Expand Down
8 changes: 4 additions & 4 deletions cfdraw/.web/src/schema/fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ interface ISelectLocalProperties {
onlyFiles: boolean;
defaultPlaceholder?: string;
}
export interface ISelectField<T> extends IBaseFields {
export interface ISelectField extends IBaseFields {
type: "select";
values: readonly T[];
default: T;
values: readonly IStr[];
default: IStr;
isMulti?: boolean;
localProperties?: ISelectLocalProperties;
}
Expand Down Expand Up @@ -71,7 +71,7 @@ export type IFieldDefinition =
| ITextField
| IImageField
| INumberField
| ISelectField<any>
| ISelectField
| IBooleanField
| IColorField
| IListField
Expand Down

0 comments on commit 607fef4

Please sign in to comment.