mirror of
https://github.com/chartdb/chartdb.git
synced 2025-11-01 20:43:49 +00:00
make the diagram icon component flexible (#476)
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import React from 'react';
|
||||
import type { Diagram } from '@/lib/domain/diagram';
|
||||
import { Tooltip, TooltipContent, TooltipTrigger } from '../tooltip/tooltip';
|
||||
import type { DatabaseEdition } from '@/lib/domain/database-edition';
|
||||
import {
|
||||
databaseEditionToImageMap,
|
||||
databaseEditionToLabelMap,
|
||||
@@ -9,39 +9,44 @@ import {
|
||||
databaseSecondaryLogoMap,
|
||||
databaseTypeToLabelMap,
|
||||
} from '@/lib/databases';
|
||||
import type { DatabaseType } from '@/lib/domain/database-type';
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
export interface DiagramIconProps {
|
||||
diagram: Diagram;
|
||||
export interface DiagramIconProps
|
||||
extends React.ComponentPropsWithoutRef<'div'> {
|
||||
databaseType: DatabaseType;
|
||||
databaseEdition?: DatabaseEdition;
|
||||
imgClassName?: string;
|
||||
}
|
||||
|
||||
export const DiagramIcon = React.forwardRef<
|
||||
React.ElementRef<typeof TooltipTrigger>,
|
||||
DiagramIconProps
|
||||
>(({ diagram }, ref) =>
|
||||
diagram.databaseEdition ? (
|
||||
>(({ databaseType, databaseEdition, className, imgClassName }, ref) =>
|
||||
databaseEdition ? (
|
||||
<Tooltip>
|
||||
<TooltipTrigger className="mr-1" ref={ref}>
|
||||
<TooltipTrigger className={cn('mr-1', className)} ref={ref}>
|
||||
<img
|
||||
src={databaseEditionToImageMap[diagram.databaseEdition]}
|
||||
className="h-5 max-w-fit rounded-full"
|
||||
src={databaseEditionToImageMap[databaseEdition]}
|
||||
className={cn('h-5 max-w-fit rounded-full', imgClassName)}
|
||||
alt="database"
|
||||
/>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>
|
||||
{databaseEditionToLabelMap[diagram.databaseEdition]}
|
||||
{databaseEditionToLabelMap[databaseEdition]}
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
) : (
|
||||
<Tooltip>
|
||||
<TooltipTrigger className="mr-2" ref={ref}>
|
||||
<TooltipTrigger className={cn('mr-2', className)} ref={ref}>
|
||||
<img
|
||||
src={databaseSecondaryLogoMap[diagram.databaseType]}
|
||||
className="h-5 max-w-fit"
|
||||
src={databaseSecondaryLogoMap[databaseType]}
|
||||
className={cn('h-5 max-w-fit', imgClassName)}
|
||||
alt="database"
|
||||
/>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>
|
||||
{databaseTypeToLabelMap[diagram.databaseType]}
|
||||
{databaseTypeToLabelMap[databaseType]}
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
)
|
||||
|
||||
@@ -137,7 +137,12 @@ export const OpenDiagramDialog: React.FC<OpenDiagramDialogProps> = ({
|
||||
<TableCell className="table-cell">
|
||||
<div className="flex justify-center">
|
||||
<DiagramIcon
|
||||
diagram={diagram}
|
||||
databaseType={
|
||||
diagram.databaseType
|
||||
}
|
||||
databaseEdition={
|
||||
diagram.databaseEdition
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
</TableCell>
|
||||
|
||||
@@ -60,7 +60,10 @@ export const DiagramName: React.FC<DiagramNameProps> = () => {
|
||||
}
|
||||
)}
|
||||
>
|
||||
<DiagramIcon diagram={currentDiagram} />
|
||||
<DiagramIcon
|
||||
databaseType={currentDiagram.databaseType}
|
||||
databaseEdition={currentDiagram.databaseEdition}
|
||||
/>
|
||||
<div className="flex">
|
||||
{isDesktop ? <Label>{t('diagrams')}/</Label> : null}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user