Skip to content

Commit

Permalink
Merge pull request #650 from Path-of-Modifiers/649-change-error-messa…
Browse files Browse the repository at this point in the history
…ge-when-there-arent-selected-modifier

#647 Fixed error message handling for plot query
  • Loading branch information
bogadisa authored Nov 14, 2024
2 parents ea79b1f + 1523172 commit 581c10e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 34 deletions.
30 changes: 14 additions & 16 deletions src/frontend/src/components/Common/QueryButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { MdExpandMore, MdExpandLess } from "react-icons/md";
import { useExpandedComponentStore } from "../../store/ExpandedComponentStore";
import { useGraphInputStore } from "../../store/GraphInputStore";
import {
checkGraphQueryLeageInput,
checkGraphQueryLeagueInput,
checkGraphQueryModifierInput,
} from "../../hooks/graphing/checkGraphQueryInput";
import { useErrorStore } from "../../store/ErrorStore";
Expand Down Expand Up @@ -47,22 +47,21 @@ const QueryButtons = (props: FlexProps) => {
if (isFetching) return;
if (stateHash) return;
setResultError(false);
const leagueValid = checkGraphQueryLeagueInput();
const modifierValid = checkGraphQueryModifierInput();
if (!leagueValid || !modifierValid) return;
const plotQuery = getOptimizedPlotQuery();
if (plotQuery === undefined) return;
setPlotQuery(plotQuery);
const leagueValid = checkGraphQueryLeageInput();
const modifierValid = checkGraphQueryModifierInput();
if (leagueValid && modifierValid) {
useGraphInputStore.getState().setQueryClicked();
setHashFromStore();
useGraphInputStore.getState().setQueryClicked();
setHashFromStore();

// This is a hack to make sure the clearClicked is set to false after the
// state is updated.
setTimeout(() => {
useGraphInputStore.getState().queryClicked = false;
useGraphInputStore.getState().stateHash = undefined;
}, 20);
}
// This is a hack to make sure the clearClicked is set to false after the
// state is updated.
setTimeout(() => {
useGraphInputStore.getState().queryClicked = false;
useGraphInputStore.getState().stateHash = undefined;
}, 20);
};
return (
<Flex
Expand Down Expand Up @@ -127,8 +126,7 @@ const QueryButtons = (props: FlexProps) => {
{filterExpanded ? "Hide Filters" : "Show Filters"}
</Button>
</Flex>

{modifiersError && !noRelatedUniqueError && (
{modifiersError && (
<ErrorMessage
alertTitle="No Modifiers Selected"
alertDescription="Please select at least one modifier."
Expand All @@ -146,7 +144,7 @@ const QueryButtons = (props: FlexProps) => {
alertDescription="No results were found for the current query."
/>
)}
{noRelatedUniqueError && (
{noRelatedUniqueError && !modifiersError && (
<ErrorMessage
alertTitle="No query performed"
alertDescription="The modifiers you have chosen cannot appear on the same Unique."
Expand Down
40 changes: 22 additions & 18 deletions src/frontend/src/hooks/graphing/checkGraphQueryInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,33 @@ const { setLeagueError, setModifiersError } = useErrorStore.getState();
* Checks whether the League input for the graph query is valid
* @returns boolean
*/
export const checkGraphQueryLeageInput = () => {
// If league is empty, return false
const league = useGraphInputStore.getState().plotQuery.league;
if (league === "") {
setLeagueError(true);
return false;
}
setLeagueError(false);
return true;
export const checkGraphQueryLeagueInput = () => {
// If league is empty, return false
const league = useGraphInputStore.getState().league;
if (league === "") {
setLeagueError(true);
return false;
}
setLeagueError(false);
return true;
};

/**
* Checks whether the modifiers input for the graph query is valid
* @returns boolean
*/
export const checkGraphQueryModifierInput = () => {
const plotModifierQueryStore =
useGraphInputStore.getState().plotQuery.wantedModifiers;
// If modifiers are empty, return false
if (plotModifierQueryStore.length === 0) {
setModifiersError(true);
return false;
}
setModifiersError(false);
return true;
const wantedModifiersExtended = useGraphInputStore
.getState()
.wantedModifierExtended.filter(
(wantedModifierExtended) => wantedModifierExtended.isSelected,
);

// If modifiers are empty, return false
if (wantedModifiersExtended.length === 0) {
setModifiersError(true);
return false;
}
setModifiersError(false);
return true;
};

0 comments on commit 581c10e

Please sign in to comment.