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

Auto-hide non-multivalued reference widget input on value selection #2363

Merged
merged 6 commits into from
Aug 22, 2023
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
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Changelog
2.5.0 (unreleased)
------------------

- #2363 Auto-hide non-multivalued reference widget input on value selection
- #2359 Improve sample create performance
- #2361 Fix KeyError if registry key not found
- #2358 Add confirmation when unlinking reference
Expand Down
1 change: 0 additions & 1 deletion src/senaite/core/behaviors/label.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ class ILabelSchema(model.Schema):
search_wildcard=True,
multi_valued=True,
allow_user_value=True,
hide_input_after_select=False,
query={
"portal_type": "Label",
"is_active": True,
Expand Down
2 changes: 1 addition & 1 deletion src/senaite/core/browser/static/bundles/senaite.core.css

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions src/senaite/core/browser/widgets/queryselect.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ class QuerySelectWidget(StringWidget):
"value_query_index": "title",
"padding": 3,
"display_template": None,
"hide_input_after_select": False,
"clear_results_after_select": False,
"results_table_width": "500px",
})
Expand Down Expand Up @@ -112,8 +111,6 @@ def get_input_widget_attributes(self, context, field, value):
"data-multi_valued": getattr(self, "multi_valued", True),
"data-disabled": getattr(self, "disabled", False),
"data-readonly": getattr(self, "readonly", False),
"data-hide_input_after_select": getattr(
self, "hide_input_after_select", True),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also remove the attribute from the DX version:

"data-hide_input_after_select": getattr(
self, "hide_input_after_select", True),

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done with b5ed67f

"data-clear_results_after_select": getattr(
self, "clear_results_after_select", False),
}
Expand Down
1 change: 0 additions & 1 deletion src/senaite/core/extender/label.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ class LabelSchemaExtender(object):
search_wildcard=True,
multi_valued=True,
allow_user_value=True,
hide_input_after_select=False,
i18n_domain="senaite.core",
query={
"portal_type": "Label",
Expand Down
5 changes: 0 additions & 5 deletions src/senaite/core/z3cform/widgets/queryselect/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,6 @@ widget directive as *additional arguments*:
Note: This option affects the length of the batch navigation to
avoid horizontal overflow for more than e.g. 50 pages.

- `hide_input_after_select`: Controls if the search input field should be rendered after a value was selected
Default: `False`
Note: Only used if for single valued fields


# Full example

Expand All @@ -128,7 +124,6 @@ This example shows how the widget can be used with most of the described setting
search_wildcard=True,
multi_valued=False,
allow_user_value=True,
hide_input_after_select=True,
columns=[
{
"name": "patient_id",
Expand Down
2 changes: 0 additions & 2 deletions src/senaite/core/z3cform/widgets/queryselect/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,6 @@ def get_input_widget_attributes(self):
"data-multi_valued": getattr(self, "multi_valued", True),
"data-disabled": getattr(self, "disabled", False),
"data-readonly": getattr(self, "readonly", False),
"data-hide_input_after_select": getattr(
self, "hide_input_after_select", True),
"data-clear_results_after_select": getattr(
self, "clear_results_after_select", False),
}
Expand Down
6 changes: 6 additions & 0 deletions webpack/app/scss/forms.scss
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,9 @@ form[name='edit_form'] {
margin-bottom: 0;
}
}

form[name=analysisrequest_add_form] {
.field {
margin-bottom: 0;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why this is here inside. Also I do not see any DOM elements in the add form with a class="field" at the moment.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See this:

Captura de 2023-08-22 22-11-02

}
2 changes: 1 addition & 1 deletion webpack/app/widgets/components/SelectedValues.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class SelectedValues extends React.Component {
<button value={value}
data-toggle="confirmation"
data-title={_t("Unlink reference?")}
className="btn btn-sm btn-link-danger"
className="btn btn-sm p-0 ml-2"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is cool. Makes the whole item smaller. Thanks for this one.

onClick={this.on_deselect}>
<i className="fas fa-times-circle"></i>
</button>
Expand Down
9 changes: 7 additions & 2 deletions webpack/app/widgets/queryselect/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ class QuerySelectWidgetController extends React.Component {
"columns", // columns to be displayed in the results popup
"display_template", // template to use for the selected values
"multi_valued", // if true, more than one value can be set
"hide_input_after_select", // only for single valued fields to hide the input after selection
"clear_results_after_select", // clear results after value select
"disabled", // if true, the field is rendered as not editable
"readonly", // if true, the field is rendered as not editable
Expand Down Expand Up @@ -236,7 +235,13 @@ class QuerySelectWidgetController extends React.Component {
* @returns {Boolean} true/false if the search field is rendered
*/
show_search_field() {
if (!this.state.multi_valued && this.state.values.length > 0 && this.state.hide_input_after_select) {
if (this.state.disabled) {
return false;
}
if (this.state.readonly) {
return false;
}
if (!this.state.multi_valued && this.state.values.length > 0) {
return false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about this. Probably the last line needs to be first to keep the input widget visible, even if it is readonly/disabled.
Or maybe just return True if this.state.multi_valued?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why one would want the input element to be displayed if it cannot be used (because is disabled or readonly)?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, good point. To see that it is disabled by purpose maybe?

}
return true;
Expand Down