-
Notifications
You must be signed in to change notification settings - Fork 166
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add history navigation to cache tab (#1394)
- Loading branch information
1 parent
8fac152
commit 84a9634
Showing
6 changed files
with
190 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"apollo-client-devtools": minor | ||
--- | ||
|
||
Add forward and back buttons to the cache tab to navigate the history of cache entries you've visited. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import type { VariantProps } from "class-variance-authority"; | ||
import { cva } from "class-variance-authority"; | ||
import type { ElementType, ReactNode } from "react"; | ||
import type { OmitNull } from "../types/utils"; | ||
import IconErrorSolid from "@apollo/icons/large/IconErrorSolid.svg"; | ||
import { twMerge } from "tailwind-merge"; | ||
|
||
type Variants = OmitNull<Required<VariantProps<typeof alert>>>; | ||
|
||
interface AlertProps extends Variants { | ||
children?: ReactNode; | ||
className?: string; | ||
} | ||
|
||
const alert = cva( | ||
["px-4", "py-3", "border-l-4", "rounded", "flex", "gap-2", "items-start"], | ||
{ | ||
variants: { | ||
variant: { | ||
error: [ | ||
"border-l-error", | ||
"dark:border-l-error-dark", | ||
"bg-error", | ||
"dark:bg-error-dark", | ||
"text-error", | ||
"dark:text-error-dark", | ||
], | ||
}, | ||
}, | ||
} | ||
); | ||
|
||
const ICONS: Record<Variants["variant"], ElementType> = { | ||
error: IconErrorSolid, | ||
}; | ||
|
||
export function Alert({ children, className, variant }: AlertProps) { | ||
const Icon = ICONS[variant]; | ||
|
||
return ( | ||
<div className={twMerge(alert({ variant }), className)}> | ||
<Icon className="size-6" /> | ||
<div className="flex-1 font-body text-md font-normal">{children}</div> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
export class History<T> { | ||
private stack: T[] = []; | ||
private currentIndex = 0; | ||
private listeners = new Set<(value: T) => void>(); | ||
|
||
constructor(initialValue: T) { | ||
this.stack.push(initialValue); | ||
} | ||
|
||
getCurrent = () => { | ||
return this.stack[this.currentIndex]; | ||
}; | ||
|
||
go = (delta: number) => { | ||
const previousIndex = this.currentIndex; | ||
this.currentIndex = Math.min( | ||
Math.max(0, this.currentIndex + delta), | ||
this.stack.length - 1 | ||
); | ||
|
||
if (this.currentIndex !== previousIndex) { | ||
this.listeners.forEach((listener) => { | ||
listener(this.getCurrent()); | ||
}); | ||
} | ||
}; | ||
|
||
back = () => { | ||
this.go(-1); | ||
}; | ||
|
||
forward = () => { | ||
this.go(1); | ||
}; | ||
|
||
canGoBack = () => { | ||
return this.currentIndex > 0; | ||
}; | ||
|
||
canGoForward = () => { | ||
return this.currentIndex < this.stack.length - 1; | ||
}; | ||
|
||
push = (value: T) => { | ||
this.stack.splice(this.currentIndex + 1); | ||
this.stack.push(value); | ||
this.forward(); | ||
}; | ||
|
||
listen = (listener: (value: T) => void) => { | ||
this.listeners.add(listener); | ||
|
||
return () => this.listeners.delete(listener); | ||
}; | ||
} |