Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ const RequestItem = ({ item, index }: Props) => {
};

const handleDeleteMapping = (key: React.Key) => {
const updated = handleDeleteMappingItems(key, listMapping, undefined);
const listClone = cloneDeep(listMapping);
const updated = handleDeleteMappingItems(key, listClone);
setListMappingStateRequest(updated);
};

Expand Down Expand Up @@ -388,6 +389,7 @@ const RequestItem = ({ item, index }: Props) => {
/>
</Flex>
))}

<Flex className={styles.itemContainer}>
<Button
style={{ marginBottom: 12 }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ const ResponseItem = ({ item, index }: Props) => {
};

const handleDeleteMapping = (key: React.Key) => {
const updated = handleDeleteMappingItems(key, listMapping, []);
const updated = handleDeleteMappingItems(key, listMapping);
setListMappingStateResponse(updated);
};

Expand Down
19 changes: 1 addition & 18 deletions kraken-app/kraken-app-portal/src/pages/NewAPIMapping/helper.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { IMappers } from "@/utils/types/component.type";
import { chain, flatMap } from "lodash";
import { IMapping } from "./components/ResponseMapping";
import { nanoid } from "nanoid";

/**
* Returns properties id whose source/target/location data is missing (applicable for seller apis, and sonata's custom fields only)
*
Expand Down Expand Up @@ -106,29 +104,14 @@ export function transformListMappingItem(
.value();
};

//Deletes a mapping item and adds a placeholder if the group becomes empty.
export function handleDeleteMappingItems(
key: React.Key,
listMapping: IMapping[],
emptyToValue: any
): IMapping[] | undefined {
const targetItem = listMapping.find((item) => item.key === key);
if (!targetItem) {
return;
}

const filtered = listMapping.filter((item) => item.key !== key);
const remainingGroupItems = filtered.filter(item => item.name === targetItem.name);
const updated = [...filtered];

if (remainingGroupItems.length === 0) {
updated.push({
name: targetItem.name,
key: nanoid(),
from: undefined,
to: emptyToValue,
});
}

return updated;
return filtered;
}
Loading