CEC-4525: add support for /tags endpoint and implement a new action for it (#361)

* add action for adding tags
This commit is contained in:
Tristan Timblin
2023-06-16 11:48:48 -07:00
committed by GitHub
parent 9ae3ef0e2e
commit 7c358a6052
10 changed files with 308 additions and 10 deletions

View File

@@ -30,8 +30,15 @@ const MainForm = () => {
type: "boolean",
value: false
},
})
const [showUpdateConfigModal, setShowUpdateConfigModal] = useState(false);
});
const [tagsToAdd, setTagsToAdd] = useState({
tags: {
label: "Tags",
type: "list.string",
value: [],
},
});
const [activeModal, setActiveModal] = useState(null);
const { setTitle, setSitePath, setMessage } = useStatusContext();
const {
token: {
@@ -80,12 +87,23 @@ const MainForm = () => {
selectedVins.forEach((vin, i) => taskRunner.push(request(vin, i)))
}
const handleAddTags = async (fn) => {
await fn(selectedVins, tagsToAdd.tags.value, token)
.then(() => setMessage(`Added ${tagsToAdd.tags.value.length} tags to ${selectedVins.length} vehicles.`))
.catch((error) => setMessage(error.message));
};
const actions = [
{
name: "Update Configs",
disabled: selectedVins.length === 0,
trigger: () => setShowUpdateConfigModal(true),
trigger: () => setActiveModal("updateConfig"),
},
{
name: "Add Tags",
disabled: selectedVins.length === 0,
trigger: () => setActiveModal("addTags"),
}
];
const handleOnlineHMI = (event) => {
@@ -150,17 +168,26 @@ const MainForm = () => {
onSelectAll={handleSelectAll}
/>
<VehicleConsumer>
{(context) => (
{(context) => (<>
<TransformModal
open={showUpdateConfigModal}
close={() => setShowUpdateConfigModal(false)}
open={activeModal === "updateConfig"}
close={() => setActiveModal(null)}
title="Update Configs"
body={`You are updating the config for the following VINs: ${selectedVins.join(", ")}.`}
data={config}
setData={setConfig}
submit={() => handleUploadConfig(context.uploadConfig)}
/>
)}
<TransformModal
open={activeModal === "addTags"}
close={() => setActiveModal(null)}
title="Add Tags"
body={`You are adding tags for the following VINs: ${selectedVins.join(", ")}.`}
data={tagsToAdd}
setData={setTagsToAdd}
submit={() => handleAddTags(context.addTags)}
/>
</>)}
</VehicleConsumer>
</div>
);