Skip to content

Commit

Permalink
fix: issues (#534)
Browse files Browse the repository at this point in the history
* fix: issues
* mod: code review
  • Loading branch information
hetao92 authored Apr 14, 2023
1 parent 230e360 commit 6c8eab1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 15 deletions.
16 changes: 3 additions & 13 deletions app/components/FileConfigSetting/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ const FileConfigSetting = (props: IProps) => {
data: [],
activeItem: null,
previewContent: [],
checkAll: false,
indeterminate: false,
loading: false,
uploading: false,
setState: (obj) => Object.assign(state, obj),
Expand All @@ -48,8 +46,6 @@ const FileConfigSetting = (props: IProps) => {
setState({
data: preUploadList,
activeItem: preUploadList[0],
checkAll: preUploadList.every((item) => item.withHeader),
indeterminate: preUploadList.some((item) => item.withHeader) && !preUploadList.every((item) => item.withHeader),
});
}, []);
useEffect(() => {
Expand Down Expand Up @@ -95,8 +91,6 @@ const FileConfigSetting = (props: IProps) => {
const { data, setState } = state;
const { checked } = e.target;
setState({
checkAll: checked,
indeterminate: false,
data: data.map(i => (i.withHeader = checked, i)),
});
}, []);
Expand All @@ -105,10 +99,7 @@ const FileConfigSetting = (props: IProps) => {
const { data, setState } = state;
const { checked } = e.target;
const nextData = data.map(i => (i === item && (i.withHeader = checked), i));
const checkedNum = data.reduce((n, file) => n + (file.withHeader & 1), 0);
setState({
checkAll: checkedNum === data.length,
indeterminate: !!checkedNum && checkedNum < data.length,
data: nextData
});
}, []);
Expand All @@ -117,10 +108,7 @@ const FileConfigSetting = (props: IProps) => {
e.stopPropagation();
const isActive = activeItem?.uid === data[index].uid;
const newData = data.filter((_, i) => i !== index);
const checkedNum = data.reduce((n, file) => n + (file.withHeader & 1), 0);
setState({
checkAll: checkedNum === newData.length && newData.length > 0,
indeterminate: !!checkedNum && checkedNum < newData.length,
data: newData,
activeItem: isActive ? null : activeItem,
previewContent: isActive ? [] : previewContent,
Expand Down Expand Up @@ -181,7 +169,7 @@ const FileConfigSetting = (props: IProps) => {
!uploading && onCancel();
}, []);

const { uploading, data, activeItem, previewContent, loading, setState, checkAll, indeterminate } = state;
const { uploading, data, activeItem, previewContent, loading, setState } = state;
const parseColumns = previewContent.length
? previewContent[0].map((header, index) => {
const textIndex = index;
Expand All @@ -193,6 +181,8 @@ const FileConfigSetting = (props: IProps) => {
};
})
: [];
const checkAll = data.length > 0 && data.every((item) => item.withHeader);
const indeterminate = data.some((item) => item.withHeader) && !checkAll;
const columns = [
{
title: intl.get('import.fileName'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ export const EditRow = (props: IEditProps) => {
message: intl.get('formRules.dataTypeRequired'),
},
]}>
<Select disabled={!(type in DataTypeTransformMap)} showSearch={true} onChange={onUpdateType} dropdownMatchSelectWidth={false}>
<Select disabled={!(type in DataTypeTransformMap) && data.alterType !== 'ADD'} showSearch={true} onChange={onUpdateType} dropdownMatchSelectWidth={false}>
{DATA_TYPE.map(item => {
if(!DataTypeTransformMap[type]?.includes(item.value) || item.value !== type) {
if(data.alterType !== 'ADD' && (!DataTypeTransformMap[type]?.includes(item.value) || item.value !== type)) {
return null;
}
return (
Expand Down

0 comments on commit 6c8eab1

Please sign in to comment.