Skip to content

Commit

Permalink
fix: select KeysType lint
Browse files Browse the repository at this point in the history
  • Loading branch information
PengYYYYY committed Aug 16, 2023
1 parent c041bc1 commit 96a5015
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
6 changes: 3 additions & 3 deletions src/select/base/Option.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import get from 'lodash/get';
import useConfig from '../../hooks/useConfig';
import useDomRefCallback from '../../hooks/useDomRefCallback';
import useRipple from '../../_util/useRipple';
import { StyledProps } from '../../common';
import { SelectValue, TdOptionProps, TdSelectProps, SelectKeysType, SelectOption } from '../type';
import { StyledProps, KeysType } from '../../common';
import { SelectValue, TdOptionProps, TdSelectProps, SelectOption } from '../type';

/**
* Option 组件属性
Expand All @@ -30,7 +30,7 @@ export interface SelectOptionProps
) => void;
onCheckAllChange?: (checkAll: boolean, e: React.MouseEvent<HTMLLIElement>) => void;
restData?: Record<string, any>;
keys?: SelectKeysType;
keys?: KeysType;
optionLength?: number;
isVirtual?: boolean;
onRowMounted?: (rowData: { ref: HTMLElement; data: SelectOption }) => void;
Expand Down
19 changes: 8 additions & 11 deletions src/select/util/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ import get from 'lodash/get';
import OptionGroup from '../base/OptionGroup';
import Option from '../base/Option';

import { SelectValue, TdOptionProps, SelectKeysType, TdSelectProps } from '../type';
import { SelectValue, TdOptionProps, TdSelectProps } from '../type';
import { KeysType } from '../../common';

type SelectLabeledValue = Required<Omit<TdOptionProps, 'disabled'>>;

type ValueToOption = {
[value: string | number]: TdOptionProps;
};

function setValueToOptionFormOptionDom(dom: ReactElement, valueToOption: ValueToOption, keys: SelectKeysType) {
function setValueToOptionFormOptionDom(dom: ReactElement, valueToOption: ValueToOption, keys: KeysType) {
const { value, label, children } = dom.props;
// eslint-disable-next-line no-param-reassign
valueToOption[value] = {
Expand All @@ -22,11 +23,7 @@ function setValueToOptionFormOptionDom(dom: ReactElement, valueToOption: ValueTo
}

// 获取 value => option,用于快速基于 value 找到对应的 option
export const getValueToOption = (
children: ReactElement,
options: TdOptionProps[],
keys: SelectKeysType,
): ValueToOption => {
export const getValueToOption = (children: ReactElement, options: TdOptionProps[], keys: KeysType): ValueToOption => {
const valueToOption = {};

// options 优先级高于 children
Expand Down Expand Up @@ -80,7 +77,7 @@ export const getLabel = (
children: ReactElement,
value: SelectValue<TdOptionProps>,
options: TdOptionProps[],
keys: SelectKeysType,
keys: KeysType,
) => {
let selectedLabel = '';
// 处理带 options 属性的情况
Expand Down Expand Up @@ -144,7 +141,7 @@ export const getLabel = (
return selectedLabel;
};

export const getMultipleTags = (values: SelectValue[], keys: SelectKeysType) => {
export const getMultipleTags = (values: SelectValue[], keys: KeysType) => {
const tags = values.map((item) => ({
label: get(item, keys?.label || 'label') || item.toString(),
value: get(item, keys?.value || 'value') || item,
Expand All @@ -157,7 +154,7 @@ export const getSelectValueArr = (
activeValue: SelectValue,
selected?: boolean,
valueType?: TdSelectProps['valueType'],
keys?: SelectKeysType,
keys?: KeysType,
objVal?: SelectValue,
) => {
// eslint-disable-next-line no-param-reassign
Expand Down Expand Up @@ -190,7 +187,7 @@ export const getSelectedOptions = (
value: SelectValue,
multiple: TdSelectProps['multiple'],
valueType: TdSelectProps['valueType'],
keys: SelectKeysType,
keys: KeysType,
tmpPropOptions: Array<unknown>,
) => {
const isObjectType = valueType === 'object';
Expand Down

0 comments on commit 96a5015

Please sign in to comment.