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

MQTT : Add better validation errors on create device form #2244

Merged
merged 2 commits into from
Feb 28, 2025
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
7 changes: 7 additions & 0 deletions front/src/config/i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -1298,6 +1298,13 @@
"notFound": "Angefordertes Gerät nicht gefunden.",
"backToList": "Zurück zur Geräteliste",
"saveError": "Fehler beim Sichern oder Löschen des Geräts",
"validationError": "Validierungsfehler: Das Gerät ist nicht korrekt ausgefüllt.",
"validationErrors": {
"name": "Das Feld \"Name\" ist erforderlich",
"min": "Das Minimalfeld ist erforderlich und muss eine ganze Zahl sein",
"max": "Das Maximalfeld ist erforderlich und muss eine ganze Zahl sein",
"external_id": "Das externe ID-Feld ist erforderlich und muss über alle Geräte hinweg eindeutig sein"
},
"saveConflictError": "Konflikt: Sind alle externen IDs wirklich eindeutig?",
"mostRecentValueAt": "Zuletzt empfangener Wert {{mostRecentValueAt}}.",
"noValueReceived": "Kein Wert empfangen."
Expand Down
7 changes: 7 additions & 0 deletions front/src/config/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1298,6 +1298,13 @@
"notFound": "Requested device not found.",
"backToList": "Back to device list",
"saveError": "Error saving or deleting device",
"validationError": "Validation error : The device is not correctly filled.",
"validationErrors": {
"name": "The name field is required",
"min": "The minimum field is required and must be an integer",
"max": "The maximum field is required and must be an integer",
"external_id": "The external ID field is required and must be unique across all devices"
},
"saveConflictError": "Conflict: Are you sure all external IDs are unique?",
"mostRecentValueAt": "Last value received {{mostRecentValueAt}}.",
"noValueReceived": "No value received."
Expand Down
7 changes: 7 additions & 0 deletions front/src/config/i18n/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -1426,6 +1426,13 @@
"notFound": "Appareil introuvable.",
"backToList": "Retour à la liste des appareils",
"saveError": "Erreur lors de l'enregistrement ou de la suppression de l'appareil",
"validationError": "Erreur de validation : L'appareil n'a pas été correctement rempli.",
"validationErrors": {
"name": "Le champ \"Nom\" est obligatoire",
"min": "Le champ \"Valeur minimum\" est obligatoire et doit être une valeur entière",
"max": "Le champ \"Valeur maximum\" est obligatoire et doit être une valeur entière",
"external_id": "Le champ \"ID Externe\" est obligatoire et doit être unique à travers tous les appareils"
},
"saveConflictError": "Conflit : êtes-vous sûr que tous les IDs externes sont uniques ?",
"mostRecentValueAt": "Dernière valeur reçue {{mostRecentValueAt}}.",
"noValueReceived": "Aucune valeur reçue."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,21 @@ const FeatureTab = ({ children, ...props }) => (
<Text id="integration.mqtt.device.saveError" />
</div>
)}
{props.saveStatus === RequestStatus.ValidationError && (
<div class="alert alert-danger">
<Text id="integration.mqtt.device.validationError" />
{props.erroredAttributes.length > 0 && (
<p>
{props.erroredAttributes.map(attribute => (
<>
<br />
- <Text id={`integration.mqtt.device.validationErrors.${attribute}`} />
</>
))}
</p>
)}
</div>
)}
{props.saveStatus === RequestStatus.ConflictError && (
<div class="alert alert-danger">
<Text id="integration.mqtt.device.saveConflictError" />
Expand Down
14 changes: 12 additions & 2 deletions front/src/routes/integration/all/mqtt/device-page/setup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,16 +210,26 @@ class MqttDeviceSetupPage extends Component {
} catch (e) {
const status = get(e, 'response.status');
if (status === 409) {
this.setState({
await this.setState({
saveStatus: RequestStatus.ConflictError,
loading: false
});
}
if (status === 422) {
const properties = get(e, 'response.data.properties', []);
await this.setState({
saveStatus: RequestStatus.ValidationError,
erroredAttributes: properties.map(p => p.attribute).filter(a => a !== 'selector'),
loading: false
});
} else {
this.setState({
await this.setState({
saveStatus: RequestStatus.Error,
loading: false
});
}
// Scroll to top so the user sees the error
window.scrollTo(0, 0);
}
}

Expand Down
Loading