From 56402b0d40067e96494c2d4d03ebbdb721b25c25 Mon Sep 17 00:00:00 2001 From: dnazarenkoo <134951516+dnazarenkoo@users.noreply.github.com> Date: Fri, 23 Jun 2023 21:39:59 +0300 Subject: [PATCH] feat: add the url pagination & update options menu (#2943) * feat: add dynamic table based on query * fix: group by repeating * fix: change view when groupBy exist in the list * fix: table scroll * feat: add the pagination and update options menu * feat: trace explorer is updated --------- Co-authored-by: Yevhen Shevchenko Co-authored-by: Nazarenko19 Co-authored-by: Palash Gupta --- frontend/src/constants/queryBuilder.ts | 1 + frontend/src/container/Controls/index.tsx | 58 +++--- frontend/src/container/LogControls/index.tsx | 5 +- .../ComponentsSlider/menuItems.ts | 8 +- .../OptionsMenu/AddColumnField/index.tsx | 30 +++- .../OptionsMenu/AddColumnField/styles.ts | 11 ++ .../OptionsMenu/FormatField/index.tsx | 2 +- .../OptionsMenu/MaxLinesField/index.tsx | 2 +- .../src/container/OptionsMenu/constants.ts | 9 + frontend/src/container/OptionsMenu/index.tsx | 26 +-- frontend/src/container/OptionsMenu/types.ts | 21 +++ .../container/OptionsMenu/useOptionsMenu.ts | 166 ++++++++++++++++++ frontend/src/container/OptionsMenu/utils.ts | 22 +++ .../TracesExplorer/Controls/index.tsx | 4 +- .../TracesExplorer/QuerySection/index.tsx | 5 +- frontend/src/hooks/queryPagination/config.ts | 8 + frontend/src/hooks/queryPagination/index.ts | 2 + frontend/src/hooks/queryPagination/types.ts | 4 + .../queryPagination/useQueryPagination.ts | 70 ++++++++ frontend/src/hooks/queryPagination/utils.ts | 12 ++ frontend/src/hooks/useUrlQueryData.ts | 44 +++++ frontend/src/pages/LogsExplorer/index.tsx | 4 +- .../src/pages/TracesExplorer/constants.ts | 6 - frontend/src/pages/TracesExplorer/index.tsx | 75 ++++---- frontend/src/pages/TracesExplorer/utils.tsx | 7 +- frontend/src/types/actions/logs.ts | 3 +- frontend/src/types/common/queryBuilder.ts | 3 +- frontend/src/types/reducer/logs.ts | 3 +- 28 files changed, 512 insertions(+), 99 deletions(-) create mode 100644 frontend/src/container/OptionsMenu/constants.ts create mode 100644 frontend/src/container/OptionsMenu/types.ts create mode 100644 frontend/src/container/OptionsMenu/useOptionsMenu.ts create mode 100644 frontend/src/container/OptionsMenu/utils.ts create mode 100644 frontend/src/hooks/queryPagination/config.ts create mode 100644 frontend/src/hooks/queryPagination/index.ts create mode 100644 frontend/src/hooks/queryPagination/types.ts create mode 100644 frontend/src/hooks/queryPagination/useQueryPagination.ts create mode 100644 frontend/src/hooks/queryPagination/utils.ts create mode 100644 frontend/src/hooks/useUrlQueryData.ts delete mode 100644 frontend/src/pages/TracesExplorer/constants.ts diff --git a/frontend/src/constants/queryBuilder.ts b/frontend/src/constants/queryBuilder.ts index 0ac5de8030..2ac56af114 100644 --- a/frontend/src/constants/queryBuilder.ts +++ b/frontend/src/constants/queryBuilder.ts @@ -233,6 +233,7 @@ export const PANEL_TYPES: Record = { TABLE: 'table', LIST: 'list', EMPTY_WIDGET: 'EMPTY_WIDGET', + TRACE: 'trace', }; export type IQueryBuilderState = 'search'; diff --git a/frontend/src/container/Controls/index.tsx b/frontend/src/container/Controls/index.tsx index a9a656bfc8..e552bc9f28 100644 --- a/frontend/src/container/Controls/index.tsx +++ b/frontend/src/container/Controls/index.tsx @@ -1,33 +1,29 @@ import { LeftOutlined, RightOutlined } from '@ant-design/icons'; import { Button, Select } from 'antd'; +import { Pagination } from 'hooks/queryPagination'; import { memo, useMemo } from 'react'; import { defaultSelectStyle, ITEMS_PER_PAGE_OPTIONS } from './config'; import { Container } from './styles'; -interface ControlsProps { - count: number; - countPerPage: number; - isLoading: boolean; - handleNavigatePrevious: () => void; - handleNavigateNext: () => void; - handleCountItemsPerPageChange: (e: number) => void; -} - -function Controls(props: ControlsProps): JSX.Element | null { - const { - count, - isLoading, - countPerPage, - handleNavigatePrevious, - handleNavigateNext, - handleCountItemsPerPageChange, - } = props; - +function Controls({ + offset = 0, + isLoading, + totalCount, + countPerPage, + handleNavigatePrevious, + handleNavigateNext, + handleCountItemsPerPageChange, +}: ControlsProps): JSX.Element | null { const isNextAndPreviousDisabled = useMemo( - () => isLoading || countPerPage === 0 || count === 0 || count < countPerPage, - [isLoading, countPerPage, count], + () => isLoading || countPerPage < 0 || totalCount === 0, + [isLoading, countPerPage, totalCount], ); + const isPreviousDisabled = useMemo(() => offset <= 0, [offset]); + const isNextDisabled = useMemo(() => totalCount < countPerPage, [ + countPerPage, + totalCount, + ]); return ( @@ -35,7 +31,7 @@ function Controls(props: ControlsProps): JSX.Element | null { loading={isLoading} size="small" type="link" - disabled={isNextAndPreviousDisabled} + disabled={isPreviousDisabled || isNextAndPreviousDisabled} onClick={handleNavigatePrevious} > Previous @@ -44,12 +40,12 @@ function Controls(props: ControlsProps): JSX.Element | null { loading={isLoading} size="small" type="link" - disabled={isNextAndPreviousDisabled} + disabled={isNextDisabled || isNextAndPreviousDisabled} onClick={handleNavigateNext} > Next -