fix(policy-explorer): handle both PolicySettingRow and PolicySettingSearchResult types
All checks were successful
Trigger Cloudarix Deploy / call-webhook (push) Successful in 2s
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:
parent
aa598452e9
commit
d9afe6d3a9
@ -11,6 +11,7 @@ import {
|
|||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import { Badge } from '@/components/ui/badge';
|
import { Badge } from '@/components/ui/badge';
|
||||||
import type { PolicySettingSearchResult } from '@/lib/actions/policySettings';
|
import type { PolicySettingSearchResult } from '@/lib/actions/policySettings';
|
||||||
|
import type { PolicySettingRow } from '@/lib/types/policy-table';
|
||||||
import { PolicyTypeBadge } from './PolicyTypeBadge';
|
import { PolicyTypeBadge } from './PolicyTypeBadge';
|
||||||
import { formatDistanceToNow } from 'date-fns';
|
import { formatDistanceToNow } from 'date-fns';
|
||||||
import { de } from 'date-fns/locale';
|
import { de } from 'date-fns/locale';
|
||||||
@ -19,7 +20,7 @@ import { useCopyToClipboard } from '@/lib/hooks/useCopyToClipboard';
|
|||||||
import { getIntunePortalLink } from '@/lib/utils/policy-table-helpers';
|
import { getIntunePortalLink } from '@/lib/utils/policy-table-helpers';
|
||||||
|
|
||||||
interface PolicyDetailSheetProps {
|
interface PolicyDetailSheetProps {
|
||||||
policy: PolicySettingSearchResult | null;
|
policy: PolicySettingSearchResult | PolicySettingRow | null;
|
||||||
open: boolean;
|
open: boolean;
|
||||||
onOpenChange: (open: boolean) => void;
|
onOpenChange: (open: boolean) => void;
|
||||||
}
|
}
|
||||||
@ -54,7 +55,9 @@ export function PolicyDetailSheet({
|
|||||||
? formatJson(policy.settingValue)
|
? formatJson(policy.settingValue)
|
||||||
: 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) => {
|
const handleCopyField = (value: string, fieldName: string) => {
|
||||||
copy(value, `${fieldName} copied to clipboard`);
|
copy(value, `${fieldName} copied to clipboard`);
|
||||||
@ -65,7 +68,7 @@ export function PolicyDetailSheet({
|
|||||||
window.open(intuneUrl, '_blank', 'noopener,noreferrer');
|
window.open(intuneUrl, '_blank', 'noopener,noreferrer');
|
||||||
} else {
|
} else {
|
||||||
// Fallback: copy policy ID
|
// 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
|
<Button
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
size="sm"
|
size="sm"
|
||||||
onClick={() => handleCopyField(policy.graphPolicyId, 'Policy ID')}
|
onClick={() => handleCopyField(policyId, 'Policy ID')}
|
||||||
className="h-7 px-2"
|
className="h-7 px-2"
|
||||||
>
|
>
|
||||||
{isCopied ? (
|
{isCopied ? (
|
||||||
@ -223,7 +226,7 @@ export function PolicyDetailSheet({
|
|||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
<p className="text-sm font-mono text-muted-foreground">
|
<p className="text-sm font-mono text-muted-foreground">
|
||||||
{policy.graphPolicyId}
|
{policyId}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -257,7 +260,7 @@ export function PolicyDetailSheet({
|
|||||||
) : (
|
) : (
|
||||||
<Button
|
<Button
|
||||||
variant="outline"
|
variant="outline"
|
||||||
onClick={() => handleCopyField(policy.graphPolicyId, 'Policy ID')}
|
onClick={() => handleCopyField(policyId, 'Policy ID')}
|
||||||
className="w-full"
|
className="w-full"
|
||||||
>
|
>
|
||||||
<Copy className="mr-2 h-4 w-4" />
|
<Copy className="mr-2 h-4 w-4" />
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user