Skip to content
Open
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
211 changes: 174 additions & 37 deletions src/frontend/src/modules/Settings/Configuration/ImportSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -118,24 +118,77 @@
<div
v-for="(r, idx) in importResult.results"
:key="idx"
class="result-row"
:class="r.success ? 'result-row--success' : 'result-row--failed'"
class="result-row-wrapper"
>
<md-icon class="result-row-icon">
{{ r.success ? "check_circle" : "error" }}
</md-icon>
<div class="result-row-content">
<strong>{{ entityLabel(r.type) }}</strong>
<span class="result-row-detail">
<template v-if="r.data && r.data.added_count != null">
{{ r.data.added_count }} added,
{{ r.data.modified_count }} modified,
{{ r.data.failed_count }} failed
</template>
<template v-else>
{{ r.success ? "Imported successfully" : r.error }}
</template>
</span>
<div
class="result-row"
:class="
r.success ? 'result-row--success' : 'result-row--failed'
"
>
<md-icon class="result-row-icon">
{{ r.success ? "check_circle" : "error" }}
</md-icon>
<div class="result-row-content">
<strong>{{ entityLabel(r.type) }}</strong>
<span class="result-row-detail">
<template v-if="r.data && r.data.added_count != null">
{{ r.data.added_count }} added,
{{ r.data.modified_count }} modified,
{{ r.data.failed_count }} failed
</template>
<template v-else>
{{ r.success ? "Imported successfully" : r.error }}
</template>
</span>
</div>
<md-button
v-if="hasErrorDetails(r)"
class="md-icon-button md-dense error-toggle-btn"
@click="toggleErrorDetails(idx)"
>
<md-icon>
{{
expandedErrors[idx]
? "keyboard_arrow_up"
: "keyboard_arrow_down"
}}
</md-icon>
</md-button>
</div>
<div
v-if="hasErrorDetails(r) && expandedErrors[idx]"
class="error-details-panel"
>
<div
v-if="r.failedItems && r.failedItems.length > 0"
class="error-list"
>
<div
v-for="(item, fIdx) in r.failedItems"
:key="'f-' + fIdx"
class="error-item"
>
<span class="error-item-name">{{ item.name }}</span>
<span
v-for="(msg, field) in item.errors"
:key="field"
class="error-item-msg"
>
{{ msg }}
</span>
</div>
</div>
<div v-if="r.validationErrors" class="error-list">
<div
v-for="(msg, field) in r.validationErrors"
:key="field"
class="error-item"
>
<span class="error-item-name">{{ field }}</span>
<span class="error-item-msg">{{ msg }}</span>
</div>
</div>
</div>
</div>
</div>
Expand Down Expand Up @@ -251,6 +304,7 @@ export default {
pollingTimeout: null,
pendingResults: [],
pollingEntityType: null,
expandedErrors: {},
}
},
computed: {
Expand Down Expand Up @@ -296,6 +350,16 @@ export default {
const entity = IMPORT_ENTITIES.find((e) => e.key === type)
return entity ? entity.label : type
},
hasErrorDetails(result) {
return (
(result.failedItems && result.failedItems.length > 0) ||
(result.validationErrors &&
Object.keys(result.validationErrors).length > 0)
)
},
toggleErrorDetails(idx) {
this.$set(this.expandedErrors, idx, !this.expandedErrors[idx])
},
async importAll() {
if (!this.hasSelectedFiles) {
this.alertNotify("warn", "Please select at least one file to import")
Expand Down Expand Up @@ -344,25 +408,36 @@ export default {
importResult.imported_count === 0 &&
importResult.failed_count > 0
)
results.push({
const resultEntry = {
type: entity.key,
success: importSuccess,
data: importResult,
error: importSuccess
? null
: importResult.message || `Failed to import ${entity.label}`,
})
}
if (importResult.failed && importResult.failed.length > 0) {
resultEntry.failedItems = importResult.failed
}
if (importResult.errors) {
resultEntry.validationErrors = importResult.errors
}
results.push(resultEntry)
this.clearFile(entity.key)
} catch (error) {
const errorMessage =
error.exception?.message ||
error.message ||
`Failed to import ${entity.label}`
results.push({
const resultEntry = {
type: entity.key,
success: false,
error: errorMessage,
})
}
if (error.errors) {
resultEntry.validationErrors = error.errors
}
results.push(resultEntry)
} finally {
this.$set(this.loadingStates, entity.key, false)
}
Expand Down Expand Up @@ -396,11 +471,17 @@ export default {
if (status.status === "completed") {
this.stopPolling()
const importResult = status.result || {}
this.onAsyncImportDone(importResult.success !== false, null, {
added_count: importResult.added_count,
modified_count: importResult.modified_count,
failed_count: importResult.failed_count,
})
this.onAsyncImportDone(
importResult.success !== false,
null,
{
added_count: importResult.added_count,
modified_count: importResult.modified_count,
failed_count: importResult.failed_count,
},
importResult.failed,
importResult.errors,
)
} else if (status.status === "failed") {
this.stopPolling()
const failedResult = status.result || {}
Expand All @@ -415,6 +496,8 @@ export default {
modified_count: failedResult.modified_count ?? 0,
failed_count: failedResult.failed_count ?? 0,
},
failedResult.failed,
failedResult.errors,
)
}
} catch (e) {
Expand All @@ -435,22 +518,25 @@ export default {
this.pollingJobId = null
this.importing = false
},
onAsyncImportDone(success, error, data) {
onAsyncImportDone(success, error, data, failedItems, validationErrors) {
const results = [...this.pendingResults]
this.pendingResults = []
const entityType = this.pollingEntityType
this.pollingEntityType = null

if (success) {
results.push({ type: entityType, success: true, data })
} else {
results.push({
type: entityType,
success: false,
error: error || "Import failed",
data,
})
const resultEntry = {
type: entityType,
success,
data,
error: success ? null : error || "Import failed",
}
if (failedItems && failedItems.length > 0) {
resultEntry.failedItems = failedItems
}
if (validationErrors) {
resultEntry.validationErrors = validationErrors
}
results.push(resultEntry)

this.showResults(results)
},
Expand Down Expand Up @@ -482,6 +568,7 @@ export default {
this.alertNotify("error", `${totalFailed} record(s) failed to import`)
}

this.expandedErrors = {}
this.importResult = {
results,
added_count: totalAdded,
Expand Down Expand Up @@ -641,7 +728,6 @@ export default {
.result-details {
display: flex;
flex-direction: column;
gap: 0.5rem;
}

.result-row {
Expand Down Expand Up @@ -684,4 +770,55 @@ export default {
font-size: 0.85rem;
color: #666;
}

.result-row-wrapper {
margin-bottom: 0.5rem;
}

.error-toggle-btn {
margin-left: auto;
flex-shrink: 0;
}

.error-details-panel {
margin-top: 0.25rem;
margin-left: 2.5rem;
max-height: 200px;
overflow-y: auto;
border: 1px solid #e0e0e0;
border-radius: 4px;
background-color: #fafafa;
}

.error-list {
padding: 0.5rem;
}

.error-item {
display: flex;
flex-direction: column;
padding: 0.375rem 0.5rem;
border-bottom: 1px solid #eee;
}

.error-item:last-child {
border-bottom: none;
}

.error-item-name {
font-weight: 500;
font-size: 0.8rem;
color: #333;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}

.error-item-msg {
font-size: 0.78rem;
color: #c62828;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
</style>
12 changes: 10 additions & 2 deletions src/frontend/src/services/ApplianceImportService.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,19 @@ export class ApplianceImportService {
}
return responseData.data
} catch (e) {
if (e.exception) {
if (e.message && e.type) {
throw e
}
const errorMessage = e.response?.data?.message || e.message
return new ErrorHandler(errorMessage, "http", e.response?.status)
const error = {
message: errorMessage,
type: "http",
status_code: e.response?.status,
}
if (e.response?.data?.errors) {
error.errors = e.response.data.errors
}
throw error
}
}
}
12 changes: 10 additions & 2 deletions src/frontend/src/services/ClusterImportService.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,19 @@ export class ClusterImportService {
}
return responseData.data
} catch (e) {
if (e.exception) {
if (e.message && e.type) {
throw e
}
const errorMessage = e.response?.data?.message || e.message
return new ErrorHandler(errorMessage, "http", e.response?.status)
const error = {
message: errorMessage,
type: "http",
status_code: e.response?.status,
}
if (e.response?.data?.errors) {
error.errors = e.response.data.errors
}
throw error
}
}
}
12 changes: 10 additions & 2 deletions src/frontend/src/services/CustomerImportService.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,19 @@ export class CustomerImportService {
}
return responseData.data
} catch (e) {
if (e.exception) {
if (e.message && e.type) {
throw e
}
const errorMessage = e.response?.data?.message || e.message
return new ErrorHandler(errorMessage, "http", e.response?.status)
const error = {
message: errorMessage,
type: "http",
status_code: e.response?.status,
}
if (e.response?.data?.errors) {
error.errors = e.response.data.errors
}
throw error
}
}
}
12 changes: 10 additions & 2 deletions src/frontend/src/services/DeviceImportService.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,19 @@ export class DeviceImportService {
}
return responseData.data
} catch (e) {
if (e.exception) {
if (e.message && e.type) {
throw e
}
const errorMessage = e.response?.data?.message || e.message
return new ErrorHandler(errorMessage, "http", e.response?.status)
const error = {
message: errorMessage,
type: "http",
status_code: e.response?.status,
}
if (e.response?.data?.errors) {
error.errors = e.response.data.errors
}
throw error
}
}
}
Loading
Loading