Skip to content

Commit

Permalink
Handle error that shouldn't be thrown.
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianmroz-allegro committed May 20, 2019
1 parent c96de00 commit d5fc0ff
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ export class SelectableStringFilterMenu extends React.Component<SelectableString
// null is here when we get out of order request, so we just ignore it
if (!dataset) return;
this.setState({ dataset });
})
.catch(_ => {
// Some weird internal error. All application logic errors are handled earlier
this.setState({ dataset: error(new Error("Unknown error")) });
});
}

Expand Down Expand Up @@ -175,10 +179,10 @@ export class SelectableStringFilterMenu extends React.Component<SelectableString
return onClauseChange(clause);
}

onValueClick = (value: string, e: React.MouseEvent<HTMLDivElement>) => {
onValueClick = (value: string, withModKey: boolean) => {
const { selectedValues, colors: oldColors } = this.state;
const colors = oldColors && oldColors.toggle(value);
if (e.altKey || e.ctrlKey || e.metaKey) {
if (withModKey) {
const isValueSingleSelected = selectedValues.contains(value) && selectedValues.count() === 1;
return this.setState({ colors, selectedValues: isValueSingleSelected ? Set.of() : Set.of(value) });
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,19 @@ interface StringValueProps {
selected: boolean;
checkboxStyle: string;
highlight: string;
onRowSelect: Binary<unknown, React.MouseEvent<HTMLDivElement>, void>;
onRowSelect: Binary<unknown, boolean, void>;
}

const hasModKey = (e: React.MouseEvent<unknown>) => e.altKey || e.ctrlKey || e.metaKey;

export const StringValue: React.SFC<StringValueProps> = props => {
const { value, selected, checkboxStyle, highlight, onRowSelect } = props;
const label = String(value);

return <div
className={classNames("string-value", { selected })}
title={label}
onClick={e => onRowSelect(value, e)}
onClick={e => onRowSelect(value, hasModKey(e))}
>
<div className="value-wrapper">
<Checkbox type={checkboxStyle as CheckboxType} selected={selected} />
Expand Down

0 comments on commit d5fc0ff

Please sign in to comment.