Skip to content

Commit

Permalink
chore: added/removed evals reflected in URL state (#2665)
Browse files Browse the repository at this point in the history
  • Loading branch information
gtarpenning authored Oct 10, 2024
1 parent b931f85 commit 5579795
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 14 deletions.
11 changes: 11 additions & 0 deletions weave-js/src/components/PagePanelComponents/Home/Browse3.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -921,16 +921,27 @@ const OpPageBinding = () => {
};

const CompareEvaluationsBinding = () => {
const history = useHistory();
const location = useLocation();
const {entity, project} = useParamsDecoded<Browse3TabParams>();
const query = useURLSearchParamsDict();
const evaluationCallIds = useMemo(() => {
return JSON.parse(query.evaluationCallIds);
}, [query.evaluationCallIds]);
const onEvaluationCallIdsUpdate = useCallback(
(newEvaluationCallIds: string[]) => {
const newQuery = new URLSearchParams(location.search);
newQuery.set('evaluationCallIds', JSON.stringify(newEvaluationCallIds));
history.push({search: newQuery.toString()});
},
[history, location.search]
);
return (
<CompareEvaluationsPage
entity={entity}
project={project}
evaluationCallIds={evaluationCallIds}
onEvaluationCallIdsUpdate={onEvaluationCallIdsUpdate}
/>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ const useCallTabs = (call: CallSchema) => {
entity={call.entity}
project={call.project}
evaluationCallIds={[call.callId]}
// Dont persist changes to evaluationCallIds in the URL
onEvaluationCallIdsUpdate={() => {}}
/>
),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type CompareEvaluationsPageProps = {
entity: string;
project: string;
evaluationCallIds: string[];
onEvaluationCallIdsUpdate: (newEvaluationCallIds: string[]) => void;
};

export const CompareEvaluationsPage: React.FC<
Expand All @@ -55,6 +56,7 @@ export const CompareEvaluationsPage: React.FC<
entity={props.entity}
project={props.project}
evaluationCallIds={props.evaluationCallIds}
onEvaluationCallIdsUpdate={props.onEvaluationCallIdsUpdate}
/>
),
},
Expand Down Expand Up @@ -113,6 +115,7 @@ export const CompareEvaluationsPageContent: React.FC<
initialEvaluationCallIds={props.evaluationCallIds}
baselineEvaluationCallId={baselineEvaluationCallId ?? undefined}
comparisonDimensions={comparisonDimensions ?? undefined}
onEvaluationCallIdsUpdate={props.onEvaluationCallIdsUpdate}
setBaselineEvaluationCallId={setBaselineEvaluationCallId}
setComparisonDimensions={setComparisonDimensionsAndClearInputDigest}
selectedInputDigest={selectedInputDigest ?? undefined}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export const CompareEvaluationsProvider: React.FC<{
entity: string;
project: string;
initialEvaluationCallIds: string[];
onEvaluationCallIdsUpdate: (newEvaluationCallIds: string[]) => void;
setBaselineEvaluationCallId: React.Dispatch<
React.SetStateAction<string | null>
>;
Expand All @@ -46,6 +47,7 @@ export const CompareEvaluationsProvider: React.FC<{
entity,
project,
initialEvaluationCallIds,
onEvaluationCallIdsUpdate,
setBaselineEvaluationCallId,
setComparisonDimensions,

Expand Down Expand Up @@ -78,15 +80,23 @@ export const CompareEvaluationsProvider: React.FC<{
setComparisonDimensions,
setSelectedInputDigest,
addEvaluationCall: (newCallId: string) => {
setEvaluationCallIds(prev => [...prev, newCallId]);
const newEvaluationCallIds = [...evaluationCallIds, newCallId];
setEvaluationCallIds(newEvaluationCallIds);
onEvaluationCallIdsUpdate(newEvaluationCallIds);
},
removeEvaluationCall: (callId: string) => {
setEvaluationCallIds(prev => prev.filter(id => id !== callId));
const newEvaluationCallIds = evaluationCallIds.filter(
id => id !== callId
);
setEvaluationCallIds(newEvaluationCallIds);
onEvaluationCallIdsUpdate(newEvaluationCallIds);
},
};
}, [
initialState.loading,
initialState.result,
evaluationCallIds,
onEvaluationCallIdsUpdate,
setEvaluationCallIds,
setBaselineEvaluationCallId,
setComparisonDimensions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,20 @@ export const EvaluationDefinition: React.FC<{
{props.callId === props.state.baselineEvaluationCallId && (
<Pill label="Baseline" color="teal" />
)}
<PopupDropdown
sections={[menuOptions]}
trigger={
<Button
className="rotate-90"
icon="overflow-horizontal"
size="small"
variant="ghost"
style={{marginLeft: '4px'}}
/>
}
/>
<div style={{marginLeft: '-14px'}}>
<PopupDropdown
sections={[menuOptions]}
trigger={
<Button
className="rotate-90"
icon="overflow-horizontal"
size="small"
variant="ghost"
style={{marginLeft: '4px'}}
/>
}
/>
</div>
</HorizontalBox>
);
};
Expand Down

0 comments on commit 5579795

Please sign in to comment.