Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Metabase
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Engineering Digital Service
Metabase
Commits
17f720ac
Unverified
Commit
17f720ac
authored
5 years ago
by
Paul Rosenzweig
Committed by
GitHub
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Display form errors in database details form (#10644)
parent
00617e87
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
frontend/src/metabase/components/DatabaseDetailsForm.jsx
+26
-5
26 additions, 5 deletions
frontend/src/metabase/components/DatabaseDetailsForm.jsx
frontend/test/metabase/components/DatabaseDetailsForm.unit.spec.js
+56
-0
56 additions, 0 deletions
...test/metabase/components/DatabaseDetailsForm.unit.spec.js
with
82 additions
and
5 deletions
frontend/src/metabase/components/DatabaseDetailsForm.jsx
+
26
−
5
View file @
17f720ac
...
...
@@ -57,10 +57,10 @@ export default class DatabaseDetailsForm extends Component {
engines
:
PropTypes
.
object
.
isRequired
,
formError
:
PropTypes
.
object
,
hiddenFields
:
PropTypes
.
object
,
isNewDatabase
:
PropTypes
.
bool
ean
,
isNewDatabase
:
PropTypes
.
bool
,
submitButtonText
:
PropTypes
.
string
.
isRequired
,
submitFn
:
PropTypes
.
func
.
isRequired
,
submitting
:
PropTypes
.
bool
ean
,
submitting
:
PropTypes
.
bool
,
};
validateForm
()
{
...
...
@@ -196,7 +196,7 @@ export default class DatabaseDetailsForm extends Component {
}
renderField
(
field
,
fieldIndex
)
{
const
{
engine
}
=
this
.
props
;
const
{
engine
,
formError
}
=
this
.
props
;
const
{
details
}
=
this
.
state
;
window
.
ENGINE
=
engine
;
...
...
@@ -415,8 +415,16 @@ export default class DatabaseDetailsForm extends Component {
);
}
else
{
return
(
<
FormField
key
=
{
field
.
name
}
fieldName
=
{
field
.
name
}
>
<
FormLabel
title
=
{
field
[
"
display-name
"
]
}
fieldName
=
{
field
.
name
}
/>
<
FormField
key
=
{
field
.
name
}
fieldName
=
{
field
.
name
}
formError
=
{
formError
}
>
<
FormLabel
title
=
{
field
[
"
display-name
"
]
}
fieldName
=
{
field
.
name
}
formError
=
{
formError
}
/>
{
this
.
renderFieldInput
(
field
,
fieldIndex
)
}
<
span
className
=
"Form-charm"
/>
</
FormField
>
...
...
@@ -460,6 +468,19 @@ export default class DatabaseDetailsForm extends Component {
hiddenFields
=
hiddenFields
||
{};
if
(
formError
&&
formError
.
data
)
{
// If we have a field error but no matching field, use that field error as
// a fallback for formError.data.message
const
{
message
,
errors
=
{}
}
=
formError
.
data
;
const
fieldNames
=
new
Set
(
fields
.
map
(
field
=>
field
.
name
));
const
[
unusedFieldKey
]
=
Object
.
keys
(
errors
).
filter
(
name
=>
!
fieldNames
.
has
(
name
),
);
if
(
unusedFieldKey
&&
!
message
)
{
formError
.
data
.
message
=
errors
[
unusedFieldKey
];
}
}
return
(
<
form
onSubmit
=
{
this
.
formSubmitted
.
bind
(
this
)
}
noValidate
>
<
div
className
=
"FormInputGroup pb2"
>
...
...
This diff is collapsed.
Click to expand it.
frontend/test/metabase/components/DatabaseDetailsForm.unit.spec.js
0 → 100644
+
56
−
0
View file @
17f720ac
import
React
from
"
react
"
;
import
{
mount
}
from
"
enzyme
"
;
import
DatabaseDetailsForm
from
"
metabase/components/DatabaseDetailsForm
"
;
const
ENGINES
=
{
h2
:
{
"
details-fields
"
:
[
{
name
:
"
db
"
,
"
display-name
"
:
"
Connection String
"
,
placeholder
:
"
file:/Users/camsaul/bird_sightings/toucans
"
,
required
:
true
,
},
],
"
driver-name
"
:
"
H2
"
,
},
};
const
DEFAULT_PROPS
=
{
details
:
{},
engines
:
ENGINES
,
engine
:
Object
.
keys
(
ENGINES
)[
0
],
submitButtonText
:
"
Next
"
,
submitFn
:
()
=>
undefined
,
};
describe
(
"
DatabaseDetailsForm
"
,
()
=>
{
it
(
"
should render
"
,
()
=>
{
mount
(
<
DatabaseDetailsForm
{...
DEFAULT_PROPS
}
/>
)
;
});
it
(
"
should render field errors
"
,
()
=>
{
const
wrapper
=
mount
(
<
DatabaseDetailsForm
{...
DEFAULT_PROPS
}
formError
=
{{
data
:
{
errors
:
{
db
:
"
fix this field
"
}
}
}}
/>
,
);
const
labels
=
wrapper
.
find
(
"
.Form-label
"
).
map
(
e
=>
e
.
text
());
expect
(
labels
).
toContain
(
"
Connection String : fix this field
"
);
});
it
(
"
should render field errors as a form message if there's no matching field
"
,
()
=>
{
const
wrapper
=
mount
(
<
DatabaseDetailsForm
{...
DEFAULT_PROPS
}
formError
=
{{
data
:
{
errors
:
{
foobar
:
"
couldn't find a field for this
"
}
},
}}
/>
,
);
const
message
=
wrapper
.
find
(
"
.Form-message
"
).
text
();
expect
(
message
).
toEqual
(
"
couldn't find a field for this
"
);
});
});
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment