Skip to content

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

feat(custom-types): add highlight fields option for custom types (#726)

Jonathan Fishner7e0483f1a551
diff --git a/src/context/chartdb-context/chartdb-context.tsx b/src/context/chartdb-context/chartdb-context.tsx
index 5a816d32..b49a00ea 100644
--- a/src/context/chartdb-context/chartdb-context.tsx
+++ b/src/context/chartdb-context/chartdb-context.tsx
@@ -78,6 +78,9 @@ export interface ChartDBContext {
events: EventEmitter<ChartDBEvent>;
readonly?: boolean;
+ highlightedCustomType?: DBCustomType;
+ highlightCustomTypeId: (id?: string) => void;
+
filteredSchemas?: string[];
filterSchemas: (schemaIds: string[]) => void;
@@ -294,6 +297,7 @@ export const chartDBContext = createContext<ChartDBContext>({
areas: [],
customTypes: [],
schemas: [],
+ highlightCustomTypeId: emptyFn,
filteredSchemas: [],
filterSchemas: emptyFn,
currentDiagram: {
diff --git a/src/context/chartdb-context/chartdb-provider.tsx b/src/context/chartdb-context/chartdb-provider.tsx
index 24826b55..d7d68f11 100644
--- a/src/context/chartdb-context/chartdb-provider.tsx
+++ b/src/context/chartdb-context/chartdb-provider.tsx
@@ -74,6 +74,9 @@ export const ChartDBProvider: React.FC<
const [hiddenTableIds, setHiddenTableIds] = useState<string[]>([]);
const { events: diffEvents } = useDiff();
+ const [highlightedCustomTypeId, setHighlightedCustomTypeId] =
+ useState<string>();
+
const diffCalculatedHandler = useCallback((event: DiffCalculatedEvent) => {
const { tablesAdded, fieldsAdded, relationshipsAdded } = event.data;
setTables((tables) =>
@@ -1531,22 +1534,37 @@ export const ChartDBProvider: React.FC<
[db, diagramId, setAreas, getArea, addUndoAction, resetRedoStack]
);
+ const highlightCustomTypeId = useCallback(
+ (id?: string) => setHighlightedCustomTypeId(id),
+ [setHighlightedCustomTypeId]
+ );
+
+ const highlightedCustomType = useMemo(() => {
+ return highlightedCustomTypeId
+ ? customTypes.find((type) => type.id === highlightedCustomTypeId)
+ : undefined;
+ }, [highlightedCustomTypeId, customTypes]);
+
const loadDiagramFromData: ChartDBContext['loadDiagramFromData'] =
useCallback(
- async (diagram) => {
+ (diagram) => {
setDiagramId(diagram.id);
setDiagramName(diagram.name);
setDatabaseType(diagram.databaseType);
setDatabaseEdition(diagram.databaseEdition);
- setTables(diagram?.tables ?? []);
- setRelationships(diagram?.relationships ?? []);
- setDependencies(diagram?.dependencies ?? []);
- setAreas(diagram?.areas ?? []);
- setCustomTypes(diagram?.customTypes ?? []);
+ setTables(diagram.tables ?? []);
+ setRelationships(diagram.relationships ?? []);
+ setDependencies(diagram.dependencies ?? []);
+ setAreas(diagram.areas ?? []);
+ setCustomTypes(diagram.customTypes ?? []);
setDiagramCreatedAt(diagram.createdAt);
setDiagramUpdatedAt(diagram.updatedAt);
+ setHighlightedCustomTypeId(undefined);
events.emit({ action: 'load_diagram', data: { diagram } });
+
+ resetRedoStack();
+ resetUndoStack();
},
[
setDiagramId,
@@ -1560,7 +1578,10 @@ export const ChartDBProvider: React.FC<
setCustomTypes,
setDiagramCreatedAt,
setDiagramUpdatedAt,
+ setHighlightedCustomTypeId,
events,
+ resetRedoStack,
+ resetUndoStack,
]
);
@@ -1825,6 +1846,8 @@ export const ChartDBProvider: React.FC<
hiddenTableIds,
addHiddenTableId,
removeHiddenTableId,
+ highlightCustomTypeId,
+ highlightedCustomType,
}}
>
{children}
diff --git a/src/i18n/locales/ar.ts b/src/i18n/locales/ar.ts
index 217be640..a87eba44 100644
--- a/src/i18n/locales/ar.ts
+++ b/src/i18n/locales/ar.ts
@@ -257,9 +257,12 @@ export const ar: LanguageTranslation = {
field_name_placeholder: 'Field name',
field_type_placeholder: 'Select type',
add_field: 'Add Field',
+ no_fields_tooltip: 'No fields defined for this custom type',
custom_type_actions: {
title: 'Actions',
+ highlight_fields: 'Highlight Fields',
delete_custom_type: 'Delete',
+ clear_field_highlight: 'Clear Highlight',
},
delete_custom_type: 'Delete Type',
},
@@ -277,6 +280,9 @@ export const ar: LanguageTranslation = {
highlight_overlapping_tables: 'تمييز الجداول المتداخلة',
// TODO: Translate
filter: 'Filter Tables',
+ clear_custom_type_highlight: 'Clear highlight for "{{typeName}}"',
+ custom_type_highlight_tooltip:
+ 'Highlighting "{{typeName}}" - Click to clear',
},
new_diagram_dialog: {
diff --git a/src/i18n/locales/bn.ts b/src/i18n/locales/bn.ts
index d7e202b1..8d0b3edf 100644
--- a/src/i18n/locales/bn.ts
+++ b/src/i18n/locales/bn.ts
@@ -258,9 +258,12 @@ export const bn: LanguageTranslation = {
field_name_placeholder: 'Field name',
field_type_placeholder: 'Select type',
add_field: 'Add Field',
+ no_fields_tooltip: 'No fields defined for this custom type',
custom_type_actions: {
title: 'Actions',
+ highlight_fields: 'Highlight Fields',
delete_custom_type: 'Delete',
+ clear_field_highlight: 'Clear Highlight',
},
delete_custom_type: 'Delete Type',
},
@@ -276,7 +279,11 @@ export const bn: LanguageTranslation = {
redo: 'পুনরায় করুন',
reorder_diagram: 'ডায়াগ্রাম পুনর্বিন্যাস করুন',
highlight_overlapping_tables: 'ওভারল্যাপিং টেবিল হাইলাইট করুন',
+
// TODO: Translate
+ clear_custom_type_highlight: 'Clear highlight for "{{typeName}}"',
+ custom_type_highlight_tooltip:
+ 'Highlighting "{{typeName}}" - Click to clear',
filter: 'Filter Tables',
},
diff --git a/src/i18n/locales/de.ts b/src/i18n/locales/de.ts
index 654b0b93..aa36ba11 100644
--- a/src/i18n/locales/de.ts
+++ b/src/i18n/locales/de.ts
@@ -260,9 +260,12 @@ export const de: LanguageTranslation = {
field_name_placeholder: 'Field name',
field_type_placeholder: 'Select type',
add_field: 'Add Field',
+ no_fields_tooltip: 'No fields defined for this custom type',
custom_type_actions: {
title: 'Actions',
+ highlight_fields: 'Highlight Fields',
delete_custom_type: 'Delete',
+ clear_field_highlight: 'Clear Highlight',
},
delete_custom_type: 'Delete Type',
},
@@ -277,6 +280,11 @@ export const de: LanguageTranslation = {
undo: 'Rückgängig',
redo: 'Wiederholen',
reorder_diagram: 'Diagramm neu anordnen',
+
+ // TODO: Translate
+ clear_custom_type_highlight: 'Clear highlight for "{{typeName}}"',
+ custom_type_highlight_tooltip:
+ 'Highlighting "{{typeName}}" - Click to clear',
highlight_overlapping_tables: 'Überlappende Tabellen hervorheben',
// TODO: Translate
filter: 'Filter Tables',
diff --git a/src/i18n/locales/en.ts b/src/i18n/locales/en.ts
index 38d955ca..b208f9d0 100644
--- a/src/i18n/locales/en.ts
+++ b/src/i18n/locales/en.ts
@@ -250,8 +250,11 @@ export const en = {
field_name_placeholder: 'Field name',
field_type_placeholder: 'Select type',
add_field: 'Add Field',
+ no_fields_tooltip: 'No fields defined for this custom type',
custom_type_actions: {
title: 'Actions',
+ highlight_fields: 'Highlight Fields',
+ clear_field_highlight: 'Clear Highlight',
delete_custom_type: 'Delete',
},
delete_custom_type: 'Delete Type',
@@ -268,6 +271,9 @@ export const en = {
redo: 'Redo',
reorder_diagram: 'Reorder Diagram',
highlight_overlapping_tables: 'Highlight Overlapping Tables',
+ clear_custom_type_highlight: 'Clear highlight for "{{typeName}}"',
+ custom_type_highlight_tooltip:
+ 'Highlighting "{{typeName}}" - Click to clear',
filter: 'Filter Tables',
},
diff --git a/src/i18n/locales/es.ts b/src/i18n/locales/es.ts
index bf284dc0..043f04c5 100644
--- a/src/i18n/locales/es.ts
+++ b/src/i18n/locales/es.ts
@@ -248,9 +248,12 @@ export const es: LanguageTranslation = {
field_name_placeholder: 'Field name',
field_type_placeholder: 'Select type',
add_field: 'Add Field',
+ no_fields_tooltip: 'No fields defined for this custom type',
custom_type_actions: {
title: 'Actions',
+ highlight_fields: 'Highlight Fields',
delete_custom_type: 'Delete',
+ clear_field_highlight: 'Clear Highlight',
},
delete_custom_type: 'Delete Type',
},
@@ -265,6 +268,10 @@ export const es: LanguageTranslation = {
undo: 'Deshacer',
redo: 'Rehacer',
reorder_diagram: 'Reordenar Diagrama',
+ // TODO: Translate
+ clear_custom_type_highlight: 'Clear highlight for "{{typeName}}"',
+ custom_type_highlight_tooltip:
+ 'Highlighting "{{typeName}}" - Click to clear',
highlight_overlapping_tables: 'Resaltar tablas superpuestas',
// TODO: Translate
filter: 'Filter Tables',
diff --git a/src/i18n/locales/fr.ts b/src/i18n/locales/fr.ts
index 86f84381..ff3535f3 100644
--- a/src/i18n/locales/fr.ts
+++ b/src/i18n/locales/fr.ts
@@ -246,9 +246,12 @@ export const fr: LanguageTranslation = {
field_name_placeholder: 'Field name',
field_type_placeholder: 'Select type',
add_field: 'Add Field',
+ no_fields_tooltip: 'No fields defined for this custom type',
custom_type_actions: {
title: 'Actions',
+ highlight_fields: 'Highlight Fields',
delete_custom_type: 'Delete',
+ clear_field_highlight: 'Clear Highlight',
},
delete_custom_type: 'Delete Type',
},
@@ -263,6 +266,10 @@ export const fr: LanguageTranslation = {
undo: 'Annuler',
redo: 'Rétablir',
reorder_diagram: 'Réorganiser le Diagramme',
+ // TODO: Translate
+ clear_custom_type_highlight: 'Clear highlight for "{{typeName}}"',
+ custom_type_highlight_tooltip:
+ 'Highlighting "{{typeName}}" - Click to clear',
highlight_overlapping_tables: 'Surligner les tables chevauchées',
// TODO: Translate
filter: 'Filter Tables',
diff --git a/src/i18n/locales/gu.ts b/src/i18n/locales/gu.ts
index 74551f2d..96598002 100644
--- a/src/i18n/locales/gu.ts
+++ b/src/i18n/locales/gu.ts
@@ -259,9 +259,12 @@ export const gu: LanguageTranslation = {
field_name_placeholder: 'Field name',
field_type_placeholder: 'Select type',
add_field: 'Add Field',
+ no_fields_tooltip: 'No fields defined for this custom type',
custom_type_actions: {
title: 'Actions',
+ highlight_fields: 'Highlight Fields',
delete_custom_type: 'Delete',
+ clear_field_highlight: 'Clear Highlight',
},
delete_custom_type: 'Delete Type',
},
@@ -276,6 +279,10 @@ export const gu: LanguageTranslation = {
undo: 'અનડુ',
redo: 'રીડુ',
reorder_diagram: 'ડાયાગ્રામ ફરીથી વ્યવસ્થિત કરો',
+ // TODO: Translate
+ clear_custom_type_highlight: 'Clear highlight for "{{typeName}}"',
+ custom_type_highlight_tooltip:
+ 'Highlighting "{{typeName}}" - Click to clear',
highlight_overlapping_tables: 'ઓવરલેપ કરતો ટેબલ હાઇલાઇટ કરો',
// TODO: Translate
filter: 'Filter Tables',
diff --git a/src/i18n/locales/hi.ts b/src/i18n/locales/hi.ts
index 0ba39cf0..796f184b 100644
--- a/src/i18n/locales/hi.ts
+++ b/src/i18n/locales/hi.ts
@@ -259,9 +259,12 @@ export const hi: LanguageTranslation = {
field_name_placeholder: 'Field name',
field_type_placeholder: 'Select type',
add_field: 'Add Field',
+ no_fields_tooltip: 'No fields defined for this custom type',
custom_type_actions: {
title: 'Actions',
+ highlight_fields: 'Highlight Fields',
delete_custom_type: 'Delete',
+ clear_field_highlight: 'Clear Highlight',
},
delete_custom_type: 'Delete Type',
},
@@ -276,6 +279,10 @@ export const hi: LanguageTranslation = {
undo: 'पूर्ववत करें',
redo: 'पुनः करें',
reorder_diagram: 'आरेख पुनः व्यवस्थित करें',
+ // TODO: Translate
+ clear_custom_type_highlight: 'Clear highlight for "{{typeName}}"',
+ custom_type_highlight_tooltip:
+ 'Highlighting "{{typeName}}" - Click to clear',
highlight_overlapping_tables: 'ओवरलैपिंग तालिकाओं को हाइलाइट करें',
// TODO: Translate
filter: 'Filter Tables',
diff --git a/src/i18n/locales/id_ID.ts b/src/i18n/locales/id_ID.ts
index c2601e67..fa4eabae 100644
--- a/src/i18n/locales/id_ID.ts
+++ b/src/i18n/locales/id_ID.ts
@@ -257,9 +257,12 @@ export const id_ID: LanguageTranslation = {
field_name_placeholder: 'Field name',
field_type_placeholder: 'Select type',
add_field: 'Add Field',
+ no_fields_tooltip: 'No fields defined for this custom type',
custom_type_actions: {
title: 'Actions',
+ highlight_fields: 'Highlight Fields',
delete_custom_type: 'Delete',
+ clear_field_highlight: 'Clear Highlight',
},
delete_custom_type: 'Delete Type',
},
@@ -274,6 +277,10 @@ export const id_ID: LanguageTranslation = {
undo: 'Undo',
redo: 'Redo',
reorder_diagram: 'Atur Ulang Diagram',
+ // TODO: Translate
+ clear_custom_type_highlight: 'Clear highlight for "{{typeName}}"',
+ custom_type_highlight_tooltip:
+ 'Highlighting "{{typeName}}" - Click to clear',
highlight_overlapping_tables: 'Sorot Tabel yang Tumpang Tindih',
// TODO: Translate
filter: 'Filter Tables',
diff --git a/src/i18n/locales/ja.ts b/src/i18n/locales/ja.ts
index 32262abf..078a9c67 100644
--- a/src/i18n/locales/ja.ts
+++ b/src/i18n/locales/ja.ts
@@ -263,9 +263,12 @@ export const ja: LanguageTranslation = {
field_name_placeholder: 'Field name',
field_type_placeholder: 'Select type',
add_field: 'Add Field',
+ no_fields_tooltip: 'No fields defined for this custom type',
custom_type_actions: {
title: 'Actions',
+ highlight_fields: 'Highlight Fields',
delete_custom_type: 'Delete',
+ clear_field_highlight: 'Clear Highlight',
},
delete_custom_type: 'Delete Type',
},
@@ -282,7 +285,9 @@ export const ja: LanguageTranslation = {
reorder_diagram: 'ダイアグラムを並べ替え',
// TODO: Translate
highlight_overlapping_tables: 'Highlight Overlapping Tables',
- // TODO: Translate
+ clear_custom_type_highlight: 'Clear highlight for "{{typeName}}"',
+ custom_type_highlight_tooltip:
+ 'Highlighting "{{typeName}}" - Click to clear', // TODO: Translate
filter: 'Filter Tables',
},
diff --git a/src/i18n/locales/ko_KR.ts b/src/i18n/locales/ko_KR.ts
index d080bae0..2fe6e08a 100644
--- a/src/i18n/locales/ko_KR.ts
+++ b/src/i18n/locales/ko_KR.ts
@@ -257,9 +257,12 @@ export const ko_KR: LanguageTranslation = {
field_name_placeholder: 'Field name',
field_type_placeholder: 'Select type',
add_field: 'Add Field',
+ no_fields_tooltip: 'No fields defined for this custom type',
custom_type_actions: {
title: 'Actions',
+ highlight_fields: 'Highlight Fields',
delete_custom_type: 'Delete',
+ clear_field_highlight: 'Clear Highlight',
},
delete_custom_type: 'Delete Type',
},
@@ -274,6 +277,10 @@ export const ko_KR: LanguageTranslation = {
undo: '실행 취소',
redo: '다시 실행',
reorder_diagram: '다이어그램 재정렬',
+ // TODO: Translate
+ clear_custom_type_highlight: 'Clear highlight for "{{typeName}}"',
+ custom_type_highlight_tooltip:
+ 'Highlighting "{{typeName}}" - Click to clear',
highlight_overlapping_tables: '겹치는 테이블 강조 표시',
// TODO: Translate
filter: 'Filter Tables',
diff --git a/src/i18n/locales/mr.ts b/src/i18n/locales/mr.ts
index 9817b392..d875c452 100644
--- a/src/i18n/locales/mr.ts
+++ b/src/i18n/locales/mr.ts
@@ -262,9 +262,12 @@ export const mr: LanguageTranslation = {
field_name_placeholder: 'Field name',
field_type_placeholder: 'Select type',
add_field: 'Add Field',
+ no_fields_tooltip: 'No fields defined for this custom type',
custom_type_actions: {
title: 'Actions',
+ highlight_fields: 'Highlight Fields',
delete_custom_type: 'Delete',
+ clear_field_highlight: 'Clear Highlight',
},
delete_custom_type: 'Delete Type',
},
@@ -279,6 +282,10 @@ export const mr: LanguageTranslation = {
undo: 'पूर्ववत करा',
redo: 'पुन्हा करा',
reorder_diagram: 'आरेख पुनःक्रमित करा',
+ // TODO: Translate
+ clear_custom_type_highlight: 'Clear highlight for "{{typeName}}"',
+ custom_type_highlight_tooltip:
+ 'Highlighting "{{typeName}}" - Click to clear',
highlight_overlapping_tables: 'ओव्हरलॅपिंग टेबल्स हायलाइट करा',
// TODO: Translate
filter: 'Filter Tables',
diff --git a/src/i18n/locales/ne.ts b/src/i18n/locales/ne.ts
index 733bd954..8ec0de9b 100644
--- a/src/i18n/locales/ne.ts
+++ b/src/i18n/locales/ne.ts
@@ -259,9 +259,12 @@ export const ne: LanguageTranslation = {
field_name_placeholder: 'Field name',
field_type_placeholder: 'Select type',
add_field: 'Add Field',
+ no_fields_tooltip: 'No fields defined for this custom type',
custom_type_actions: {
title: 'Actions',
+ highlight_fields: 'Highlight Fields',
delete_custom_type: 'Delete',
+ clear_field_highlight: 'Clear Highlight',
},
delete_custom_type: 'Delete Type',
},
@@ -276,6 +279,10 @@ export const ne: LanguageTranslation = {
undo: 'पूर्ववत',
redo: 'पुनः गर्नुहोस्',
reorder_diagram: 'पुनः क्रमबद्ध गर्नुहोस्',
+ // TODO: Translate
+ clear_custom_type_highlight: 'Clear highlight for "{{typeName}}"',
+ custom_type_highlight_tooltip:
+ 'Highlighting "{{typeName}}" - Click to clear',
highlight_overlapping_tables:
'अतिरिक्त तालिकाहरू हाइलाइट गर्नुहोस्',
// TODO: Translate
diff --git a/src/i18n/locales/pt_BR.ts b/src/i18n/locales/pt_BR.ts
index 0d75a5dd..65662b64 100644
--- a/src/i18n/locales/pt_BR.ts
+++ b/src/i18n/locales/pt_BR.ts
@@ -258,9 +258,12 @@ export const pt_BR: LanguageTranslation = {
field_name_placeholder: 'Field name',
field_type_placeholder: 'Select type',
add_field: 'Add Field',
+ no_fields_tooltip: 'No fields defined for this custom type',
custom_type_actions: {
title: 'Actions',
+ highlight_fields: 'Highlight Fields',
delete_custom_type: 'Delete',
+ clear_field_highlight: 'Clear Highlight',
},
delete_custom_type: 'Delete Type',
},
@@ -275,6 +278,10 @@ export const pt_BR: LanguageTranslation = {
undo: 'Desfazer',
redo: 'Refazer',
reorder_diagram: 'Reordenar Diagrama',
+ // TODO: Translate
+ clear_custom_type_highlight: 'Clear highlight for "{{typeName}}"',
+ custom_type_highlight_tooltip:
+ 'Highlighting "{{typeName}}" - Click to clear',
highlight_overlapping_tables: 'Destacar Tabelas Sobrepostas',
// TODO: Translate
filter: 'Filter Tables',
diff --git a/src/i18n/locales/ru.ts b/src/i18n/locales/ru.ts
index 0eac1c81..a6486682 100644
--- a/src/i18n/locales/ru.ts
+++ b/src/i18n/locales/ru.ts
@@ -255,9 +255,12 @@ export const ru: LanguageTranslation = {
field_name_placeholder: 'Field name',
field_type_placeholder: 'Select type',
add_field: 'Add Field',
+ no_fields_tooltip: 'No fields defined for this custom type',
custom_type_actions: {
title: 'Actions',
+ highlight_fields: 'Highlight Fields',
delete_custom_type: 'Delete',
+ clear_field_highlight: 'Clear Highlight',
},
delete_custom_type: 'Delete Type',
},
@@ -272,6 +275,10 @@ export const ru: LanguageTranslation = {
undo: 'Отменить',
redo: 'Вернуть',
reorder_diagram: 'Переупорядочить диаграмму',
+ // TODO: Translate
+ clear_custom_type_highlight: 'Clear highlight for "{{typeName}}"',
+ custom_type_highlight_tooltip:
+ 'Highlighting "{{typeName}}" - Click to clear',
highlight_overlapping_tables: 'Выделение перекрывающихся таблиц',
// TODO: Translate
filter: 'Filter Tables',
diff --git a/src/i18n/locales/te.ts b/src/i18n/locales/te.ts
index 0c6cdda1..9c1647bc 100644
--- a/src/i18n/locales/te.ts
+++ b/src/i18n/locales/te.ts
@@ -259,9 +259,12 @@ export const te: LanguageTranslation = {
field_name_placeholder: 'Field name',
field_type_placeholder: 'Select type',
add_field: 'Add Field',
+ no_fields_tooltip: 'No fields defined for this custom type',
custom_type_actions: {
title: 'Actions',
+ highlight_fields: 'Highlight Fields',
delete_custom_type: 'Delete',
+ clear_field_highlight: 'Clear Highlight',
},
delete_custom_type: 'Delete Type',
},
@@ -276,6 +279,10 @@ export const te: LanguageTranslation = {
undo: 'తిరిగి చేయు',
redo: 'మరలా చేయు',
reorder_diagram: 'చిత్రాన్ని పునఃసరిచేయండి',
+ // TODO: Translate
+ clear_custom_type_highlight: 'Clear highlight for "{{typeName}}"',
+ custom_type_highlight_tooltip:
+ 'Highlighting "{{typeName}}" - Click to clear',
highlight_overlapping_tables: 'అవకాశించు పట్టికలను హైలైట్ చేయండి',
// TODO: Translate
filter: 'Filter Tables',
diff --git a/src/i18n/locales/tr.ts b/src/i18n/locales/tr.ts
index 346b34d6..065cee3e 100644
--- a/src/i18n/locales/tr.ts
+++ b/src/i18n/locales/tr.ts
@@ -258,9 +258,12 @@ export const tr: LanguageTranslation = {
field_name_placeholder: 'Field name',
field_type_placeholder: 'Select type',
add_field: 'Add Field',
+ no_fields_tooltip: 'No fields defined for this custom type',
custom_type_actions: {
title: 'Actions',
+ highlight_fields: 'Highlight Fields',
delete_custom_type: 'Delete',
+ clear_field_highlight: 'Clear Highlight',
},
delete_custom_type: 'Delete Type',
},
@@ -274,6 +277,10 @@ export const tr: LanguageTranslation = {
undo: 'Geri Al',
redo: 'Yinele',
reorder_diagram: 'Diyagramı Yeniden Sırala',
+ // TODO: Translate
+ clear_custom_type_highlight: 'Clear highlight for "{{typeName}}"',
+ custom_type_highlight_tooltip:
+ 'Highlighting "{{typeName}}" - Click to clear',
highlight_overlapping_tables: 'Çakışan Tabloları Vurgula',
// TODO: Translate
filter: 'Filter Tables',
diff --git a/src/i18n/locales/uk.ts b/src/i18n/locales/uk.ts
index ea9ef705..19a76d8b 100644
--- a/src/i18n/locales/uk.ts
+++ b/src/i18n/locales/uk.ts
@@ -256,9 +256,12 @@ export const uk: LanguageTranslation = {
field_name_placeholder: 'Field name',
field_type_placeholder: 'Select type',
add_field: 'Add Field',
+ no_fields_tooltip: 'No fields defined for this custom type',
custom_type_actions: {
title: 'Actions',
+ highlight_fields: 'Highlight Fields',
delete_custom_type: 'Delete',
+ clear_field_highlight: 'Clear Highlight',
},
delete_custom_type: 'Delete Type',
},
@@ -273,6 +276,10 @@ export const uk: LanguageTranslation = {
undo: 'Скасувати',
redo: 'Повторити',
reorder_diagram: 'Перевпорядкувати діаграму',
+ // TODO: Translate
+ clear_custom_type_highlight: 'Clear highlight for "{{typeName}}"',
+ custom_type_highlight_tooltip:
+ 'Highlighting "{{typeName}}" - Click to clear',
highlight_overlapping_tables: 'Показати таблиці, що перекриваються',
// TODO: Translate
filter: 'Filter Tables',
diff --git a/src/i18n/locales/vi.ts b/src/i18n/locales/vi.ts
index 9f89f7f9..106db0d1 100644
--- a/src/i18n/locales/vi.ts
+++ b/src/i18n/locales/vi.ts
@@ -257,9 +257,12 @@ export const vi: LanguageTranslation = {
field_name_placeholder: 'Field name',
field_type_placeholder: 'Select type',
add_field: 'Add Field',
+ no_fields_tooltip: 'No fields defined for this custom type',
custom_type_actions: {
title: 'Actions',
+ highlight_fields: 'Highlight Fields',
delete_custom_type: 'Delete',
+ clear_field_highlight: 'Clear Highlight',
},
delete_custom_type: 'Delete Type',
},
@@ -274,6 +277,10 @@ export const vi: LanguageTranslation = {
undo: 'Hoàn tác',
redo: 'Làm lại',
reorder_diagram: 'Sắp xếp lại sơ đồ',
+ // TODO: Translate
+ clear_custom_type_highlight: 'Clear highlight for "{{typeName}}"',
+ custom_type_highlight_tooltip:
+ 'Highlighting "{{typeName}}" - Click to clear',
highlight_overlapping_tables: 'Làm nổi bật các bảng chồng chéo',
// TODO: Translate
filter: 'Filter Tables',
diff --git a/src/i18n/locales/zh_CN.ts b/src/i18n/locales/zh_CN.ts
index ba64a6e6..76fc7137 100644
--- a/src/i18n/locales/zh_CN.ts
+++ b/src/i18n/locales/zh_CN.ts
@@ -254,9 +254,12 @@ export const zh_CN: LanguageTranslation = {
field_name_placeholder: 'Field name',
field_type_placeholder: 'Select type',
add_field: 'Add Field',
+ no_fields_tooltip: 'No fields defined for this custom type',
custom_type_actions: {
title: 'Actions',
+ highlight_fields: 'Highlight Fields',
delete_custom_type: 'Delete',
+ clear_field_highlight: 'Clear Highlight',
},
delete_custom_type: 'Delete Type',
},
@@ -271,6 +274,10 @@ export const zh_CN: LanguageTranslation = {
undo: '撤销',
redo: '重做',
reorder_diagram: '重新排列关系图',
+ // TODO: Translate
+ clear_custom_type_highlight: 'Clear highlight for "{{typeName}}"',
+ custom_type_highlight_tooltip:
+ 'Highlighting "{{typeName}}" - Click to clear',
highlight_overlapping_tables: '突出显示重叠的表',
// TODO: Translate
filter: 'Filter Tables',
diff --git a/src/i18n/locales/zh_TW.ts b/src/i18n/locales/zh_TW.ts
index 8c40a1a5..9cffe335 100644
--- a/src/i18n/locales/zh_TW.ts
+++ b/src/i18n/locales/zh_TW.ts
@@ -254,9 +254,12 @@ export const zh_TW: LanguageTranslation = {
field_name_placeholder: 'Field name',
field_type_placeholder: 'Select type',
add_field: 'Add Field',
+ no_fields_tooltip: 'No fields defined for this custom type',
custom_type_actions: {
title: 'Actions',
+ highlight_fields: 'Highlight Fields',
delete_custom_type: 'Delete',
+ clear_field_highlight: 'Clear Highlight',
},
delete_custom_type: 'Delete Type',
},
@@ -271,6 +274,10 @@ export const zh_TW: LanguageTranslation = {
undo: '復原',
redo: '重做',
reorder_diagram: '重新排列圖表',
+ // TODO: Translate
+ clear_custom_type_highlight: 'Clear highlight for "{{typeName}}"',
+ custom_type_highlight_tooltip:
+ 'Highlighting "{{typeName}}" - Click to clear',
highlight_overlapping_tables: '突出顯示重疊表格',
// TODO: Translate
filter: 'Filter Tables',
diff --git a/src/pages/editor-page/canvas/canvas.tsx b/src/pages/editor-page/canvas/canvas.tsx
index cefaacc1..8ec81a02 100644
--- a/src/pages/editor-page/canvas/canvas.tsx
+++ b/src/pages/editor-page/canvas/canvas.tsx
@@ -40,7 +40,13 @@ import {
} from './table-node/table-node-field';
import { Toolbar } from './toolbar/toolbar';
import { useToast } from '@/components/toast/use-toast';
-import { Pencil, LayoutGrid, AlertTriangle, Magnet } from 'lucide-react';
+import {
+ Pencil,
+ LayoutGrid,
+ AlertTriangle,
+ Magnet,
+ Highlighter,
+} from 'lucide-react';
import { Button } from '@/components/button/button';
import { useLayout } from '@/hooks/use-layout';
import { useBreakpoint } from '@/hooks/use-breakpoint';
@@ -175,6 +181,9 @@ export const Canvas: React.FC<CanvasProps> = ({ initialTables }) => {
readonly,
removeArea,
updateArea,
+ highlightedCustomType,
+ highlightCustomTypeId,
+ getCustomType,
hiddenTableIds,
} = useChartDB();
const { showSidePanel } = useLayout();
@@ -385,12 +394,22 @@ export const Canvas: React.FC<CanvasProps> = ({ initialTables }) => {
hiddenTableIds,
});
+ // Check if table uses the highlighted custom type
+ let hasHighlightedCustomType = false;
+ if (highlightedCustomType) {
+ hasHighlightedCustomType = table.fields.some(
+ (field) =>
+ field.type.name === highlightedCustomType.name
+ );
+ }
+
return {
...node,
data: {
...node.data,
isOverlapping,
highlightOverlappingTables,
+ hasHighlightedCustomType,
},
};
}),
@@ -413,6 +432,8 @@ export const Canvas: React.FC<CanvasProps> = ({ initialTables }) => {
overlapGraph.lastUpdated,
overlapGraph.graph,
highlightOverlappingTables,
+ highlightedCustomType,
+ getCustomType,
]);
const prevFilteredSchemas = useRef<string[] | undefined>(undefined);
@@ -1162,6 +1183,34 @@ export const Canvas: React.FC<CanvasProps> = ({ initialTables }) => {
})}
</TooltipContent>
</Tooltip>
+ {highlightedCustomType ? (
+ <Tooltip>
+ <TooltipTrigger asChild>
+ <span>
+ <Button
+ variant="secondary"
+ className="size-8 border border-yellow-400 bg-yellow-200 p-1 shadow-none hover:bg-yellow-300 dark:border-yellow-700 dark:bg-yellow-800 dark:hover:bg-yellow-700"
+ onClick={() =>
+ highlightCustomTypeId(
+ undefined
+ )
+ }
+ >
+ <Highlighter className="size-4" />
+ </Button>
+ </span>
+ </TooltipTrigger>
+ <TooltipContent>
+ {t(
+ 'toolbar.custom_type_highlight_tooltip',
+ {
+ typeName:
+ highlightedCustomType.name,
+ }
+ )}
+ </TooltipContent>
+ </Tooltip>
+ ) : null}
</>
) : null}
diff --git a/src/pages/editor-page/canvas/table-node/table-node-field.tsx b/src/pages/editor-page/canvas/table-node/table-node-field.tsx
index e3c63090..05a3b60b 100644
--- a/src/pages/editor-page/canvas/table-node/table-node-field.tsx
+++ b/src/pages/editor-page/canvas/table-node/table-node-field.tsx
@@ -74,8 +74,13 @@ const arePropsEqual = (
export const TableNodeField: React.FC<TableNodeFieldProps> = React.memo(
({ field, focused, tableNodeId, highlighted, visible, isConnectable }) => {
- const { removeField, relationships, readonly, updateField } =
- useChartDB();
+ const {
+ removeField,
+ relationships,
+ readonly,
+ updateField,
+ highlightedCustomType,
+ } = useChartDB();
const [editMode, setEditMode] = useState(false);
const [fieldName, setFieldName] = useState(field.name);
const inputRef = React.useRef<HTMLInputElement>(null);
@@ -208,6 +213,10 @@ export const TableNodeField: React.FC<TableNodeFieldProps> = React.memo(
setEditMode(true);
}, []);
+ const isCustomTypeHighlighted = useMemo(() => {
+ if (!highlightedCustomType) return false;
+ return field.type.name === highlightedCustomType.name;
+ }, [highlightedCustomType, field.type.name]);
const { showFieldAttributes } = useLocalConfig();
return (
@@ -216,7 +225,10 @@ export const TableNodeField: React.FC<TableNodeFieldProps> = React.memo(
'group relative flex h-8 items-center justify-between gap-1 border-t px-3 text-sm last:rounded-b-[6px] hover:bg-slate-100 dark:hover:bg-slate-800',
'transition-all duration-200 ease-in-out',
{
- 'bg-pink-100 dark:bg-pink-900': highlighted,
+ 'bg-pink-100 dark:bg-pink-900':
+ highlighted && !isCustomTypeHighlighted,
+ 'bg-yellow-100 dark:bg-yellow-900':
+ isCustomTypeHighlighted,
'max-h-8 opacity-100': visible,
'z-0 max-h-0 overflow-hidden opacity-0': !visible,
'bg-sky-200 dark:bg-sky-800 hover:bg-sky-100 dark:hover:bg-sky-900 border-sky-300 dark:border-sky-700':
@@ -310,12 +322,6 @@ export const TableNodeField: React.FC<TableNodeFieldProps> = React.memo(
</Button>
</>
) : (
- // <span
- // className="truncate"
- // onClick={readonly ? undefined : enterEditMode}
- // >
- // {field.name}
- // </span>
<span
className={cn('truncate min-w-0', {
'text-red-800 font-normal dark:text-red-200':
@@ -340,7 +346,6 @@ export const TableNodeField: React.FC<TableNodeFieldProps> = React.memo(
)}
</span>
)}
- {/* <span className="truncate">{field.name}</span> */}
{field.comments && !editMode ? (
<Tooltip>
<TooltipTrigger asChild>
diff --git a/src/pages/editor-page/canvas/table-node/table-node.tsx b/src/pages/editor-page/canvas/table-node/table-node.tsx
index 098a1c91..81a690d4 100644
--- a/src/pages/editor-page/canvas/table-node/table-node.tsx
+++ b/src/pages/editor-page/canvas/table-node/table-node.tsx
@@ -53,6 +53,7 @@ export type TableNodeType = Node<
table: DBTable;
isOverlapping: boolean;
highlightOverlappingTables?: boolean;
+ hasHighlightedCustomType?: boolean;
},
'table'
>;
@@ -62,7 +63,12 @@ export const TableNode: React.FC<NodeProps<TableNodeType>> = React.memo(
selected,
dragging,
id,
- data: { table, isOverlapping, highlightOverlappingTables },
+ data: {
+ table,
+ isOverlapping,
+ highlightOverlappingTables,
+ hasHighlightedCustomType,
+ },
}) => {
const { updateTable, relationships, readonly } = useChartDB();
const edges = useStore((store) => store.edges) as EdgeType[];
@@ -303,6 +309,9 @@ export const TableNode: React.FC<NodeProps<TableNodeType>> = React.memo(
highlightOverlappingTables && isOverlapping
? 'animate-scale-2'
: '',
+ hasHighlightedCustomType
+ ? 'ring-2 ring-offset-slate-50 dark:ring-offset-slate-900 ring-yellow-500 ring-offset-2 animate-scale'
+ : '',
isDiffTableChanged && !isDiffNewTable && !isDiffTableRemoved
? 'outline outline-[3px] outline-sky-500 dark:outline-sky-900 outline-offset-[5px]'
: '',
@@ -317,6 +326,8 @@ export const TableNode: React.FC<NodeProps<TableNodeType>> = React.memo(
selected,
isOverlapping,
highlightOverlappingTables,
+ hasHighlightedCustomType,
+
isDiffTableChanged,
isDiffNewTable,
isDiffTableRemoved,
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 4d8cb1f0..d2377a86 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
@@ -16,11 +16,17 @@ import {
customTypeKindToLabel,
DBCustomTypeKind,
} from '@/lib/domain/db-custom-type';
-import { Trash2, Braces } from 'lucide-react';
-import React, { useCallback } from 'react';
+import { Trash2, Braces, Highlighter } from 'lucide-react';
+import React, { useCallback, useMemo } from 'react';
import { useTranslation } from 'react-i18next';
import { CustomTypeEnumValues } from './enum-values/enum-values';
import { CustomTypeCompositeFields } from './composite-fields/composite-fields';
+import {
+ Tooltip,
+ TooltipContent,
+ TooltipTrigger,
+} from '@/components/tooltip/tooltip';
+import { checkIfCustomTypeUsed } from '../utils';
export interface CustomTypeListItemContentProps {
customType: DBCustomType;
@@ -29,7 +35,13 @@ export interface CustomTypeListItemContentProps {
export const CustomTypeListItemContent: React.FC<
CustomTypeListItemContentProps
> = ({ customType }) => {
- const { removeCustomType, updateCustomType } = useChartDB();
+ const {
+ removeCustomType,
+ updateCustomType,
+ highlightedCustomType,
+ highlightCustomTypeId,
+ tables,
+ } = useChartDB();
const { t } = useTranslation();
const deleteCustomTypeHandler = useCallback(() => {
@@ -92,6 +104,43 @@ export const CustomTypeListItemContent: React.FC<
[customType.id, updateCustomType]
);
+ const toggleHighlightCustomType = useCallback(() => {
+ if (highlightedCustomType?.id === customType.id) {
+ highlightCustomTypeId(undefined);
+ } else {
+ highlightCustomTypeId(customType.id);
+ }
+ }, [customType.id, highlightCustomTypeId, highlightedCustomType?.id]);
+
+ const canHighlight = useMemo(
+ () => checkIfCustomTypeUsed({ customType, tables }),
+ [customType, tables]
+ );
+
+ const isHighlighted = useMemo(
+ () => highlightedCustomType?.id === customType.id,
+ [highlightedCustomType, customType.id]
+ );
+
+ const renderHighlightButton = useCallback(
+ () => (
+ <Button
+ variant="ghost"
+ disabled={!canHighlight}
+ className="flex h-8 w-full items-center justify-center p-2 text-xs"
+ onClick={toggleHighlightCustomType}
+ >
+ <Highlighter className="mr-1 size-3.5" />
+ {t(
+ isHighlighted
+ ? 'side_panel.custom_types_section.custom_type.custom_type_actions.clear_field_highlight'
+ : 'side_panel.custom_types_section.custom_type.custom_type_actions.highlight_fields'
+ )}
+ </Button>
+ ),
+ [isHighlighted, canHighlight, toggleHighlightCustomType, t]
+ );
+
return (
<div className="my-1 flex flex-col rounded-b-md px-1">
<div className="flex flex-col gap-6">
@@ -148,10 +197,24 @@ export const CustomTypeListItemContent: React.FC<
/>
)}
</div>
- <div className="flex flex-1 items-center justify-center pt-2">
+ <div className="flex flex-col items-center justify-center pt-2">
+ {!canHighlight ? (
+ <Tooltip>
+ <TooltipTrigger asChild>
+ <span>{renderHighlightButton()}</span>
+ </TooltipTrigger>
+ <TooltipContent>
+ {t(
+ 'side_panel.custom_types_section.custom_type.no_fields_tooltip'
+ )}
+ </TooltipContent>
+ </Tooltip>
+ ) : (
+ renderHighlightButton()
+ )}
<Button
variant="ghost"
- className="h-8 p-2 text-xs"
+ 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" />
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 7c5aebd9..0dbdeae1 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
@@ -1,10 +1,11 @@
-import React, { useCallback } from 'react';
+import React, { useCallback, useMemo } from 'react';
import {
GripVertical,
Pencil,
EllipsisVertical,
Trash2,
Check,
+ Highlighter,
} from 'lucide-react';
import { ListItemHeaderButton } from '@/pages/editor-page/side-panel/list-item-header-button/list-item-header-button';
import { Input } from '@/components/input/input';
@@ -32,6 +33,7 @@ import {
type DBCustomType,
} from '@/lib/domain/db-custom-type';
import { Badge } from '@/components/badge/badge';
+import { checkIfCustomTypeUsed } from '../utils';
export interface CustomTypeListItemHeaderProps {
customType: DBCustomType;
@@ -40,8 +42,15 @@ export interface CustomTypeListItemHeaderProps {
export const CustomTypeListItemHeader: React.FC<
CustomTypeListItemHeaderProps
> = ({ customType }) => {
- const { updateCustomType, removeCustomType, schemas, filteredSchemas } =
- useChartDB();
+ const {
+ updateCustomType,
+ removeCustomType,
+ schemas,
+ filteredSchemas,
+ highlightedCustomType,
+ highlightCustomTypeId,
+ tables,
+ } = useChartDB();
const { t } = useTranslation();
const [editMode, setEditMode] = React.useState(false);
const [customTypeName, setCustomTypeName] = React.useState(customType.name);
@@ -71,12 +80,40 @@ export const CustomTypeListItemHeader: React.FC<
setEditMode(true);
};
- const deleteCustomTypeHandler = useCallback(() => {
- removeCustomType(customType.id);
- }, [customType.id, removeCustomType]);
+ const deleteCustomTypeHandler = useCallback(
+ (e: React.MouseEvent<HTMLDivElement, MouseEvent>) => {
+ e.stopPropagation();
- const renderDropDownMenu = useCallback(
- () => (
+ removeCustomType(customType.id);
+ },
+ [customType.id, removeCustomType]
+ );
+
+ const isHighlighted = useMemo(
+ () => highlightedCustomType?.id === customType.id,
+ [highlightedCustomType, customType.id]
+ );
+
+ const toggleHighlightCustomType = useCallback(
+ (e: React.MouseEvent<HTMLDivElement, MouseEvent>) => {
+ e.stopPropagation();
+
+ if (isHighlighted) {
+ highlightCustomTypeId(undefined);
+ } else {
+ highlightCustomTypeId(customType.id);
+ }
+ },
+ [customType.id, highlightCustomTypeId, isHighlighted]
+ );
+
+ const canHighlight = useMemo(
+ () => checkIfCustomTypeUsed({ customType, tables }),
+ [customType, tables]
+ );
+
+ const renderDropDownMenu = useCallback(() => {
+ return (
<DropdownMenu>
<DropdownMenuTrigger>
<ListItemHeaderButton>
@@ -91,6 +128,18 @@ export const CustomTypeListItemHeader: React.FC<
</DropdownMenuLabel>
<DropdownMenuSeparator />
<DropdownMenuGroup>
+ <DropdownMenuItem
+ onClick={toggleHighlightCustomType}
+ disabled={!canHighlight}
+ className="flex justify-between"
+ >
+ {t(
+ isHighlighted
+ ? 'side_panel.custom_types_section.custom_type.custom_type_actions.clear_field_highlight'
+ : 'side_panel.custom_types_section.custom_type.custom_type_actions.highlight_fields'
+ )}
+ <Highlighter className="size-3.5" />
+ </DropdownMenuItem>
<DropdownMenuItem
onClick={deleteCustomTypeHandler}
className="flex justify-between !text-red-700"
@@ -103,9 +152,14 @@ export const CustomTypeListItemHeader: React.FC<
</DropdownMenuGroup>
</DropdownMenuContent>
</DropdownMenu>
- ),
- [deleteCustomTypeHandler, t]
- );
+ );
+ }, [
+ deleteCustomTypeHandler,
+ t,
+ toggleHighlightCustomType,
+ canHighlight,
+ isHighlighted,
+ ]);
let schemaToDisplay;
diff --git a/src/pages/editor-page/side-panel/custom-types-section/custom-type-list/custom-type-list-item/utils.ts b/src/pages/editor-page/side-panel/custom-types-section/custom-type-list/custom-type-list-item/utils.ts
new file mode 100644
index 00000000..f81e9c1c
--- /dev/null
+++ b/src/pages/editor-page/side-panel/custom-types-section/custom-type-list/custom-type-list-item/utils.ts
@@ -0,0 +1,20 @@
+import type { DBCustomType, DBTable } from '@/lib/domain';
+
+export const checkIfCustomTypeUsed = ({
+ customType,
+ tables,
+}: {
+ customType: DBCustomType;
+ tables: DBTable[];
+}): boolean => {
+ const typeNameToFind = customType.name;
+
+ for (const table of tables) {
+ for (const field of table.fields) {
+ if (field.type.name === typeNameToFind) {
+ return true;
+ }
+ }
+ }
+ return false;
+};