|
@@ -41,8 +41,8 @@ const InsertContainer: FC<InsertContentProps> = ({
|
|
defaultSelectedCollection,
|
|
defaultSelectedCollection,
|
|
defaultSelectedPartition,
|
|
defaultSelectedPartition,
|
|
|
|
|
|
- partitions = [],
|
|
|
|
- schema = [],
|
|
|
|
|
|
+ partitions,
|
|
|
|
+ schema,
|
|
handleInsert,
|
|
handleInsert,
|
|
}) => {
|
|
}) => {
|
|
const classes = getStyles();
|
|
const classes = getStyles();
|
|
@@ -53,7 +53,7 @@ const InsertContainer: FC<InsertContentProps> = ({
|
|
const [activeStep, setActiveStep] = useState<InsertStepperEnum>(
|
|
const [activeStep, setActiveStep] = useState<InsertStepperEnum>(
|
|
InsertStepperEnum.import
|
|
InsertStepperEnum.import
|
|
);
|
|
);
|
|
- const [insertStatus, setInsertStauts] = useState<InsertStatusEnum>(
|
|
|
|
|
|
+ const [insertStatus, setInsertStatus] = useState<InsertStatusEnum>(
|
|
InsertStatusEnum.init
|
|
InsertStatusEnum.init
|
|
);
|
|
);
|
|
const [insertFailMsg, setInsertFailMsg] = useState<string>('');
|
|
const [insertFailMsg, setInsertFailMsg] = useState<string>('');
|
|
@@ -127,7 +127,7 @@ const InsertContainer: FC<InsertContentProps> = ({
|
|
|
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
// if not on partitions page, we need to fetch partitions according to selected collection
|
|
// if not on partitions page, we need to fetch partitions according to selected collection
|
|
- if (partitions.length === 0) {
|
|
|
|
|
|
+ if (!partitions || partitions.length === 0) {
|
|
fetchPartition();
|
|
fetchPartition();
|
|
} else {
|
|
} else {
|
|
const options = partitions
|
|
const options = partitions
|
|
@@ -203,7 +203,7 @@ const InsertContainer: FC<InsertContentProps> = ({
|
|
|
|
|
|
const schemaOptions: Option[] = useMemo(() => {
|
|
const schemaOptions: Option[] = useMemo(() => {
|
|
const list =
|
|
const list =
|
|
- schema.length > 0
|
|
|
|
|
|
+ schema && schema.length > 0
|
|
? schema
|
|
? schema
|
|
: collections.find(c => c._name === collectionValue)?._fields;
|
|
: collections.find(c => c._name === collectionValue)?._fields;
|
|
return (list || []).map(s => ({
|
|
return (list || []).map(s => ({
|
|
@@ -232,11 +232,11 @@ const InsertContainer: FC<InsertContentProps> = ({
|
|
};
|
|
};
|
|
|
|
|
|
const handleInsertData = async () => {
|
|
const handleInsertData = async () => {
|
|
|
|
+ // start loading
|
|
|
|
+ setInsertStatus(InsertStatusEnum.loading);
|
|
// combine table heads and data
|
|
// combine table heads and data
|
|
const tableData = isContainFieldNames ? csvData.slice(1) : csvData;
|
|
const tableData = isContainFieldNames ? csvData.slice(1) : csvData;
|
|
const data = combineHeadsAndData(tableHeads, tableData);
|
|
const data = combineHeadsAndData(tableHeads, tableData);
|
|
-
|
|
|
|
- setInsertStauts(InsertStatusEnum.loading);
|
|
|
|
const { result, msg } = await handleInsert(
|
|
const { result, msg } = await handleInsert(
|
|
collectionValue,
|
|
collectionValue,
|
|
partitionValue,
|
|
partitionValue,
|
|
@@ -247,7 +247,7 @@ const InsertContainer: FC<InsertContentProps> = ({
|
|
setInsertFailMsg(msg);
|
|
setInsertFailMsg(msg);
|
|
}
|
|
}
|
|
const status = result ? InsertStatusEnum.success : InsertStatusEnum.error;
|
|
const status = result ? InsertStatusEnum.success : InsertStatusEnum.error;
|
|
- setInsertStauts(status);
|
|
|
|
|
|
+ setInsertStatus(status);
|
|
};
|
|
};
|
|
|
|
|
|
const handleCollectionChange = (name: string) => {
|
|
const handleCollectionChange = (name: string) => {
|