|
1 | | -import { useLayoutEffect, useRef, useState } from 'react'; |
| 1 | +import { useEffect, useLayoutEffect, useRef, useState } from 'react'; |
2 | 2 | import PropTypes from 'prop-types'; |
3 | 3 | import countBy from 'lodash/countBy'; |
4 | 4 | import { Button } from 'react-bootstrap'; |
@@ -27,6 +27,9 @@ import { notify } from '../../shared/stores/notificationStore'; |
27 | 27 | import { getAction } from '../../helpers/taskcluster'; |
28 | 28 | import { formatTaskclusterError } from '../../helpers/errorMessage'; |
29 | 29 |
|
| 30 | +// Cache job.searchStr so we can hover over multiple data points |
| 31 | +const jobSearchStrCache = new Map(); |
| 32 | + |
30 | 33 | const GraphTooltip = ({ |
31 | 34 | testData, |
32 | 35 | infraAffectedData, |
@@ -115,11 +118,41 @@ const GraphTooltip = ({ |
115 | 118 | }); |
116 | 119 | } |
117 | 120 |
|
| 121 | + const cacheKey = `${testDetails.repository_name}/${dataPointDetails.jobId}`; |
| 122 | + const [jobSearchStr, setJobSearchStr] = useState( |
| 123 | + dataPointDetails.jobId ? jobSearchStrCache.get(cacheKey) || '' : '', |
| 124 | + ); |
| 125 | + |
| 126 | + useEffect(() => { |
| 127 | + if (!dataPointDetails.jobId) return undefined; |
| 128 | + |
| 129 | + if (jobSearchStrCache.has(cacheKey)) { |
| 130 | + setJobSearchStr(jobSearchStrCache.get(cacheKey)); |
| 131 | + return undefined; |
| 132 | + } |
| 133 | + |
| 134 | + let cancelled = false; |
| 135 | + JobModel.get(testDetails.repository_name, dataPointDetails.jobId) |
| 136 | + .then((job) => { |
| 137 | + const searchStr = job.searchStr || ''; |
| 138 | + jobSearchStrCache.set(cacheKey, searchStr); |
| 139 | + if (!cancelled) setJobSearchStr(searchStr); |
| 140 | + }) |
| 141 | + .catch(() => { |
| 142 | + if (!cancelled) setJobSearchStr(''); |
| 143 | + }); |
| 144 | + |
| 145 | + return () => { |
| 146 | + cancelled = true; |
| 147 | + }; |
| 148 | + }, [cacheKey, dataPointDetails.jobId, testDetails.repository_name]); |
| 149 | + |
118 | 150 | const jobsUrl = getJobsUrl({ |
119 | 151 | repo: testDetails.repository_name, |
120 | 152 | revision: dataPointDetails.revision, |
121 | 153 | selectedJob: dataPointDetails.jobId, |
122 | 154 | group_state: 'expanded', |
| 155 | + ...(jobSearchStr ? { searchStr: jobSearchStr.split(' ') } : {}), |
123 | 156 | }); |
124 | 157 |
|
125 | 158 | const createAlert = async () => { |
|
0 commit comments