Skip to content

Database diagrams editor that allows you to visualize and design your DB with a single query.

readonly editor (#899)

Guy Ben-Aharon534d2858af8f
diff --git a/src/components/color-picker/color-picker.tsx b/src/components/color-picker/color-picker.tsx
index f9d803e7..bc02462b 100644
--- a/src/components/color-picker/color-picker.tsx
+++ b/src/components/color-picker/color-picker.tsx
@@ -5,21 +5,33 @@ import {
PopoverTrigger,
} from '@/components/popover/popover';
import { colorOptions } from '@/lib/colors';
+import { cn } from '@/lib/utils';
export interface ColorPickerProps {
color: string;
onChange: (color: string) => void;
+ disabled?: boolean;
}
export const ColorPicker = React.forwardRef<
React.ElementRef<typeof PopoverTrigger>,
ColorPickerProps
->(({ color, onChange }, ref) => {
+>(({ color, onChange, disabled }, ref) => {
return (
<Popover>
- <PopoverTrigger asChild ref={ref}>
+ <PopoverTrigger
+ asChild
+ ref={ref}
+ disabled={disabled}
+ {...(disabled ? { onClick: (e) => e.preventDefault() } : {})}
+ >
<div
- className="h-6 w-8 cursor-pointer rounded-md border-2 border-muted transition-shadow hover:shadow-md"
+ className={cn(
+ 'h-6 w-8 cursor-pointer rounded-md border-2 border-muted transition-shadow hover:shadow-md',
+ {
+ 'hover:shadow-none cursor-default': disabled,
+ }
+ )}
style={{
backgroundColor: color,
}}
diff --git a/src/components/select-box/select-box.tsx b/src/components/select-box/select-box.tsx
index 0130f502..642fd959 100644
--- a/src/components/select-box/select-box.tsx
+++ b/src/components/select-box/select-box.tsx
@@ -53,6 +53,7 @@ export interface SelectBoxProps {
open?: boolean;
onOpenChange?: (open: boolean) => void;
popoverClassName?: string;
+ readonly?: boolean;
}
export const SelectBox = React.forwardRef<HTMLInputElement, SelectBoxProps>(
@@ -78,6 +79,7 @@ export const SelectBox = React.forwardRef<HTMLInputElement, SelectBoxProps>(
open,
onOpenChange: setOpen,
popoverClassName,
+ readonly,
},
ref
) => {
@@ -152,18 +154,20 @@ export const SelectBox = React.forwardRef<HTMLInputElement, SelectBoxProps>(
className={`inline-flex min-w-0 shrink-0 items-center gap-1 rounded-md border py-0.5 pl-2 pr-1 text-xs font-medium text-foreground transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 ${oneLine ? 'mx-0.5' : ''}`}
>
<span>{option.label}</span>
- <span
- onClick={(e) => {
- e.preventDefault();
- handleSelect(option.value);
- }}
- className="flex items-center rounded-sm px-px text-muted-foreground/60 hover:bg-accent hover:text-muted-foreground"
- >
- <Cross2Icon />
- </span>
+ {!readonly ? (
+ <span
+ onClick={(e) => {
+ e.preventDefault();
+ handleSelect(option.value);
+ }}
+ className="flex items-center rounded-sm px-px text-muted-foreground/60 hover:bg-accent hover:text-muted-foreground"
+ >
+ <Cross2Icon />
+ </span>
+ ) : null}
</span>
)),
- [options, value, handleSelect, oneLine, keepOrder]
+ [options, value, handleSelect, oneLine, keepOrder, readonly]
);
const isAllSelected = React.useMemo(
@@ -284,7 +288,7 @@ export const SelectBox = React.forwardRef<HTMLInputElement, SelectBoxProps>(
<PopoverTrigger asChild tabIndex={0} onKeyDown={handleKeyDown}>
<div
className={cn(
- `flex min-h-[36px] cursor-pointer items-center justify-between rounded-md border px-3 py-1 data-[state=open]:border-ring ${disabled ? 'bg-muted pointer-events-none' : ''}`,
+ `flex min-h-[36px] cursor-pointer items-center justify-between rounded-md border px-3 py-1 data-[state=open]:border-ring ${disabled ? 'bg-muted pointer-events-none' : ''} ${readonly ? 'pointer-events-none' : ''}`,
className
)}
>
diff --git a/src/context/chartdb-context/chartdb-provider.tsx b/src/context/chartdb-context/chartdb-provider.tsx
index 99a3b985..b712cf8c 100644
--- a/src/context/chartdb-context/chartdb-provider.tsx
+++ b/src/context/chartdb-context/chartdb-provider.tsx
@@ -41,8 +41,7 @@ export const ChartDBProvider: React.FC<
React.PropsWithChildren<ChartDBProviderProps>
> = ({ children, diagram, readonly: readonlyProp }) => {
const { hasDiff } = useDiff();
- const dbStorage = useStorage();
- let db = dbStorage;
+ const storageDB = useStorage();
const events = useEventEmitter<ChartDBEvent>();
const { addUndoAction, resetRedoStack, resetUndoStack } =
useRedoUndoStack();
@@ -102,10 +101,6 @@ export const ChartDBProvider: React.FC<
[readonlyProp, hasDiff]
);
- if (readonly) {
- db = storageInitialValue;
- }
-
const schemas = useMemo(
() =>
databasesWithSchemas.includes(databaseType)
@@ -134,6 +129,11 @@ export const ChartDBProvider: React.FC<
[tables, defaultSchemaName, databaseType]
);
+ const db = useMemo(
+ () => (readonly ? storageInitialValue : storageDB),
+ [storageDB, readonly]
+ );
+
const currentDiagram: Diagram = useMemo(
() => ({
id: diagramId,
@@ -1580,17 +1580,17 @@ export const ChartDBProvider: React.FC<
const updateDiagramData: ChartDBContext['updateDiagramData'] = useCallback(
async (diagram, options) => {
- const st = options?.forceUpdateStorage ? dbStorage : db;
+ const st = options?.forceUpdateStorage ? storageDB : db;
await st.deleteDiagram(diagram.id);
await st.addDiagram({ diagram });
loadDiagramFromData(diagram);
},
- [db, dbStorage, loadDiagramFromData]
+ [db, storageDB, loadDiagramFromData]
);
const loadDiagram: ChartDBContext['loadDiagram'] = useCallback(
async (diagramId: string) => {
- const diagram = await db.getDiagram(diagramId, {
+ const diagram = await storageDB.getDiagram(diagramId, {
includeRelationships: true,
includeTables: true,
includeDependencies: true,
@@ -1604,7 +1604,7 @@ export const ChartDBProvider: React.FC<
return diagram;
},
- [db, loadDiagramFromData]
+ [storageDB, loadDiagramFromData]
);
// Custom type operations
diff --git a/src/i18n/locales/ar.ts b/src/i18n/locales/ar.ts
index b01e6ee3..03cf4a2c 100644
--- a/src/i18n/locales/ar.ts
+++ b/src/i18n/locales/ar.ts
@@ -248,6 +248,7 @@ export const ar: LanguageTranslation = {
enum_values: 'Enum Values',
composite_fields: 'Fields',
no_fields: 'No fields defined',
+ no_values: 'لم يتم تحديد قيم التعداد',
field_name_placeholder: 'Field name',
field_type_placeholder: 'Select type',
add_field: 'Add Field',
diff --git a/src/i18n/locales/bn.ts b/src/i18n/locales/bn.ts
index d6633444..55b8b0c7 100644
--- a/src/i18n/locales/bn.ts
+++ b/src/i18n/locales/bn.ts
@@ -249,6 +249,7 @@ export const bn: LanguageTranslation = {
enum_values: 'Enum Values',
composite_fields: 'Fields',
no_fields: 'No fields defined',
+ no_values: 'কোন enum মান সংজ্ঞায়িত নেই',
field_name_placeholder: 'Field name',
field_type_placeholder: 'Select type',
add_field: 'Add Field',
diff --git a/src/i18n/locales/de.ts b/src/i18n/locales/de.ts
index fa015c9b..82345a62 100644
--- a/src/i18n/locales/de.ts
+++ b/src/i18n/locales/de.ts
@@ -250,6 +250,7 @@ export const de: LanguageTranslation = {
enum_values: 'Enum Values',
composite_fields: 'Fields',
no_fields: 'No fields defined',
+ no_values: 'Keine Enum-Werte definiert',
field_name_placeholder: 'Field name',
field_type_placeholder: 'Select type',
add_field: 'Add Field',
diff --git a/src/i18n/locales/en.ts b/src/i18n/locales/en.ts
index b6968fce..0772d75c 100644
--- a/src/i18n/locales/en.ts
+++ b/src/i18n/locales/en.ts
@@ -242,6 +242,7 @@ export const en = {
enum_values: 'Enum Values',
composite_fields: 'Fields',
no_fields: 'No fields defined',
+ no_values: 'No enum values defined',
field_name_placeholder: 'Field name',
field_type_placeholder: 'Select type',
add_field: 'Add Field',
diff --git a/src/i18n/locales/es.ts b/src/i18n/locales/es.ts
index 1f346fe8..95f482cb 100644
--- a/src/i18n/locales/es.ts
+++ b/src/i18n/locales/es.ts
@@ -248,6 +248,7 @@ export const es: LanguageTranslation = {
enum_values: 'Enum Values',
composite_fields: 'Fields',
no_fields: 'No fields defined',
+ no_values: 'No hay valores de enum definidos',
field_name_placeholder: 'Field name',
field_type_placeholder: 'Select type',
add_field: 'Add Field',
diff --git a/src/i18n/locales/fr.ts b/src/i18n/locales/fr.ts
index a324088c..f465e024 100644
--- a/src/i18n/locales/fr.ts
+++ b/src/i18n/locales/fr.ts
@@ -246,6 +246,7 @@ export const fr: LanguageTranslation = {
enum_values: 'Enum Values',
composite_fields: 'Fields',
no_fields: 'No fields defined',
+ no_values: "Aucune valeur d'énumération définie",
field_name_placeholder: 'Field name',
field_type_placeholder: 'Select type',
add_field: 'Add Field',
diff --git a/src/i18n/locales/gu.ts b/src/i18n/locales/gu.ts
index 5fa38e7f..92fc3b25 100644
--- a/src/i18n/locales/gu.ts
+++ b/src/i18n/locales/gu.ts
@@ -250,6 +250,7 @@ export const gu: LanguageTranslation = {
enum_values: 'Enum Values',
composite_fields: 'Fields',
no_fields: 'No fields defined',
+ no_values: 'કોઈ enum મૂલ્યો વ્યાખ્યાયિત નથી',
field_name_placeholder: 'Field name',
field_type_placeholder: 'Select type',
add_field: 'Add Field',
diff --git a/src/i18n/locales/hi.ts b/src/i18n/locales/hi.ts
index aed10097..c638846d 100644
--- a/src/i18n/locales/hi.ts
+++ b/src/i18n/locales/hi.ts
@@ -249,6 +249,7 @@ export const hi: LanguageTranslation = {
enum_values: 'Enum Values',
composite_fields: 'Fields',
no_fields: 'No fields defined',
+ no_values: 'कोई enum मान परिभाषित नहीं',
field_name_placeholder: 'Field name',
field_type_placeholder: 'Select type',
add_field: 'Add Field',
diff --git a/src/i18n/locales/hr.ts b/src/i18n/locales/hr.ts
index bd90aa00..672bb92c 100644
--- a/src/i18n/locales/hr.ts
+++ b/src/i18n/locales/hr.ts
@@ -245,6 +245,7 @@ export const hr: LanguageTranslation = {
enum_values: 'Enum vrijednosti',
composite_fields: 'Polja',
no_fields: 'Nema definiranih polja',
+ no_values: 'Nema definiranih enum vrijednosti',
field_name_placeholder: 'Naziv polja',
field_type_placeholder: 'Odaberi tip',
add_field: 'Dodaj polje',
diff --git a/src/i18n/locales/id_ID.ts b/src/i18n/locales/id_ID.ts
index 2a0ef679..580993e6 100644
--- a/src/i18n/locales/id_ID.ts
+++ b/src/i18n/locales/id_ID.ts
@@ -248,6 +248,7 @@ export const id_ID: LanguageTranslation = {
enum_values: 'Enum Values',
composite_fields: 'Fields',
no_fields: 'No fields defined',
+ no_values: 'Tidak ada nilai enum yang ditentukan',
field_name_placeholder: 'Field name',
field_type_placeholder: 'Select type',
add_field: 'Add Field',
diff --git a/src/i18n/locales/ja.ts b/src/i18n/locales/ja.ts
index fd0980a1..1fcfb590 100644
--- a/src/i18n/locales/ja.ts
+++ b/src/i18n/locales/ja.ts
@@ -253,6 +253,7 @@ export const ja: LanguageTranslation = {
enum_values: 'Enum Values',
composite_fields: 'Fields',
no_fields: 'No fields defined',
+ no_values: '列挙値が定義されていません',
field_name_placeholder: 'Field name',
field_type_placeholder: 'Select type',
add_field: 'Add Field',
diff --git a/src/i18n/locales/ko_KR.ts b/src/i18n/locales/ko_KR.ts
index 5dbc068c..2bd2394c 100644
--- a/src/i18n/locales/ko_KR.ts
+++ b/src/i18n/locales/ko_KR.ts
@@ -248,6 +248,7 @@ export const ko_KR: LanguageTranslation = {
enum_values: 'Enum Values',
composite_fields: 'Fields',
no_fields: 'No fields defined',
+ no_values: '정의된 열거형 값이 없습니다',
field_name_placeholder: 'Field name',
field_type_placeholder: 'Select type',
add_field: 'Add Field',
diff --git a/src/i18n/locales/mr.ts b/src/i18n/locales/mr.ts
index bb945eb4..e358a7c5 100644
--- a/src/i18n/locales/mr.ts
+++ b/src/i18n/locales/mr.ts
@@ -252,6 +252,7 @@ export const mr: LanguageTranslation = {
enum_values: 'Enum Values',
composite_fields: 'Fields',
no_fields: 'No fields defined',
+ no_values: 'कोणतीही enum मूल्ये परिभाषित नाहीत',
field_name_placeholder: 'Field name',
field_type_placeholder: 'Select type',
add_field: 'Add Field',
diff --git a/src/i18n/locales/ne.ts b/src/i18n/locales/ne.ts
index 6303c343..3fba4d8f 100644
--- a/src/i18n/locales/ne.ts
+++ b/src/i18n/locales/ne.ts
@@ -249,6 +249,7 @@ export const ne: LanguageTranslation = {
enum_values: 'Enum Values',
composite_fields: 'Fields',
no_fields: 'No fields defined',
+ no_values: 'कुनै enum मानहरू परिभाषित छैनन्',
field_name_placeholder: 'Field name',
field_type_placeholder: 'Select type',
add_field: 'Add Field',
diff --git a/src/i18n/locales/pt_BR.ts b/src/i18n/locales/pt_BR.ts
index 0ef7017b..1cbbc5d1 100644
--- a/src/i18n/locales/pt_BR.ts
+++ b/src/i18n/locales/pt_BR.ts
@@ -249,6 +249,7 @@ export const pt_BR: LanguageTranslation = {
enum_values: 'Enum Values',
composite_fields: 'Fields',
no_fields: 'No fields defined',
+ no_values: 'Nenhum valor de enum definido',
field_name_placeholder: 'Field name',
field_type_placeholder: 'Select type',
add_field: 'Add Field',
diff --git a/src/i18n/locales/ru.ts b/src/i18n/locales/ru.ts
index b008c855..f5052e66 100644
--- a/src/i18n/locales/ru.ts
+++ b/src/i18n/locales/ru.ts
@@ -246,6 +246,7 @@ export const ru: LanguageTranslation = {
enum_values: 'Enum Values',
composite_fields: 'Fields',
no_fields: 'No fields defined',
+ no_values: 'Значения перечисления не определены',
field_name_placeholder: 'Field name',
field_type_placeholder: 'Select type',
add_field: 'Add Field',
diff --git a/src/i18n/locales/te.ts b/src/i18n/locales/te.ts
index 623e948f..554cc8f4 100644
--- a/src/i18n/locales/te.ts
+++ b/src/i18n/locales/te.ts
@@ -250,6 +250,7 @@ export const te: LanguageTranslation = {
enum_values: 'Enum Values',
composite_fields: 'Fields',
no_fields: 'No fields defined',
+ no_values: 'ఏ enum విలువలు నిర్వచించబడలేదు',
field_name_placeholder: 'Field name',
field_type_placeholder: 'Select type',
add_field: 'Add Field',
diff --git a/src/i18n/locales/tr.ts b/src/i18n/locales/tr.ts
index dfe47dc4..5ff468a1 100644
--- a/src/i18n/locales/tr.ts
+++ b/src/i18n/locales/tr.ts
@@ -249,6 +249,7 @@ export const tr: LanguageTranslation = {
enum_values: 'Enum Values',
composite_fields: 'Fields',
no_fields: 'No fields defined',
+ no_values: 'Tanımlanmış enum değeri yok',
field_name_placeholder: 'Field name',
field_type_placeholder: 'Select type',
add_field: 'Add Field',
diff --git a/src/i18n/locales/uk.ts b/src/i18n/locales/uk.ts
index 63186a77..7af43f2c 100644
--- a/src/i18n/locales/uk.ts
+++ b/src/i18n/locales/uk.ts
@@ -247,6 +247,7 @@ export const uk: LanguageTranslation = {
enum_values: 'Enum Values',
composite_fields: 'Fields',
no_fields: 'No fields defined',
+ no_values: 'Значення переліку не визначені',
field_name_placeholder: 'Field name',
field_type_placeholder: 'Select type',
add_field: 'Add Field',
diff --git a/src/i18n/locales/vi.ts b/src/i18n/locales/vi.ts
index 436d43b4..aa24ed8d 100644
--- a/src/i18n/locales/vi.ts
+++ b/src/i18n/locales/vi.ts
@@ -248,6 +248,7 @@ export const vi: LanguageTranslation = {
enum_values: 'Enum Values',
composite_fields: 'Fields',
no_fields: 'No fields defined',
+ no_values: 'Không có giá trị enum được định nghĩa',
field_name_placeholder: 'Field name',
field_type_placeholder: 'Select type',
add_field: 'Add Field',
diff --git a/src/i18n/locales/zh_CN.ts b/src/i18n/locales/zh_CN.ts
index ec2a3357..97e68db9 100644
--- a/src/i18n/locales/zh_CN.ts
+++ b/src/i18n/locales/zh_CN.ts
@@ -245,6 +245,7 @@ export const zh_CN: LanguageTranslation = {
enum_values: 'Enum Values',
composite_fields: 'Fields',
no_fields: 'No fields defined',
+ no_values: '没有定义枚举值',
field_name_placeholder: 'Field name',
field_type_placeholder: 'Select type',
add_field: 'Add Field',
diff --git a/src/i18n/locales/zh_TW.ts b/src/i18n/locales/zh_TW.ts
index b3384cc5..bf197346 100644
--- a/src/i18n/locales/zh_TW.ts
+++ b/src/i18n/locales/zh_TW.ts
@@ -245,6 +245,7 @@ export const zh_TW: LanguageTranslation = {
enum_values: 'Enum Values',
composite_fields: 'Fields',
no_fields: 'No fields defined',
+ no_values: '沒有定義列舉值',
field_name_placeholder: 'Field name',
field_type_placeholder: 'Select type',
add_field: 'Add Field',
diff --git a/src/pages/editor-page/canvas/area-node/area-node.tsx b/src/pages/editor-page/canvas/area-node/area-node.tsx
index 7023011a..1164dbf4 100644
--- a/src/pages/editor-page/canvas/area-node/area-node.tsx
+++ b/src/pages/editor-page/canvas/area-node/area-node.tsx
@@ -77,13 +77,15 @@ export const AreaNode: React.FC<NodeProps<AreaNodeType>> = React.memo(
}
}}
>
- <NodeResizer
- isVisible={focused}
- lineClassName="!border-4 !border-transparent"
- handleClassName="!h-[10px] !w-[10px] !rounded-full !bg-pink-600"
- minHeight={100}
- minWidth={100}
- />
+ {!readonly ? (
+ <NodeResizer
+ isVisible={focused}
+ lineClassName="!border-4 !border-transparent"
+ handleClassName="!h-[10px] !w-[10px] !rounded-full !bg-pink-600"
+ minHeight={100}
+ minWidth={100}
+ />
+ ) : null}
<div className="group flex h-8 items-center justify-between rounded-t-md px-2">
<div className="flex w-full items-center gap-1">
<GripVertical className="size-4 shrink-0 text-slate-700 opacity-60 dark:text-slate-300" />
diff --git a/src/pages/editor-page/side-panel/areas-section/areas-list/area-list-item/area-list-item.tsx b/src/pages/editor-page/side-panel/areas-section/areas-list/area-list-item/area-list-item.tsx
index 1cfb4142..c18f7131 100644
--- a/src/pages/editor-page/side-panel/areas-section/areas-list/area-list-item/area-list-item.tsx
+++ b/src/pages/editor-page/side-panel/areas-section/areas-list/area-list-item/area-list-item.tsx
@@ -41,7 +41,7 @@ export interface AreaListItemProps {
export const AreaListItem = React.forwardRef<HTMLDivElement, AreaListItemProps>(
({ area }, forwardedRef) => {
- const { updateArea, removeArea } = useChartDB();
+ const { updateArea, removeArea, readonly } = useChartDB();
const { t } = useTranslation();
const { fitView, setNodes } = useReactFlow();
const { hideSidePanel } = useLayout();
@@ -189,12 +189,14 @@ export const AreaListItem = React.forwardRef<HTMLDivElement, AreaListItemProps>(
{...attributes}
>
<div className="group flex h-11 items-center justify-between gap-1 overflow-hidden p-2">
- <div
- className="flex cursor-move items-center justify-center"
- {...listeners}
- >
- <GripVertical className="size-4 text-muted-foreground" />
- </div>
+ {!readonly ? (
+ <div
+ className="flex cursor-move items-center justify-center"
+ {...listeners}
+ >
+ <GripVertical className="size-4 text-muted-foreground" />
+ </div>
+ ) : null}
<div className="flex min-w-0 flex-1">
{editMode ? (
@@ -208,7 +210,7 @@ export const AreaListItem = React.forwardRef<HTMLDivElement, AreaListItemProps>(
onChange={(e) => setAreaName(e.target.value)}
className="h-7 w-full focus-visible:ring-0"
/>
- ) : (
+ ) : !readonly ? (
<Tooltip>
<TooltipTrigger asChild>
<div
@@ -222,16 +224,21 @@ export const AreaListItem = React.forwardRef<HTMLDivElement, AreaListItemProps>(
{t('tool_tips.double_click_to_edit')}
</TooltipContent>
</Tooltip>
+ ) : (
+ <div className="truncate px-2 py-0.5 text-sm font-medium">
+ {area.name}
+ </div>
)}
</div>
<div className="flex items-center gap-1">
{!editMode ? (
<div className="flex flex-row-reverse items-center gap-1">
- {renderDropDownMenu()}
+ {!readonly ? renderDropDownMenu() : null}
<ColorPicker
color={area.color}
onChange={handleColorChange}
+ disabled={readonly}
/>
<div className="hidden md:group-hover:flex">
<ListItemHeaderButton onClick={focusOnArea}>
diff --git a/src/pages/editor-page/side-panel/areas-section/areas-section.tsx b/src/pages/editor-page/side-panel/areas-section/areas-section.tsx
index a25e9a03..c24da0f8 100644
--- a/src/pages/editor-page/side-panel/areas-section/areas-section.tsx
+++ b/src/pages/editor-page/side-panel/areas-section/areas-section.tsx
@@ -14,7 +14,7 @@ import { useViewport } from '@xyflow/react';
export interface AreasSectionProps {}
export const AreasSection: React.FC<AreasSectionProps> = () => {
- const { createArea, areas } = useChartDB();
+ const { createArea, areas, readonly } = useChartDB();
const viewport = useViewport();
const { t } = useTranslation();
const { openAreaFromSidebar } = useLayout();
@@ -73,14 +73,16 @@ export const AreasSection: React.FC<AreasSectionProps> = () => {
onChange={(e) => setFilterText(e.target.value)}
/>
</div>
- <Button
- variant="secondary"
- className="h-8 p-2 text-xs"
- onClick={handleCreateArea}
- >
- <Group className="h-4" />
- {t('side_panel.areas_section.add_area')}
- </Button>
+ {!readonly ? (
+ <Button
+ variant="secondary"
+ className="h-8 p-2 text-xs"
+ onClick={handleCreateArea}
+ >
+ <Group className="h-4" />
+ {t('side_panel.areas_section.add_area')}
+ </Button>
+ ) : null}
</div>
<div className="flex flex-1 flex-col overflow-hidden">
<ScrollArea className="h-full">
diff --git a/src/pages/editor-page/side-panel/custom-types-section/custom-type-list/custom-type-list-item/custom-type-list-item-content/composite-fields/composite-field.tsx b/src/pages/editor-page/side-panel/custom-types-section/custom-type-list/custom-type-list-item/custom-type-list-item-content/composite-fields/composite-field.tsx
index 33dff524..ca964e8d 100644
--- a/src/pages/editor-page/side-panel/custom-types-section/custom-type-list/custom-type-list-item/custom-type-list-item-content/composite-fields/composite-field.tsx
+++ b/src/pages/editor-page/side-panel/custom-types-section/custom-type-list/custom-type-list-item/custom-type-list-item-content/composite-fields/composite-field.tsx
@@ -4,6 +4,7 @@ import { Button } from '@/components/button/button';
import type { DBCustomTypeField } from '@/lib/domain/db-custom-type';
import { useSortable } from '@dnd-kit/sortable';
import { CSS } from '@dnd-kit/utilities';
+import { useChartDB } from '@/hooks/use-chartdb';
export interface CompositeFieldProps {
field: DBCustomTypeField;
@@ -22,6 +23,7 @@ export const CompositeField: React.FC<{
transition,
isDragging,
} = useSortable({ id: field.field });
+ const { readonly } = useChartDB();
const style = {
transform: CSS.Transform.toString(transform),
@@ -35,23 +37,27 @@ export const CompositeField: React.FC<{
style={style}
className="flex items-center gap-2 rounded-md border p-2"
>
- <div
- className="flex cursor-move items-center justify-center"
- {...attributes}
- {...listeners}
- >
- <GripVertical className="size-3 text-muted-foreground" />
- </div>
+ {!readonly ? (
+ <div
+ className="flex cursor-move items-center justify-center"
+ {...attributes}
+ {...listeners}
+ >
+ <GripVertical className="size-3 text-muted-foreground" />
+ </div>
+ ) : null}
<div className="flex-1 text-sm">{field.field}</div>
<div className="text-xs text-muted-foreground">{field.type}</div>
- <Button
- variant="ghost"
- size="sm"
- className="size-6 p-0 text-muted-foreground hover:text-red-500"
- onClick={onRemove}
- >
- <X className="size-3" />
- </Button>
+ {!readonly ? (
+ <Button
+ variant="ghost"
+ size="sm"
+ className="size-6 p-0 text-muted-foreground hover:text-red-500"
+ onClick={onRemove}
+ >
+ <X className="size-3" />
+ </Button>
+ ) : null}
</div>
);
};
diff --git a/src/pages/editor-page/side-panel/custom-types-section/custom-type-list/custom-type-list-item/custom-type-list-item-content/composite-fields/composite-fields.tsx b/src/pages/editor-page/side-panel/custom-types-section/custom-type-list/custom-type-list-item/custom-type-list-item-content/composite-fields/composite-fields.tsx
index 7e4fabdf..c3c30adf 100644
--- a/src/pages/editor-page/side-panel/custom-types-section/custom-type-list/custom-type-list-item/custom-type-list-item-content/composite-fields/composite-fields.tsx
+++ b/src/pages/editor-page/side-panel/custom-types-section/custom-type-list/custom-type-list-item/custom-type-list-item-content/composite-fields/composite-fields.tsx
@@ -43,7 +43,7 @@ export const CustomTypeCompositeFields: React.FC<
CustomTypeCompositeFieldsProps
> = ({ fields, addField, removeField, reorderFields }) => {
const { t } = useTranslation();
- const { currentDiagram, customTypes } = useChartDB();
+ const { currentDiagram, customTypes, readonly } = useChartDB();
const [newFieldName, setNewFieldName] = useState('');
const [newFieldType, setNewFieldType] = useState('');
@@ -162,70 +162,76 @@ export const CustomTypeCompositeFields: React.FC<
</DndContext>
)}
- <div className="flex flex-col gap-2">
- <div className="flex gap-2">
- <Input
- placeholder={t(
- 'side_panel.custom_types_section.custom_type.field_name_placeholder'
- )}
- value={newFieldName}
- onChange={(e) => setNewFieldName(e.target.value)}
- onKeyDown={handleKeyDown}
- className="h-8 flex-1 text-xs"
- />
- <Select
- value={newFieldType}
- onValueChange={setNewFieldType}
+ {!readonly ? (
+ <div className="flex flex-col gap-2">
+ <div className="flex gap-2">
+ <Input
+ placeholder={t(
+ 'side_panel.custom_types_section.custom_type.field_name_placeholder'
+ )}
+ value={newFieldName}
+ onChange={(e) => setNewFieldName(e.target.value)}
+ onKeyDown={handleKeyDown}
+ className="h-8 flex-1 text-xs"
+ />
+ <Select
+ value={newFieldType}
+ onValueChange={setNewFieldType}
+ >
+ <SelectTrigger className="h-8 w-32 text-xs">
+ <SelectValue
+ placeholder={t(
+ 'side_panel.custom_types_section.custom_type.field_type_placeholder'
+ )}
+ />
+ </SelectTrigger>
+ <SelectContent>
+ <SelectGroup>
+ <SelectLabel>Standard Types</SelectLabel>
+ {dataTypes.map((dataType) => (
+ <SelectItem
+ key={dataType.id}
+ value={dataType.name}
+ >
+ {dataType.name}
+ </SelectItem>
+ ))}
+ </SelectGroup>
+ {customDataTypes.length > 0 ? (
+ <>
+ <SelectSeparator />
+ <SelectGroup>
+ <SelectLabel>
+ Custom Types
+ </SelectLabel>
+ {customDataTypes.map((dataType) => (
+ <SelectItem
+ key={dataType.id}
+ value={dataType.name}
+ >
+ {dataType.name}
+ </SelectItem>
+ ))}
+ </SelectGroup>
+ </>
+ ) : null}
+ </SelectContent>
+ </Select>
+ </div>
+ <Button
+ variant="ghost"
+ size="sm"
+ className="h-6 gap-1 self-start text-xs"
+ onClick={handleAddField}
+ disabled={!newFieldName.trim() || !newFieldType.trim()}
>
- <SelectTrigger className="h-8 w-32 text-xs">
- <SelectValue
- placeholder={t(
- 'side_panel.custom_types_section.custom_type.field_type_placeholder'
- )}
- />
- </SelectTrigger>
- <SelectContent>
- <SelectGroup>
- <SelectLabel>Standard Types</SelectLabel>
- {dataTypes.map((dataType) => (
- <SelectItem
- key={dataType.id}
- value={dataType.name}
- >
- {dataType.name}
- </SelectItem>
- ))}
- </SelectGroup>
- {customDataTypes.length > 0 ? (
- <>
- <SelectSeparator />
- <SelectGroup>
- <SelectLabel>Custom Types</SelectLabel>
- {customDataTypes.map((dataType) => (
- <SelectItem
- key={dataType.id}
- value={dataType.name}
- >
- {dataType.name}
- </SelectItem>
- ))}
- </SelectGroup>
- </>
- ) : null}
- </SelectContent>
- </Select>
+ <Plus className="size-3" />
+ {t(
+ 'side_panel.custom_types_section.custom_type.add_field'
+ )}
+ </Button>
</div>
- <Button
- variant="ghost"
- size="sm"
- className="h-6 gap-1 self-start text-xs"
- onClick={handleAddField}
- disabled={!newFieldName.trim() || !newFieldType.trim()}
- >
- <Plus className="size-3" />
- {t('side_panel.custom_types_section.custom_type.add_field')}
- </Button>
- </div>
+ ) : null}
</div>
);
};
diff --git a/src/pages/editor-page/side-panel/custom-types-section/custom-type-list/custom-type-list-item/custom-type-list-item-content/custom-type-list-item-content.tsx b/src/pages/editor-page/side-panel/custom-types-section/custom-type-list/custom-type-list-item/custom-type-list-item-content/custom-type-list-item-content.tsx
index d2377a86..90fcfc19 100644
--- a/src/pages/editor-page/side-panel/custom-types-section/custom-type-list/custom-type-list-item/custom-type-list-item-content/custom-type-list-item-content.tsx
+++ b/src/pages/editor-page/side-panel/custom-types-section/custom-type-list/custom-type-list-item/custom-type-list-item-content/custom-type-list-item-content.tsx
@@ -41,6 +41,7 @@ export const CustomTypeListItemContent: React.FC<
highlightedCustomType,
highlightCustomTypeId,
tables,
+ readonly,
} = useChartDB();
const { t } = useTranslation();
@@ -157,6 +158,7 @@ export const CustomTypeListItemContent: React.FC<
<Select
value={customType.kind}
onValueChange={updateCustomTypeKind}
+ disabled={readonly}
>
<SelectTrigger className="h-8">
<SelectValue />
@@ -212,18 +214,20 @@ export const CustomTypeListItemContent: React.FC<
) : (
renderHighlightButton()
)}
- <Button
- variant="ghost"
- className="flex h-8 w-full items-center justify-center p-2 text-xs"
- onClick={deleteCustomTypeHandler}
- >
- <Trash2 className="mr-1 size-3.5 text-red-700" />
- <div className="text-red-700">
- {t(
- 'side_panel.custom_types_section.custom_type.delete_custom_type'
- )}
- </div>
- </Button>
+ {!readonly ? (
+ <Button
+ variant="ghost"
+ className="flex h-8 w-full items-center justify-center p-2 text-xs"
+ onClick={deleteCustomTypeHandler}
+ >
+ <Trash2 className="mr-1 size-3.5 text-red-700" />
+ <div className="text-red-700">
+ {t(
+ 'side_panel.custom_types_section.custom_type.delete_custom_type'
+ )}
+ </div>
+ </Button>
+ ) : null}
</div>
</div>
);
diff --git a/src/pages/editor-page/side-panel/custom-types-section/custom-type-list/custom-type-list-item/custom-type-list-item-content/enum-values/enum-values.tsx b/src/pages/editor-page/side-panel/custom-types-section/custom-type-list/custom-type-list-item/custom-type-list-item-content/enum-values/enum-values.tsx
index b26b8bf4..d31133a7 100644
--- a/src/pages/editor-page/side-panel/custom-types-section/custom-type-list/custom-type-list-item/custom-type-list-item-content/enum-values/enum-values.tsx
+++ b/src/pages/editor-page/side-panel/custom-types-section/custom-type-list/custom-type-list-item/custom-type-list-item-content/enum-values/enum-values.tsx
@@ -3,6 +3,7 @@ import React, { useCallback, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { Input } from '@/components/input/input';
import { Button } from '@/components/button/button';
+import { useChartDB } from '@/hooks/use-chartdb';
export interface EnumValuesProps {
values: string[];
@@ -17,6 +18,7 @@ export const CustomTypeEnumValues: React.FC<EnumValuesProps> = ({
}) => {
const { t } = useTranslation();
const [newValue, setNewValue] = useState('');
+ const { readonly } = useChartDB();
const handleAddValue = useCallback(() => {
if (newValue.trim() && !values.includes(newValue.trim())) {
@@ -55,36 +57,46 @@ export const CustomTypeEnumValues: React.FC<EnumValuesProps> = ({
<span className="flex-1 truncate text-sm font-medium">
{value}
</span>
- <Button
- variant="ghost"
- className="size-6 p-0 text-muted-foreground hover:bg-destructive/10 hover:text-destructive"
- onClick={() => removeValue(value)}
- >
- <X className="size-3.5" />
- </Button>
+ {!readonly ? (
+ <Button
+ variant="ghost"
+ className="size-6 p-0 text-muted-foreground hover:bg-destructive/10 hover:text-destructive"
+ onClick={() => removeValue(value)}
+ >
+ <X className="size-3.5" />
+ </Button>
+ ) : null}
</div>
))}
</div>
- <div className="flex items-center gap-1">
- <Input
- value={newValue}
- onChange={(e) => setNewValue(e.target.value)}
- onKeyDown={handleKeyDown}
- placeholder="Add enum value..."
- className="h-8 flex-1 text-xs focus-visible:ring-0"
- />
- <Button
- variant="outline"
- className="h-8 px-2 text-xs"
- onClick={handleAddValue}
- disabled={
- !newValue.trim() || values.includes(newValue.trim())
- }
- >
- <Plus className="size-3.5" />
- </Button>
- </div>
+ {values.length === 0 ? (
+ <div className="py-2 text-muted-foreground">
+ {t('side_panel.custom_types_section.custom_type.no_values')}
+ </div>
+ ) : null}
+
+ {!readonly ? (
+ <div className="flex items-center gap-1">
+ <Input
+ value={newValue}
+ onChange={(e) => setNewValue(e.target.value)}
+ onKeyDown={handleKeyDown}
+ placeholder="Add enum value..."
+ className="h-8 flex-1 text-xs focus-visible:ring-0"
+ />
+ <Button
+ variant="outline"
+ className="h-8 px-2 text-xs"
+ onClick={handleAddValue}
+ disabled={
+ !newValue.trim() || values.includes(newValue.trim())
+ }
+ >
+ <Plus className="size-3.5" />
+ </Button>
+ </div>
+ ) : null}
</div>
);
};
diff --git a/src/pages/editor-page/side-panel/custom-types-section/custom-type-list/custom-type-list-item/custom-type-list-item-header/custom-type-list-item-header.tsx b/src/pages/editor-page/side-panel/custom-types-section/custom-type-list/custom-type-list-item/custom-type-list-item-header/custom-type-list-item-header.tsx
index e25647ce..4b1e516e 100644
--- a/src/pages/editor-page/side-panel/custom-types-section/custom-type-list/custom-type-list-item/custom-type-list-item-header/custom-type-list-item-header.tsx
+++ b/src/pages/editor-page/side-panel/custom-types-section/custom-type-list/custom-type-list-item/custom-type-list-item-header/custom-type-list-item-header.tsx
@@ -51,6 +51,7 @@ export const CustomTypeListItemHeader: React.FC<
highlightCustomTypeId,
tables,
databaseType,
+ readonly,
} = useChartDB();
const { schemasDisplayed } = useDiagramFilter();
const { t } = useTranslation();
@@ -142,15 +143,17 @@ export const CustomTypeListItemHeader: React.FC<
)}
<Highlighter className="size-3.5" />
</DropdownMenuItem>
- <DropdownMenuItem
- onClick={deleteCustomTypeHandler}
- className="flex justify-between !text-red-700"
- >
- {t(
- 'side_panel.custom_types_section.custom_type.custom_type_actions.delete_custom_type'
- )}
- <Trash2 className="size-3.5 text-red-700" />
- </DropdownMenuItem>
+ {!readonly ? (
+ <DropdownMenuItem
+ onClick={deleteCustomTypeHandler}
+ className="flex justify-between !text-red-700"
+ >
+ {t(
+ 'side_panel.custom_types_section.custom_type.custom_type_actions.delete_custom_type'
+ )}
+ <Trash2 className="size-3.5 text-red-700" />
+ </DropdownMenuItem>
+ ) : null}
</DropdownMenuGroup>
</DropdownMenuContent>
</DropdownMenu>
@@ -161,6 +164,7 @@ export const CustomTypeListItemHeader: React.FC<
toggleHighlightCustomType,
canHighlight,
isHighlighted,
+ readonly,
]);
const schemaToDisplay = useMemo(() => {
@@ -171,12 +175,14 @@ export const CustomTypeListItemHeader: React.FC<
return (
<div className="group flex h-11 flex-1 items-center justify-between gap-1 overflow-hidden">
- <div
- className="flex cursor-move items-center justify-center"
- {...listeners}
- >
- <GripVertical className="size-4 text-muted-foreground" />
- </div>
+ {!readonly ? (
+ <div
+ className="flex cursor-move items-center justify-center"
+ {...listeners}
+ >
+ <GripVertical className="size-4 text-muted-foreground" />
+ </div>
+ ) : null}
<div className="flex min-w-0 flex-1 px-1">
{editMode ? (
<Input
@@ -189,7 +195,7 @@ export const CustomTypeListItemHeader: React.FC<
onChange={(e) => setCustomTypeName(e.target.value)}
className="h-7 w-full focus-visible:ring-0"
/>
- ) : (
+ ) : !readonly ? (
<Tooltip>
<TooltipTrigger asChild>
<div
@@ -208,6 +214,13 @@ export const CustomTypeListItemHeader: React.FC<
{t('tool_tips.double_click_to_edit')}
</TooltipContent>
</Tooltip>
+ ) : (
+ <div className="truncate px-2 py-0.5">
+ {customType.name}
+ <span className="text-xs text-muted-foreground">
+ {schemaToDisplay ? ` (${schemaToDisplay})` : ''}
+ </span>
+ </div>
)}
</div>
<div className="flex flex-row-reverse items-center">
@@ -222,11 +235,13 @@ export const CustomTypeListItemHeader: React.FC<
{customTypeKindToLabel[customType.kind]}
</Badge>
) : null}
- <div className="flex flex-row-reverse md:hidden md:group-hover:flex">
- <ListItemHeaderButton onClick={enterEditMode}>
- <Pencil />
- </ListItemHeaderButton>
- </div>
+ {!readonly ? (
+ <div className="flex flex-row-reverse md:hidden md:group-hover:flex">
+ <ListItemHeaderButton onClick={enterEditMode}>
+ <Pencil />
+ </ListItemHeaderButton>
+ </div>
+ ) : null}
</>
) : (
<ListItemHeaderButton onClick={editCustomTypeName}>
diff --git a/src/pages/editor-page/side-panel/custom-types-section/custom-types-section.tsx b/src/pages/editor-page/side-panel/custom-types-section/custom-types-section.tsx
index e350cac8..6040ebaf 100644
--- a/src/pages/editor-page/side-panel/custom-types-section/custom-types-section.tsx
+++ b/src/pages/editor-page/side-panel/custom-types-section/custom-types-section.tsx
@@ -7,18 +7,15 @@ import { EmptyState } from '@/components/empty-state/empty-state';
import { ScrollArea } from '@/components/scroll-area/scroll-area';
import { useTranslation } from 'react-i18next';
import { CustomTypeList } from './custom-type-list/custom-type-list';
-import { DatabaseType } from '@/lib/domain/database-type';
export interface CustomTypesSectionProps {}
export const CustomTypesSection: React.FC<CustomTypesSectionProps> = () => {
const { t } = useTranslation();
- const { customTypes, createCustomType, databaseType } = useChartDB();
+ const { customTypes, createCustomType, readonly } = useChartDB();
const [filterText, setFilterText] = React.useState('');
const filterInputRef = React.useRef<HTMLInputElement>(null);
- const isPostgres = databaseType === DatabaseType.POSTGRESQL;
-
const filteredCustomTypes = useMemo(() => {
return customTypes.filter(
(type) =>
@@ -53,7 +50,7 @@ export const CustomTypesSection: React.FC<CustomTypesSectionProps> = () => {
onChange={(e) => setFilterText(e.target.value)}
/>
</div>
- {isPostgres && (
+ {!readonly ? (
<Button
variant="secondary"
size="sm"
@@ -63,7 +60,7 @@ export const CustomTypesSection: React.FC<CustomTypesSectionProps> = () => {
<Plus className="mr-1 size-4" />
New Type
</Button>
- )}
+ ) : null}
</div>
<div className="flex flex-1 flex-col overflow-hidden">
<ScrollArea className="h-full">
diff --git a/src/pages/editor-page/side-panel/dbml-section/table-dbml/table-dbml.tsx b/src/pages/editor-page/side-panel/dbml-section/table-dbml/table-dbml.tsx
index b5bae139..e2e5e671 100644
--- a/src/pages/editor-page/side-panel/dbml-section/table-dbml/table-dbml.tsx
+++ b/src/pages/editor-page/side-panel/dbml-section/table-dbml/table-dbml.tsx
@@ -42,7 +42,8 @@ const getEditorTheme = (theme: EffectiveTheme) => {
};
export const TableDBML: React.FC<TableDBMLProps> = () => {
- const { currentDiagram, updateDiagramData, databaseType } = useChartDB();
+ const { currentDiagram, updateDiagramData, databaseType, readonly } =
+ useChartDB();
const { effectiveTheme } = useTheme();
const { toast } = useToast();
const [dbmlFormat, setDbmlFormat] = useState<'inline' | 'standard'>(
@@ -368,15 +369,21 @@ export const TableDBML: React.FC<TableDBMLProps> = () => {
icon: ArrowLeftRight,
onClick: toggleFormat,
},
- {
- label: 'Edit',
- icon: Pencil,
- onClick: () =>
- setIsEditMode((prev) => !prev),
- className: isEditButtonEmphasized
- ? 'dbml-edit-button-emphasis'
- : undefined,
- },
+ ...(!readonly
+ ? [
+ {
+ label: 'Edit',
+ icon: Pencil,
+ onClick: () =>
+ setIsEditMode(
+ (prev) => !prev
+ ),
+ className: isEditButtonEmphasized
+ ? 'dbml-edit-button-emphasis'
+ : undefined,
+ },
+ ]
+ : []),
]
}
editorProps={{
diff --git a/src/pages/editor-page/side-panel/refs-section/refs-list/relationship-list-item/relationship-list-item-content/relationship-list-item-content.tsx b/src/pages/editor-page/side-panel/refs-section/refs-list/relationship-list-item/relationship-list-item-content/relationship-list-item-content.tsx
index 984d857c..32a1b86d 100644
--- a/src/pages/editor-page/side-panel/refs-section/refs-list/relationship-list-item/relationship-list-item-content/relationship-list-item-content.tsx
+++ b/src/pages/editor-page/side-panel/refs-section/refs-list/relationship-list-item/relationship-list-item-content/relationship-list-item-content.tsx
@@ -38,8 +38,13 @@ export interface RelationshipListItemContentProps {
export const RelationshipListItemContent: React.FC<
RelationshipListItemContentProps
> = ({ relationship }) => {
- const { getTable, getField, updateRelationship, removeRelationship } =
- useChartDB();
+ const {
+ getTable,
+ getField,
+ updateRelationship,
+ removeRelationship,
+ readonly,
+ } = useChartDB();
const { deleteElements } = useReactFlow();
const { t } = useTranslation();
const relationshipType = useMemo(
@@ -83,7 +88,7 @@ export const RelationshipListItemContent: React.FC<
}, [relationship.id, removeRelationship, deleteElements]);
return (
- <div className="my-1 flex flex-col rounded-b-md px-1">
+ <div className="my-1 flex flex-col rounded-b-md px-1 py-2">
<div className="flex flex-col gap-6">
<div className="flex items-center justify-between gap-1 text-xs">
<div className="flex basis-1/2 flex-col gap-2 overflow-hidden text-xs">
@@ -152,6 +157,7 @@ export const RelationshipListItemContent: React.FC<
<Select
value={relationshipType}
onValueChange={updateCardinalities}
+ disabled={readonly}
>
<SelectTrigger className="h-8">
<SelectValue />
@@ -175,20 +181,22 @@ export const RelationshipListItemContent: React.FC<
</Select>
</div>
</div>
- <div className="flex flex-1 items-center justify-center pt-2">
- <Button
- variant="ghost"
- className="h-8 p-2 text-xs"
- onClick={deleteRelationshipHandler}
- >
- <Trash2 className="mr-1 size-3.5 text-red-700" />
- <div className="text-red-700">
- {t(
- 'side_panel.refs_section.relationship.delete_relationship'
- )}
- </div>
- </Button>
- </div>
+ {!readonly ? (
+ <div className="flex flex-1 items-center justify-center pt-2">
+ <Button
+ variant="ghost"
+ className="h-8 p-2 text-xs"
+ onClick={deleteRelationshipHandler}
+ >
+ <Trash2 className="mr-1 size-3.5 text-red-700" />
+ <div className="text-red-700">
+ {t(
+ 'side_panel.refs_section.relationship.delete_relationship'
+ )}
+ </div>
+ </Button>
+ </div>
+ ) : null}
</div>
);
};
diff --git a/src/pages/editor-page/side-panel/refs-section/refs-list/relationship-list-item/relationship-list-item-header/relationship-list-item-header.tsx b/src/pages/editor-page/side-panel/refs-section/refs-list/relationship-list-item/relationship-list-item-header/relationship-list-item-header.tsx
index f2079a5e..3c338e52 100644
--- a/src/pages/editor-page/side-panel/refs-section/refs-list/relationship-list-item/relationship-list-item-header/relationship-list-item-header.tsx
+++ b/src/pages/editor-page/side-panel/refs-section/refs-list/relationship-list-item/relationship-list-item-header/relationship-list-item-header.tsx
@@ -32,7 +32,7 @@ export interface RelationshipListItemHeaderProps {
export const RelationshipListItemHeader: React.FC<
RelationshipListItemHeaderProps
> = ({ relationship }) => {
- const { updateRelationship, removeRelationship } = useChartDB();
+ const { updateRelationship, removeRelationship, readonly } = useChartDB();
const { fitView, deleteElements, setEdges } = useReactFlow();
const { t } = useTranslation();
const { hideSidePanel } = useLayout();
@@ -175,11 +175,13 @@ export const RelationshipListItemHeader: React.FC<
<div className="flex flex-row-reverse items-center">
{!editMode ? (
<>
- <div>{renderDropDownMenu()}</div>
+ {!readonly ? <div>{renderDropDownMenu()}</div> : null}
<div className="flex flex-row-reverse md:hidden md:group-hover:flex">
- <ListItemHeaderButton onClick={enterEditMode}>
- <Pencil />
- </ListItemHeaderButton>
+ {!readonly ? (
+ <ListItemHeaderButton onClick={enterEditMode}>
+ <Pencil />
+ </ListItemHeaderButton>
+ ) : null}
<ListItemHeaderButton onClick={focusOnRelationship}>
<CircleDotDashed />
</ListItemHeaderButton>
diff --git a/src/pages/editor-page/side-panel/refs-section/refs-section.tsx b/src/pages/editor-page/side-panel/refs-section/refs-section.tsx
index 34f005e6..8fa68b24 100644
--- a/src/pages/editor-page/side-panel/refs-section/refs-section.tsx
+++ b/src/pages/editor-page/side-panel/refs-section/refs-section.tsx
@@ -36,7 +36,7 @@ export interface Ref {
export interface RefsSectionProps {}
export const RefsSection: React.FC<RefsSectionProps> = () => {
- const { relationships, dependencies, databaseType, getTable } =
+ const { relationships, dependencies, databaseType, getTable, readonly } =
useChartDB();
const { filter } = useDiagramFilter();
const [filterText, setFilterText] = React.useState('');
@@ -194,14 +194,16 @@ export const RefsSection: React.FC<RefsSectionProps> = () => {
onChange={(e) => setFilterText(e.target.value)}
/>
</div>
- <Button
- variant="secondary"
- className="h-8 p-2 text-xs"
- onClick={handleCreateRelationship}
- >
- <Workflow className="h-4" />
- {t('side_panel.refs_section.add_relationship')}
- </Button>
+ {!readonly ? (
+ <Button
+ variant="secondary"
+ className="h-8 p-2 text-xs"
+ onClick={handleCreateRelationship}
+ >
+ <Workflow className="h-4" />
+ {t('side_panel.refs_section.add_relationship')}
+ </Button>
+ ) : null}
</div>
<div className="flex flex-1 flex-col overflow-hidden">
<ScrollArea className="h-full">
diff --git a/src/pages/editor-page/side-panel/tables-section/table-list/table-list-item/table-list-item-content/table-field/table-field-modal/table-field-modal.tsx b/src/pages/editor-page/side-panel/tables-section/table-list/table-list-item/table-list-item-content/table-field/table-field-modal/table-field-modal.tsx
index d94abd8a..0151170c 100644
--- a/src/pages/editor-page/side-panel/tables-section/table-list/table-list-item/table-list-item-content/table-field/table-field-modal/table-field-modal.tsx
+++ b/src/pages/editor-page/side-panel/tables-section/table-list/table-list-item/table-list-item-content/table-field/table-field-modal/table-field-modal.tsx
@@ -29,6 +29,7 @@ import {
SelectTrigger,
SelectValue,
} from '@/components/select/select';
+import { useChartDB } from '@/hooks/use-chartdb';
export interface TableFieldPopoverProps {
field: DBField;
@@ -45,6 +46,7 @@ export const TableFieldPopover: React.FC<TableFieldPopoverProps> = ({
updateField,
removeField,
}) => {
+ const { readonly } = useChartDB();
const { t } = useTranslation();
const [localField, setLocalField] = React.useState<DBField>(field);
const [isOpen, setIsOpen] = React.useState(false);
@@ -137,7 +139,7 @@ export const TableFieldPopover: React.FC<TableFieldPopoverProps> = ({
</Label>
<Checkbox
checked={localField.unique}
- disabled={isOnlyPrimaryKey}
+ disabled={isOnlyPrimaryKey || readonly}
onCheckedChange={(value) =>
setLocalField((current) => ({
...current,
@@ -158,7 +160,9 @@ export const TableFieldPopover: React.FC<TableFieldPopoverProps> = ({
</Label>
<Checkbox
checked={localField.increment ?? false}
- disabled={!localField.primaryKey}
+ disabled={
+ !localField.primaryKey || readonly
+ }
onCheckedChange={(value) =>
setLocalField((current) => ({
...current,
@@ -186,6 +190,7 @@ export const TableFieldPopover: React.FC<TableFieldPopoverProps> = ({
'side_panel.tables_section.table.field_actions.no_default'
)}
className="w-full rounded-md bg-muted text-sm"
+ readOnly={readonly}
/>
</div>
{dataFieldType?.fieldAttributes?.hasCharMaxLength ? (
@@ -237,6 +242,7 @@ export const TableFieldPopover: React.FC<TableFieldPopoverProps> = ({
);
}
}}
+ disabled={readonly}
>
<SelectTrigger className="w-full bg-muted">
<SelectValue placeholder="Select length" />
@@ -277,6 +283,7 @@ export const TableFieldPopover: React.FC<TableFieldPopoverProps> = ({
)
}
className="w-24 rounded-md bg-muted text-sm"
+ readOnly={readonly}
/>
) : null}
</div>
@@ -295,6 +302,7 @@ export const TableFieldPopover: React.FC<TableFieldPopoverProps> = ({
}))
}
className="w-full rounded-md bg-muted text-sm"
+ readOnly={readonly}
/>
)}
</div>
@@ -349,6 +357,7 @@ export const TableFieldPopover: React.FC<TableFieldPopoverProps> = ({
}))
}
className="w-full rounded-md bg-muted text-sm"
+ readOnly={readonly}
/>
</div>
<div className="flex flex-1 flex-col gap-2">
@@ -399,6 +408,7 @@ export const TableFieldPopover: React.FC<TableFieldPopoverProps> = ({
}))
}
className="w-full rounded-md bg-muted text-sm"
+ readOnly={readonly}
/>
</div>
</div>
@@ -421,20 +431,25 @@ export const TableFieldPopover: React.FC<TableFieldPopoverProps> = ({
'side_panel.tables_section.table.field_actions.no_comments'
)}
className="w-full rounded-md bg-muted text-sm"
+ readOnly={readonly}
/>
</div>
</div>
- <Separator orientation="horizontal" />
- <Button
- variant="outline"
- className="flex gap-2 !text-red-700"
- onClick={removeField}
- >
- <Trash2 className="size-3.5 text-red-700" />
- {t(
- 'side_panel.tables_section.table.field_actions.delete_field'
- )}
- </Button>
+ {!readonly ? (
+ <>
+ <Separator orientation="horizontal" />
+ <Button
+ variant="outline"
+ className="flex gap-2 !text-red-700"
+ onClick={removeField}
+ >
+ <Trash2 className="size-3.5 text-red-700" />
+ {t(
+ 'side_panel.tables_section.table.field_actions.delete_field'
+ )}
+ </Button>
+ </>
+ ) : null}
</div>
</PopoverContent>
</Popover>
diff --git a/src/pages/editor-page/side-panel/tables-section/table-list/table-list-item/table-list-item-content/table-field/table-field.tsx b/src/pages/editor-page/side-panel/tables-section/table-list/table-list-item/table-list-item-content/table-field/table-field.tsx
index daeca681..7c1219ac 100644
--- a/src/pages/editor-page/side-panel/tables-section/table-list/table-list-item/table-list-item-content/table-field/table-field.tsx
+++ b/src/pages/editor-page/side-panel/tables-section/table-list/table-list-item/table-list-item-content/table-field/table-field.tsx
@@ -83,7 +83,7 @@ export const TableField: React.FC<TableFieldProps> = ({
updateField,
removeField,
}) => {
- const { databaseType, customTypes } = useChartDB();
+ const { databaseType, customTypes, readonly } = useChartDB();
const { t } = useTranslation();
// Only calculate primary key fields, not just count
@@ -247,12 +247,14 @@ export const TableField: React.FC<TableFieldProps> = ({
{...attributes}
>
<div className="flex flex-1 items-center justify-start gap-1 overflow-hidden">
- <div
- className="flex w-4 shrink-0 cursor-move items-center justify-center"
- {...listeners}
- >
- <GripVertical className="size-3.5 text-muted-foreground" />
- </div>
+ {!readonly ? (
+ <div
+ className="flex w-4 shrink-0 cursor-move items-center justify-center"
+ {...listeners}
+ >
+ <GripVertical className="size-3.5 text-muted-foreground" />
+ </div>
+ ) : null}
<Tooltip>
<TooltipTrigger asChild>
<span className="min-w-0 flex-1">
@@ -264,6 +266,7 @@ export const TableField: React.FC<TableFieldProps> = ({
)}
value={field.name}
onChange={handleNameChange}
+ readOnly={readonly}
/>
</span>
</TooltipTrigger>
@@ -292,6 +295,7 @@ export const TableField: React.FC<TableFieldProps> = ({
emptyPlaceholder={t(
'side_panel.tables_section.table.no_types_found'
)}
+ readonly={readonly}
/>
</span>
</TooltipTrigger>
@@ -310,6 +314,7 @@ export const TableField: React.FC<TableFieldProps> = ({
<TableFieldToggle
pressed={field.nullable}
onPressedChange={handleNullableToggle}
+ disabled={readonly}
>
N
</TableFieldToggle>
@@ -325,6 +330,7 @@ export const TableField: React.FC<TableFieldProps> = ({
<TableFieldToggle
pressed={field.primaryKey}
onPressedChange={handlePrimaryKeyToggle}
+ disabled={readonly}
>
<KeyRound className="h-3.5" />
</TableFieldToggle>
diff --git a/src/pages/editor-page/side-panel/tables-section/table-list/table-list-item/table-list-item-content/table-index/table-index.tsx b/src/pages/editor-page/side-panel/tables-section/table-list/table-list-item/table-list-item-content/table-index/table-index.tsx
index dbf754f7..29179962 100644
--- a/src/pages/editor-page/side-panel/tables-section/table-list/table-list-item/table-list-item-content/table-index/table-index.tsx
+++ b/src/pages/editor-page/side-panel/tables-section/table-list/table-list-item/table-list-item-content/table-index/table-index.tsx
@@ -45,7 +45,7 @@ export const TableIndex: React.FC<TableIndexProps> = ({
removeIndex,
}) => {
const { t } = useTranslation();
- const { databaseType } = useChartDB();
+ const { databaseType, readonly } = useChartDB();
const fieldOptions = fields.map((field) => ({
label: field.name,
value: field.id,
@@ -107,6 +107,7 @@ export const TableIndex: React.FC<TableIndexProps> = ({
)}
keepOrder
disabled={index.isPrimaryKey ?? false}
+ readonly={readonly}
/>
<div className="flex shrink-0 gap-1">
{index.isPrimaryKey ? (
@@ -133,6 +134,7 @@ export const TableIndex: React.FC<TableIndexProps> = ({
unique: !!value,
})
}
+ disabled={readonly}
>
U
</TableIndexToggle>
@@ -178,6 +180,7 @@ export const TableIndex: React.FC<TableIndexProps> = ({
name: value.target.value,
})
}
+ readOnly={readonly}
/>
</div>
{!index.isPrimaryKey ? (
@@ -198,6 +201,7 @@ export const TableIndex: React.FC<TableIndexProps> = ({
unique: !!value,
})
}
+ disabled={readonly}
/>
</div>
{indexTypeOptions.length > 0 ? (
@@ -214,20 +218,25 @@ export const TableIndex: React.FC<TableIndexProps> = ({
options={indexTypeOptions}
value={index.type || 'btree'}
onChange={updateIndexType}
+ readonly={readonly}
/>
</div>
) : null}
- <Separator orientation="horizontal" />
- <Button
- variant="outline"
- className="flex gap-2 !text-red-700"
- onClick={removeIndex}
- >
- <Trash2 className="size-3.5 text-red-700" />
- {t(
- 'side_panel.tables_section.table.index_actions.delete_index'
- )}
- </Button>
+ {!readonly ? (
+ <>
+ <Separator orientation="horizontal" />
+ <Button
+ variant="outline"
+ className="flex gap-2 !text-red-700"
+ onClick={removeIndex}
+ >
+ <Trash2 className="size-3.5 text-red-700" />
+ {t(
+ 'side_panel.tables_section.table.index_actions.delete_index'
+ )}
+ </Button>
+ </>
+ ) : null}
</>
) : null}
</div>
diff --git a/src/pages/editor-page/side-panel/tables-section/table-list/table-list-item/table-list-item-content/table-list-item-content.tsx b/src/pages/editor-page/side-panel/tables-section/table-list/table-list-item/table-list-item-content/table-list-item-content.tsx
index 309562ee..640f6d58 100644
--- a/src/pages/editor-page/side-panel/tables-section/table-list/table-list-item/table-list-item-content/table-list-item-content.tsx
+++ b/src/pages/editor-page/side-panel/tables-section/table-list/table-list-item/table-list-item-content/table-list-item-content.tsx
@@ -48,6 +48,7 @@ export const TableListItemContent: React.FC<TableListItemContentProps> = ({
removeIndex,
updateIndex,
updateTable,
+ readonly,
} = useChartDB();
const { t } = useTranslation();
const { color } = table;
@@ -146,17 +147,19 @@ export const TableListItemContent: React.FC<TableListItemContentProps> = ({
<FileType2 className="size-4" />
{t('side_panel.tables_section.table.fields')}
</div>
- <div className="flex flex-row-reverse">
- <div className="hidden flex-row-reverse group-hover:flex">
- <Button
- variant="ghost"
- className="size-4 p-0 text-xs hover:bg-primary-foreground"
- onClick={createFieldHandler}
- >
- <Plus className="size-4 shrink-0 text-muted-foreground transition-transform duration-200" />
- </Button>
+ {!readonly ? (
+ <div className="flex flex-row-reverse">
+ <div className="hidden flex-row-reverse group-hover:flex">
+ <Button
+ variant="ghost"
+ className="size-4 p-0 text-xs hover:bg-primary-foreground"
+ onClick={createFieldHandler}
+ >
+ <Plus className="size-4 shrink-0 text-muted-foreground transition-transform duration-200" />
+ </Button>
+ </div>
</div>
- </div>
+ ) : null}
</div>
</AccordionTrigger>
<AccordionContent className="flex flex-col pb-0 pt-1">
@@ -183,18 +186,20 @@ export const TableListItemContent: React.FC<TableListItemContentProps> = ({
/>
))}
</SortableContext>
- <div className="flex justify-start p-1">
- <Button
- variant="ghost"
- className="flex h-7 items-center gap-1 px-2 text-xs"
- onClick={createFieldHandler}
- >
- <Plus className="size-4 text-muted-foreground" />
- {t(
- 'side_panel.tables_section.table.add_field'
- )}
- </Button>
- </div>
+ {!readonly ? (
+ <div className="flex justify-start p-1">
+ <Button
+ variant="ghost"
+ className="flex h-7 items-center gap-1 px-2 text-xs"
+ onClick={createFieldHandler}
+ >
+ <Plus className="size-4 text-muted-foreground" />
+ {t(
+ 'side_panel.tables_section.table.add_field'
+ )}
+ </Button>
+ </div>
+ ) : null}
</DndContext>
</AccordionContent>
</AccordionItem>
@@ -210,17 +215,19 @@ export const TableListItemContent: React.FC<TableListItemContentProps> = ({
<FileKey2 className="size-4" />
{t('side_panel.tables_section.table.indexes')}
</div>
- <div className="flex flex-row-reverse">
- <div className="hidden flex-row-reverse group-hover:flex">
- <Button
- variant="ghost"
- className="size-4 p-0 text-xs hover:bg-primary-foreground"
- onClick={createIndexHandler}
- >
- <Plus className="size-4 shrink-0 text-muted-foreground transition-transform duration-200" />
- </Button>
+ {!readonly ? (
+ <div className="flex flex-row-reverse">
+ <div className="hidden flex-row-reverse group-hover:flex">
+ <Button
+ variant="ghost"
+ className="size-4 p-0 text-xs hover:bg-primary-foreground"
+ onClick={createIndexHandler}
+ >
+ <Plus className="size-4 shrink-0 text-muted-foreground transition-transform duration-200" />
+ </Button>
+ </div>
</div>
- </div>
+ ) : null}
</div>
</AccordionTrigger>
<AccordionContent className="pb-0 pt-1">
@@ -245,16 +252,21 @@ export const TableListItemContent: React.FC<TableListItemContentProps> = ({
fields={table.fields}
/>
))}
- <div className="flex justify-start p-1">
- <Button
- variant="ghost"
- className="flex h-7 items-center gap-1 px-2 text-xs"
- onClick={createIndexHandler}
- >
- <Plus className="size-4 text-muted-foreground" />
- {t('side_panel.tables_section.table.add_index')}
- </Button>
- </div>
+
+ {!readonly ? (
+ <div className="flex justify-start p-1">
+ <Button
+ variant="ghost"
+ className="flex h-7 items-center gap-1 px-2 text-xs"
+ onClick={createIndexHandler}
+ >
+ <Plus className="size-4 text-muted-foreground" />
+ {t(
+ 'side_panel.tables_section.table.add_index'
+ )}
+ </Button>
+ </div>
+ ) : null}
</AccordionContent>
</AccordionItem>
@@ -283,13 +295,15 @@ export const TableListItemContent: React.FC<TableListItemContentProps> = ({
'side_panel.tables_section.table.no_comments'
)}
className="w-full rounded-md bg-muted text-sm focus-visible:ring-0"
+ readOnly={readonly}
/>
</AccordionContent>
</AccordionItem>
</Accordion>
- <Separator className="" />
+ {!readonly ? <Separator className="" /> : null}
+
<div className="flex flex-1 items-center justify-between">
- {!table.isView ? (
+ {!table.isView && !readonly ? (
<ColorPicker
color={color}
onChange={(color) => updateTable(table.id, { color })}
@@ -298,24 +312,26 @@ export const TableListItemContent: React.FC<TableListItemContentProps> = ({
<div />
)}
- <div className="flex gap-1">
- <Button
- variant="outline"
- className="h-8 p-2 text-xs"
- onClick={createIndexHandler}
- >
- <FileKey2 className="h-4" />
- {t('side_panel.tables_section.table.add_index')}
- </Button>
- <Button
- variant="outline"
- className="h-8 p-2 text-xs"
- onClick={createFieldHandler}
- >
- <FileType2 className="h-4" />
- {t('side_panel.tables_section.table.add_field')}
- </Button>
- </div>
+ {!readonly ? (
+ <div className="flex gap-1">
+ <Button
+ variant="outline"
+ className="h-8 p-2 text-xs"
+ onClick={createIndexHandler}
+ >
+ <FileKey2 className="h-4" />
+ {t('side_panel.tables_section.table.add_index')}
+ </Button>
+ <Button
+ variant="outline"
+ className="h-8 p-2 text-xs"
+ onClick={createFieldHandler}
+ >
+ <FileType2 className="h-4" />
+ {t('side_panel.tables_section.table.add_field')}
+ </Button>
+ </div>
+ ) : null}
</div>
</div>
);
diff --git a/src/pages/editor-page/side-panel/tables-section/table-list/table-list-item/table-list-item-header/table-list-item-header.tsx b/src/pages/editor-page/side-panel/tables-section/table-list/table-list-item/table-list-item-header/table-list-item-header.tsx
index b2fefde1..70d55001 100644
--- a/src/pages/editor-page/side-panel/tables-section/table-list/table-list-item/table-list-item-header/table-list-item-header.tsx
+++ b/src/pages/editor-page/side-panel/tables-section/table-list/table-list-item/table-list-item-header/table-list-item-header.tsx
@@ -57,6 +57,7 @@ export const TableListItemHeader: React.FC<TableListItemHeaderProps> = ({
createTable,
schemas,
databaseType,
+ readonly,
} = useChartDB();
const { schemasDisplayed } = useDiagramFilter();
const { openTableSchemaDialog } = useDialog();
@@ -280,12 +281,14 @@ export const TableListItemHeader: React.FC<TableListItemHeaderProps> = ({
return (
<div className="group flex h-11 flex-1 items-center justify-between gap-1 overflow-hidden">
- <div
- className="flex cursor-move items-center justify-center"
- {...listeners}
- >
- <GripVertical className="size-4 text-muted-foreground" />
- </div>
+ {!readonly ? (
+ <div
+ className="flex cursor-move items-center justify-center"
+ {...listeners}
+ >
+ <GripVertical className="size-4 text-muted-foreground" />
+ </div>
+ ) : null}
<div className="flex min-w-0 flex-1 px-1">
{editMode ? (
<Input
@@ -298,7 +301,7 @@ export const TableListItemHeader: React.FC<TableListItemHeaderProps> = ({
onChange={(e) => setTableName(e.target.value)}
className="h-7 w-full focus-visible:ring-0"
/>
- ) : (
+ ) : !readonly ? (
<Tooltip>
<TooltipTrigger asChild>
<div
@@ -317,16 +320,25 @@ export const TableListItemHeader: React.FC<TableListItemHeaderProps> = ({
{t('tool_tips.double_click_to_edit')}
</TooltipContent>
</Tooltip>
+ ) : (
+ <div className="truncate px-2 py-0.5">
+ {table.name}
+ <span className="text-xs text-muted-foreground">
+ {schemaToDisplay ? ` (${schemaToDisplay})` : ''}
+ </span>
+ </div>
)}
</div>
<div className="flex flex-row-reverse">
{!editMode ? (
<>
- <div>{renderDropDownMenu()}</div>
+ {!readonly ? <div>{renderDropDownMenu()}</div> : null}
<div className="flex flex-row-reverse md:hidden md:group-hover:flex">
- <ListItemHeaderButton onClick={enterEditMode}>
- <Pencil />
- </ListItemHeaderButton>
+ {!readonly ? (
+ <ListItemHeaderButton onClick={enterEditMode}>
+ <Pencil />
+ </ListItemHeaderButton>
+ ) : null}
<ListItemHeaderButton onClick={focusOnTable}>
<CircleDotDashed />
</ListItemHeaderButton>
diff --git a/src/pages/editor-page/side-panel/tables-section/tables-section.tsx b/src/pages/editor-page/side-panel/tables-section/tables-section.tsx
index 5164ff71..44c3faae 100644
--- a/src/pages/editor-page/side-panel/tables-section/tables-section.tsx
+++ b/src/pages/editor-page/side-panel/tables-section/tables-section.tsx
@@ -21,7 +21,7 @@ import { useLocalConfig } from '@/hooks/use-local-config';
export interface TablesSectionProps {}
export const TablesSection: React.FC<TablesSectionProps> = () => {
- const { createTable, tables, databaseType } = useChartDB();
+ const { createTable, tables, databaseType, readonly } = useChartDB();
const { filter, schemasDisplayed } = useDiagramFilter();
const { openTableSchemaDialog } = useDialog();
const viewport = useViewport();
@@ -145,31 +145,33 @@ export const TablesSection: React.FC<TablesSectionProps> = () => {
onChange={(e) => setFilterText(e.target.value)}
/>
</div>
- <ButtonWithAlternatives
- variant="secondary"
- className="h-8 p-2 text-xs"
- onClick={() => handleCreateTable({ view: false })}
- dropdownTriggerClassName="px-1"
- chevronDownIconClassName="!size-3.5"
- alternatives={
- showDBViews
- ? [
- {
- label: t(
- 'side_panel.tables_section.add_view'
- ),
- onClick: () =>
- handleCreateTable({ view: true }),
- icon: <View className="size-4" />,
- className: 'text-xs',
- },
- ]
- : []
- }
- >
- <Table className="h-4" />
- {t('side_panel.tables_section.add_table')}
- </ButtonWithAlternatives>
+ {!readonly ? (
+ <ButtonWithAlternatives
+ variant="secondary"
+ className="h-8 p-2 text-xs"
+ onClick={() => handleCreateTable({ view: false })}
+ dropdownTriggerClassName="px-1"
+ chevronDownIconClassName="!size-3.5"
+ alternatives={
+ showDBViews
+ ? [
+ {
+ label: t(
+ 'side_panel.tables_section.add_view'
+ ),
+ onClick: () =>
+ handleCreateTable({ view: true }),
+ icon: <View className="size-4" />,
+ className: 'text-xs',
+ },
+ ]
+ : []
+ }
+ >
+ <Table className="h-4" />
+ {t('side_panel.tables_section.add_table')}
+ </ButtonWithAlternatives>
+ ) : null}
</div>
<div className="flex flex-1 flex-col overflow-hidden">
<ScrollArea className="h-full">