Skip to content

Commit

Permalink
refactor: judgment grammar simplification
Browse files Browse the repository at this point in the history
  • Loading branch information
1587315093 committed Jul 10, 2023
1 parent cce2221 commit 21277d4
Show file tree
Hide file tree
Showing 15 changed files with 103 additions and 144 deletions.
5 changes: 2 additions & 3 deletions src/components/calendar/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ export function convertValueToRange(
): DateRange {
if (selectionMode === undefined || value === null) return null

if (Array.isArray(value)) {
return value
}
if (Array.isArray(value)) return value

return [value, value]
}
export function convertPageToDayjs(page: Page) {
Expand Down
14 changes: 5 additions & 9 deletions src/components/capsule-tabs/capsule-tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ export type CapsuleTabProps = {
children?: ReactNode
} & NativeProps

export const CapsuleTab: FC<CapsuleTabProps> = () => {
return null
}
export const CapsuleTab: FC<CapsuleTabProps> = () => null

export type CapsuleTabsProps = {
activeKey?: string | null
Expand Down Expand Up @@ -91,9 +89,8 @@ export const CapsuleTabs: FC<CapsuleTabsProps> = props => {
onClick={() => {
const { key } = pane
if (pane.props.disabled) return
if (key === undefined || key === null) {
return
}
if (key === undefined || key === null) return

setActiveKey(key.toString())
}}
className={classNames(`${classPrefix}-tab`, {
Expand All @@ -109,9 +106,8 @@ export const CapsuleTabs: FC<CapsuleTabsProps> = props => {
</animated.div>
</div>
{panes.map(pane => {
if (pane.props.children === undefined) {
return null
}
if (pane.props.children === undefined) return null

const active = pane.key === activeKey
return (
<ShouldRender
Expand Down
10 changes: 4 additions & 6 deletions src/components/card/card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ export type CardProps = {

export const Card: FC<CardProps> = props => {
const renderHeader = () => {
if (!(props.title || props.extra)) {
return null
}
if (!(props.title || props.extra)) return null

return (
<div
className={classNames(`${classPrefix}-header`, props.headerClassName)}
Expand All @@ -35,9 +34,8 @@ export const Card: FC<CardProps> = props => {
}

const renderBody = () => {
if (!props.children) {
return null
}
if (!props.children) return null

return (
<div
className={classNames(`${classPrefix}-body`, props.bodyClassName)}
Expand Down
60 changes: 24 additions & 36 deletions src/components/date-picker/date-picker-date-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,10 @@ export function generateDatePickerColumns(
const upper = maxYear
const years = generateColumn(lower, upper, 'year')
ret.push(
years.map(v => {
return {
label: renderLabel('year', v),
value: v.toString(),
}
})
years.map(v => ({
label: renderLabel('year', v),
value: v.toString(),
}))
)
}

Expand All @@ -118,64 +116,54 @@ export function generateDatePickerColumns(
const upper = isInMaxYear ? maxMonth : 12
const months = generateColumn(lower, upper, 'month')
ret.push(
months.map(v => {
return {
label: renderLabel('month', v),
value: v.toString(),
}
})
months.map(v => ({
label: renderLabel('month', v),
value: v.toString(),
}))
)
}
if (rank >= precisionRankRecord.day) {
const lower = isInMinMonth ? minDay : 1
const upper = isInMaxMonth ? maxDay : firstDayInSelectedMonth.daysInMonth()
const days = generateColumn(lower, upper, 'day')
ret.push(
days.map(v => {
return {
label: renderLabel('day', v),
value: v.toString(),
}
})
days.map(v => ({
label: renderLabel('day', v),
value: v.toString(),
}))
)
}
if (rank >= precisionRankRecord.hour) {
const lower = isInMinDay ? minHour : 0
const upper = isInMaxDay ? maxHour : 23
const hours = generateColumn(lower, upper, 'hour')
ret.push(
hours.map(v => {
return {
label: renderLabel('hour', v),
value: v.toString(),
}
})
hours.map(v => ({
label: renderLabel('hour', v),
value: v.toString(),
}))
)
}
if (rank >= precisionRankRecord.minute) {
const lower = isInMinHour ? minMinute : 0
const upper = isInMaxHour ? maxMinute : 59
const minutes = generateColumn(lower, upper, 'minute')
ret.push(
minutes.map(v => {
return {
label: renderLabel('minute', v),
value: v.toString(),
}
})
minutes.map(v => ({
label: renderLabel('minute', v),
value: v.toString(),
}))
)
}
if (rank >= precisionRankRecord.second) {
const lower = isInMinMinute ? minSecond : 0
const upper = isInMaxMinute ? maxSecond : 59
const seconds = generateColumn(lower, upper, 'second')
ret.push(
seconds.map(v => {
return {
label: renderLabel('second', v),
value: v.toString(),
}
})
seconds.map(v => ({
label: renderLabel('second', v),
value: v.toString(),
}))
)
}

Expand Down
30 changes: 12 additions & 18 deletions src/components/date-picker/date-picker-week-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,10 @@ export function generateDatePickerColumns(
const upper = maxYear
const years = generateColumn(lower, upper, 'year')
ret.push(
years.map(v => {
return {
label: renderLabel('year', v),
value: v.toString(),
}
})
years.map(v => ({
label: renderLabel('year', v),
value: v.toString(),
}))
)
}

Expand All @@ -91,25 +89,21 @@ export function generateDatePickerColumns(
const upper = isInMaxYear ? maxWeek : selectedYearWeeks
const weeks = generateColumn(lower, upper, 'week')
ret.push(
weeks.map(v => {
return {
label: renderLabel('week', v),
value: v.toString(),
}
})
weeks.map(v => ({
label: renderLabel('week', v),
value: v.toString(),
}))
)
}
if (rank >= precisionRankRecord['week-day']) {
const lower = isInMinWeek ? minWeekday : 1
const upper = isInMaxWeek ? maxWeekday : 7
const weeks = generateColumn(lower, upper, 'week-day')
ret.push(
weeks.map(v => {
return {
label: renderLabel('week-day', v),
value: v.toString(),
}
})
weeks.map(v => ({
label: renderLabel('week-day', v),
value: v.toString(),
}))
)
}

Expand Down
1 change: 0 additions & 1 deletion src/components/dropdown/dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export type DropdownProps = {
closeOnMaskClick?: boolean
closeOnClickAway?: boolean
onChange?: (key: string | null) => void
// mask?: boolean;
arrow?: React.ReactNode
getContainer?: PopupProps['getContainer']
} & NativeProps
Expand Down
52 changes: 24 additions & 28 deletions src/components/footer/footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,40 +60,36 @@ export const Footer: FC<FooterProps> = p => {
<Divider>{label}</Divider>
</div>
)}
{links && links.length > 0 && (
{!!links?.length && (
<div className={`${classPrefix}-links`}>
{links.map((link, index) => {
return (
<React.Fragment key={index}>
<a
href={link.href}
rel='noopener noreferrer'
onClick={event => clickLinkItem(link, index, event)}
>
{link.text}
</a>
{index !== links.length - 1 && <Divider direction='vertical' />}
</React.Fragment>
)
})}
{links.map((link, index) => (
<React.Fragment key={index}>
<a
href={link.href}
rel='noopener noreferrer'
onClick={event => clickLinkItem(link, index, event)}
>
{link.text}
</a>
{index !== links.length - 1 && <Divider direction='vertical' />}
</React.Fragment>
))}
</div>
)}
{content && <div className={`${classPrefix}-content`}>{content}</div>}
{chips && chips.length > 0 && (
<div className={`${classPrefix}-chips`}>
{chips.map((chip, index) => {
return (
<div
key={index}
onClick={() => clickChipItem(chip, index)}
className={classNames(`${classPrefix}-chip`, {
[`${classPrefix}-chip-link`]: chip.type === 'link',
})}
>
{chip.text}
</div>
)
})}
{chips.map((chip, index) => (
<div
key={index}
onClick={() => clickChipItem(chip, index)}
className={classNames(`${classPrefix}-chip`, {
[`${classPrefix}-chip-link`]: chip.type === 'link',
})}
>
{chip.text}
</div>
))}
</div>
)}
</div>
Expand Down
1 change: 0 additions & 1 deletion src/components/form/form-array.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export interface FormArrayOperation {

export interface FormArrayProps {
name: string | number | (string | number)[]
// rules?: ValidatorRule[]
initialValue?: any[]
renderHeader?: (
field: FormArrayField,
Expand Down
2 changes: 1 addition & 1 deletion src/components/grid/grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const Grid: FC<GridProps> = props => {
'--columns': props.columns.toString(),
}
const { gap } = props
if (gap !== undefined) {
if (gap) {
if (Array.isArray(gap)) {
style['--gap-horizontal'] = toCSSLength(gap[0])
style['--gap-vertical'] = toCSSLength(gap[1])
Expand Down
13 changes: 4 additions & 9 deletions src/components/image-uploader/image-uploader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,18 +159,14 @@ export const ImageUploader: FC<ImageUploaderProps> = p => {
e.target.value = '' // HACK: fix the same file doesn't trigger onChange

if (props.beforeUpload) {
const postFiles = files.map(file => {
return processFile(file, files)
})
const postFiles = files.map(file => processFile(file, files))

await Promise.all(postFiles).then(filesList => {
files = filesList.filter(Boolean) as File[]
})
}

if (files.length === 0) {
return
}
if (files.length === 0) return

if (maxCount > 0) {
const exceed = value.length + files.length - maxCount
Expand Down Expand Up @@ -279,9 +275,8 @@ export const ImageUploader: FC<ImageUploaderProps> = p => {
<>
{renderImages()}
{tasks.map(task => {
if (!props.showFailed && task.status === 'fail') {
return null
}
if (!props.showFailed && task.status === 'fail') return null

return (
<PreviewItem
key={task.id}
Expand Down
1 change: 1 addition & 0 deletions src/components/input/input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ export const Input = forwardRef<InputRef, InputProps>((p, ref) => {

const shouldShowClear = (() => {
if (!props.clearable || !value || props.readOnly) return false

if (props.onlyShowClearWhenFocus) {
return hasFocus
} else {
Expand Down
10 changes: 4 additions & 6 deletions src/components/jumbo-tabs/jumbo-tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,8 @@ export const JumboTabs: FC<JumboTabsProps> = props => {
onClick={() => {
const { key } = pane
if (pane.props.disabled) return
if (key === undefined || key === null) {
return
}
if (key === undefined || key === null) return

setActiveKey(key.toString())
}}
className={classNames(`${classPrefix}-tab`, {
Expand All @@ -116,9 +115,8 @@ export const JumboTabs: FC<JumboTabsProps> = props => {
</animated.div>
</div>
{panes.map(pane => {
if (pane.props.children === undefined) {
return null
}
if (pane.props.children === undefined) return null

const active = pane.key === activeKey
return (
<ShouldRender
Expand Down
Loading

0 comments on commit 21277d4

Please sign in to comment.