Skip to content

Commit 51aaf0c

Browse files
committed
Better error handling
1 parent 2f87af2 commit 51aaf0c

File tree

4 files changed

+55
-23
lines changed

4 files changed

+55
-23
lines changed

src/components/questions/QuestionList.tsx

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { useGetQuestionsQuery } from "redux/apis/questions";
1414
import { useGetLOIsQuery } from "redux/apis/lois";
1515
import { TextPart } from "./QuestionHelpers";
1616
import { getId } from "DISK/util";
17+
import WarnIcon from '@mui/icons-material/Warning';
1718

1819
interface QuestionListProps {
1920
expanded?: boolean,
@@ -111,7 +112,7 @@ export const QuestionList = ({expanded=false, kind} : QuestionListProps) => {
111112
return null
112113
return <Fragment>
113114
<Divider/>
114-
<Typography>Hypotheses based on this question:</Typography>
115+
<Typography sx={{p:"6px 2px", fontWeight: "500", color:"#555"}}>Hypotheses based on this question:</Typography>
115116
<List sx={{p:0}}>
116117
{myHyp.map((h:Goal) =>
117118
<ListItem sx={{p:"4px 16px"}} key={h.id}>
@@ -147,15 +148,17 @@ export const QuestionList = ({expanded=false, kind} : QuestionListProps) => {
147148
});
148149
return <Fragment>
149150
<ScienceIcon sx={{mx: "5px", color:'darkorange'}}/>
150-
{parts.map((part:string,i:number) => part.startsWith('?') ?
151-
<b key={`pv_${i}`} style={{color:'green', margin: '4px'}}>
152-
{normalizeTextValue(values[part])}
153-
</b>
154-
:
155-
<TextPart key={`p_${i}`}>
156-
{part}
157-
</TextPart>
158-
)}
151+
<Box sx={{display:'flex', flexWrap: "wrap", alignItems:'center', textDecoration: 'none', width:"100%"}}>
152+
{parts.map((part:string,i:number) => part.startsWith('?') ?
153+
<b key={`pv_${i}`} style={{color:'green', margin: '4px', whiteSpace: 'nowrap'}}>
154+
{normalizeTextValue(values[part])}
155+
</b>
156+
:
157+
<TextPart key={`p_${i}`}>
158+
{part}
159+
</TextPart>
160+
)}
161+
</Box>
159162
</Fragment>
160163
}
161164

@@ -182,14 +185,13 @@ export const QuestionList = ({expanded=false, kind} : QuestionListProps) => {
182185
{isLoading ?
183186
<CircularProgress/>
184187
: (isError ?
185-
<Box>
186-
<span style={{marginRight:'5px'}}>
187-
An error has ocurred while loading.
188-
</span>
188+
<Card variant="outlined" sx={{mt:"1em", display:'flex', justifyContent:'center', gap: ".5em", p: "10px", width:"100%"}}>
189+
<WarnIcon sx={{color:"orangered"}}></WarnIcon>
190+
An error has ocurred while loading.
189191
<MuiLink onClick={() => refetch()} sx={{cursor: 'pointer'}}>
190192
Click here to reload
191193
</MuiLink>
192-
</Box>
194+
</Card>
193195
:
194196
<Box>
195197
{sortedQuestions

src/pages/Goals/GoalView.tsx

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import { useExecuteHypothesisByIdMutation, useGetTLOIsQuery } from "redux/apis/t
1414
import { TypographyLabel, TypographyInline, InfoInline, TypographySubtitle } from "components/Styles";
1515
import { getId } from "DISK/util";
1616
import { TLOIBundle } from "components/tlois/TLOIBundle";
17+
import { useGetLOIsQuery } from "redux/apis/lois";
18+
import WarnIcon from '@mui/icons-material/Warning';
1719

1820

1921
export const HypothesisView = () => {
@@ -24,6 +26,8 @@ export const HypothesisView = () => {
2426
const { data:TLOIs, isLoading:TLOIloading } = useGetTLOIsQuery();
2527
const [execHypothesis, {}] = useExecuteHypothesisByIdMutation();
2628
const [LOIList, setLOIList] = useState<string[]>([]);
29+
const { data:localLOIs, isError:error2, isLoading: loading2} = useGetLOIsQuery();
30+
const [noQuery, setNoQuery] = useState<boolean>(true);
2731

2832
useEffect(() => {
2933
let list : string[] = (TLOIs||[])
@@ -32,6 +36,17 @@ export const HypothesisView = () => {
3236
setLOIList(Array.from(new Set(list)));
3337
}, [TLOIs, goalId]);
3438

39+
useEffect(() => {
40+
let found = false;
41+
if (localLOIs && hypothesis) {
42+
localLOIs.forEach((loi) => {
43+
if (loi.question.id === hypothesis.question.id)
44+
found = true;
45+
})
46+
}
47+
setNoQuery(!found);
48+
}, [localLOIs, hypothesis])
49+
3550
const onTestHypothesisClicked = () => {
3651
if (goalId == undefined)
3752
return;
@@ -119,16 +134,23 @@ export const HypothesisView = () => {
119134
<CachedIcon sx={{mr:"5px"}}/> Update
120135
</Button>
121136
</Box>
122-
{TLOIloading ? (
137+
{TLOIloading || loading2 ? (
123138
<Skeleton/>
124139
) : (
125-
LOIList.length === 0 ? (
126-
<Card variant="outlined" sx={{display:'flex', justifyContent:'center'}}>
127-
No executions
140+
noQuery ? (
141+
<Card variant="outlined" sx={{display:'flex', justifyContent:'center', gap: ".5em", p: "10px"}}>
142+
<WarnIcon sx={{color:"orangered"}}></WarnIcon>
143+
No lines of inquiry are configured to run this question.
128144
</Card>
129145
) : (
130-
hypothesis && (
131-
LOIList.map((loiId:string) => <TLOIBundle loiId={loiId} key={loiId} goal={hypothesis} />)
146+
LOIList.length === 0 ? (
147+
<Card variant="outlined" sx={{display:'flex', justifyContent:'center', p: "10px"}}>
148+
No executions
149+
</Card>
150+
) : (
151+
hypothesis && (
152+
LOIList.map((loiId:string) => <TLOIBundle loiId={loiId} key={loiId} goal={hypothesis} />)
153+
)
132154
)
133155
)
134156
)}

src/pages/Goals/Goals.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { PATH_GOAL_NEW } from "constants/routes";
88
import { Link } from "react-router-dom";
99
import { HypothesisList } from "components/goals/GoalsList";
1010
import { useGetGoalsQuery } from "redux/apis/goals";
11+
import WarnIcon from '@mui/icons-material/Warning';
1112

1213
type OrderType = 'date'|'author';
1314

@@ -63,7 +64,10 @@ export const Goals = ({myPage=false} : ViewProps) => {
6364
<Skeleton sx={{margin: "0px 10px"}} height={90}/>
6465
:
6566
(isError || !data?
66-
<Box> Error loading Hypotheses </Box>
67+
<Card variant="outlined" sx={{display:'flex', justifyContent:'center', gap: ".5em", p: "10px"}}>
68+
<WarnIcon sx={{color:"orangered"}}></WarnIcon>
69+
Error loading Hypotheses
70+
</Card>
6771
:
6872
<HypothesisList list={data.filter(applyFilters)} enableDeletion enableEdition/>
6973
)

src/pages/LOI/LOIs.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import SearchIcon from '@mui/icons-material/Search';
88
import { Link } from "react-router-dom";
99
import { useGetLOIsQuery } from "redux/apis/lois";
1010
import { LOIList } from "components/lois/LOIList";
11+
import WarnIcon from '@mui/icons-material/Warning';
1112

1213
type OrderType = 'date'|'author';
1314

@@ -63,7 +64,10 @@ export const LinesOfInquiry = ({myPage=false} : ViewProps) => {
6364
<Skeleton sx={{margin: "0px 10px"}} height={90}/>
6465
:
6566
(error || !LOIs?
66-
<Box> Error loading Lines of Inquiry </Box>
67+
<Card variant="outlined" sx={{display:'flex', justifyContent:'center', gap: ".5em", p: "10px"}}>
68+
<WarnIcon sx={{color:"orangered"}}></WarnIcon>
69+
Error loading Lines of Inquiry
70+
</Card>
6771
:
6872
<LOIList list={LOIs.filter(applyFilters)} enableDeletion enableEdition/>
6973
)

0 commit comments

Comments
 (0)