fix(policy-explorer): handle both PolicySettingRow and PolicySettingSearchResult types
All checks were successful
Trigger Cloudarix Deploy / call-webhook (push) Successful in 2s

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.
This commit is contained in:
Ahmed Darrazi 2025-12-10 00:45:52 +01:00
parent aa598452e9
commit d9afe6d3a9

View File

@ -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({
<Button
variant="ghost"
size="sm"
onClick={() => handleCopyField(policy.graphPolicyId, 'Policy ID')}
onClick={() => handleCopyField(policyId, 'Policy ID')}
className="h-7 px-2"
>
{isCopied ? (
@ -223,7 +226,7 @@ export function PolicyDetailSheet({
</Button>
</div>
<p className="text-sm font-mono text-muted-foreground">
{policy.graphPolicyId}
{policyId}
</p>
</div>
@ -257,7 +260,7 @@ export function PolicyDetailSheet({
) : (
<Button
variant="outline"
onClick={() => handleCopyField(policy.graphPolicyId, 'Policy ID')}
onClick={() => handleCopyField(policyId, 'Policy ID')}
className="w-full"
>
<Copy className="mr-2 h-4 w-4" />