Skip to content

Commit

Permalink
chore: remove getValueByValue
Browse files Browse the repository at this point in the history
  • Loading branch information
janryWang committed Jul 7, 2022
1 parent 7bada5c commit 2ca7aaf
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 101 deletions.
51 changes: 0 additions & 51 deletions packages/antd/src/preview-text/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,57 +25,6 @@ const usePlaceholder = (value?: any) => {
return isValid(value) && value !== '' ? value : placeholder
}

interface IGetValueByValue {
(
array: any[],
inputValue: any,
keyMap?: { inputKey?: string; outputKey?: string; childrenKey?: string },
path?: any[]
): any
}

const getValueByValue: IGetValueByValue = (
array,
inputValue,
keyMap,
path = []
) => {
const {
inputKey = 'value',
outputKey = 'label',
childrenKey = 'children',
} = keyMap || {}
let outputValue: any
if (isArr(array)) {
if (isArr(inputValue)) {
outputValue = inputValue.map((v) =>
getValueByValue(array, v, keyMap, path)
)
} else {
array.forEach((obj) => {
if (outputValue === undefined) {
const currentPath = [...path, obj?.[outputKey]]
if (obj?.[inputKey] === inputValue) {
outputValue = {
leaf: obj?.[outputKey],
whole: currentPath,
}
} else if (obj?.[childrenKey]?.length) {
outputValue = getValueByValue(
obj?.[childrenKey],
inputValue,
keyMap,
currentPath
)
}
}
})
}
return outputValue
}
return undefined
}

const Input: React.FC<React.PropsWithChildren<InputProps>> = (props) => {
const prefixCls = usePrefixCls('form-text', props)
return (
Expand Down
50 changes: 0 additions & 50 deletions packages/next/src/preview-text/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,56 +33,6 @@ const usePlaceholder = (value?: any) => {
return !isEmpty(value) ? value : placeholder
}

interface IGetValueByValue {
(
array: any[],
inputValue: any,
keyMap?: { inputKey?: string; outputKey?: string; childrenKey?: string },
path?: any[]
): any
}
const getValueByValue: IGetValueByValue = (
array,
inputValue,
keyMap,
path = []
) => {
const {
inputKey = 'value',
outputKey = 'label',
childrenKey = 'children',
} = keyMap || {}
let outputValue: any
if (isArr(array)) {
if (isArr(inputValue)) {
outputValue = inputValue.map((v) =>
getValueByValue(array, v, keyMap, path)
)
} else {
array.forEach((obj) => {
if (outputValue === undefined) {
const currentPath = [...path, obj?.[outputKey]]
if (obj?.[inputKey] === inputValue) {
outputValue = {
leaf: obj?.[outputKey],
whole: currentPath,
}
} else if (obj?.[childrenKey]?.length) {
outputValue = getValueByValue(
obj?.[childrenKey],
inputValue,
keyMap,
currentPath
)
}
}
})
}
return outputValue
}
return undefined
}

const Input: React.FC<React.PropsWithChildren<InputProps>> = (props) => {
return <NextInput {...props} isPreview />
}
Expand Down

0 comments on commit 2ca7aaf

Please sign in to comment.