mirror of
https://github.com/reduxjs/redux-devtools.git
synced 2025-07-27 00:19:55 +03:00
feat(rtk-query): display status flags in QueryPreviewInfo
This commit is contained in:
parent
1cda9adfca
commit
6f4ae9b11b
|
@ -1,7 +1,13 @@
|
||||||
import { createSelector, Selector } from '@reduxjs/toolkit';
|
import { createSelector, Selector } from '@reduxjs/toolkit';
|
||||||
import React, { ReactNode, PureComponent } from 'react';
|
import React, { ReactNode, PureComponent } from 'react';
|
||||||
import { QueryInfo, QueryPreviewTabProps, RtkQueryState } from '../types';
|
import {
|
||||||
|
QueryInfo,
|
||||||
|
QueryPreviewTabProps,
|
||||||
|
RtkQueryState,
|
||||||
|
RTKStatusFlags,
|
||||||
|
} from '../types';
|
||||||
import { identity } from '../utils/object';
|
import { identity } from '../utils/object';
|
||||||
|
import { getQueryStatusFlags } from '../utils/rtk-query';
|
||||||
import { TreeView } from './TreeView';
|
import { TreeView } from './TreeView';
|
||||||
|
|
||||||
type ComputedQueryInfo = {
|
type ComputedQueryInfo = {
|
||||||
|
@ -11,6 +17,7 @@ type ComputedQueryInfo = {
|
||||||
|
|
||||||
interface FormattedQuery extends ComputedQueryInfo {
|
interface FormattedQuery extends ComputedQueryInfo {
|
||||||
queryKey: string;
|
queryKey: string;
|
||||||
|
statusFlags: RTKStatusFlags;
|
||||||
query: RtkQueryState;
|
query: RtkQueryState;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,10 +42,13 @@ export class QueryPreviewInfo extends PureComponent<QueryPreviewTabProps> {
|
||||||
? new Date(query.fulfilledTimeStamp).toISOString()
|
? new Date(query.fulfilledTimeStamp).toISOString()
|
||||||
: '-';
|
: '-';
|
||||||
|
|
||||||
|
const statusFlags = getQueryStatusFlags(query);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
queryKey,
|
queryKey,
|
||||||
startedAt,
|
startedAt,
|
||||||
latestFetchAt,
|
latestFetchAt,
|
||||||
|
statusFlags,
|
||||||
query: queryInfo.query,
|
query: queryInfo.query,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -123,3 +123,13 @@ export type QueryPreviewTabOption = TabOption<
|
||||||
QueryPreviewTabs,
|
QueryPreviewTabs,
|
||||||
QueryPreviewTabProps
|
QueryPreviewTabProps
|
||||||
>;
|
>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* It is Omit<RequestStatusFlags, 'status'> & { isFetching: boolean; }
|
||||||
|
*/
|
||||||
|
export interface RTKStatusFlags {
|
||||||
|
readonly isUninitialized: boolean;
|
||||||
|
readonly isFetching: boolean;
|
||||||
|
readonly isSuccess: boolean;
|
||||||
|
readonly isError: boolean;
|
||||||
|
}
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
import { isPlainObject } from '@reduxjs/toolkit';
|
import { isPlainObject } from '@reduxjs/toolkit';
|
||||||
|
import { QueryStatus } from '@reduxjs/toolkit/query';
|
||||||
import {
|
import {
|
||||||
QueryInfo,
|
QueryInfo,
|
||||||
RtkQueryInspectorMonitorState,
|
RtkQueryInspectorMonitorState,
|
||||||
RtkQueryApiState,
|
RtkQueryApiState,
|
||||||
RTKQuerySubscribers,
|
RTKQuerySubscribers,
|
||||||
RtkQueryTag,
|
RtkQueryTag,
|
||||||
|
RTKStatusFlags,
|
||||||
|
RtkQueryState,
|
||||||
} from '../types';
|
} from '../types';
|
||||||
import { missingTagId } from '../monitor-config';
|
import { missingTagId } from '../monitor-config';
|
||||||
import { Comparator } from './comparators';
|
import { Comparator } from './comparators';
|
||||||
|
@ -182,3 +185,21 @@ export function getQueryTagsOf(
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Computes query status flags.
|
||||||
|
* @param status
|
||||||
|
* @see https://redux-toolkit.js.org/rtk-query/usage/queries#frequently-used-query-hook-return-values
|
||||||
|
* @see https://github.com/reduxjs/redux-toolkit/blob/b718e01d323d3ab4b913e5d88c9b90aa790bb975/src/query/core/apiState.ts#L63
|
||||||
|
*/
|
||||||
|
export function getQueryStatusFlags({
|
||||||
|
status,
|
||||||
|
data,
|
||||||
|
}: RtkQueryState): RTKStatusFlags {
|
||||||
|
return {
|
||||||
|
isUninitialized: status === QueryStatus.uninitialized,
|
||||||
|
isFetching: status === QueryStatus.pending,
|
||||||
|
isSuccess: status === QueryStatus.fulfilled && !!data,
|
||||||
|
isError: status === QueryStatus.rejected,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user