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

Enhance column suggestion differentiation #88

Merged
merged 2 commits into from
Jul 13, 2022
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
23 changes: 23 additions & 0 deletions asset/css/search-base.less
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@
}
}

.relation-path {
padding: 0 .2em;
background-color: var(--suggestions-relation-path-bg, @suggestions-relation-path-bg);
}

[type="button"] {
.appearance(none);
border: none;
Expand All @@ -52,6 +57,10 @@
background: var(--suggestions-focus-bg, @suggestions-focus-bg);
color: var(--suggestions-focus-color, @suggestions-focus-color);
outline: none;

.relation-path {
background-color: var(--suggestions-relation-path-focus-bg, @suggestions-relation-path-focus-bg);
}
}

[type="button"]:not(:focus):hover {
Expand Down Expand Up @@ -96,5 +105,19 @@
&[data-class="operator"], &[data-class="logical_operator"] {
text-align: center;
}

&.has-details {
display: flex;
align-items: baseline;
justify-content: space-between;
}

.relation-path {
margin-left: .5em;

&::first-line {
font-size: .8em;
}
}
}
}
4 changes: 4 additions & 0 deletions asset/css/variables.less
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@
@suggestions-border-color: @base-gray-light;
@suggestions-separation-bg: @base-gray-lighter;
@suggestions-failure-message-color: @default-text-color-light;
@suggestions-relation-path-bg: @base-gray-light;
@suggestions-relation-path-focus-bg: @base-gray;

@card-border-color: @base-gray-light;

Expand Down Expand Up @@ -156,6 +158,8 @@
--suggestions-border-color: var(--base-gray-light);
--suggestions-separation-bg: var(--base-gray-lighter);
--suggestions-failure-message-color: var(--default-text-color-light);
--suggestions-relation-path-bg: var(--base-gray-lighter);
--suggestions-relation-path-focus-bg: var(--base-gray);

--card-border-color: var(--base-gray-light);
}
Expand Down
14 changes: 14 additions & 0 deletions asset/js/widget/BaseInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ define(["../notjQuery", "Completer"], function ($, Completer) {
termData['class'] = label.className;
}

if (label.title) {
termData['title'] = label.title;
}

this.registerTerm(this.decodeTerm(termData), label.dataset.index);
});
}
Expand Down Expand Up @@ -338,6 +342,12 @@ define(["../notjQuery", "Completer"], function ($, Completer) {
if (!! termData.search || termData.search === '') {
label.dataset.search = termData.search;
}

if (!! termData.title) {
label.title = termData.title;
} else {
label.title = '';
}
}

termsToQueryString(terms) {
Expand Down Expand Up @@ -475,6 +485,10 @@ define(["../notjQuery", "Completer"], function ($, Completer) {
label.classList.add(termData.class);
}

if (termData.title) {
label.title = termData.title;
}

label.dataset.label = termData.label;
label.dataset.search = termData.search;
label.dataset.index = termIndex;
Expand Down
2 changes: 2 additions & 0 deletions asset/js/widget/Completer.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,8 @@ define(["../notjQuery"], function ($) {
}

dataElement.value = data[name];
} else if (name === 'title') {
input.title = data[name];
}
}
}
Expand Down
38 changes: 32 additions & 6 deletions src/Control/SearchBar/Suggestions.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,18 @@ public function setFailureMessage($message)
return $this;
}

/**
* Return whether the relation should be shown for the given column
*
* @param string $column
*
* @return bool
*/
protected function shouldShowRelationFor(string $column): bool
{
return false;
}

/**
* Create a filter to provide as default for column suggestions
*
Expand Down Expand Up @@ -236,7 +248,8 @@ protected function assemble()
$attributes = [
'type' => 'button',
'tabindex' => -1,
'data-search' => $term
'data-search' => $term,
'data-title' => $term
];
if ($this->type !== null) {
$attributes['data-type'] = $this->type;
Expand All @@ -245,17 +258,30 @@ protected function assemble()
if (is_array($meta)) {
foreach ($meta as $key => $value) {
if ($key === 'label') {
$attributes['value'] = $value;
$label = $value;
}

$attributes['data-' . $key] = $value;
}
} else {
$attributes['value'] = $meta;
$label = $meta;
$attributes['data-label'] = $meta;
}

$this->addHtml(new HtmlElement('li', null, new InputElement(null, $attributes)));
$button = (new ButtonElement(null, $attributes))
->setAttribute('value', $label)
->addHtml(Text::create($label));
if ($this->shouldShowRelationFor($term)) {
$relationPath = substr($term, 0, strrpos($term, '.'));
$button->getAttributes()->add('class', 'has-details');
$button->addHtml(new HtmlElement(
'span',
Attributes::create(['class' => 'relation-path']),
Text::create($relationPath)
));
}

$this->addHtml(new HtmlElement('li', null, $button));
}

if ($this->hasMore($data, self::DEFAULT_LIMIT)) {
Expand All @@ -265,8 +291,8 @@ protected function assemble()
$showDefault = true;
if ($this->searchTerm && $this->count() === 1) {
// The default option is only shown if the user's input does not result in an exact match
$input = $this->getFirst('li')->getFirst('input');
$showDefault = $input->getValue() != $this->searchTerm
$input = $this->getFirst('li')->getFirst('button');
$showDefault = $input->getContent() != $this->searchTerm
&& $input->getAttributes()->get('data-search')->getValue() != $this->searchTerm;
}

Expand Down
7 changes: 6 additions & 1 deletion src/Control/SearchBar/Terms.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ protected function assembleCondition(Filter\Condition $filter, BaseHtmlElement $
'class' => 'column',
'type' => 'column',
'search' => rawurlencode($column),
'label' => $columnLabel
'label' => $columnLabel,
'title' => $column
];
if ($filter->metaData()->has('invalidColumnPattern')) {
$columnData['pattern'] = $filter->metaData()->get('invalidColumnPattern');
Expand Down Expand Up @@ -235,6 +236,10 @@ protected function assembleTerm(array $data, BaseHtmlElement $where)
'value' => $data['label']
])));

if (isset($data['title'])) {
$term->setAttribute('title', $data['title']);
}

if (isset($data['pattern'])) {
$term->getFirst('input')->setAttribute('pattern', $data['pattern']);

Expand Down
3 changes: 3 additions & 0 deletions src/Control/SearchEditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,9 @@ protected function createCondition(Filter\Condition $condition, $identifier)
? $condition->getColumn()
: null
),
'title' => $condition->getColumn() !== static::FAKE_COLUMN
? $condition->getColumn()
: null,
'required' => true,
'autocomplete' => 'off',
'data-type' => 'column',
Expand Down