Skip to content
Draft
Changes from 1 commit
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
e62f545
Initial reactotron-apollo-client
Sep 8, 2023
325cd83
fix(apollo-client): get build working
frankcalise Oct 15, 2023
0c984ca
chore: lint fixes
frankcalise Oct 15, 2023
a028397
feat(search): search obj values from display cmd
frankcalise Oct 17, 2023
9d80011
feat(app): apollo client ui and routes
frankcalise Oct 17, 2023
4a31bd4
feat(apollo-client): cache subscriptions
frankcalise Oct 17, 2023
1f278a4
Add apollo to the reactotron example app.
markrickert Feb 14, 2024
490f544
Readme update for reactotron-apollo-client
markrickert Feb 14, 2024
0f5281e
feat(reactotron-app): Each client now has an explicit list of plugins.
markrickert Feb 14, 2024
467392e
Fix some linting issues in reactotron-apollo-client
markrickert Feb 14, 2024
6308fcf
Reapply changes from #1439 to the reactotron-apollo-client
markrickert Feb 14, 2024
13664a1
Export the apollo-client properly.
markrickert Feb 14, 2024
76e5942
refactor: remove prev deleted files
frankcalise Mar 22, 2024
adea63d
chore: fix bad merge
frankcalise Mar 22, 2024
ed6688e
feat(example-app): apollo detail screen
frankcalise Mar 22, 2024
3c40be8
chore(apollo-client): add some debug
frankcalise Mar 22, 2024
ae12112
Adding name to redux plugin to fix build error
morganick Mar 22, 2024
86371c9
fix(example-app): observer apollo screens
frankcalise Mar 22, 2024
24506a6
feat(apollo-client): WIP server side comms
frankcalise Sep 25, 2024
a32cd02
feat(core-ui): add apollo client context
frankcalise Oct 17, 2024
81cc42c
feat(core-ui): allow for valueRenderer override in TreeView
frankcalise Oct 17, 2024
609d2e5
feat(apollo-client): render cache keys and body with search
frankcalise Oct 17, 2024
ff0f52d
chore(tree-view): remove console log
frankcalise Oct 18, 2024
53e4d41
fix(reactotron): move apollo provider
frankcalise Oct 18, 2024
7d0fcea
fix(core-ui): add cache key to apollo ctx
frankcalise Oct 18, 2024
53cded5
fix(core-ui): expose checkbox component
frankcalise Oct 18, 2024
61ee561
feat(apollo-client): search cache by key or data
frankcalise Oct 18, 2024
99954d9
feat(apollo-client): cache expand initially option
frankcalise Oct 18, 2024
928af8e
feat(cache): implement pinned keys
frankcalise Oct 18, 2024
bfbab46
chore(cache): clean up
frankcalise Oct 18, 2024
c163c69
fix(apollo-client): highlight selected pinned cache key
frankcalise Oct 18, 2024
b750011
fix(core-ui): add foregroundDarker
frankcalise Oct 18, 2024
fad56bc
feat(apollo-client): add cache forward/back history buttons
frankcalise Oct 18, 2024
3092bc8
feat(apollo-client): add launch external url for specific data
frankcalise Oct 19, 2024
19820d2
feat(apollo-client): view __ref data via tooltip
frankcalise Oct 19, 2024
5c1c148
feat(apollo-client): restore last viewed key after tab nav
frankcalise Oct 20, 2024
465cca4
feat(apollo-client): persist pinned keys across tab change
frankcalise Oct 20, 2024
6cd773a
refactor(apollo-client): move data to ctx
frankcalise Oct 20, 2024
5f0340c
fix(example-app): remove temp mutate button on ApolloScreen
frankcalise Oct 20, 2024
d2f7d8d
feat(apollo-client): wire up edit cache data with temp value
frankcalise Oct 20, 2024
1845ec0
feat(apollo-client): implement edit cache value from UI
frankcalise Oct 20, 2024
efad80a
fix(apollo-client): type specific inputs for edit cache values
frankcalise Oct 21, 2024
cf083c9
feat(apollo-client): lock root query and cache key editing
frankcalise Oct 22, 2024
7c7c587
fix(sidebar): only load apollo tab if plugin available
frankcalise Oct 22, 2024
bd33335
feat(apollo-client): add copy object
frankcalise Oct 29, 2024
3945d17
refactor(apollo-client): move polling apollo state out of cache tab
frankcalise Oct 29, 2024
0968774
style(cache): fix left/right panel scrolling
frankcalise Oct 29, 2024
8476583
chore: merge branch 'master' into frankcalise/reactotron-apollo-client
frankcalise Oct 30, 2024
ef093f6
fix(apollo-client): fix rollup config
frankcalise Oct 30, 2024
f62d7af
chore: lint fixes
frankcalise Oct 30, 2024
06416f4
chore: merge branch 'master' into frankcalise/reactotron-apollo-client
frankcalise Oct 30, 2024
484519a
test: fix plugin objects needing name
frankcalise Oct 30, 2024
4c1b345
test(filter-commands): remove search object value test
frankcalise Oct 30, 2024
2776ac8
chore: typecheck fixes
frankcalise Oct 30, 2024
86ff6cd
Merge branch 'master' into frankcalise/reactotron-apollo-client
frankcalise Nov 14, 2024
4deadb7
chore: merge branch 'master' into frankcalise/reactotron-apollo-client
frankcalise Mar 17, 2025
1da3d20
fix(apollo-client): remove exports.react-native
frankcalise Mar 17, 2025
bc595a1
chore: lint fix
frankcalise Mar 17, 2025
df7cf7b
fix(cache): get theme from hook
frankcalise Mar 17, 2025
bdaeef6
Merge branch 'master' into frankcalise/reactotron-apollo-client
frankcalise Mar 17, 2025
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
Prev Previous commit
Next Next commit
feat(apollo-client): search cache by key or data
  • Loading branch information
frankcalise committed Oct 18, 2024
commit 61ee56188962b119e416a5bd9e66cb00b6282a54
126 changes: 108 additions & 18 deletions apps/reactotron-app/src/renderer/pages/apolloClient/Cache.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import React, { useCallback, useContext, useMemo } from "react"
import React, { useCallback, useContext, useEffect, useMemo } from "react"
import styled from "styled-components"
import { Header, ReactotronContext, TreeView, ApolloClientContext, theme } from "reactotron-core-ui"
import {
Header,
ReactotronContext,
TreeView,
ApolloClientContext,
theme,
Checkbox,
} from "reactotron-core-ui"
import { MdSearch, MdWarning } from "react-icons/md"
import { HiDocumentSearch, HiOutlinePencilAlt } from "react-icons/hi"
import lodashDebounce from "lodash.debounce"
import { TbDatabaseDollar } from "react-icons/tb"
import { Title } from "../reactNative/components/Shared"
import { OverlayButton } from "./components/Button"
import { CommandType } from "reactotron-core-contract"
import { FaTimes } from "react-icons/fa"
import { Link, useParams } from "react-router-dom"
import { Link, useNavigate, useParams } from "react-router-dom"

const Container = styled.div`
display: flex;
Expand Down Expand Up @@ -46,12 +50,13 @@ const SearchContainer = styled.div`
align-items: center;
padding-bottom: 10px;
padding-top: 4px;
padding-right: 10px;
padding-left: 10px;
`
const SearchLabel = styled.p`
padding: 0 10px;
font-size: 14px;
color: ${(props) => props.theme.foregroundDark};
vertical-align: middle;
`
const SearchInput = styled.input`
border-radius: 4px;
Expand Down Expand Up @@ -109,6 +114,36 @@ const CacheKeyLabel = styled.span`
color: ${(props) => props.theme.foregroundDark};
`

const Highlight = styled.span`
background-color: yellow;
color: black;
`

const VerticalContainer = styled.div`
display: flex;
flex: 1;
flex-direction: column;
`

const HighlightText = ({ text, searchTerm }) => {
try {
const parts = text.toString().split(new RegExp(`(${searchTerm})`, "gi"))
return (
<>
{parts.map((part, index) =>
part.toLowerCase() === searchTerm.toLowerCase() ? (
<Highlight key={index}>{part}</Highlight>
) : (
part
)
)}
</>
)
} catch (error) {
return text
}
}

let timer: ReturnType<typeof setTimeout>

function debounce(func: (...args: any) => any, timeout = 7000): void {
Expand All @@ -130,8 +165,14 @@ const INITIAL_DATA = {
function Cache() {
const [data, setData] = React.useState<any>(INITIAL_DATA)
const { sendCommand, addCommandListener } = React.useContext(ReactotronContext)
const { isSearchOpen, toggleSearch, closeSearch, setSearch, search } =
useContext(ApolloClientContext)
const {
isSearchOpen,
toggleSearch,
closeSearch,
setSearch,
search,
cacheKey: storedCacheKey,
} = useContext(ApolloClientContext)

// const sendMessage = React.useCallback(() => {
// sendCommand("apollo.request", {})
Expand Down Expand Up @@ -181,8 +222,29 @@ function Cache() {
// const { searchString, handleInputChange } = useDebouncedSearchInput(search, setSearch, 300)

let { cacheKey } = useParams()
const navigate = useNavigate()
// const prevCacheKey = React.useRef(cacheKey)

const cacheData = data.cache[cacheKey] ?? "No data found"

// console.log({ cacheKey, storedCacheKey })

useEffect(() => {
if (storedCacheKey) {
navigate(`/apolloClient/cache/${storedCacheKey}`)
}
}, [])

const clearSearch = () => {
if (search === "") {
closeSearch()
} else {
setSearch("")
}
}

const [searchObjects, setSearchObjects] = React.useState(false)

const valueRenderer = (transformed: any, untransformed: any, ...keyPath: any) => {
if (keyPath[0] === "__ref") {
return (
Expand All @@ -191,7 +253,11 @@ function Cache() {
</StyledLink>
)
} else {
return <SpanContainer>{untransformed || transformed}</SpanContainer>
if (searchObjects && search) {
return <HighlightText text={untransformed || transformed} searchTerm={search} />
} else {
return <SpanContainer>{untransformed || transformed}</SpanContainer>
}
}
}

Expand Down Expand Up @@ -239,11 +305,24 @@ function Cache() {
>
{isSearchOpen && (
<SearchContainer>
<SearchLabel>Search</SearchLabel>
<SearchInput autoFocus value={search} onChange={handleInputChange} />
<ButtonContainer>
<FaTimes size={24} />
</ButtonContainer>
<VerticalContainer>
<SearchContainer>
<SearchInput
placeholder="Search..."
autoFocus
value={search}
onChange={handleInputChange}
/>
<ButtonContainer onClick={clearSearch}>
<FaTimes size={24} />
</ButtonContainer>
</SearchContainer>
<Checkbox
label="Include object values"
onToggle={() => setSearchObjects(!searchObjects)}
isChecked={searchObjects}
/>
</VerticalContainer>
</SearchContainer>
)}
</Header>
Expand All @@ -257,16 +336,27 @@ function Cache() {
{Object.keys(data.cache)
.filter((key) => {
if (search) {
return key.toLowerCase().includes(search.toLowerCase())
if (searchObjects) {
const searchDataJson = JSON.stringify(data.cache[key])
return searchDataJson.toLowerCase().includes(search.toLowerCase())
} else {
return key.toLowerCase().includes(search.toLowerCase())
}
}

return key
})
.map((key: string) => {
const LinkWrapper = key === cacheKey ? SelectedCacheKeyLink : CacheKeyLink
return (
<LinkWrapper to={`/apolloClient/cache/${key}`}>
<CacheKeyLabel key={key}>{key}</CacheKeyLabel>
<LinkWrapper key={key} to={`/apolloClient/cache/${key}`}>
<CacheKeyLabel>
{!searchObjects ? (
<HighlightText text={key} searchTerm={search} />
) : (
<SpanContainer>{key}</SpanContainer>
)}
</CacheKeyLabel>
</LinkWrapper>
)
})}
Expand Down