-
Notifications
You must be signed in to change notification settings - Fork 295
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sessions): filter sessions via substring search on root span inp…
…ut output values (#5257)
- Loading branch information
1 parent
7e9b4b4
commit 1ecd28e
Showing
13 changed files
with
348 additions
and
71 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
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,45 @@ | ||
import React, { | ||
createContext, | ||
PropsWithChildren, | ||
startTransition, | ||
useCallback, | ||
useContext, | ||
useState, | ||
} from "react"; | ||
|
||
export type SessionSearchContextType = { | ||
filterIoSubstring: string; | ||
setFilterIoSubstring: (condition: string) => void; | ||
}; | ||
|
||
export const SessionSearchContext = | ||
createContext<SessionSearchContextType | null>(null); | ||
|
||
export function useSessionSearchContext() { | ||
const context = useContext(SessionSearchContext); | ||
if (context === null) { | ||
throw new Error( | ||
"useSessionSubstring must be used within a SessionSubstringProvider" | ||
); | ||
} | ||
return context; | ||
} | ||
|
||
export function SessionSearchProvider(props: PropsWithChildren) { | ||
const [substring, _setSubstring] = useState<string>(""); | ||
const setSubstring = useCallback((condition: string) => { | ||
startTransition(() => { | ||
_setSubstring(condition); | ||
}); | ||
}, []); | ||
return ( | ||
<SessionSearchContext.Provider | ||
value={{ | ||
filterIoSubstring: substring, | ||
setFilterIoSubstring: setSubstring, | ||
}} | ||
> | ||
{props.children} | ||
</SessionSearchContext.Provider> | ||
); | ||
} |
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,103 @@ | ||
import React, { useState } from "react"; | ||
import { nord } from "@uiw/codemirror-theme-nord"; | ||
import CodeMirror from "@uiw/react-codemirror"; | ||
import { css } from "@emotion/react"; | ||
|
||
import { AddonBefore, Flex, Icon, Icons } from "@arizeai/components"; | ||
|
||
import { useTheme } from "../../contexts"; | ||
|
||
import { useSessionSearchContext } from "./SessionSearchContext"; | ||
|
||
const codeMirrorCSS = css` | ||
flex: 1 1 auto; | ||
.cm-content { | ||
padding: var(--ac-global-dimension-static-size-100) 0; | ||
} | ||
.cm-editor { | ||
background-color: transparent; | ||
} | ||
.cm-focused { | ||
outline: none; | ||
} | ||
.cm-selectionLayer .cm-selectionBackground { | ||
background: var(--ac-global-color-cyan-400) !important; | ||
} | ||
`; | ||
|
||
const fieldCSS = css` | ||
border-width: var(--ac-global-border-size-thin); | ||
border-style: solid; | ||
border-color: var(--ac-global-input-field-border-color); | ||
border-radius: var(--ac-global-rounding-small); | ||
background-color: var(--ac-global-input-field-background-color); | ||
transition: all 0.2s ease-in-out; | ||
overflow-x: hidden; | ||
&:hover, | ||
&[data-is-focused="true"] { | ||
border-color: var(--ac-global-input-field-border-color-active); | ||
background-color: var(--ac-global-input-field-background-color-active); | ||
} | ||
&[data-is-invalid="true"] { | ||
border-color: var(--ac-global-color-danger); | ||
} | ||
box-sizing: border-box; | ||
`; | ||
|
||
type SessionsSubstringFieldProps = { | ||
placeholder?: string; | ||
}; | ||
export function SessionSearchField(props: SessionsSubstringFieldProps) { | ||
const { placeholder = "Search messages" } = props; | ||
const [isFocused, setIsFocused] = useState<boolean>(false); | ||
const { filterIoSubstring, setFilterIoSubstring } = useSessionSearchContext(); | ||
const { theme } = useTheme(); | ||
const codeMirrorTheme = theme === "dark" ? nord : undefined; | ||
|
||
const hasSubstring = filterIoSubstring !== ""; | ||
return ( | ||
<div | ||
data-is-focused={isFocused} | ||
className="sessions-substring-field" | ||
css={fieldCSS} | ||
> | ||
<Flex direction="row"> | ||
<AddonBefore> | ||
<Icon svg={<Icons.Search />} /> | ||
</AddonBefore> | ||
<CodeMirror | ||
css={codeMirrorCSS} | ||
indentWithTab={false} | ||
basicSetup={{ | ||
lineNumbers: false, | ||
foldGutter: false, | ||
bracketMatching: false, | ||
syntaxHighlighting: false, | ||
highlightActiveLine: false, | ||
highlightActiveLineGutter: false, | ||
defaultKeymap: false, | ||
}} | ||
onFocus={() => setIsFocused(true)} | ||
onBlur={() => setIsFocused(false)} | ||
value={filterIoSubstring} | ||
onChange={setFilterIoSubstring} | ||
height="36px" | ||
width="100%" | ||
theme={codeMirrorTheme} | ||
placeholder={placeholder} | ||
/> | ||
<button | ||
css={css` | ||
margin-right: var(--ac-global-dimension-static-size-100); | ||
color: var(--ac-global-text-color-700); | ||
visibility: ${hasSubstring ? "visible" : "hidden"}; | ||
`} | ||
onClick={() => setFilterIoSubstring("")} | ||
className="button--reset" | ||
> | ||
<Icon svg={<Icons.CloseCircleOutline />} /> | ||
</button> | ||
</Flex> | ||
</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
3 changes: 2 additions & 1 deletion
3
app/src/pages/project/__generated__/ProjectPageSessionsQuery.graphql.ts
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.