From 88077f283cbfe9801a1ada6286d27e3e0670b953 Mon Sep 17 00:00:00 2001 From: Birk Johansson Date: Mon, 21 Oct 2024 16:56:12 +0200 Subject: [PATCH] fix: refactor useLocationSearchState name --- .../sectionList/listActions/SectionListActions.tsx | 10 +++------- src/components/sectionList/toolbar/ToolbarNormal.tsx | 4 ++-- src/lib/routeUtils/useLocationSearchState.ts | 10 +++++----- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/components/sectionList/listActions/SectionListActions.tsx b/src/components/sectionList/listActions/SectionListActions.tsx index c84364f5..a20bc57a 100644 --- a/src/components/sectionList/listActions/SectionListActions.tsx +++ b/src/components/sectionList/listActions/SectionListActions.tsx @@ -13,11 +13,7 @@ import { } from '@dhis2/ui' import React, { useRef, useState } from 'react' import { useHref, useLinkClickHandler } from 'react-router-dom' -import { - TOOLTIPS, - BaseListModel, - useCreateLocationSearchState, -} from '../../../lib' +import { TOOLTIPS, BaseListModel, useLocationSearchState } from '../../../lib' import { LinkButton } from '../../LinkButton' import { TooltipWrapper } from '../../tooltip' import { DeleteAction } from './DeleteAction' @@ -32,7 +28,7 @@ export const ListActions = ({ children }: React.PropsWithChildren) => { } export const ActionEdit = ({ modelId }: { modelId: string }) => { - const preservedSearchState = useCreateLocationSearchState() + const preservedSearchState = useLocationSearchState() return ( setManageColumnsOpen(false) return ( diff --git a/src/lib/routeUtils/useLocationSearchState.ts b/src/lib/routeUtils/useLocationSearchState.ts index 113c0f7f..a9014a25 100644 --- a/src/lib/routeUtils/useLocationSearchState.ts +++ b/src/lib/routeUtils/useLocationSearchState.ts @@ -17,15 +17,15 @@ type LocationSearchState = { search?: string } | null -export const createLocationState = (search: string): LocationSearchState => ({ +const createLocationState = (search: string): LocationSearchState => ({ search, }) -const applySearchState = (to: To, location: LocationSearchState) => { +const applySearchState = (to: To, locationSearchState: LocationSearchState) => { if (typeof to === 'string') { - return { pathname: to, search: location?.search } + return { pathname: to, search: locationSearchState?.search } } - return { ...to, search: to.search || location?.search } + return { ...to, search: to.search || locationSearchState?.search } } /** @@ -33,7 +33,7 @@ const applySearchState = (to: To, location: LocationSearchState) => { * Pass the returned state to Link components or as options to navigate as "state"-property. * @returns an object that holds the current search-state. */ -export const useCreateLocationSearchState = () => { +export const useLocationSearchState = () => { const location = useLocation() return useMemo(