Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/components/EditorCanvas/Canvas.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ export default function Canvas() {
table,
settings.tableWidth,
settings.showComments,
settings.showMaxFields,
),
};
if (shouldAddElement(tableRect, element)) {
Expand Down
20 changes: 14 additions & 6 deletions src/components/EditorCanvas/Table.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export default function Table({
tableData,
settings.tableWidth,
settings.showComments,
settings.showMaxFields,
);

const isSelected = useMemo(() => {
Expand Down Expand Up @@ -279,7 +280,9 @@ export default function Table({
)}
</div>

{tableData.fields.map((e, i) => {
{tableData.fields
.slice(0, settings.showMaxFields === 0 ? tableData.fields.length : settings.showMaxFields)
.map((e, i) => {
return settings.showFieldSummary ? (
<Popover
key={i}
Expand Down Expand Up @@ -382,7 +385,7 @@ export default function Table({
index === tableData.fields.length - 1
? ""
: "border-b border-gray-400"
} group h-[36px] px-2 py-1 flex justify-between items-center gap-1 w-full overflow-hidden`}
} group h-9 px-2 flex justify-between items-center gap-1 w-full overflow-hidden`}
onPointerEnter={(e) => {
if (!e.isPrimary) return;

Expand Down Expand Up @@ -410,10 +413,10 @@ export default function Table({
<div
className={`${
hoveredField === index ? "text-zinc-400" : ""
} flex items-center gap-2 overflow-hidden`}
} flex items-center gap-2 overflow-hidden w-full min-w-0`}
>
<button
className="shrink-0 w-[10px] h-[10px] bg-[#2f68adcc] rounded-full"
className="shrink-0 w-2.5 h-2.5 bg-[#2f68adcc] rounded-full"
onPointerDown={(e) => {
if (!e.isPrimary) return;

Expand Down Expand Up @@ -449,11 +452,16 @@ export default function Table({
}));
}}
/>
<span className="overflow-hidden text-ellipsis whitespace-nowrap">
<span className="min-w-0 overflow-hidden whitespace-nowrap text-ellipsis">
{fieldData.name}
{settings.showComments && fieldData.comment ? (
<span className="text-[10px] text-zinc-500 ms-2 overflow-hidden whitespace-nowrap text-ellipsis">
{fieldData.comment}
</span>
) : null}
</span>
</div>
<div className="text-zinc-400">
<div className="text-zinc-400 shrink-0">
{hoveredField === index ? (
<Button
theme="solid"
Expand Down
14 changes: 13 additions & 1 deletion src/components/EditorHeader/ControlPanel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ export default function ControlPanel({ title, setTitle, lastSaved }) {
minMaxXY.maxY = Math.max(
minMaxXY.maxY,
table.y +
getTableHeight(table, settings.tableWidth, settings.showComments),
getTableHeight(table, settings.tableWidth, settings.showComments, settings.showMaxFields),
);
});

Expand Down Expand Up @@ -1435,6 +1435,18 @@ export default function ControlPanel({ title, setTitle, lastSaved }) {
showDebugCoordinates: !prev.showDebugCoordinates,
})),
},
limit_fields: {
state: settings.showMaxFields === 0 ? (
<i className="bi bi-toggle-on" />
) : (
<i className="bi bi-toggle-off" />
),
function: () =>
setSettings((prev) => ({
...prev,
showMaxFields: prev.showMaxFields === 0 ? 10 : 0,
})),
},
theme: {
children: [
{
Expand Down
1 change: 1 addition & 0 deletions src/context/SettingsContext.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const defaultSettings = {
tableWidth: tableWidth,
showDebugCoordinates: false,
showComments: true,
showMaxFields: 0, // 0 means show all fields
};

export const SettingsContext = createContext(defaultSettings);
Expand Down
1 change: 1 addition & 0 deletions src/i18n/locales/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const english = {

const en = {
translation: {
limit_fields: "Show all fields",
report_bug: "Report a bug",
import: "Import",
inherits: "Inherits",
Expand Down
2 changes: 2 additions & 0 deletions src/i18n/locales/zh.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ const chinese = {

const zh = {
translation: {
show_comments: "显示注释",
limit_fields: "显示所有字段",
report_bug: "报告问题",
import_from: "导入",
import: "导入",
Expand Down
11 changes: 10 additions & 1 deletion src/utils/importFrom/dbml.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ export function fromDBML(src) {

field.id = nanoid();
field.name = column.name;
field.type = column.type.type_name.toUpperCase();
field.type = extractTypeName(column.type.type_name).toUpperCase();
field.size = column.type.args ?? "";
field.default = column.dbdefault?.value ?? "";
field.check = "";
field.primary = !!column.pk;
Expand Down Expand Up @@ -125,3 +126,11 @@ export function fromDBML(src) {

return diagram;
}

function extractTypeName(type) {
const match = type.match(/^(\w+)(?:\([^)]*\))?/);
if (match && match[1]) {
return match[1];
}
return type;
}
5 changes: 3 additions & 2 deletions src/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,10 @@ export function getCommentHeight(comment, containerWidth, showComments = true) {
return height + paddingBottom;
}

export function getTableHeight(table, width, showComments = true) {
export function getTableHeight(table, width, showComments = true, showMaxFields = 0) {
const displayFieldsCount = showMaxFields === 0 ? table.fields.length : Math.min(table.fields.length, showMaxFields);
return (
table.fields.length * tableFieldHeight +
displayFieldsCount * tableFieldHeight +
tableHeaderHeight +
tableColorStripHeight +
getCommentHeight(table.comment, width, showComments)
Expand Down