Skip to content

Commit

Permalink
Merge pull request #1182 from noobaa/ohad-fixes
Browse files Browse the repository at this point in the history
Apply custom match op to both timezone fields
  • Loading branch information
nb-ohad committed May 10, 2016
2 parents 4045bf6 + 4ba77ac commit bc5d19b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ <h2 class="heading2" data-bind="click: () => expanded.toggle()">
<dropdown params="
options: timezones,
selected: timezone,
searchSelector: timezoneSearchSelector
matchOperator: matchByTimezoneName
"></dropdown>
</editor>

Expand Down Expand Up @@ -64,7 +64,11 @@ <h2 class="heading2" data-bind="click: () => expanded.toggle()">
<!-- ko if: usingNTP -->
<section class="container">
<editor params="label: 'Time Zone'">
<dropdown params="options: timezones, selected: timezone"></dropdown>
<dropdown params="
options: timezones,
selected: timezone,
matchOperator: matchByTimezoneName
"></dropdown>
</editor>

<editor params="label: 'NTP Server'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@ const configTypes = Object.freeze([
{ label: 'Network Time (NTP)', value: 'NTP' }
]);

function timezoneSearchSelector({ label }, input) {
return !!label.toLowerCase().match(
new RegExp(`\\b${input.replace('/', '\\/')}`)
);
}

class ServerTimeFormViewModel {
constructor() {
this.expanded = ko.observable(false);
Expand Down Expand Up @@ -156,7 +150,11 @@ class ServerTimeFormViewModel {
ntpServer: this.ntpServer
});

this.timezoneSearchSelector = timezoneSearchSelector;
this.matchByTimezoneName = function({ label }, input) {
return !!label.toLowerCase().match(
new RegExp(`\\b${input.replace('/', '\\/')}`)
);
};
}

applyChanges() {
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/app/components/shared/dropdown/dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { isDefined } from 'utils';

const INPUT_THROTTLE = 1000;

function defaultSearchSelector({ label }, input) {
function matchByPrefix({ label }, input) {
return label.toString().toLowerCase().startsWith(input);
}

Expand All @@ -15,7 +15,7 @@ class DropdownViewModel {
options = [],
placeholder = '',
disabled = false,
searchSelector = defaultSearchSelector
matchOperator = matchByPrefix
}) {
this.name = randomString(5);
this.options = options;
Expand Down Expand Up @@ -47,7 +47,7 @@ class DropdownViewModel {
}
);

this.searchSelector = searchSelector;
this.matchOperator = matchOperator;
this.searchInput = '';
this.lastInput = 0;
}
Expand Down Expand Up @@ -100,7 +100,7 @@ class DropdownViewModel {
char;

let option = ko.unwrap(this.options).find(
option => this.searchSelector(option, this.searchInput)
option => this.matchOperator(option, this.searchInput)
);

if (option) {
Expand Down

0 comments on commit bc5d19b

Please sign in to comment.