From 3b6c76a37fdbf227d2cb46b75c37c19da01a55b0 Mon Sep 17 00:00:00 2001 From: Annika Hannig Date: Mon, 25 Jul 2022 17:49:38 +0200 Subject: [PATCH] show result summary --- ui/src/app/components/search/SearchStatus.js | 78 ++++++++++++++++++++ ui/src/app/components/status/Status.js | 1 - ui/src/app/context/api-status.js | 3 +- ui/src/app/context/search.js | 33 ++++++++- ui/src/app/pages/SearchGlobalPage.js | 20 ++--- 5 files changed, 116 insertions(+), 19 deletions(-) diff --git a/ui/src/app/components/search/SearchStatus.js b/ui/src/app/components/search/SearchStatus.js index e69de29..571bf6a 100644 --- a/ui/src/app/components/search/SearchStatus.js +++ b/ui/src/app/components/search/SearchStatus.js @@ -0,0 +1,78 @@ +import moment from 'moment'; + + +import { useApiStatus } + from 'app/context/api-status'; +import { useRoutesLoading } + from 'app/context/routes'; +import { useSearchStatus } + from 'app/context/search'; + +import RelativeTime + from 'app/components/datetime/RelativeTime'; + + + + +const RefreshState = () => { + const status = useApiStatus(); + if (!status.cachedAt || !status.ttlTime) { + return null; + } + + const cachedAt = moment.utc(status.cachedAt); + const cacheTtl = moment.utc(status.ttlTime); + + if (cacheTtl.isBefore(moment.utc())) { + // This means cache is currently being rebuilt + return ( +
  • + Routes cache was built + + and is currently being refreshed. +
  • + ); + } + + return ( +
  • + Routes cache was built + and will be refreshed . +
  • + ); +} + +const SearchStatus = () => { + const isLoading = useRoutesLoading(); + const { queryDurationMs + , totalReceived + , totalFiltered + } = useSearchStatus(); + + + if (isLoading) { + return null; + } + + const queryDuration = queryDurationMs && queryDurationMs.toFixed(2); + + return ( +
    +
    +
      +
    • + Found {totalReceived} received + and {totalFiltered} filtered routes. +
    • +
    • Query took {queryDuration} ms to complete.
    • + +
    +
    +
    + ); +} + +export default SearchStatus; diff --git a/ui/src/app/components/status/Status.js b/ui/src/app/components/status/Status.js index 02316dc..600d4be 100644 --- a/ui/src/app/components/status/Status.js +++ b/ui/src/app/components/status/Status.js @@ -35,7 +35,6 @@ import RelativeTime */ export const CacheStatus = () => { const status = useApiStatus(); - console.log(status); if (!status) { return null; } diff --git a/ui/src/app/context/api-status.js b/ui/src/app/context/api-status.js index 74ef391..29183b4 100644 --- a/ui/src/app/context/api-status.js +++ b/ui/src/app/context/api-status.js @@ -17,8 +17,7 @@ export const useApiStatus = () => useContext(ApiStatusContext); * and version to downstream components */ export const ApiStatusProvider = ({children, api}) => { - let ctx = null; - + let ctx = {}; const cachedAt = api?.cache_status?.cached_at; if (cachedAt) { const ttl = parseServerTime(api.ttl); diff --git a/ui/src/app/context/search.js b/ui/src/app/context/search.js index 890f5c3..25050a4 100644 --- a/ui/src/app/context/search.js +++ b/ui/src/app/context/search.js @@ -4,6 +4,8 @@ import axios from 'axios'; import { useState , useEffect , useMemo + , useContext + , createContext } from 'react'; @@ -13,6 +15,8 @@ import { RoutesReceivedContext , paginationState , filtersState , apiStatusState + , useRoutesReceived + , useRoutesFiltered } from 'app/context/routes'; import { ApiStatusProvider } @@ -26,6 +30,7 @@ import { useQuery import { encodeFilters } from 'app/context/filters'; + const initialRoutesState = { requested: true, loading: false, @@ -169,6 +174,30 @@ const useSearchResults = ({ } +const SearchStatusContext = createContext(); + +export const useSearchStatus = () => useContext(SearchStatusContext); + +export const SearchStatusProvider = ({children, api}) => { + const received = useRoutesReceived(); + const filtered = useRoutesFiltered(); + + const context = { + totalReceived: received.totalResults, + totalFiltered: filtered.totalResults, + queryDurationMs: api.request_duration_ms, + }; + + return ( + + + {children} + + + ); +} + + /** * RoutesSearchProvider provides routes received, filtered * and not exportet. @@ -192,9 +221,9 @@ export const RoutesSearchProvider = ({ - + {children} - + diff --git a/ui/src/app/pages/SearchGlobalPage.js b/ui/src/app/pages/SearchGlobalPage.js index c55089f..6dfc23b 100644 --- a/ui/src/app/pages/SearchGlobalPage.js +++ b/ui/src/app/pages/SearchGlobalPage.js @@ -21,25 +21,19 @@ import PageHeader from 'app/components/page/Header'; import SearchGlobalInput from 'app/components/search/SearchGlobalInput'; +import SearchStatus + from 'app/components/search/SearchStatus'; import WaitingCard from 'app/components/spinners/WaitingCard'; import FiltersEditor from 'app/components/filters/FiltersEditor'; import Routes from 'app/components/routes/Routes'; -import { CacheStatus } - from 'app/components/status/Status'; -const SearchStatus = () => { - return ( - - - - -
    - ); -} +/** + * Show global search input and results + */ const SearchGlobalContent = () => { const isLoading = useRoutesLoading(); const search = useSearchQuery(); @@ -58,9 +52,7 @@ const SearchGlobalContent = () => { { hasQuery &&
    -
    - -
    +
    }