Skip to content

Commit

Permalink
fix: Dict value loses 1 trailing character on UI Launch. (#561)
Browse files Browse the repository at this point in the history
fix: dict lose trailing issue

Signed-off-by: James <[email protected]>

Signed-off-by: James <[email protected]>
  • Loading branch information
james-union authored Aug 22, 2022
1 parent cdd94b7 commit b6e1e40
Showing 1 changed file with 17 additions and 20 deletions.
37 changes: 17 additions & 20 deletions packages/zapp/console/src/components/Launch/LaunchForm/MapInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ export const MapInput = (props: InputProps) => {
setData((data) => [...data, getNewMapItem(data.length)]);
};

const updateUpperStream = () => {
const newPairs = data
const updateUpperStream = (newData: MapInputItem[]) => {
const newPairs = newData
.filter((item) => {
// we filter out delted values and items with errors or empty keys/values
return item.id !== null && !!item.key && !!item.value;
Expand All @@ -145,32 +145,29 @@ export const MapInput = (props: InputProps) => {

const onSetKey = (id: number | null, key: string) => {
if (id === null) return;
setData((data) => {
data[id].key = key;
return [...data];
});
updateUpperStream();
const newData = [...data];
newData[id].key = key;
setData([...newData]);
updateUpperStream([...newData]);
};

const onSetValue = (id: number | null, value: string) => {
if (id === null) return;
setData((data) => {
data[id].value = value;
return [...data];
});
updateUpperStream();
const newData = [...data];
newData[id].value = value;
setData([...newData]);
updateUpperStream([...newData]);
};

const onDeleteItem = (id: number | null) => {
if (id === null) return;
setData((data) => {
const dataIndex = data.findIndex((item) => item.id === id);
if (dataIndex >= 0 && dataIndex < data.length) {
data[dataIndex].id = null;
}
return [...data];
});
updateUpperStream();
const newData = [...data];
const dataIndex = newData.findIndex((item) => item.id === id);
if (dataIndex >= 0 && dataIndex < newData.length) {
newData[dataIndex].id = null;
}
setData([...newData]);
updateUpperStream([...newData]);
};

const isValid = (id: number | null, value: string) => {
Expand Down

0 comments on commit b6e1e40

Please sign in to comment.