Skip to content

Commit

Permalink
make variable spotlight ignore the case of search term and existing v…
Browse files Browse the repository at this point in the history
…ariables when searching
  • Loading branch information
jthrilly committed Oct 4, 2023
1 parent 77ac262 commit 4a3bebe
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion network-canvas
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 22 additions & 22 deletions src/components/Form/Fields/VariablePicker/VariableSpotlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const ListItem = ({
onSelect,
children,
setSelected,
removeSelected = () => {},
removeSelected = () => { },
}) => {
const ref = useRef(null);

Expand Down Expand Up @@ -49,7 +49,7 @@ const ListItem = ({
onClick={onSelect}
>
{children}
{ selected && (
{selected && (
<kbd>
Enter&nbsp;&#8629;
</kbd>
Expand All @@ -73,8 +73,8 @@ ListItem.defaultProps = {
selected: false,
onSelect: null,
children: null,
setSelected: () => {},
removeSelected: () => {},
setSelected: () => { },
removeSelected: () => { },
};

const Divider = ({ legend }) => (
Expand Down Expand Up @@ -118,7 +118,7 @@ const VariableSpotlight = (props) => {
options.sort(sortByLabel);

if (!filterTerm) { return options; }
return options.filter((item) => item.label.includes(filterTerm));
return options.filter((item) => item.label.toLowerCase().includes(filterTerm.toLowerCase()));
}, [filterTerm, options]);

const existingVariables = useSelector(
Expand All @@ -143,29 +143,29 @@ const VariableSpotlight = (props) => {
const renderResults = () => (
<Scroller>
<ol>
{ filterTerm && options.filter((item) => item.label === filterTerm).length !== 1 && (
{filterTerm && options.filter((item) => item.label === filterTerm).length !== 1 && (
<>
{
disallowCreation
&& hasFilterTerm
&& !hasFilterResults
&& (
<div className="variable-spotlight__empty">
<Icon name="warning" />
<div>
<p>
You cannot create a new
variable from here. Please create one or more variables elsewhere
in your protocol, and return here to select them.
</p>
<div className="variable-spotlight__empty">
<Icon name="warning" />
<div>
<p>
You cannot create a new
variable from here. Please create one or more variables elsewhere
in your protocol, and return here to select them.
</p>
</div>
</div>
</div>
)
}
{ !disallowCreation && (
{!disallowCreation && (
<>
<Divider legend="Create" />
{ !invalidVariableName ? (
{!invalidVariableName ? (
<ListItem
onSelect={handleCreateOption}
selected={showCursor && cursor === -1}
Expand Down Expand Up @@ -199,12 +199,12 @@ const VariableSpotlight = (props) => {
)}
</>
)}
{ hasFilterResults && (
{hasFilterResults && (
<Divider
legend={hasFilterTerm ? `Existing Variables Containing "${filterTerm}"` : 'Existing Variables'}
/>
)}
{ sortedAndFilteredItems.map(({ value, label, type: optionType }, index) => (
{sortedAndFilteredItems.map(({ value, label, type: optionType }, index) => (
<ListItem
key={value}
onSelect={() => onSelect(value)}
Expand Down Expand Up @@ -340,7 +340,7 @@ const VariableSpotlight = (props) => {
variants={resultsVariants}
transition={{ duration: 0.2, ease: 'easeInOut' }}
>
{ !disallowCreation && !hasOptions && (
{!disallowCreation && !hasOptions && (
<div className="variable-spotlight__empty">
<Icon name="info" />
<div>
Expand All @@ -353,7 +353,7 @@ const VariableSpotlight = (props) => {
</div>
</div>
)}
{ disallowCreation && !hasFilterTerm && !hasOptions && (
{disallowCreation && !hasFilterTerm && !hasOptions && (
<div className="variable-spotlight__empty">
<Icon name="warning" />
<div>
Expand All @@ -365,7 +365,7 @@ const VariableSpotlight = (props) => {
</div>
</div>
)}
{ renderResults() }
{renderResults()}
</motion.main>
</motion.div>
);
Expand Down
4 changes: 2 additions & 2 deletions src/utils/validations.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export const uniqueByList = (list = [], message) => (value) => {
.some((existingValue) => isRoughlyEqual(existingValue, value));

if (existsAlready) {
return messageWithDefault(message, `"${value}" is already used elsewhere in your protocol`);
return messageWithDefault(message, `"${value}" is already in use`);
}

return undefined;
Expand All @@ -104,7 +104,7 @@ export const ISODate = (dateFormat, message) => (value) => {
const dt = DateTime.fromISO(value);
if (
(value && dateFormat.length !== value.length)
|| (value && !dt.isValid)
|| (value && !dt.isValid)
) {
return messageWithDefault(message, `Date is not valid (${dateFormat.toUpperCase()})`);
}
Expand Down

0 comments on commit 4a3bebe

Please sign in to comment.