Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix page not rendering correctly after creating a new device. #287

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
50 changes: 29 additions & 21 deletions packages/frontend/components/Forms/CreateContainer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ import { postProvenance } from '~/services/azureFuncs';
import { makeEncodedDeviceKey } from '~/utils/keyFuncs';

import ButtonComponent from '../ButtonComponent.vue';
import { isNavigationFailure } from 'vue-router';

export default {
data() {
Expand All @@ -88,6 +89,7 @@ export default {
createReportingKey: false,
hasParent: false, // states whether this device is contained within a box/container
pictures: [] as File[] | null,
formSubmitted: false
}
},
methods: {
Expand Down Expand Up @@ -225,28 +227,34 @@ export default {
childrenDeviceName.push(childName);
}
};
postProvenance(deviceKey, {
blobType: 'deviceInitializer',
deviceName: this.name,
description: this.description,
tags:this.tags,
reportingKey: reportingKey,
children_key: childrenDeviceList,
children_name: childrenDeviceName,
hasParent: false,
isReportingKey: false
}, this.pictures || [])
.then(response => {
// Handle the successful response here
console.log('Post request successful:', response);
})
.catch(error => {
// Handle the error here
console.error('Error in post request:', error);
});
try {
if (!this.formSubmitted) {
this.formSubmitted = true;
const response = await postProvenance(deviceKey, {
blobType: 'deviceInitializer',
deviceName: this.name,
description: this.description,
tags:this.tags,
reportingKey: reportingKey,
children_key: childrenDeviceList,
children_name: childrenDeviceName,
hasParent: false,
isReportingKey: false
}, this.pictures || [])

console.log('Succesfully created the container:', response);

//Routing to display the device QR code etc.
this.$router.push({ path: `/device/${deviceKey}` });
// Navigate to the new container page
const failure = await this.$router.push({ path: `/device/${deviceKey}` });

if (isNavigationFailure(failure)) {
console.error(`Navigation failure - ${failure.message}`);
}
}
} catch (error) {
this.formSubmitted = false;
console.error('Failed to create the container:', error);
}
},
}

Expand Down
48 changes: 28 additions & 20 deletions packages/frontend/components/Forms/CreateDevice.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>. -->
-->

<template>
<!-- Form for creating a new device. Uses custom form submission. -->
<form enctype="multipart/form-data" class="bg-frost p-3" @submit.prevent="submitForm">
<h4 class="text-iris mt-1 mb-3">Create New Device</h4>

Expand Down Expand Up @@ -53,6 +54,7 @@ import { postProvenance } from '~/services/azureFuncs';
import { makeEncodedDeviceKey } from '~/utils/keyFuncs';

import ButtonComponent from '../ButtonComponent.vue';
import { isNavigationFailure } from 'vue-router';

export default {
data() {
Expand All @@ -63,6 +65,7 @@ export default {
children_key: '',
hasParent: false, // states whether a device is contained within a box/container
pictures: [] as File[] | null,
formSubmitted: false,
}
},
methods: {
Expand All @@ -78,28 +81,33 @@ export default {
}
},
async submitForm() {
try {
if (!this.formSubmitted) {
this.formSubmitted = true;
const deviceKey = await makeEncodedDeviceKey();
const response = await postProvenance(deviceKey, {
blobType: 'deviceInitializer',
deviceName: this.name,
description: this.description,
tags: this.tags,
children_key: '',
hasParent: false,
isReportingKey: false,
}, this.pictures || []);

console.log('Succesfully created the device:', response);

const deviceKey = await makeEncodedDeviceKey();
postProvenance(deviceKey, {
blobType: 'deviceInitializer',
deviceName: this.name,
description: this.description,
tags: this.tags,
children_key: '',
hasParent: false,
isReportingKey: false,
}, this.pictures || [])
.then(response => {
// Handle the successful response here
console.log('Post request successful:', response);
})
.catch(error => {
// Handle the error here
console.error('Error in post request:', error);
});
// Navigate to the new device page
const failure = await this.$router.push({ path: `/device/${deviceKey}` });

//Routing to display the device QR code etc.
this.$router.push({ path: `/device/${deviceKey}` });
if (isNavigationFailure(failure)) {
console.error(`Navigation failure - ${failure.message}`);
}
}
} catch (error) {
this.formSubmitted = false;
console.error('Failed to create the device:', error);
}
},
}

Expand Down