-
-
Notifications
You must be signed in to change notification settings - Fork 332
fix: presets和maxDate的对比 #930
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
base: master
Are you sure you want to change the base?
Changes from 2 commits
1e172c4
ac97da7
8ea1389
74137d8
14591ab
65e65df
dac6b70
193a8a0
9433f3d
fbfa751
68aaf81
7fc89fe
8e29e88
7ba2b3d
5618439
f4e2ad8
3a76aa6
201eb0b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
import * as React from 'react'; | ||
import type { ValueDate } from '../../interface'; | ||
import moment from 'moment'; | ||
|
||
export interface PresetPanelProps<ValueType = any> { | ||
prefixCls: string; | ||
presets: ValueDate<ValueType>[]; | ||
onClick: (value: ValueType) => void; | ||
onHover: (value: ValueType) => void; | ||
maxDate?: dateTy; | ||
} | ||
|
||
function executeValue<ValueType extends object>(value: ValueDate<ValueType>['value']): ValueType { | ||
|
@@ -15,7 +17,7 @@ function executeValue<ValueType extends object>(value: ValueDate<ValueType>['val | |
export default function PresetPanel<DateType extends object = any>( | ||
props: PresetPanelProps<DateType>, | ||
) { | ||
const { prefixCls, presets, onClick, onHover } = props; | ||
const { prefixCls, presets, onClick, onHover, maxDate } = props; | ||
Comment on lines
17
to
+20
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chain需要 generateConfig 进行日期比较 为了与项目其他部分保持一致并支持不同的日期库,建议通过 props 传入 export interface PresetPanelProps<ValueType = any> {
prefixCls: string;
presets: ValueDate<ValueType>[];
onClick: (value: ValueType) => void;
onHover: (value: ValueType) => void;
- maxDate?: DateType;
+ maxDate?: ValueType;
+ generateConfig: GenerateConfig<ValueType>;
}
export default function PresetPanel<DateType extends object = any>(
props: PresetPanelProps<DateType>,
) {
- const { prefixCls, presets, onClick, onHover, maxDate } = props;
+ const { prefixCls, presets, onClick, onHover, maxDate, generateConfig } = props; 还需要在调用此组件的地方传入 🏁 Script executed: #!/bin/bash
# 检查 PresetPanel 的使用位置,确认是否可以访问 generateConfig
echo "=== 查找 PresetPanel 的使用位置 ==="
rg "PresetPanel" --type ts --type tsx -A 5 -B 5
echo -e "\n=== 检查 generateConfig 的使用模式 ==="
ast-grep --pattern 'generateConfig' Length of output: 33299 🏁 Script executed: #!/bin/bash
echo "=== Inspect PresetPanel.tsx ==="
sed -n '1,200p' src/PickerInput/Popup/PresetPanel.tsx || true
echo -e "\n=== Search for maxDate usage ==="
grep -R "maxDate" -n src/PickerInput/Popup/PresetPanel.tsx || true Length of output: 1930 需要为 PresetPanel 添加 generateConfig 支持,移除对 moment 的直接依赖 为了与项目其他地方保持一致并支持多种日期库,建议对 • 在 Props 接口中:
• 在组件签名和解构 props 时引入 • 将 const isDisabled = moment(value).isAfter(maxDate) || moment(value).isSame(maxDate); 替换为 const rawValue = executeValue(value);
const isDisabled =
generateConfig.isAfter(rawValue, maxDate) ||
generateConfig.isSame(rawValue, maxDate); • 在调用此组件的地方(如 示例 diff: --- a/src/PickerInput/Popup/PresetPanel.tsx
+++ b/src/PickerInput/Popup/PresetPanel.tsx
@@
-export interface PresetPanelProps<ValueType = any> {
+export interface PresetPanelProps<ValueType = any> {
prefixCls: string;
presets: ValueDate<ValueType>[];
onClick: (value: ValueType) => void;
onHover: (value: ValueType) => void;
- maxDate?: dateTy;
+ maxDate?: ValueType;
+ generateConfig: GenerateConfig<ValueType>;
}
-export default function PresetPanel<DateType extends object = any>(
- props: PresetPanelProps<DateType>,
-) {
- const { prefixCls, presets, onClick, onHover, maxDate } = props;
+export default function PresetPanel<DateType extends object = any>(
+ props: PresetPanelProps<DateType>,
+) {
+ const { prefixCls, presets, onClick, onHover, maxDate, generateConfig } = props;
@@
- const isDisabled = moment(value).isAfter(maxDate) || moment(value).isSame(maxDate);
+ const raw = executeValue(value);
+ const isDisabled =
+ generateConfig.isAfter(raw, maxDate) ||
+ generateConfig.isSame(raw, maxDate); 请同时在使用 🤖 Prompt for AI Agents
|
||
|
||
if (!presets.length) { | ||
return null; | ||
|
@@ -24,22 +26,29 @@ export default function PresetPanel<DateType extends object = any>( | |
return ( | ||
<div className={`${prefixCls}-presets`}> | ||
<ul> | ||
{presets.map(({ label, value }, index) => ( | ||
<li | ||
key={index} | ||
onClick={() => { | ||
onClick(executeValue(value)); | ||
}} | ||
onMouseEnter={() => { | ||
onHover(executeValue(value)); | ||
}} | ||
onMouseLeave={() => { | ||
onHover(null); | ||
}} | ||
> | ||
{label} | ||
</li> | ||
))} | ||
{presets.map(({ label, value }, index) => { | ||
const isDisabled = moment(value).isAfter(maxDate) || moment(value).isSame(maxDate); | ||
return ( | ||
<li | ||
key={index} | ||
onClick={() => { | ||
if (!isDisabled) { | ||
onClick(executeValue(value)); | ||
} | ||
}} | ||
onMouseEnter={() => { | ||
if (!isDisabled) { | ||
onHover(executeValue(value)); | ||
} | ||
}} | ||
onMouseLeave={() => { | ||
onHover(null); | ||
}} | ||
> | ||
{label} | ||
</li> | ||
); | ||
})} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion 修复禁用逻辑和处理函数值 当前实现存在几个问题需要修复:
- {presets.map(({ label, value }, index) => {
- const isDisabled = moment(value).isAfter(maxDate) || moment(value).isSame(maxDate);
- return (
- <li
- key={index}
- onClick={() => {
- if (!isDisabled) {
- onClick(executeValue(value));
- }
- }}
- onMouseEnter={() => {
- if (!isDisabled) {
- onHover(executeValue(value));
- }
- }}
- onMouseLeave={() => {
- onHover(null);
- }}
- >
- {label}
- </li>
- );
- })}
+ {presets.map(({ label, value }, index) => {
+ const actualValue = executeValue(value);
+ const isDisabled = maxDate && generateConfig.isAfter(actualValue, maxDate);
+ return (
+ <li
+ key={index}
+ className={isDisabled ? `${prefixCls}-presets-item-disabled` : undefined}
+ onClick={() => {
+ if (!isDisabled) {
+ onClick(actualValue);
+ }
+ }}
+ onMouseEnter={() => {
+ if (!isDisabled) {
+ onHover(actualValue);
+ }
+ }}
+ onMouseLeave={() => {
+ onHover(null);
+ }}
+ >
+ {label}
+ </li>
+ );
+ })} 注意:这里假设组件可以访问
🤖 Prompt for AI Agents
|
||
</ul> | ||
</div> | ||
); | ||
|
Uh oh!
There was an error while loading. Please reload this page.