Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat:Refetch DAG on tab change if not yet available #12

Merged
merged 1 commit into from
Oct 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/hooks/useResource/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export interface Resource<T> {
getResult: () => DataModel<T> | null;
target: string;
status: AsyncStatus;
retry: () => void;
}

//
Expand Down Expand Up @@ -151,6 +152,8 @@ export default function useResource<T, U>({
const [status, statusDispatch] = useReducer(StatusReducer, { id: 0, status: 'NotAsked' });
const q = new URLSearchParams(queryParams).toString();
const target = apiHttp(`${url}${q ? '?' + q : ''}`);
const [retryCounter, setRetryCounter] = useState(0);

// Call batch update
useInterval(() => {
if (useBatching && onUpdate && updateBatcher[target] && (updateBatcher[target] as Array<U>).length > 0) {
Expand Down Expand Up @@ -299,9 +302,13 @@ export default function useResource<T, U>({
abortCtrl.abort();
}
};
}, [target, pause]); // eslint-disable-line
}, [target, pause, retryCounter]); // eslint-disable-line

function retry() {
setRetryCounter((val) => val + 1);
}

return { url, target, data, error, getResult: () => result, status: status.status };
return { url, target, data, error, getResult: () => result, status: status.status, retry };
}

function getWebsocketUrl<T>(url: string, data: T | null, wsUrl?: string | ((result: T) => string)): string {
Expand Down
6 changes: 6 additions & 0 deletions src/pages/Run/RunPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,12 @@ const RunPage: React.FC<RunPageProps> = ({ run, params }) => {
subscribeToEvents: false,
initialData: null,
});
// Refetch dag on tab change if dag fetching failed
useEffect(() => {
if ((dagResult.status === 'Error' || dagResult.data === null) && tab === 'dag') {
dagResult.retry();
}
}, [tab]); //eslint-disable-line

return (
<>
Expand Down
1 change: 1 addition & 0 deletions src/utils/testhelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export function createResource<T>(data: T, props: Partial<Resource<T>>): Resourc
getResult: () => null,
target: '',
status: 'Ok',
retry: () => null,
...props,
};
}
Expand Down