github.com/grafana/pyroscope@v1.18.0/public/app/redux/reducers/continuous/selectors.ts (about) 1 import { brandQuery, Query, queryToAppName } from '@pyroscope/models/query'; 2 import type { RootState } from '@pyroscope/redux/store'; 3 import { TagsState } from './state'; 4 5 export const selectContinuousState = (state: RootState) => state.continuous; 6 export const selectApplicationName = (state: RootState) => { 7 const { query } = selectQueries(state); 8 9 const appName = queryToAppName(query); 10 11 return appName.map((q) => q.split('{')[0]).unwrapOrElse(() => ''); 12 }; 13 14 export const selectAppNamesState = (state: RootState) => state.continuous.apps; 15 16 /** Selected all applications and sort alphabetically by name */ 17 export const selectApps = (state: RootState) => { 18 // Shallow copy, since sort is in place 19 return state.continuous.apps.data 20 .slice(0) 21 .sort((a, b) => a.name.localeCompare(b.name)); 22 }; 23 24 export const selectAppNames = (state: RootState) => { 25 return selectApps(state).map((a) => a.name); 26 }; 27 28 export const selectAppTags = (query?: Query) => (state: RootState) => { 29 if (query) { 30 const appName = queryToAppName(query); 31 if (appName.isJust) { 32 if (state.continuous.tags[appName.value]) { 33 return state.continuous.tags[appName.value]; 34 } 35 } 36 } 37 38 return { 39 type: 'pristine', 40 tags: {}, 41 } as TagsState; 42 }; 43 44 export const selectTimelineSides = (state: RootState) => { 45 return { 46 left: state.continuous.leftTimeline, 47 right: state.continuous.rightTimeline, 48 }; 49 }; 50 51 export const selectTimelineSidesData = (state: RootState) => { 52 return { 53 left: state.continuous.leftTimeline.timeline, 54 right: state.continuous.rightTimeline.timeline, 55 }; 56 }; 57 58 export const selectQueries = (state: RootState) => { 59 return { 60 leftQuery: brandQuery(state.continuous.leftQuery || ''), 61 rightQuery: brandQuery(state.continuous.rightQuery || ''), 62 query: brandQuery(state.continuous.query), 63 }; 64 }; 65 66 export const selectRanges = (rootState: RootState) => { 67 const state = rootState.continuous; 68 69 return { 70 left: { 71 from: state.leftFrom, 72 until: state.leftUntil, 73 }, 74 right: { 75 from: state.rightFrom, 76 until: state.rightUntil, 77 }, 78 regular: { 79 from: state.from, 80 until: state.until, 81 }, 82 }; 83 };