Skip to content

Commit

Permalink
Add some basic runtime icons
Browse files Browse the repository at this point in the history
  • Loading branch information
dcramer committed Jan 23, 2025
1 parent 044d00d commit 31a3830
Show file tree
Hide file tree
Showing 3 changed files with 4,511 additions and 2,762 deletions.
2 changes: 1 addition & 1 deletion packages/overlay/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"eslint-plugin-react-refresh": "^0.4.12",
"happy-dom": "^15.10.2",
"magic-string": "^0.30.11",
"platformicons": "^5.10.10",
"platformicons": "^7.0.4",
"postcss": "^8.4.47",
"react": "^18.3.1",
"react-diff-viewer-continued": "^3.4.0",
Expand Down
112 changes: 92 additions & 20 deletions packages/overlay/src/integrations/sentry/components/PlatformIcon.tsx
Original file line number Diff line number Diff line change
@@ -1,61 +1,133 @@
import { ReactComponent as AstroIcon } from 'platformicons/svg/astro.svg';
import { ReactComponent as DefaultIcon } from 'platformicons/svg/default.svg';
import { ReactComponent as DotNetIcon } from 'platformicons/svg/dotnet.svg';
import { ReactComponent as FirefoxIcon } from 'platformicons/svg/firefox.svg';
import { ReactComponent as ChromeIcon } from 'platformicons/svg/google.svg';
import { ReactComponent as JavaScriptIcon } from 'platformicons/svg/javascript.svg';
import { ReactComponent as PhpLaravelIcon } from 'platformicons/svg/laravel.svg';
import { ReactComponent as DotNetMauiIcon } from 'platformicons/svg/maui.svg';
import { ReactComponent as NestJsIcon } from 'platformicons/svg/nestjs.svg';
import { ReactComponent as NextJsIcon } from 'platformicons/svg/nextjs.svg';
import { ReactComponent as NodeIcon } from 'platformicons/svg/nodejs.svg';
import { ReactComponent as PhpIcon } from 'platformicons/svg/php.svg';
import { ReactComponent as PythonIcon } from 'platformicons/svg/python.svg';
import { ReactComponent as RemixIcon } from 'platformicons/svg/remix.svg';
import { ReactComponent as RubyIcon } from 'platformicons/svg/ruby.svg';
import { ReactComponent as SafariIcon } from 'platformicons/svg/safari.svg';
import { ReactComponent as PhpSymfonyIcon } from 'platformicons/svg/symfony.svg';

import { SentryEvent } from '../types';

import { ComponentPropsWithoutRef } from 'react';

type Platform = 'python' | 'javascript' | 'node' | 'ruby' | 'csharp' | string;

export default function PlatformIcon({
platform,
type PlatformIconProps = ComponentPropsWithoutRef<'svg'> & {
size?: number;
platform?: Platform;
event?: SentryEvent;
height?: number;
width?: number;
title?: string;
};

export default function PlatformIcon({ platform, event, size = 42, title, ...props }: PlatformIconProps) {
return (
<WrappedIcon platform={platform} event={event} size={size} title={title} {...props}>
<CorePlatformIcon platform={platform} event={event} size={size} title={title} {...props} />
</WrappedIcon>
);
}

Check warning on line 39 in packages/overlay/src/integrations/sentry/components/PlatformIcon.tsx

View check run for this annotation

Codecov / codecov/patch

packages/overlay/src/integrations/sentry/components/PlatformIcon.tsx#L33-L39

Added lines #L33 - L39 were not covered by tests

function WrappedIcon({ event, size = 42, ...props }: PlatformIconProps) {
const wrappedWidth = size / 3;
const wrappedHeight = size / 3;

return (
<div className="relative">
{props.children}
<RuntimeIcon
event={event}
size={size}
width={wrappedWidth}
height={wrappedHeight}
{...props}
className="absolute bottom-1 right-1"
/>
</div>
);
}

Check warning on line 58 in packages/overlay/src/integrations/sentry/components/PlatformIcon.tsx

View check run for this annotation

Codecov / codecov/patch

packages/overlay/src/integrations/sentry/components/PlatformIcon.tsx#L41-L58

Added lines #L41 - L58 were not covered by tests

function RuntimeIcon({

Check warning on line 60 in packages/overlay/src/integrations/sentry/components/PlatformIcon.tsx

View check run for this annotation

Codecov / codecov/patch

packages/overlay/src/integrations/sentry/components/PlatformIcon.tsx#L60

Added line #L60 was not covered by tests
event,
size,
width = 42,
height = 42,
title,
size = 42,

Check warning on line 62 in packages/overlay/src/integrations/sentry/components/PlatformIcon.tsx

View check run for this annotation

Codecov / codecov/patch

packages/overlay/src/integrations/sentry/components/PlatformIcon.tsx#L62

Added line #L62 was not covered by tests
...props
}: ComponentPropsWithoutRef<'svg'> & {
size?: number;
platform?: Platform;
event?: SentryEvent;
height?: number;
width?: number;
title?: string;
}) {
const runtimeName = `${event?.contexts?.runtime?.name || ''}`;
if (!runtimeName) return null;

const runtimeTitle = `${runtimeName} ${event?.contexts?.runtime?.version}`;
switch (runtimeName) {
case 'node':
return <NodeIcon title={runtimeTitle} width={size} height={size} {...props} />;
}

const browserName = `${event?.contexts?.browser?.name || ''}`;
const browserTitle = `${browserName} ${event?.contexts?.browser?.version}`;

if (browserName.includes('Safari')) {
return <SafariIcon title={browserTitle} width={size} height={size} {...props} />;
}
if (browserName.includes('Chrome')) {
return <ChromeIcon title={browserTitle} width={size} height={size} {...props} />;
}
if (browserName.includes('Firefox')) {
return <FirefoxIcon title={browserTitle} width={size} height={size} {...props} />;
}

return null;
}

Check warning on line 94 in packages/overlay/src/integrations/sentry/components/PlatformIcon.tsx

View check run for this annotation

Codecov / codecov/patch

packages/overlay/src/integrations/sentry/components/PlatformIcon.tsx#L71-L94

Added lines #L71 - L94 were not covered by tests

function CorePlatformIcon({ platform, event, size = 42, title, ...props }: PlatformIconProps) {

Check warning on line 96 in packages/overlay/src/integrations/sentry/components/PlatformIcon.tsx

View check run for this annotation

Codecov / codecov/patch

packages/overlay/src/integrations/sentry/components/PlatformIcon.tsx#L96

Added line #L96 was not covered by tests
const name = platform || event?.platform || 'unknown';
const sdk = event?.sdk?.name || '';
const newTitle = title ?? name;
if (sdk.startsWith('sentry.javascript.nextjs')) {
return <NextJsIcon title={newTitle} width={size} height={size} {...props} />;
} else if (sdk.startsWith('sentry.javascript.astro')) {
return <AstroIcon title={newTitle} width={size} height={size} {...props} />;
} else if (sdk.startsWith('sentry.javascript.remix')) {
return <RemixIcon title={newTitle} width={size} height={size} {...props} />;
} else if (sdk.startsWith('sentry.javascript.nestjs')) {
return <NestJsIcon title={newTitle} width={size} height={size} {...props} />;
}

Check warning on line 109 in packages/overlay/src/integrations/sentry/components/PlatformIcon.tsx

View check run for this annotation

Codecov / codecov/patch

packages/overlay/src/integrations/sentry/components/PlatformIcon.tsx#L98-L109

Added lines #L98 - L109 were not covered by tests
switch (name) {
case 'ruby':
return <RubyIcon title={title} width={size ?? width} height={size ?? height} {...props} />;
return <RubyIcon title={newTitle} width={size} height={size} {...props} />;

Check warning on line 112 in packages/overlay/src/integrations/sentry/components/PlatformIcon.tsx

View check run for this annotation

Codecov / codecov/patch

packages/overlay/src/integrations/sentry/components/PlatformIcon.tsx#L112

Added line #L112 was not covered by tests
case 'python':
return <PythonIcon title={title} width={size ?? width} height={size ?? height} {...props} />;
case 'javascript.astro':
return <AstroIcon title={title} width={size ?? width} height={size ?? height} {...props} />;
return <PythonIcon title={newTitle} width={size} height={size} {...props} />;

Check warning on line 114 in packages/overlay/src/integrations/sentry/components/PlatformIcon.tsx

View check run for this annotation

Codecov / codecov/patch

packages/overlay/src/integrations/sentry/components/PlatformIcon.tsx#L114

Added line #L114 was not covered by tests
case 'javascript':
return <JavaScriptIcon title={title} width={size ?? width} height={size ?? height} {...props} />;
return <JavaScriptIcon title={newTitle} width={size} height={size} {...props} />;

Check warning on line 116 in packages/overlay/src/integrations/sentry/components/PlatformIcon.tsx

View check run for this annotation

Codecov / codecov/patch

packages/overlay/src/integrations/sentry/components/PlatformIcon.tsx#L116

Added line #L116 was not covered by tests
case 'node':
return <NodeIcon title={title} width={size ?? width} height={size ?? height} {...props} />;
return <NodeIcon title={newTitle} width={size} height={size} {...props} />;

Check warning on line 118 in packages/overlay/src/integrations/sentry/components/PlatformIcon.tsx

View check run for this annotation

Codecov / codecov/patch

packages/overlay/src/integrations/sentry/components/PlatformIcon.tsx#L118

Added line #L118 was not covered by tests
case 'php':
return <PhpIcon title={title} width={size ?? width} height={size ?? height} {...props} />;
return <PhpIcon title={newTitle} width={size} height={size} {...props} />;

Check warning on line 120 in packages/overlay/src/integrations/sentry/components/PlatformIcon.tsx

View check run for this annotation

Codecov / codecov/patch

packages/overlay/src/integrations/sentry/components/PlatformIcon.tsx#L120

Added line #L120 was not covered by tests
case 'php.laravel':
return <PhpLaravelIcon title={title} width={size ?? width} height={size ?? height} {...props} />;
return <PhpLaravelIcon title={newTitle} width={size} height={size} {...props} />;

Check warning on line 122 in packages/overlay/src/integrations/sentry/components/PlatformIcon.tsx

View check run for this annotation

Codecov / codecov/patch

packages/overlay/src/integrations/sentry/components/PlatformIcon.tsx#L122

Added line #L122 was not covered by tests
case 'php.symfony':
return <PhpSymfonyIcon title={title} width={size ?? width} height={size ?? height} {...props} />;
return <PhpSymfonyIcon title={newTitle} width={size} height={size} {...props} />;

Check warning on line 124 in packages/overlay/src/integrations/sentry/components/PlatformIcon.tsx

View check run for this annotation

Codecov / codecov/patch

packages/overlay/src/integrations/sentry/components/PlatformIcon.tsx#L124

Added line #L124 was not covered by tests
case 'dotnet':
case 'csharp': // event.platform is 'csharp'
return <DotNetIcon title={title} width={size ?? width} height={size ?? height} {...props} />;
return <DotNetIcon title={newTitle} width={size} height={size} {...props} />;

Check warning on line 127 in packages/overlay/src/integrations/sentry/components/PlatformIcon.tsx

View check run for this annotation

Codecov / codecov/patch

packages/overlay/src/integrations/sentry/components/PlatformIcon.tsx#L127

Added line #L127 was not covered by tests
case 'dotnet.maui':
return <DotNetMauiIcon title={title} width={size ?? width} height={size ?? height} {...props} />;
return <DotNetMauiIcon title={newTitle} width={size} height={size} {...props} />;

Check warning on line 129 in packages/overlay/src/integrations/sentry/components/PlatformIcon.tsx

View check run for this annotation

Codecov / codecov/patch

packages/overlay/src/integrations/sentry/components/PlatformIcon.tsx#L129

Added line #L129 was not covered by tests
default:
return <DefaultIcon title={title} width={size ?? width} height={size ?? height} {...props} />;
return <DefaultIcon title={newTitle} width={size} height={size} {...props} />;

Check warning on line 131 in packages/overlay/src/integrations/sentry/components/PlatformIcon.tsx

View check run for this annotation

Codecov / codecov/patch

packages/overlay/src/integrations/sentry/components/PlatformIcon.tsx#L131

Added line #L131 was not covered by tests
}
}
Loading

0 comments on commit 31a3830

Please sign in to comment.