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

fix: fix issues #534

Merged
merged 2 commits into from
Apr 14, 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
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