mirror of
https://github.com/hanzoai/sentinel.git
synced 2026-09-29 22:34:33 +00:00
59 lines
1.8 KiB
TypeScript
59 lines
1.8 KiB
TypeScript
import type {NewQuery} from 'sentry/types';
|
|
import EventView from 'sentry/utils/discover/eventView';
|
|
import {DiscoverDatasets} from 'sentry/utils/discover/types';
|
|
import {MutableSearch} from 'sentry/utils/tokenizeSearch';
|
|
import {useLocation} from 'sentry/utils/useLocation';
|
|
import usePageFilters from 'sentry/utils/usePageFilters';
|
|
import {useReleaseSelection} from 'sentry/views/starfish/queries/useReleases';
|
|
import {appendReleaseFilters} from 'sentry/views/starfish/utils/releaseComparison';
|
|
import {useTableQuery} from 'sentry/views/starfish/views/screens/screensTable';
|
|
|
|
export function useTTFDConfigured(additionalFilters?: string[]) {
|
|
const location = useLocation();
|
|
|
|
const {
|
|
primaryRelease,
|
|
secondaryRelease,
|
|
isLoading: isReleasesLoading,
|
|
} = useReleaseSelection();
|
|
|
|
const {selection} = usePageFilters();
|
|
|
|
const query = new MutableSearch([
|
|
'event.type:transaction',
|
|
'transaction.op:ui.load',
|
|
...(additionalFilters ?? []),
|
|
]);
|
|
|
|
const queryString = appendReleaseFilters(query, primaryRelease, secondaryRelease);
|
|
|
|
const newQuery: NewQuery = {
|
|
name: '',
|
|
fields: [
|
|
`avg(measurements.time_to_initial_display)`,
|
|
`avg(measurements.time_to_full_display)`,
|
|
'count()',
|
|
],
|
|
query: queryString,
|
|
dataset: DiscoverDatasets.METRICS,
|
|
version: 2,
|
|
projects: selection.projects,
|
|
};
|
|
const eventView = EventView.fromNewQueryWithLocation(newQuery, location);
|
|
|
|
const result = useTableQuery({
|
|
eventView,
|
|
enabled: !isReleasesLoading,
|
|
staleTime: Infinity,
|
|
});
|
|
|
|
const hasTTFD: boolean | undefined = result.data?.data?.length
|
|
? !(
|
|
result.data.data?.[0]['avg(measurements.time_to_initial_display)'] !== 0 &&
|
|
result.data.data?.[0]['avg(measurements.time_to_full_display)'] === 0
|
|
)
|
|
: undefined;
|
|
|
|
return {...result, hasTTFD};
|
|
}
|