feat(core-blocks): CB-1199 support for external img

This commit is contained in:
Naumov Alexey
2021-08-27 15:32:00 +03:00
parent 0e22a6b911
commit 89d95305f9
3 changed files with 7 additions and 5 deletions
@@ -8,6 +8,8 @@
import { useMemo } from 'react';
import { isValidUrl } from '@cloudbeaver/core-utils';
import { Icon } from './Icon';
import { StaticImage } from './StaticImage';
@@ -19,13 +21,13 @@ export interface IconOrImageProps {
viewBox?: string;
}
export const IconOrImage = function IconOrImage({ icon, className, title, onClick, viewBox }: IconOrImageProps) {
export const IconOrImage: React.FC<IconOrImageProps> = function IconOrImage({ icon, className, title, onClick, viewBox }) {
const isStaticIcon = useMemo(
() => icon && (icon.startsWith('platform:') || icon.startsWith('/')),
[icon]
);
if (isStaticIcon) {
if (isStaticIcon || isValidUrl(icon)) {
return <StaticImage title={title} icon={icon} className={className} onClick={onClick} />;
}
@@ -6,7 +6,7 @@
* you may not use this file except in compliance with the License.
*/
import { GlobalConstants } from '@cloudbeaver/core-utils';
import { GlobalConstants, isValidUrl } from '@cloudbeaver/core-utils';
interface Props {
icon?: string;
@@ -22,7 +22,7 @@ export const StaticImage: React.FC<Props> = function StaticImage({
return null;
}
const url = GlobalConstants.absoluteUrl(icon);
const url = isValidUrl(icon) ? icon : GlobalConstants.absoluteUrl(icon);
return <img className={className} src={url} title={title} onClick={onClick} />;
};
@@ -57,7 +57,7 @@ export const AuthConfiguration: React.FC<Props> = observer(function AuthConfigur
<TableItemExpand />
</TableColumnValue>
<TableColumnValue centerContent flex expand>
<StaticImage icon={icon} />
<StaticImage icon={icon} title={`${configuration.displayName} icon`} />
</TableColumnValue>
<TableColumnValue expand>{configuration.displayName}</TableColumnValue>
<TableColumnValue>{configuration.providerId}</TableColumnValue>