-
Notifications
You must be signed in to change notification settings - Fork 24
DEVPROD-5762 Replace all hardcoded slugs with an enum slug and consolidate slug name to associated resource #2312
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should keep the explicit typing in useParams without the use of slug variables. When a slug changes, it will be super easy to see which useParams are affected because of type errors. These kinds of changes wouldn't have been easily possible before slugs.
* @param matchedPathParams - Params object from react-router-dom's matchPath | ||
* @returns string | undefined | ||
*/ | ||
const slugToId = (matchedPathParams: Params): string | undefined => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code could potentially save tab, taskName, variantName as id based on the order of Object.keys(slugs)
. If you move forward with this abstraction you should create a separate set of slugs that represent ids. Since the URLs in the legacy UI are done coded and complete, I think this abstraction is overkill.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch on this I updated it so that non id slugs are no longer included in the check. I preferred this approach over the previous implementation of just casing on every single slug.
src/pages/Version.tsx
Outdated
@@ -38,7 +38,7 @@ import { NameChangeModal } from "./version/NameChangeModal"; | |||
// docs/decisions/2023-12-13_version_page_logic.md | |||
export const VersionPage: React.FC = () => { | |||
const spruceConfig = useSpruceConfig(); | |||
const { id } = useParams<{ id: string }>(); | |||
const { [slugs.versionId]: id } = useParams(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const { [slugs.versionId]: id } = useParams(); | |
const { [slugs.versionId]: versionId } = useParams(); |
src/pages/host/index.tsx
Outdated
@@ -33,7 +34,7 @@ const { getLimitFromSearch, getPageFromSearch } = url; | |||
|
|||
const Host: React.FC = () => { | |||
const dispatchToast = useToastContext(); | |||
const { id } = useParams<{ id: string }>(); | |||
const { [slugs.hostId]: id } = useParams(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const { [slugs.hostId]: id } = useParams(); | |
const { [slugs.hostId]: hostId } = useParams(); |
}>(); | ||
const { [slugs.projectIdentifier]: identifier, [slugs.tab]: tab } = | ||
useParams<{ | ||
[slugs.projectIdentifier]: string | null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just curious if | null
is required here:
[slugs.projectIdentifier]: string | null; | |
[slugs.projectIdentifier]: string; |
src/pages/taskQueue/index.tsx
Outdated
@@ -27,7 +27,7 @@ import TaskQueueTable from "./TaskQueueTable"; | |||
const TaskQueue = () => { | |||
const taskQueueAnalytics = useTaskQueueAnalytics(); | |||
|
|||
const { distro } = useParams<{ distro: string }>(); | |||
const { [slugs.distro]: distro } = useParams(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you think we should just make TaskQueue use the distroId
slug?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea we can consolidate them
src/pages/preferences/index.tsx
Outdated
import { usePageTitle } from "hooks"; | ||
import { PreferencesTabs } from "pages/preferences/PreferencesTabs"; | ||
|
||
const Preferences: React.FC = () => { | ||
usePageTitle("Preferences"); | ||
const { tab } = useParams<{ tab: string }>(); | ||
const { [slugs.tab]: tab } = useParams(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same comment
src/pages/spawn/index.tsx
Outdated
import { SpawnHost } from "./SpawnHost"; | ||
import { SpawnVolume } from "./SpawnVolume"; | ||
|
||
const Spawn: React.FC = () => { | ||
const { tab } = useParams<{ tab: string }>(); | ||
const { [slugs.tab]: tab } = useParams(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can add more type specificity with <{ tab: SpawnTab }>
src/pages/version/VersionTabs.tsx
Outdated
@@ -109,9 +109,9 @@ export const VersionTabs: React.FC<Props> = ({ | |||
taskCount, | |||
childPatches, | |||
numFailedChildPatches, | |||
patchId: id, | |||
patchId: versionId, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changing this parameter to be called versionId
might make this a bit less confusing to read
src/constants/routes.ts
Outdated
hosts: paths.hosts, | ||
jobLogs: `${paths.jobLogs}/:buildId`, | ||
jobLogs: `${paths.jobLogs}/:${slugs.buildId}`, | ||
jobLogsGroup: `${paths.jobLogs}/:${slugs.taskId}`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where does this one come from? is taskId
the correct parameter rather than something like groupId
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch this is from my job logs pr I must have mixed up the commits
login: paths.login, | ||
myPatches: `${paths.user}/${PageNames.Patches}`, | ||
patch: `${paths.patch}/:id`, | ||
patch: `${paths.patch}/:${slugs.versionId}`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should it be patchId
? (not sure, just guessing since it seems odd)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Woah this page should not exist it looks like we have 2 version pages with 2 urls
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(i saw you tried deleting it but it didn't work, just curious what you found out this page is for)
@@ -152,7 +152,7 @@ export const useConfigurePatch = ( | |||
): HookResult => { | |||
const navigate = useNavigate(); | |||
const location = useLocation(); | |||
const { tab } = useParams<{ tab: PatchTab | null }>(); | |||
const { [slugs.tab]: tab } = useParams<{ [slugs.tab]: PatchTab | null }>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tab
will be undefined if the query param doesn't exist
@@ -125,7 +125,7 @@ interface HookResult extends ConfigurePatchState { | |||
const useConfigurePatch = (patch: ConfigurePatchQuery["patch"]): HookResult => { | |||
const navigate = useNavigate(); | |||
const location = useLocation(); | |||
const { tab } = useParams<{ tab: PatchTab | null }>(); | |||
const { [slugs.tab]: tab } = useParams(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bump!
src/constants/routes.ts
Outdated
taskQueue: paths.taskQueue, | ||
task: `${paths.task}/:${slugs.taskId}`, | ||
taskHistory: `${paths.taskHistory}/:${slugs.projectIdentifier}/:${slugs.taskName}`, | ||
taskQueue: `${paths.taskQueue}`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
taskQueue: `${paths.taskQueue}`, | |
taskQueue: paths.taskQueue, |
login: paths.login, | ||
myPatches: `${paths.user}/${PageNames.Patches}`, | ||
patch: `${paths.patch}/:id`, | ||
patch: `${paths.patch}/:${slugs.versionId}`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(i saw you tried deleting it but it didn't work, just curious what you found out this page is for)
Closing this PR since it has already been moved to the UI repo |
DEVPROD-5762
Description
This should not break any existing pages or urls and only serves to consolidate the slug names we use internally in the Spruce application.
Testing
Existing tests should suffice to catch any edge cases that could have been missed.