Skip to content

Commit

Permalink
fix: matching parameters of Upload component、fixed date formatting an…
Browse files Browse the repository at this point in the history
…d Reduced reference (#1914)

# Description

Please include a summary of the change and which issue is fixed. Please
also include relevant motivation and context. List any dependencies that
are required for this change.

# How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide
instructions so we can reproduce. Please also list any relevant details
for your test configuration

# Snapshots:

Include snapshots for easier review.

# Checklist:

- [ ] My code follows the style guidelines of this project
- [ ] I have already rebased the commits and make the commit message
conform to the project standard.
- [ ] I have performed a self-review of my own code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [ ] Any dependent changes have been merged and published in downstream
modules
  • Loading branch information
Dreammy23 authored Aug 28, 2024
2 parents d7a893e + 72e9200 commit 48d2ed1
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 17 deletions.
6 changes: 1 addition & 5 deletions web/components/flow/canvas-node.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ type CanvasNodeProps = {
function TypeLabel({ label }: { label: string }) {
return <div className='w-full h-8 align-middle font-semibold'>{label}</div>;
}
const forceTypeList = ['file', 'multiple_files', 'time','images','csv_file'];

const CanvasNode: React.FC<CanvasNodeProps> = ({ data }) => {
const node = data;
Expand Down Expand Up @@ -135,10 +134,7 @@ const CanvasNode: React.FC<CanvasNodeProps> = ({ data }) => {

function onParameterValuesChange(changedValues: any, allValues: any) {
const [changedKey, changedVal] = Object.entries(changedValues)[0];

if (!allValues?.force && forceTypeList.includes(changedKey)) {
return;
}

updateCurrentNodeValue(changedKey, changedVal);
if (changedVal) {
updateDependsNodeValue(changedKey, changedVal);
Expand Down
2 changes: 1 addition & 1 deletion web/components/flow/node-param-handler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ const NodeParamHandler: React.FC<NodeParamHandlerProps> = ({ formValuesChange,no
case 'slider':
return renderSlider(data);
case 'date_picker':
return renderDatePicker( data );
return renderDatePicker({ data,formValuesChange });
case 'time_picker':
return renderTimePicker({ data,formValuesChange });
case 'tree_select':
Expand Down
18 changes: 16 additions & 2 deletions web/components/flow/node-renderer/date-picker.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
import { IFlowNodeParameter } from '@/types/flow';
import { convertKeysToCamelCase } from '@/utils/flow';
import { DatePicker } from 'antd';
import type { DatePickerProps } from 'antd';

export const renderDatePicker = (data: IFlowNodeParameter) => {
type Props = {
formValuesChange:any,
data: IFlowNodeParameter;
onChange?: (value: any) => void;
};
export const renderDatePicker = (params: Props) => {
const { data ,formValuesChange} = params;
const attr = convertKeysToCamelCase(data.ui?.attr || {});

return <DatePicker {...attr} className="w-full" placeholder="please select a date" />;
const onChange: DatePickerProps['onChange'] = (date, dateString) => {
formValuesChange({
[data.name]:dateString
})
};


return <DatePicker onChange={onChange} {...attr} className="w-full" placeholder="please select a date" />;
};
4 changes: 2 additions & 2 deletions web/components/flow/node-renderer/time-picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ export const renderTimePicker = (params: Props) => {

const onChangeTime: TimePickerProps['onChange'] = (time, timeString) => {
formValuesChange({
time:timeString
},{force:true})
[data.name]:timeString
})
};

return <TimePicker {...attr} onChange={onChangeTime} className="w-full" placeholder="please select a moment" />;
Expand Down
14 changes: 7 additions & 7 deletions web/components/flow/node-renderer/upload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,19 @@ export const renderUpload = (params: Props) => {
const { t } = useTranslation();
const urlList = useRef<string[]>([]);
const { data ,formValuesChange} = params;
const form = Form.useFormInstance()


const attr = convertKeysToCamelCase(data.ui?.attr || {});
const [uploading, setUploading] = useState(false);
const [uploadType, setUploadType] = useState('');

const getUploadSuccessUrl = (url: string) => {
if (urlList.current.length === data.ui.attr.max_count) {
urlList.current.pop();
}
urlList.current.push(url);
if (data.ui.attr.max_count === 1) {
formValuesChange({file:urlList.current.toString()},{force:true})
formValuesChange({[data.name]:urlList.current.toString()})
}else{
formValuesChange({multiple_files:JSON.stringify(urlList.current)},{force:true})
formValuesChange({[data.name]:urlList.current})
}
};

Expand All @@ -38,10 +36,11 @@ export const renderUpload = (params: Props) => {
if (index !== -1) {
urlList.current.splice(index, 1);
}
setUploading(false);
if (data.ui.attr.max_count === 1) {
formValuesChange({file:urlList.current.toString()},{force:true})
formValuesChange({[data.name]:urlList.current.toString()})
}else{
formValuesChange({multiple_files:JSON.stringify(urlList.current)},{force:true})
formValuesChange({[data.name]:urlList.current})
}
};

Expand All @@ -54,6 +53,7 @@ export const renderUpload = (params: Props) => {
onChange(info) {
setUploading(true);
if (info.file.status !== 'uploading') {
setUploading(false);
}
if (info.file.status === 'done') {
setUploading(false);
Expand Down

0 comments on commit 48d2ed1

Please sign in to comment.