Skip to content

Commit

Permalink
Merge pull request #34 from KelvinTegelaar/dev
Browse files Browse the repository at this point in the history
[pull] dev from KelvinTegelaar:dev
  • Loading branch information
pull[bot] authored Jan 24, 2025
2 parents 7596fab + eda639f commit 15b94d5
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
22 changes: 17 additions & 5 deletions src/components/CippComponents/CippApiDialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,16 @@ import { useSettings } from "../../hooks/use-settings";
import CippFormComponent from "./CippFormComponent";

export const CippApiDialog = (props) => {
const { createDialog, title, fields, api, row = {}, relatedQueryKeys, ...other } = props;
const {
createDialog,
title,
fields,
api,
row = {},
relatedQueryKeys,
dialogAfterEffect,
...other
} = props;
const router = useRouter();
const [addedFieldData, setAddedFieldData] = useState({});
const [partialResults, setPartialResults] = useState([]);
Expand Down Expand Up @@ -64,8 +73,6 @@ export const CippApiDialog = (props) => {
return api.dataFunction(row);
}
var newData = {};
console.log("the received row", row);
console.log("the received dataObject", dataObject);

if (api?.postEntireRow) {
newData = row;
Expand Down Expand Up @@ -93,7 +100,6 @@ export const CippApiDialog = (props) => {
}
});
}
console.log("output", newData);
return newData;
};
const tenantFilter = useSettings().currentTenant;
Expand Down Expand Up @@ -138,6 +144,7 @@ export const CippApiDialog = (props) => {
data: arrayOfObjects,
});
}

return;
}

Expand Down Expand Up @@ -191,7 +198,12 @@ export const CippApiDialog = (props) => {
});
}
};

//add a useEffect, when dialogAfterEffect exists, and the post or get request is successful, run the dialogAfterEffect function
useEffect(() => {
if (dialogAfterEffect && (actionPostRequest.isSuccess || actionGetRequest.isSuccess)) {
dialogAfterEffect(actionPostRequest.data.data || actionGetRequest.data);
}
}, [actionPostRequest.isSuccess, actionGetRequest.isSuccess]);
const formHook = useForm();
const onSubmit = (data) => handleActionClick(row, api, data);
const selectedType = api.type === "POST" ? actionPostRequest : actionGetRequest;
Expand Down
6 changes: 6 additions & 0 deletions src/components/CippStandards/CippStandardsSideBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ const CippStandardsSideBar = ({
edit,
}) => {
const [currentStep, setCurrentStep] = useState(0);
const [savedItem, setSavedItem] = useState(null);
const dialogAfterEffect = (id) => {
setSavedItem(id);
};

const watchForm = useWatch({ control: formControl.control });

Expand Down Expand Up @@ -208,6 +212,7 @@ const CippStandardsSideBar = ({
</ActionList>
<Divider />
<CippApiDialog
dialogAfterEffect={(data) => dialogAfterEffect(data.id)}
createDialog={createDialog}
title="Add Standard"
api={{
Expand All @@ -223,6 +228,7 @@ const CippStandardsSideBar = ({
templateName: "templateName",
standards: "standards",
...(edit ? { GUID: "GUID" } : {}),
...(savedItem ? { GUID: savedItem } : {}),
runManually: "runManually",
},
}}
Expand Down
10 changes: 9 additions & 1 deletion src/components/CippWizard/CippWizardCSVImport.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ export const CippWizardCSVImport = (props) => {
const handleAddItem = () => {
const newRowData = formControl.getValues("addrow");
if (newRowData === undefined) return false;

const newTableData = [...tableData, newRowData];
setTableData(newTableData);
setOpen(false);
Expand Down Expand Up @@ -87,6 +86,15 @@ export const CippWizardCSVImport = (props) => {
label={getCippTranslation(field)}
type="textField"
formControl={formControl}
onKeyDown={(e) => {
if (e.key === "Enter") {
if (e.target.value === "") return false;
handleAddItem();
setTimeout(() => {
formControl.setValue(`addrow.${field}`, "");
}, 500);
}
}}
/>
</Grid>
</>
Expand Down

0 comments on commit 15b94d5

Please sign in to comment.