Skip to content

Toggle datatypes for table directly from view dropdown #366

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
26 changes: 15 additions & 11 deletions src/components/EditorCanvas/Table.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -356,17 +356,21 @@ export default function Table(props) {
/>
) : (
<div className="flex gap-1 items-center">
{fieldData.primary && <IconKeyStroked />}
{!fieldData.notNull && <span>?</span>}
<span>
{fieldData.type +
((dbToTypes[database][fieldData.type].isSized ||
dbToTypes[database][fieldData.type].hasPrecision) &&
fieldData.size &&
fieldData.size !== ""
? "(" + fieldData.size + ")"
: "")}
</span>
{settings.showDataTypes && (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also try putting the condition before the div so that an emty element doesnt get added to the dom

<>
{fieldData.primary && <IconKeyStroked />}
{!fieldData.notNull && <span>?</span>}
<span>
{fieldData.type +
((dbToTypes[database][fieldData.type].isSized ||
dbToTypes[database][fieldData.type].hasPrecision) &&
fieldData.size &&
fieldData.size !== ""
? "(" + fieldData.size + ")"
: "")}
</span>
</>
)}
</div>
)}
</div>
Expand Down
11 changes: 11 additions & 0 deletions src/components/EditorHeader/ControlPanel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -1211,6 +1211,17 @@ export default function ControlPanel({
function: resetView,
shortcut: "Ctrl+R",
},
show_datatype: {
state: settings.showDataTypes ? (
<i className="bi bi-toggle-on" />
) : (
<i className="bi bi-toggle-off" />
),
function: () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
function: () => {
function: () =>
setSettings((prev) => ({
...prev,
showDataTypes: !prev.showDataTypes,
})),

Please make sure to update the state using the setSettings function. Also the build fails here, please take a lokk https://github.com/drawdb-io/drawdb/actions/runs/13877624768/job/38843669905?pr=366

showDataTypes: !prevSettings.showDataTypes
}));
},
},
show_grid: {
state: settings.showGrid ? (
<i className="bi bi-toggle-on" />
Expand Down
1 change: 1 addition & 0 deletions src/context/SettingsContext.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const defaultSettings = {
strictMode: false,
showFieldSummary: true,
showGrid: true,
showDataTypes: true,
mode: "light",
autosave: true,
panning: true,
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 @@ -49,6 +49,7 @@ const en = {
field_details: "Field details",
reset_view: "Reset view",
show_grid: "Show grid",
show_datatype: "Show datatype",
show_cardinality: "Show cardinality",
theme: "Theme",
light: "Light",
Expand Down
Loading