From 8e90dab7cce766b730a3fecc69d2187fe60ea9c0 Mon Sep 17 00:00:00 2001 From: Kristin Lindquist Date: Tue, 23 Jan 2024 14:23:52 -0700 Subject: [PATCH 1/4] tabs saved in params --- .../dashboard/characteristics/control.tsx | 8 +-- src/app/core/dashboard/content.tsx | 13 +++-- src/app/core/dashboard/page.tsx | 2 + src/components/layout/tabs.tsx | 50 +++++++++++-------- src/hooks/navigation.tsx | 17 +++++-- 5 files changed, 56 insertions(+), 34 deletions(-) diff --git a/src/app/core/dashboard/characteristics/control.tsx b/src/app/core/dashboard/characteristics/control.tsx index e5fbf5a..042d4fa 100644 --- a/src/app/core/dashboard/characteristics/control.tsx +++ b/src/app/core/dashboard/characteristics/control.tsx @@ -13,7 +13,7 @@ export const PatentCharacteristicsControl = ({ terms, children, }: PatentSearchArgs & { children: ReactNode; headField: HeadField }) => { - const { params, navigate } = useNavigation(); + const { setParam } = useNavigation(); return ( <> @@ -31,11 +31,7 @@ export const PatentCharacteristicsControl = ({ label="Dimension" onChange={(e: unknown, value: HeadField | null) => { if (value) { - const newParams = new URLSearchParams(params); - newParams.set('headField', value); - navigate(`?${newParams.toString()}`, { - scroll: false, - }); + setParam('headField', value); } }} options={['priority_date', 'id']} diff --git a/src/app/core/dashboard/content.tsx b/src/app/core/dashboard/content.tsx index 4693b1d..6b3477b 100644 --- a/src/app/core/dashboard/content.tsx +++ b/src/app/core/dashboard/content.tsx @@ -16,12 +16,16 @@ import { PatentCharacteristics } from './characteristics'; import { OverTime } from './over-time'; import { Summary } from './summary'; -export type ContentArgs = PatentSearchArgs & { headField: HeadField }; +export type ContentArgs = PatentSearchArgs & { + headField: HeadField; + tab: string; +}; -export const Content = (args: ContentArgs) => { +export const Content = ({ tab, ...args }: ContentArgs) => { try { const tabs = [ { + id: 'assets', label: 'Assets', panel: ( }> @@ -30,6 +34,7 @@ export const Content = (args: ContentArgs) => { ), }, { + id: 'summary', label: 'Summary', panel: ( }> @@ -38,6 +43,7 @@ export const Content = (args: ContentArgs) => { ), }, { + id: 'over-time', label: 'Over Time', panel: ( }> @@ -46,6 +52,7 @@ export const Content = (args: ContentArgs) => { ), }, { + id: 'characteristics', label: 'Characteristics', panel: ( }> @@ -56,7 +63,7 @@ export const Content = (args: ContentArgs) => { ]; return ( - + ); } catch (e) { diff --git a/src/app/core/dashboard/page.tsx b/src/app/core/dashboard/page.tsx index 4c3e83d..8c17363 100644 --- a/src/app/core/dashboard/page.tsx +++ b/src/app/core/dashboard/page.tsx @@ -25,6 +25,7 @@ const Page = ({ searchParams }: { searchParams: Record }) => { ? parseInt(searchParams.endYear, 10) : undefined; const headField = (searchParams.headField as HeadField) || 'priority_date'; + const { tab } = searchParams; return ( <> @@ -57,6 +58,7 @@ const Page = ({ searchParams }: { searchParams: Record }) => { headField={headField} queryType={queryType} startYear={startYear} + tab={tab} terms={terms || []} /> diff --git a/src/components/layout/tabs.tsx b/src/components/layout/tabs.tsx index 638847d..096c265 100644 --- a/src/components/layout/tabs.tsx +++ b/src/components/layout/tabs.tsx @@ -6,9 +6,10 @@ import TabList from '@mui/joy/TabList'; import TabPanel from '@mui/joy/TabPanel'; import JoyTabs from '@mui/joy/Tabs'; -import { getSelectableId } from '@/utils/string'; +import { useNavigation } from '@/hooks/navigation'; type TabDef = { + id: string; label: string; panel: ReactNode; }; @@ -17,23 +18,32 @@ type TabDef = { * Tab component * @param props.tabs */ -export const Tabs = ({ tabs }: { tabs: TabDef[] }): JSX.Element => ( - - - {tabs.map(({ label }) => ( - - {label} - +export const Tabs = ({ + openId, + tabs, +}: { + openId?: string; + tabs: TabDef[]; +}): JSX.Element => { + const { setParam } = useNavigation(); + return ( + setParam('tab', `${id}`)} value={openId}> + + {tabs.map(({ id, label }) => ( + + {label} + + ))} + + {tabs.map(({ id, panel }) => ( + + {panel} + ))} - - {tabs.map(({ label, panel }, idx) => ( - - {panel} - - ))} - -); + + ); +}; diff --git a/src/hooks/navigation.tsx b/src/hooks/navigation.tsx index 8c7265c..220b61c 100644 --- a/src/hooks/navigation.tsx +++ b/src/hooks/navigation.tsx @@ -18,6 +18,7 @@ type NavigationContextType = { isPending: boolean; navigate: (url: string, options?: NavigateOptions) => void; params: ReadonlyURLSearchParams; + setParam: (key: string, value: string) => void; }; const NavigationContext = createContext({ @@ -26,6 +27,9 @@ const NavigationContext = createContext({ console.warn(`No impl when attempting to route to ${url}`); }) as NavigationContextType['navigate'], params: new URLSearchParams() as ReadonlyURLSearchParams, + setParam: (key: string, value: string) => { + console.warn(`No impl when attempting to set param ${key} to ${value}`); + }, }); export const NavigationProvider = ({ children }: { children: ReactNode }) => { @@ -38,11 +42,14 @@ export const NavigationProvider = ({ children }: { children: ReactNode }) => { isPending, navigate: (url: string, options?: NavigateOptions) => { startTransition(() => { - if (options?.scroll === false) { - Router.replace(url, options); - } else { - Router.push(url, options); - } + Router.push(url, options); + }); + }, + setParam: (key: string, value: string) => { + const newParams = new URLSearchParams(params); + newParams.set(key, value); + Router.replace(`?${newParams.toString()}`, { + scroll: false, // TODO! }); }, params, From c52d233e26ad016adf2ece79e8d1879f6bdba89d Mon Sep 17 00:00:00 2001 From: Kristin Lindquist Date: Tue, 23 Jan 2024 14:26:35 -0700 Subject: [PATCH 2/4] disabling exemplar patent field --- src/components/composite/search/search-bar.tsx | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/components/composite/search/search-bar.tsx b/src/components/composite/search/search-bar.tsx index 4eeb7a7..ec6c6fd 100644 --- a/src/components/composite/search/search-bar.tsx +++ b/src/components/composite/search/search-bar.tsx @@ -18,7 +18,7 @@ import { FetchAutocompletions } from './types'; */ export const SearchBar = ({ endYear = 2024, - exemplarPatents, + // exemplarPatents, fetchAutocompletions, queryType, startYear = 2014, @@ -29,9 +29,9 @@ export const SearchBar = ({ const { navigate } = useNavigation(); const pathname = usePathname(); const [newTerms, setTerms] = useState(terms); - const [newExemplarPatents, setExemplarPatents] = useState( - exemplarPatents || null - ); + // const [newExemplarPatents, setExemplarPatents] = useState( + // exemplarPatents || null + // ); const [newQueryType, setQueryType] = useState( queryType || null ); @@ -72,6 +72,7 @@ export const SearchBar = ({ minDistance={2} max={2025} size="lg" + sx={{ mr: 3 }} valueLabelDisplay="on" /> @@ -90,7 +91,7 @@ export const SearchBar = ({ /> - + {/* isMultiple @@ -116,7 +117,7 @@ export const SearchBar = ({ variant="soft" /> - + */}