-
Notifications
You must be signed in to change notification settings - Fork 11
fix: Select release channel filter on deployment page #214
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,5 +1,6 @@ | ||||||||||||||||||||||||||||||||||||||||
| "use client"; | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| import type * as SCHEMA from "@ctrlplane/db/schema"; | ||||||||||||||||||||||||||||||||||||||||
| import type { ReleaseCondition } from "@ctrlplane/validators/releases"; | ||||||||||||||||||||||||||||||||||||||||
| import React, { useState } from "react"; | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
|
|
@@ -13,6 +14,16 @@ import { | |||||||||||||||||||||||||||||||||||||||
| DialogTitle, | ||||||||||||||||||||||||||||||||||||||||
| DialogTrigger, | ||||||||||||||||||||||||||||||||||||||||
| } from "@ctrlplane/ui/dialog"; | ||||||||||||||||||||||||||||||||||||||||
| import { | ||||||||||||||||||||||||||||||||||||||||
| Select, | ||||||||||||||||||||||||||||||||||||||||
| SelectContent, | ||||||||||||||||||||||||||||||||||||||||
| SelectGroup, | ||||||||||||||||||||||||||||||||||||||||
| SelectItem, | ||||||||||||||||||||||||||||||||||||||||
| SelectLabel, | ||||||||||||||||||||||||||||||||||||||||
| SelectTrigger, | ||||||||||||||||||||||||||||||||||||||||
| SelectValue, | ||||||||||||||||||||||||||||||||||||||||
| } from "@ctrlplane/ui/select"; | ||||||||||||||||||||||||||||||||||||||||
| import { Tabs, TabsContent, TabsList, TabsTrigger } from "@ctrlplane/ui/tabs"; | ||||||||||||||||||||||||||||||||||||||||
| import { | ||||||||||||||||||||||||||||||||||||||||
| defaultCondition, | ||||||||||||||||||||||||||||||||||||||||
| isValidReleaseCondition, | ||||||||||||||||||||||||||||||||||||||||
|
|
@@ -22,26 +33,37 @@ import { | |||||||||||||||||||||||||||||||||||||||
| import { api } from "~/trpc/react"; | ||||||||||||||||||||||||||||||||||||||||
| import { ReleaseBadgeList } from "../ReleaseBadgeList"; | ||||||||||||||||||||||||||||||||||||||||
| import { ReleaseConditionRender } from "./ReleaseConditionRender"; | ||||||||||||||||||||||||||||||||||||||||
| import { useReleaseFilter } from "./useReleaseFilter"; | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| type ReleaseConditionDialogProps = { | ||||||||||||||||||||||||||||||||||||||||
| condition?: ReleaseCondition; | ||||||||||||||||||||||||||||||||||||||||
| deploymentId?: string; | ||||||||||||||||||||||||||||||||||||||||
| onChange: (condition: ReleaseCondition | undefined) => void; | ||||||||||||||||||||||||||||||||||||||||
| releaseChannels?: SCHEMA.ReleaseChannel[]; | ||||||||||||||||||||||||||||||||||||||||
| children: React.ReactNode; | ||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| export const ReleaseConditionDialog: React.FC<ReleaseConditionDialogProps> = ({ | ||||||||||||||||||||||||||||||||||||||||
| condition, | ||||||||||||||||||||||||||||||||||||||||
| deploymentId, | ||||||||||||||||||||||||||||||||||||||||
| onChange, | ||||||||||||||||||||||||||||||||||||||||
| releaseChannels = [], | ||||||||||||||||||||||||||||||||||||||||
| children, | ||||||||||||||||||||||||||||||||||||||||
| }) => { | ||||||||||||||||||||||||||||||||||||||||
| const [open, setOpen] = useState(false); | ||||||||||||||||||||||||||||||||||||||||
| const [error, setError] = useState<string | null>(null); | ||||||||||||||||||||||||||||||||||||||||
| const [localCondition, setLocalCondition] = useState( | ||||||||||||||||||||||||||||||||||||||||
| condition ?? defaultCondition, | ||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||
| const isLocalConditionValid = isValidReleaseCondition(localCondition); | ||||||||||||||||||||||||||||||||||||||||
| const { releaseChannelId, setReleaseChannel, removeReleaseChannel } = | ||||||||||||||||||||||||||||||||||||||||
| useReleaseFilter(); | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| const [localReleaseChannelId, setLocalReleaseChannelId] = useState< | ||||||||||||||||||||||||||||||||||||||||
| string | undefined | ||||||||||||||||||||||||||||||||||||||||
| >(releaseChannelId); | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| const [localCondition, setLocalCondition] = useState< | ||||||||||||||||||||||||||||||||||||||||
| ReleaseCondition | undefined | ||||||||||||||||||||||||||||||||||||||||
| >(condition ?? defaultCondition); | ||||||||||||||||||||||||||||||||||||||||
| const isLocalConditionValid = | ||||||||||||||||||||||||||||||||||||||||
| localCondition == null || isValidReleaseCondition(localCondition); | ||||||||||||||||||||||||||||||||||||||||
| const releasesQ = api.release.list.useQuery( | ||||||||||||||||||||||||||||||||||||||||
| { deploymentId: deploymentId ?? "", filter: localCondition, limit: 5 }, | ||||||||||||||||||||||||||||||||||||||||
| { enabled: deploymentId != null && isLocalConditionValid }, | ||||||||||||||||||||||||||||||||||||||||
|
|
@@ -55,45 +77,125 @@ export const ReleaseConditionDialog: React.FC<ReleaseConditionDialogProps> = ({ | |||||||||||||||||||||||||||||||||||||||
| className="min-w-[1000px]" | ||||||||||||||||||||||||||||||||||||||||
| onClick={(e) => e.stopPropagation()} | ||||||||||||||||||||||||||||||||||||||||
| > | ||||||||||||||||||||||||||||||||||||||||
| <DialogHeader> | ||||||||||||||||||||||||||||||||||||||||
| <DialogTitle>Edit Release Condition</DialogTitle> | ||||||||||||||||||||||||||||||||||||||||
| <DialogDescription> | ||||||||||||||||||||||||||||||||||||||||
| Edit the release filter, up to a depth of {MAX_DEPTH_ALLOWED + 1}. | ||||||||||||||||||||||||||||||||||||||||
| </DialogDescription> | ||||||||||||||||||||||||||||||||||||||||
| </DialogHeader> | ||||||||||||||||||||||||||||||||||||||||
| <ReleaseConditionRender | ||||||||||||||||||||||||||||||||||||||||
| condition={localCondition} | ||||||||||||||||||||||||||||||||||||||||
| onChange={setLocalCondition} | ||||||||||||||||||||||||||||||||||||||||
| /> | ||||||||||||||||||||||||||||||||||||||||
| {releases != null && <ReleaseBadgeList releases={releases} />} | ||||||||||||||||||||||||||||||||||||||||
| {error && <span className="text-sm text-red-600">{error}</span>} | ||||||||||||||||||||||||||||||||||||||||
| <DialogFooter> | ||||||||||||||||||||||||||||||||||||||||
| <Button | ||||||||||||||||||||||||||||||||||||||||
| variant="outline" | ||||||||||||||||||||||||||||||||||||||||
| onClick={() => { | ||||||||||||||||||||||||||||||||||||||||
| <Tabs | ||||||||||||||||||||||||||||||||||||||||
| defaultValue={ | ||||||||||||||||||||||||||||||||||||||||
| releaseChannels.length > 0 ? "release-channels" : "new-filter" | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
| className="space-y-4" | ||||||||||||||||||||||||||||||||||||||||
| onValueChange={(value) => { | ||||||||||||||||||||||||||||||||||||||||
| if (value === "new-filter") { | ||||||||||||||||||||||||||||||||||||||||
| setLocalCondition(defaultCondition); | ||||||||||||||||||||||||||||||||||||||||
| setError(null); | ||||||||||||||||||||||||||||||||||||||||
| }} | ||||||||||||||||||||||||||||||||||||||||
| > | ||||||||||||||||||||||||||||||||||||||||
| Clear | ||||||||||||||||||||||||||||||||||||||||
| </Button> | ||||||||||||||||||||||||||||||||||||||||
| <div className="flex-grow" /> | ||||||||||||||||||||||||||||||||||||||||
| <Button | ||||||||||||||||||||||||||||||||||||||||
| onClick={() => { | ||||||||||||||||||||||||||||||||||||||||
| if (!isValidReleaseCondition(localCondition)) { | ||||||||||||||||||||||||||||||||||||||||
| setError( | ||||||||||||||||||||||||||||||||||||||||
| "Invalid release condition, ensure all fields are filled out correctly.", | ||||||||||||||||||||||||||||||||||||||||
| setLocalReleaseChannelId(undefined); | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
| }} | ||||||||||||||||||||||||||||||||||||||||
| > | ||||||||||||||||||||||||||||||||||||||||
| {releaseChannels.length > 0 && ( | ||||||||||||||||||||||||||||||||||||||||
| <TabsList> | ||||||||||||||||||||||||||||||||||||||||
| <TabsTrigger value="release-channels"> | ||||||||||||||||||||||||||||||||||||||||
| Release Channels | ||||||||||||||||||||||||||||||||||||||||
| </TabsTrigger> | ||||||||||||||||||||||||||||||||||||||||
| <TabsTrigger value="new-filter">New Filter</TabsTrigger> | ||||||||||||||||||||||||||||||||||||||||
| </TabsList> | ||||||||||||||||||||||||||||||||||||||||
| )} | ||||||||||||||||||||||||||||||||||||||||
| <TabsContent value="release-channels" className="space-y-4"> | ||||||||||||||||||||||||||||||||||||||||
| <DialogHeader> | ||||||||||||||||||||||||||||||||||||||||
| <DialogTitle>Select Release Channel</DialogTitle> | ||||||||||||||||||||||||||||||||||||||||
| <DialogDescription> | ||||||||||||||||||||||||||||||||||||||||
| View releases by release channel. | ||||||||||||||||||||||||||||||||||||||||
| </DialogDescription> | ||||||||||||||||||||||||||||||||||||||||
| </DialogHeader> | ||||||||||||||||||||||||||||||||||||||||
| <Select | ||||||||||||||||||||||||||||||||||||||||
| value={localReleaseChannelId} | ||||||||||||||||||||||||||||||||||||||||
| onValueChange={(value) => { | ||||||||||||||||||||||||||||||||||||||||
| const releaseChannel = releaseChannels.find( | ||||||||||||||||||||||||||||||||||||||||
| (rc) => rc.id === value, | ||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
| onChange(localCondition); | ||||||||||||||||||||||||||||||||||||||||
| setOpen(false); | ||||||||||||||||||||||||||||||||||||||||
| setError(null); | ||||||||||||||||||||||||||||||||||||||||
| }} | ||||||||||||||||||||||||||||||||||||||||
| > | ||||||||||||||||||||||||||||||||||||||||
| Save | ||||||||||||||||||||||||||||||||||||||||
| </Button> | ||||||||||||||||||||||||||||||||||||||||
| </DialogFooter> | ||||||||||||||||||||||||||||||||||||||||
| if (releaseChannel == null) return; | ||||||||||||||||||||||||||||||||||||||||
| setLocalReleaseChannelId(value); | ||||||||||||||||||||||||||||||||||||||||
| setLocalCondition(releaseChannel.releaseFilter ?? undefined); | ||||||||||||||||||||||||||||||||||||||||
| }} | ||||||||||||||||||||||||||||||||||||||||
| > | ||||||||||||||||||||||||||||||||||||||||
| <SelectTrigger> | ||||||||||||||||||||||||||||||||||||||||
| <SelectValue placeholder="Select release channel..." /> | ||||||||||||||||||||||||||||||||||||||||
| </SelectTrigger> | ||||||||||||||||||||||||||||||||||||||||
| <SelectContent> | ||||||||||||||||||||||||||||||||||||||||
| {releaseChannels.length === 0 && ( | ||||||||||||||||||||||||||||||||||||||||
| <SelectGroup> | ||||||||||||||||||||||||||||||||||||||||
| <SelectLabel>No release channels found</SelectLabel> | ||||||||||||||||||||||||||||||||||||||||
| </SelectGroup> | ||||||||||||||||||||||||||||||||||||||||
| )} | ||||||||||||||||||||||||||||||||||||||||
| {releaseChannels.map((rc) => ( | ||||||||||||||||||||||||||||||||||||||||
| <SelectItem key={rc.id} value={rc.id}> | ||||||||||||||||||||||||||||||||||||||||
| {rc.name} | ||||||||||||||||||||||||||||||||||||||||
| </SelectItem> | ||||||||||||||||||||||||||||||||||||||||
| ))} | ||||||||||||||||||||||||||||||||||||||||
| </SelectContent> | ||||||||||||||||||||||||||||||||||||||||
| </Select> | ||||||||||||||||||||||||||||||||||||||||
| <DialogFooter> | ||||||||||||||||||||||||||||||||||||||||
| <Button | ||||||||||||||||||||||||||||||||||||||||
| onClick={() => { | ||||||||||||||||||||||||||||||||||||||||
| const releaseChannel = releaseChannels.find( | ||||||||||||||||||||||||||||||||||||||||
| (rc) => rc.id === localReleaseChannelId, | ||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||
| if (releaseChannel == null) return; | ||||||||||||||||||||||||||||||||||||||||
| setReleaseChannel(releaseChannel); | ||||||||||||||||||||||||||||||||||||||||
| setOpen(false); | ||||||||||||||||||||||||||||||||||||||||
| setError(null); | ||||||||||||||||||||||||||||||||||||||||
| }} | ||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+136
to
+144
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Ensure consistent state updates by invoking In the "Release Channels" tab, the Apply this diff to fix the issue: onClick={() => {
const releaseChannel = releaseChannels.find(
(rc) => rc.id === localReleaseChannelId,
);
if (releaseChannel == null) return;
setReleaseChannel(releaseChannel);
+ onChange(releaseChannel.releaseFilter ?? undefined);
setOpen(false);
setError(null);
}}📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||
| disabled={localReleaseChannelId == null} | ||||||||||||||||||||||||||||||||||||||||
| > | ||||||||||||||||||||||||||||||||||||||||
| Save | ||||||||||||||||||||||||||||||||||||||||
| </Button> | ||||||||||||||||||||||||||||||||||||||||
| </DialogFooter> | ||||||||||||||||||||||||||||||||||||||||
| </TabsContent> | ||||||||||||||||||||||||||||||||||||||||
| <TabsContent value="new-filter" className="space-y-4"> | ||||||||||||||||||||||||||||||||||||||||
| <DialogHeader> | ||||||||||||||||||||||||||||||||||||||||
| <DialogTitle>Edit Release Condition</DialogTitle> | ||||||||||||||||||||||||||||||||||||||||
| <DialogDescription> | ||||||||||||||||||||||||||||||||||||||||
| Edit the release filter, up to a depth of{" "} | ||||||||||||||||||||||||||||||||||||||||
| {MAX_DEPTH_ALLOWED + 1}. | ||||||||||||||||||||||||||||||||||||||||
| </DialogDescription> | ||||||||||||||||||||||||||||||||||||||||
| </DialogHeader> | ||||||||||||||||||||||||||||||||||||||||
| <ReleaseConditionRender | ||||||||||||||||||||||||||||||||||||||||
| condition={localCondition ?? defaultCondition} | ||||||||||||||||||||||||||||||||||||||||
| onChange={setLocalCondition} | ||||||||||||||||||||||||||||||||||||||||
| /> | ||||||||||||||||||||||||||||||||||||||||
| {releases != null && <ReleaseBadgeList releases={releases} />} | ||||||||||||||||||||||||||||||||||||||||
| {error && <span className="text-sm text-red-600">{error}</span>} | ||||||||||||||||||||||||||||||||||||||||
| <DialogFooter> | ||||||||||||||||||||||||||||||||||||||||
| <Button | ||||||||||||||||||||||||||||||||||||||||
| variant="outline" | ||||||||||||||||||||||||||||||||||||||||
| onClick={() => { | ||||||||||||||||||||||||||||||||||||||||
| setLocalCondition(defaultCondition); | ||||||||||||||||||||||||||||||||||||||||
| setError(null); | ||||||||||||||||||||||||||||||||||||||||
| }} | ||||||||||||||||||||||||||||||||||||||||
| > | ||||||||||||||||||||||||||||||||||||||||
| Clear | ||||||||||||||||||||||||||||||||||||||||
| </Button> | ||||||||||||||||||||||||||||||||||||||||
| <div className="flex-grow" /> | ||||||||||||||||||||||||||||||||||||||||
| <Button | ||||||||||||||||||||||||||||||||||||||||
| onClick={() => { | ||||||||||||||||||||||||||||||||||||||||
| console.log(">>> localCondition", localCondition); | ||||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Remove debugging The Apply this diff to remove the debug statement: - console.log(">>> localCondition", localCondition);📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||
| if ( | ||||||||||||||||||||||||||||||||||||||||
| localCondition != null && | ||||||||||||||||||||||||||||||||||||||||
| !isValidReleaseCondition(localCondition) | ||||||||||||||||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||||||||||||||||
| setError( | ||||||||||||||||||||||||||||||||||||||||
| "Invalid release condition, ensure all fields are filled out correctly.", | ||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
| removeReleaseChannel(); | ||||||||||||||||||||||||||||||||||||||||
| onChange(localCondition); | ||||||||||||||||||||||||||||||||||||||||
| setOpen(false); | ||||||||||||||||||||||||||||||||||||||||
| setError(null); | ||||||||||||||||||||||||||||||||||||||||
| }} | ||||||||||||||||||||||||||||||||||||||||
| > | ||||||||||||||||||||||||||||||||||||||||
| Save | ||||||||||||||||||||||||||||||||||||||||
| </Button> | ||||||||||||||||||||||||||||||||||||||||
| </DialogFooter> | ||||||||||||||||||||||||||||||||||||||||
| </TabsContent> | ||||||||||||||||||||||||||||||||||||||||
| </Tabs> | ||||||||||||||||||||||||||||||||||||||||
| </DialogContent> | ||||||||||||||||||||||||||||||||||||||||
| </Dialog> | ||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,3 +1,4 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import type * as SCHEMA from "@ctrlplane/db/schema"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import type { ReleaseCondition } from "@ctrlplane/validators/releases"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { useCallback, useMemo } from "react"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { useRouter, useSearchParams } from "next/navigation"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -17,6 +18,11 @@ export const useReleaseFilter = () => { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, [urlParams]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const releaseChannelId = useMemo<string | undefined>( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| () => urlParams.get("release-channel") ?? undefined, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [urlParams], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+21
to
+24
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ?
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const setFilter = useCallback( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (filter: ReleaseCondition | undefined) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (filter == null) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -36,5 +42,36 @@ export const useReleaseFilter = () => { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [router], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return { filter, setFilter }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const setReleaseChannel = useCallback( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (releaseChannel: SCHEMA.ReleaseChannel) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const query = new URLSearchParams(window.location.search); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| query.set("release-channel", releaseChannel.id); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (releaseChannel.releaseFilter != null) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const filterJson = LZString.compressToEncodedURIComponent( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| JSON.stringify(releaseChannel.releaseFilter), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| query.set("filter", filterJson); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| router.replace(`?${query.toString()}`); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| router.refresh(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [router], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+45
to
+60
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consider adding validation and error handling The implementation has several potential improvements:
Consider this improved implementation: const setReleaseChannel = useCallback(
(releaseChannel: SCHEMA.ReleaseChannel) => {
+ if (!releaseChannel?.id) {
+ console.error('Invalid release channel');
+ return;
+ }
const query = new URLSearchParams(window.location.search);
query.set("release-channel", releaseChannel.id);
if (releaseChannel.releaseFilter != null) {
+ try {
const filterJson = LZString.compressToEncodedURIComponent(
JSON.stringify(releaseChannel.releaseFilter),
);
query.set("filter", filterJson);
+ } catch (error) {
+ console.error('Failed to compress release filter:', error);
+ // Optionally handle the error case
+ }
}
router.replace(`?${query.toString()}`);
- router.refresh();
+ // Consider if refresh is necessary based on your use case
},
[router],
);📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const removeReleaseChannel = useCallback(() => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const query = new URLSearchParams(window.location.search); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| query.delete("release-channel"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| query.delete("filter"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| router.replace(`?${query.toString()}`); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| router.refresh(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, [router]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| filter, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| setFilter, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| releaseChannelId, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| setReleaseChannel, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| removeReleaseChannel, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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.
💡 Codebase verification
Ensure all
releaseChannelIdreferences are properly handled upon deletion.Some instances of
releaseChannelIdare not associated with removal functions, which may lead to inconsistent state.🔗 Analysis chain
Verify proper cleanup of release channel references.
Let's ensure that all references to the deleted release channel are properly cleaned up.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 612
Script:
Length of output: 9498
Script:
Length of output: 5223