tablo_core/declaration/editable.rs
1//! The declaration mistakes of a column editing its field in place, and their wording.
2
3use std::fmt;
4
5/// Why a column cannot edit its field in place:
6/// [`DeclarationErrorKind::EditableColumn`](super::DeclarationErrorKind::EditableColumn).
7#[derive(Debug, Clone, PartialEq, Eq)]
8#[non_exhaustive]
9pub enum EditableColumnFault {
10 /// The resource has no form, so no edit route takes the cell's post.
11 ///
12 /// Give the resource a form, or show the field read-only.
13 NoForm,
14 /// The resource's record form binds no control for the field.
15 ///
16 /// Bind the field in the record form.
17 Unplaced,
18 /// The form edits the field with another control than the column's, carrying the one the
19 /// column needs: a checkbox or switch for a `ToggleColumn`, a choice over static options for
20 /// a `SelectColumn`, a one-line text field for a `TextInputColumn`.
21 ///
22 /// Edit the field with that control, or pick the column that matches the form's.
23 OtherControl(&'static str),
24 /// The form's choice offers other options than the `SelectColumn`'s type, or labels them
25 /// otherwise: the cell would offer a value the form refuses.
26 ///
27 /// Offer the type's options in the form, or show the field read-only.
28 OtherOptions,
29 /// The form's control shows only while a condition holds, which reads fields the cell does
30 /// not post.
31 ///
32 /// Show the field read-only.
33 Conditional,
34 /// The form's control is disabled on the edit form, so the edit route drops what it posts.
35 ///
36 /// Show the field read-only.
37 Disabled,
38}
39
40impl EditableColumnFault {
41 /// The sentence a mount error says after the column's name.
42 pub(super) fn fmt(&self, f: &mut fmt::Formatter<'_>, column: &str) -> fmt::Result {
43 match self {
44 Self::NoForm => write!(
45 f,
46 "column '{column}' edits its field in place and the resource has no form to \
47 post it to: give the resource a form, or show the field read-only"
48 ),
49 Self::Unplaced => write!(
50 f,
51 "column '{column}' edits its field in place and the record form binds no control \
52 for it: bind the field in the record form"
53 ),
54 Self::OtherControl(control) => write!(
55 f,
56 "column '{column}' edits its field in place and the form edits it with another \
57 control than {control}: use that control, or the column matching the form's"
58 ),
59 Self::OtherOptions => write!(
60 f,
61 "column '{column}' edits its field in place and the form's choice offers other \
62 options than the column's type: offer the type's options in the form, or show \
63 the field read-only"
64 ),
65 Self::Conditional => write!(
66 f,
67 "column '{column}' edits its field in place and the form shows it only while a \
68 condition holds, which reads fields the cell does not post: show the field \
69 read-only"
70 ),
71 Self::Disabled => write!(
72 f,
73 "column '{column}' edits its field in place and the edit form disables it, so the \
74 save drops what the cell posts: show the field read-only"
75 ),
76 }
77 }
78}