Skip to content

Commit 4a3bebe

Browse files
committed
make variable spotlight ignore the case of search term and existing variables when searching
1 parent 77ac262 commit 4a3bebe

File tree

4 files changed

+26
-26
lines changed

4 files changed

+26
-26
lines changed

network-canvas

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/Form/Fields/VariablePicker/VariableSpotlight.js

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const ListItem = ({
2020
onSelect,
2121
children,
2222
setSelected,
23-
removeSelected = () => {},
23+
removeSelected = () => { },
2424
}) => {
2525
const ref = useRef(null);
2626

@@ -49,7 +49,7 @@ const ListItem = ({
4949
onClick={onSelect}
5050
>
5151
{children}
52-
{ selected && (
52+
{selected && (
5353
<kbd>
5454
Enter&nbsp;&#8629;
5555
</kbd>
@@ -73,8 +73,8 @@ ListItem.defaultProps = {
7373
selected: false,
7474
onSelect: null,
7575
children: null,
76-
setSelected: () => {},
77-
removeSelected: () => {},
76+
setSelected: () => { },
77+
removeSelected: () => { },
7878
};
7979

8080
const Divider = ({ legend }) => (
@@ -118,7 +118,7 @@ const VariableSpotlight = (props) => {
118118
options.sort(sortByLabel);
119119

120120
if (!filterTerm) { return options; }
121-
return options.filter((item) => item.label.includes(filterTerm));
121+
return options.filter((item) => item.label.toLowerCase().includes(filterTerm.toLowerCase()));
122122
}, [filterTerm, options]);
123123

124124
const existingVariables = useSelector(
@@ -143,29 +143,29 @@ const VariableSpotlight = (props) => {
143143
const renderResults = () => (
144144
<Scroller>
145145
<ol>
146-
{ filterTerm && options.filter((item) => item.label === filterTerm).length !== 1 && (
146+
{filterTerm && options.filter((item) => item.label === filterTerm).length !== 1 && (
147147
<>
148148
{
149149
disallowCreation
150150
&& hasFilterTerm
151151
&& !hasFilterResults
152152
&& (
153-
<div className="variable-spotlight__empty">
154-
<Icon name="warning" />
155-
<div>
156-
<p>
157-
You cannot create a new
158-
variable from here. Please create one or more variables elsewhere
159-
in your protocol, and return here to select them.
160-
</p>
153+
<div className="variable-spotlight__empty">
154+
<Icon name="warning" />
155+
<div>
156+
<p>
157+
You cannot create a new
158+
variable from here. Please create one or more variables elsewhere
159+
in your protocol, and return here to select them.
160+
</p>
161+
</div>
161162
</div>
162-
</div>
163163
)
164164
}
165-
{ !disallowCreation && (
165+
{!disallowCreation && (
166166
<>
167167
<Divider legend="Create" />
168-
{ !invalidVariableName ? (
168+
{!invalidVariableName ? (
169169
<ListItem
170170
onSelect={handleCreateOption}
171171
selected={showCursor && cursor === -1}
@@ -199,12 +199,12 @@ const VariableSpotlight = (props) => {
199199
)}
200200
</>
201201
)}
202-
{ hasFilterResults && (
202+
{hasFilterResults && (
203203
<Divider
204204
legend={hasFilterTerm ? `Existing Variables Containing "${filterTerm}"` : 'Existing Variables'}
205205
/>
206206
)}
207-
{ sortedAndFilteredItems.map(({ value, label, type: optionType }, index) => (
207+
{sortedAndFilteredItems.map(({ value, label, type: optionType }, index) => (
208208
<ListItem
209209
key={value}
210210
onSelect={() => onSelect(value)}
@@ -340,7 +340,7 @@ const VariableSpotlight = (props) => {
340340
variants={resultsVariants}
341341
transition={{ duration: 0.2, ease: 'easeInOut' }}
342342
>
343-
{ !disallowCreation && !hasOptions && (
343+
{!disallowCreation && !hasOptions && (
344344
<div className="variable-spotlight__empty">
345345
<Icon name="info" />
346346
<div>
@@ -353,7 +353,7 @@ const VariableSpotlight = (props) => {
353353
</div>
354354
</div>
355355
)}
356-
{ disallowCreation && !hasFilterTerm && !hasOptions && (
356+
{disallowCreation && !hasFilterTerm && !hasOptions && (
357357
<div className="variable-spotlight__empty">
358358
<Icon name="warning" />
359359
<div>
@@ -365,7 +365,7 @@ const VariableSpotlight = (props) => {
365365
</div>
366366
</div>
367367
)}
368-
{ renderResults() }
368+
{renderResults()}
369369
</motion.main>
370370
</motion.div>
371371
);

src/utils/validations.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export const uniqueByList = (list = [], message) => (value) => {
9494
.some((existingValue) => isRoughlyEqual(existingValue, value));
9595

9696
if (existsAlready) {
97-
return messageWithDefault(message, `"${value}" is already used elsewhere in your protocol`);
97+
return messageWithDefault(message, `"${value}" is already in use`);
9898
}
9999

100100
return undefined;
@@ -104,7 +104,7 @@ export const ISODate = (dateFormat, message) => (value) => {
104104
const dt = DateTime.fromISO(value);
105105
if (
106106
(value && dateFormat.length !== value.length)
107-
|| (value && !dt.isValid)
107+
|| (value && !dt.isValid)
108108
) {
109109
return messageWithDefault(message, `Date is not valid (${dateFormat.toUpperCase()})`);
110110
}

0 commit comments

Comments
 (0)