From d9afe6d3a946fbf2670e9106d4fec42ba3d8ea08 Mon Sep 17 00:00:00 2001 From: Ahmed Darrazi Date: Wed, 10 Dec 2025 00:45:52 +0100 Subject: [PATCH] fix(policy-explorer): handle both PolicySettingRow and PolicySettingSearchResult types The PolicyDetailSheet component now properly handles both type unions: - PolicySettingRow (has graphPolicyId) - used in V2 - PolicySettingSearchResult (has id) - used in V1 Uses type guard to check for 'graphPolicyId' property and falls back to 'id' field. This fixes the TypeScript compilation error in production builds. --- components/policy-explorer/PolicyDetailSheet.tsx | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/components/policy-explorer/PolicyDetailSheet.tsx b/components/policy-explorer/PolicyDetailSheet.tsx index 52a1911..b9f93e8 100644 --- a/components/policy-explorer/PolicyDetailSheet.tsx +++ b/components/policy-explorer/PolicyDetailSheet.tsx @@ -11,6 +11,7 @@ import { import { Button } from '@/components/ui/button'; import { Badge } from '@/components/ui/badge'; import type { PolicySettingSearchResult } from '@/lib/actions/policySettings'; +import type { PolicySettingRow } from '@/lib/types/policy-table'; import { PolicyTypeBadge } from './PolicyTypeBadge'; import { formatDistanceToNow } from 'date-fns'; import { de } from 'date-fns/locale'; @@ -19,7 +20,7 @@ import { useCopyToClipboard } from '@/lib/hooks/useCopyToClipboard'; import { getIntunePortalLink } from '@/lib/utils/policy-table-helpers'; interface PolicyDetailSheetProps { - policy: PolicySettingSearchResult | null; + policy: PolicySettingSearchResult | PolicySettingRow | null; open: boolean; onOpenChange: (open: boolean) => void; } @@ -54,7 +55,9 @@ export function PolicyDetailSheet({ ? formatJson(policy.settingValue) : policy.settingValue; - const intuneUrl = getIntunePortalLink(policy.policyType, policy.graphPolicyId); + // Handle both PolicySettingRow (has graphPolicyId) and PolicySettingSearchResult (has id) + const policyId = 'graphPolicyId' in policy ? policy.graphPolicyId : policy.id; + const intuneUrl = getIntunePortalLink(policy.policyType, policyId); const handleCopyField = (value: string, fieldName: string) => { copy(value, `${fieldName} copied to clipboard`); @@ -65,7 +68,7 @@ export function PolicyDetailSheet({ window.open(intuneUrl, '_blank', 'noopener,noreferrer'); } else { // Fallback: copy policy ID - copy(policy.graphPolicyId, 'Policy ID copied to clipboard'); + copy(policyId, 'Policy ID copied to clipboard'); } }; @@ -212,7 +215,7 @@ export function PolicyDetailSheet({

- {policy.graphPolicyId} + {policyId}

@@ -257,7 +260,7 @@ export function PolicyDetailSheet({ ) : (