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

chore: code style simplify #6241

Merged
merged 1 commit into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 1 addition & 3 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
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 @@
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,71 +116,61 @@
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 => ({

Check warning on line 163 in src/components/date-picker/date-picker-date-utils.ts

View check run for this annotation

Codecov / codecov/patch

src/components/date-picker/date-picker-date-utils.ts#L163

Added line #L163 was not covered by tests
label: renderLabel('second', v),
value: v.toString(),
}))
)
}

// Till Now
if (tillNow) {
ret[0].push({
label: renderLabel('now', null!),

Check warning on line 173 in src/components/date-picker/date-picker-date-utils.ts

View workflow job for this annotation

GitHub Actions / check

Forbidden non-null assertion
value: TILL_NOW,
})

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
4 changes: 1 addition & 3 deletions src/components/image-uploader/image-uploader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,7 @@ 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[]
Expand Down
32 changes: 15 additions & 17 deletions src/components/modal/modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,23 +72,21 @@ export const Modal: FC<ModalProps> = p => {
props.actions.length === 0 && cls('footer-empty')
)}
>
{props.actions.map((action, index) => {
return (
<ModalActionButton
key={action.key}
action={action}
onAction={async () => {
await Promise.all([
action.onClick?.(),
props.onAction?.(action, index),
])
if (props.closeOnAction) {
props.onClose?.()
}
}}
/>
)
})}
{props.actions.map((action, index) => (
<ModalActionButton
key={action.key}
action={action}
onAction={async () => {
await Promise.all([
action.onClick?.(),
props.onAction?.(action, index),
])
if (props.closeOnAction) {
props.onClose?.()
}
}}
/>
))}
</Space>
</>
)
Expand Down
12 changes: 5 additions & 7 deletions src/components/popover/popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,11 @@

useImperativeHandle(
ref,
() => {
return {
show: () => setVisible(true),
hide: () => setVisible(false),
visible,
}
},
() => ({
show: () => setVisible(true),
hide: () => setVisible(false),

Check warning on line 82 in src/components/popover/popover.tsx

View check run for this annotation

Codecov / codecov/patch

src/components/popover/popover.tsx#L80-L82

Added lines #L80 - L82 were not covered by tests
visible,
}),
[visible]
)

Expand Down
8 changes: 4 additions & 4 deletions src/components/popup/popup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,24 @@ const defaultProps = {

export const Popup: FC<PopupProps> = p => {
const props = mergeProps(defaultProps, p)
const { locale } = useConfig()

const bodyCls = classNames(
`${classPrefix}-body`,
props.bodyClassName,
`${classPrefix}-body-position-${props.position}`
)

const { locale } = useConfig()
const [active, setActive] = useState(props.visible)
const ref = useRef<HTMLDivElement>(null)
useLockScroll(ref, props.disableBodyScroll && active ? 'strict' : false)

useIsomorphicLayoutEffect(() => {
if (props.visible) {
setActive(true)
}
}, [props.visible])

const ref = useRef<HTMLDivElement>(null)
useLockScroll(ref, props.disableBodyScroll && active ? 'strict' : false)

const unmountedRef = useUnmountedRef()
const { percent } = useSpring({
percent: props.visible ? 0 : 100,
Expand Down
4 changes: 2 additions & 2 deletions src/components/result/result.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ export const Result: FC<ResultProps> = p => {
<div className={classNames(classPrefix, `${classPrefix}-${status}`)}>
<div className={`${classPrefix}-icon`}>{resultIcon}</div>
<div className={`${classPrefix}-title`}>{title}</div>
{description ? (
{!!description && (
<div className={`${classPrefix}-description`}>{description}</div>
) : null}
)}
</div>
)
}
7 changes: 1 addition & 6 deletions src/components/stepper/stepper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ export function InnerStepper<ValueType extends number | string>(
defaultValue = 0 as ValueType,
value,
onChange,

disabled,
step,
max,
Expand Down Expand Up @@ -153,11 +152,7 @@ export function InnerStepper<ValueType extends number | string>(
const formatValue = (value: ValueType | null): string => {
if (value === null) return ''

if (formatter) {
return formatter(value)
} else {
return fixedValue(value)
}
return formatter ? formatter(value) : fixedValue(value)
}

// ======================== Value & InputValue ========================
Expand Down
8 changes: 2 additions & 6 deletions src/components/tree-select/multiple.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -320,18 +320,14 @@ export const Multiple: FC<MultipleProps> = p => {
return (
<>
{renderSelectAllLeafItem(columnOptions, index)}
{columnOptions.map(option => {
return renderLeafItem(option)
})}
{columnOptions.map(option => renderLeafItem(option))}
</>
)
}
return (
<>
{renderSelectAllItem(columnOptions, index)}
{columnOptions.map(option => {
return renderItem(option)
})}
{columnOptions.map(option => renderItem(option))}
</>
)
}
Expand Down
Loading