mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-09 03:18:44 +00:00
address greptile review feedback (greploop iteration 3)
- Move callbacks outside try/catch so only mutation errors are caught, not errors from onVersionCreated/onVersionStatusUpdated callbacks - Replace policyName! non-null assertion with DISABLED_POLICY_KEY sentinel to avoid undefined in cache keys when query is disabled Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
41d12ed106
commit
492c0cd3ba
2 changed files with 18 additions and 11 deletions
|
|
@ -44,16 +44,20 @@ export interface UsePolicyVersionsOptions {
|
|||
enabled?: boolean;
|
||||
}
|
||||
|
||||
/** Stable key used when the query is disabled to avoid undefined in cache keys. */
|
||||
const DISABLED_POLICY_KEY = "__disabled__";
|
||||
|
||||
export const usePolicyVersions = ({
|
||||
policyName,
|
||||
enabled = true,
|
||||
}: UsePolicyVersionsOptions) => {
|
||||
const { accessToken } = useAuthorized();
|
||||
const isEnabled = Boolean(accessToken && policyName && enabled);
|
||||
|
||||
return useQuery<PolicyVersionsResponse, Error, PolicyVersionsData>({
|
||||
queryKey: policyVersionKeys.detail(policyName!),
|
||||
queryKey: policyVersionKeys.detail(policyName ?? DISABLED_POLICY_KEY),
|
||||
queryFn: async () => await fetchPolicyVersions(accessToken!, policyName!),
|
||||
enabled: Boolean(accessToken && policyName && enabled),
|
||||
enabled: isEnabled,
|
||||
select: (data) => ({
|
||||
...data,
|
||||
versions: data.versions ?? [],
|
||||
|
|
|
|||
|
|
@ -1316,12 +1316,13 @@ export const FlowBuilderPage: React.FC<FlowBuilderPageProps> = ({
|
|||
const updateStatusMutation = useUpdatePolicyVersionStatus(editingPolicy?.policy_name);
|
||||
|
||||
const handleNewVersion = async () => {
|
||||
let newPolicy: Policy;
|
||||
try {
|
||||
const newPolicy = await createVersionMutation.mutateAsync();
|
||||
onVersionCreated?.(newPolicy);
|
||||
newPolicy = await createVersionMutation.mutateAsync();
|
||||
} catch {
|
||||
// Notification already shown by onError in the mutation hook
|
||||
return; // Notification already shown by onError in the mutation hook
|
||||
}
|
||||
onVersionCreated?.(newPolicy);
|
||||
};
|
||||
|
||||
const handleSelectVersion = (policy: Policy) => {
|
||||
|
|
@ -1330,28 +1331,30 @@ export const FlowBuilderPage: React.FC<FlowBuilderPageProps> = ({
|
|||
|
||||
const handlePublishVersion = async () => {
|
||||
if (!editingPolicy?.policy_id) return;
|
||||
let updated: Policy;
|
||||
try {
|
||||
const updated = await updateStatusMutation.mutateAsync({
|
||||
updated = await updateStatusMutation.mutateAsync({
|
||||
policyId: editingPolicy.policy_id,
|
||||
status: "published",
|
||||
});
|
||||
onVersionStatusUpdated?.(updated);
|
||||
} catch {
|
||||
// Notification already shown by onError in the mutation hook
|
||||
return; // Notification already shown by onError in the mutation hook
|
||||
}
|
||||
onVersionStatusUpdated?.(updated);
|
||||
};
|
||||
|
||||
const handlePromoteToProduction = async () => {
|
||||
if (!editingPolicy?.policy_id) return;
|
||||
let updated: Policy;
|
||||
try {
|
||||
const updated = await updateStatusMutation.mutateAsync({
|
||||
updated = await updateStatusMutation.mutateAsync({
|
||||
policyId: editingPolicy.policy_id,
|
||||
status: "production",
|
||||
});
|
||||
onVersionStatusUpdated?.(updated);
|
||||
} catch {
|
||||
// Notification already shown by onError in the mutation hook
|
||||
return; // Notification already shown by onError in the mutation hook
|
||||
}
|
||||
onVersionStatusUpdated?.(updated);
|
||||
};
|
||||
|
||||
const handleSave = async () => {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue