-
Notifications
You must be signed in to change notification settings - Fork 347
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(experiments): add experiment run filter to compare experiments p…
…age (#5738)
- Loading branch information
1 parent
4aa4ec2
commit 0bf194d
Showing
16 changed files
with
3,402 additions
and
117 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
56 changes: 56 additions & 0 deletions
56
app/src/pages/experiment/ExperimentRunFilterConditionContext.tsx
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,56 @@ | ||
import React, { | ||
createContext, | ||
PropsWithChildren, | ||
startTransition, | ||
useCallback, | ||
useContext, | ||
useState, | ||
} from "react"; | ||
|
||
export type ExperimentRunFilterConditionContextType = { | ||
filterCondition: string; | ||
setFilterCondition: (condition: string) => void; | ||
appendFilterCondition: (condition: string) => void; | ||
}; | ||
|
||
export const ExperimentRunFilterConditionContext = | ||
createContext<ExperimentRunFilterConditionContextType | null>(null); | ||
|
||
export function useExperimentRunFilterCondition() { | ||
const context = useContext(ExperimentRunFilterConditionContext); | ||
if (context === null) { | ||
throw new Error( | ||
"useExperimentRunFilterCondition must be used within a ExperimentRunFilterConditionProvider" | ||
); | ||
} | ||
return context; | ||
} | ||
|
||
export function ExperimentRunFilterConditionProvider(props: PropsWithChildren) { | ||
const [filterCondition, _setFilterCondition] = useState<string>(""); | ||
const setFilterCondition = useCallback((condition: string) => { | ||
startTransition(() => { | ||
_setFilterCondition(condition); | ||
}); | ||
}, []); | ||
const appendFilterCondition = useCallback( | ||
(condition: string) => { | ||
startTransition(() => { | ||
if (filterCondition.length > 0) { | ||
_setFilterCondition(filterCondition + " and " + condition); | ||
} else { | ||
_setFilterCondition(condition); | ||
} | ||
}); | ||
}, | ||
[filterCondition] | ||
); | ||
|
||
return ( | ||
<ExperimentRunFilterConditionContext.Provider | ||
value={{ filterCondition, setFilterCondition, appendFilterCondition }} | ||
> | ||
{props.children} | ||
</ExperimentRunFilterConditionContext.Provider> | ||
); | ||
} |
Oops, something went wrong.