bbovenzi commented on code in PR #23392:
URL: https://github.com/apache/airflow/pull/23392#discussion_r864199233
##########
airflow/www/static/js/grid/api/useGridData.js:
##########
@@ -17,42 +17,39 @@
* under the License.
*/
-/* global gridData, autoRefreshInterval */
+/* global autoRefreshInterval */
import { useQuery } from 'react-query';
import axios from 'axios';
import { getMetaValue } from '../../utils';
import { useAutoRefresh } from '../context/autorefresh';
-import { formatData, areActiveRuns } from '../utils/gridData';
+import { areActiveRuns } from '../utils/gridData';
import useErrorToast from '../utils/useErrorToast';
+import useFilters from '../utils/useFilters';
// dagId comes from dag.html
const dagId = getMetaValue('dag_id');
const gridDataUrl = getMetaValue('grid_data_url') || '';
-const numRuns = getMetaValue('num_runs');
const urlRoot = getMetaValue('root');
-const baseDate = getMetaValue('base_date');
-
-const emptyData = {
- dagRuns: [],
- groups: {},
-};
const useGridData = () => {
- const initialData = formatData(gridData, emptyData);
const { isRefreshOn, stopRefresh } = useAutoRefresh();
const errorToast = useErrorToast();
- return useQuery('gridData', async () => {
- try {
- const params = new URLSearchParams({
- dag_id: dagId,
- });
- if (numRuns && numRuns !== 25) params.append('num_runs', numRuns);
- if (urlRoot) params.append('root', urlRoot);
- if (baseDate) params.append('base_date', baseDate);
+ const {
+ filters: {
+ baseDate, numRuns, runType, runState,
+ },
+ } = useFilters();
- const newData = await axios.get(gridDataUrl, { params });
+ const { data, isSuccess, ...rest } = useQuery(['useGridData', baseDate,
numRuns, runType, runState], async () => {
+ try {
+ const rootParam = urlRoot ? `&root=${urlRoot}` : '';
+ const baseDateParam = baseDate ? `&base_date=${baseDate}` : '';
+ const numRunsParam = numRuns ? `&num_runs=${numRuns}` : '';
+ const runTypeParam = runType ? `&run_type=${runType}` : '';
+ const runStateParam = runState ? `&run_state=${runState}` : '';
+ const newData = await
axios.get(`${gridDataUrl}?dag_id=${dagId}${numRunsParam}${rootParam}${baseDateParam}${runTypeParam}${runStateParam}`);
Review Comment:
Let's still use`params.append()` here to avoid manually writing them.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]