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 fileDialogCallback promise logic #1497

Merged
merged 5 commits into from
Aug 26, 2024
Merged
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 @@ -356,7 +356,7 @@ export default {
)}?bucket=OPENC3_${this.root.toUpperCase()}_BUCKET`,
)
// This pushes the file into storage by using the fields in the presignedRequest
// See storage_controller.rb get_presigned_request()
// See storage_controller.rb get_upload_presigned_request()
const response = await axios({
...presignedRequest,
data: this.file,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1933,6 +1933,7 @@ export default {
}
this.showMetadata()
break
// This is called continuously by the backend
case 'open_file_dialog':
case 'open_files_dialog':
this.file.title = data.args[0]
Expand All @@ -1953,34 +1954,46 @@ export default {
}
},
async fileDialogCallback(files) {
this.file.show = false // Close the dialog
// Set fileNames to 'Cancel' in case they cancelled
// otherwise we will populate it with the file names they selected
let fileNames = 'Cancel'
// Record all the API request promises so we can ensure they complete
let promises = []
if (files != 'Cancel') {
fileNames = []
await files.forEach(async (file) => {
files.forEach((file) => {
fileNames.push(file.name)
// Reassign data to presignedRequest for readability
const { data: presignedRequest } = await Api.get(
`/openc3-api/storage/upload/${encodeURIComponent(
`${window.openc3Scope}/tmp/${file.name}`,
)}?bucket=OPENC3_CONFIG_BUCKET`,
promises.push(
Api.get(
`/openc3-api/storage/upload/${encodeURIComponent(
`${window.openc3Scope}/tmp/${file.name}`,
)}?bucket=OPENC3_CONFIG_BUCKET`,
).then((response) => {
// This pushes the file into storage by using the fields in the presignedRequest
// See storage_controller.rb get_upload_presigned_request()
promises.push(
axios({
...response.data,
data: file,
}),
)
}),
)
// This pushes the file into storage by using the fields in the presignedRequest
// See storage_controller.rb get_presigned_request()
const response = await axios({
...presignedRequest,
data: file,
})
})
}
await Api.post(`/script-api/running-script/${this.scriptId}/prompt`, {
data: {
method: this.file.multiple ? 'open_files_dialog' : 'open_file_dialog',
answer: fileNames,
prompt_id: this.activePromptId,
},
// We have to wait for all the upload API requests to finish before notifying the prompt
Promise.all(promises).then((responses) => {
Api.post(`/script-api/running-script/${this.scriptId}/prompt`, {
data: {
method: this.file.multiple
? 'open_files_dialog'
: 'open_file_dialog',
answer: fileNames,
prompt_id: this.activePromptId,
},
}).then((response) => {
this.file.show = false // Close the dialog
})
})
},
setError(event) {
Expand Down
9 changes: 6 additions & 3 deletions playwright/tests/data-viewer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,11 +422,14 @@ test('works with UTC date / times', async ({ page, utils }) => {

await addComponent(page, utils, 'INST', 'ADCS')
await page.locator('[data-test=start-button]').click()
await utils.sleep(500)
localStartTime = addSeconds(localStartTime, 3)
localStartTime = addSeconds(localStartTime, 5)
expect(
await page.inputValue('[data-test=history-component-text-area]'),
).toContain(localStartTime.toISOString().split('.')[0])
).toContain(
// Original string is like '2024-08-26T21:23:41.319Z'
// So we split on ':' to just get the year and hour
localStartTime.toISOString().split(':').slice(0, 1).join(':'),
)

// Switch back to local time
await page.goto('/tools/admin/settings')
Expand Down
Loading