Skip to content

fix: Fix tab default #5104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions site/src/hooks/useTab.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { useSearchParams } from "react-router-dom"

export interface UseTabResult {
value: string | null
value: string
set: (value: string) => void
}

export const useTab = (tabKey: string): UseTabResult => {
export const useTab = (tabKey: string, defaultValue: string): UseTabResult => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we assign a default value here in case the consumer doesn't pass one in?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't know what value it can be so I think we can left it required for now.

const [searchParams, setSearchParams] = useSearchParams()
const value = searchParams.get(tabKey)
const value = searchParams.get(tabKey) ?? defaultValue

return {
value,
Expand Down
2 changes: 1 addition & 1 deletion site/src/pages/TemplateVersionPage/TemplateVersionPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const TemplateVersionPage: FC = () => {
const [state] = useMachine(templateVersionMachine, {
context: { versionName, orgId },
})
const tab = useTab("file")
const tab = useTab("file", "0")
const { t } = useTranslation("templateVersionPage")

return (
Expand Down