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
11 changes: 11 additions & 0 deletions web/pgadmin/browser/register_browser_preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,17 @@ def register_browser_preferences(self):
)
)

self.preference.register(
'display', 'show_server_color_indicator',
gettext("Show server color indicator in panel tabs?"), 'boolean', False,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Fix pycodestyle E501 on Line 106.

The new preference line exceeds the 79-char limit and is currently failing CI.

✂️ Suggested style-only fix
-        gettext("Show server color indicator in panel tabs?"), 'boolean', False,
+        gettext("Show server color indicator in panel tabs?"),
+        'boolean', False,
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
gettext("Show server color indicator in panel tabs?"), 'boolean', False,
gettext("Show server color indicator in panel tabs?"),
'boolean', False,
🧰 Tools
🪛 GitHub Actions: Check Python style

[error] 106-106: pycodestyle reported E501: line too long (80 > 79 characters).

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@web/pgadmin/browser/register_browser_preferences.py` at line 106, The
preference declaration gettext("Show server color indicator in panel tabs?"),
'boolean', False exceeds the 79-character line length; fix by wrapping the tuple
across multiple lines or breaking the long string into concatenated parts so the
gettext(...) call or the tuple elements fit within the 79-char limit (e.g.,
place each tuple element on its own line inside the surrounding list/tuple using
parentheses) while keeping the symbol gettext("Show server color indicator in
panel tabs?"), 'boolean', False intact.

category_label=PREF_LABEL_DISPLAY,
help_str=gettext(
'If enabled, a colored circle indicator will be shown in panel '
'tabs (Query Tool, ERD Tool, etc.) matching the server\'s custom '
'background color.'
)
)

self.table_row_count_threshold = self.preference.register(
'properties', 'table_row_count_threshold',
gettext("Count rows if estimated less than"), 'integer', 2000,
Expand Down
26 changes: 25 additions & 1 deletion web/pgadmin/static/js/helpers/Layout/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,15 @@ import { BROWSER_PANELS, WORKSPACES } from '../../../../browser/static/js/consta
export function TabTitle({id, closable, defaultInternal}) {
const layoutDocker = React.useContext(LayoutDockerContext);
const internal = layoutDocker?.find(id)?.internal ?? defaultInternal;
const showServerColorIndicator = usePreferences(
React.useCallback((state) => state.getPreferencesForModule('browser')?.show_server_color_indicator ?? false, [])
);
const [attrs, setAttrs] = useState({
icon: internal.icon,
title: internal.title,
tooltip: internal.tooltip ?? internal.title,
bgcolor: internal.bgcolor,
fgcolor: internal.fgcolor,
});
const onContextMenu = useCallback((e)=>{
const g = layoutDocker.find(id)?.group??'';
Expand All @@ -53,6 +58,8 @@ export function TabTitle({id, closable, defaultInternal}) {
icon: internal.icon,
title: internal.title,
tooltip: internal.tooltip ?? internal.title,
bgcolor: internal.bgcolor,
fgcolor: internal.fgcolor,
});
layoutDocker.saveLayout();
}
Expand All @@ -64,6 +71,21 @@ export function TabTitle({id, closable, defaultInternal}) {
return (
<Box display="flex" alignItems="center" title={attrs.tooltip} onContextMenu={onContextMenu} width="100%">
{attrs.icon && <span className={`dock-tab-icon ${attrs.icon}`}></span>}
{showServerColorIndicator && attrs.bgcolor && !layoutDocker.isTabVisible(id) && (
<Box
component="span"
sx={{
width: '12px',
height: '12px',
borderRadius: '50%',
backgroundColor: attrs.bgcolor,
marginLeft: '2px',
marginRight: '4px',
flexShrink: 0,
border: '1px solid rgba(0, 0, 0, 0.1)',
}}
/>
)}
<span style={{textOverflow: 'ellipsis', overflow: 'hidden', whiteSpace: 'nowrap'}} data-visible={layoutDocker.isTabVisible(id)}>{attrs.title}</span>
{closable && <PgIconButton title={gettext('Close')} icon={<CloseIcon style={{height: '0.7em'}} />} size="xs" noBorder onClick={()=>{
layoutDocker.close(id);
Expand Down Expand Up @@ -368,14 +390,16 @@ export class LayoutDocker {
this.saveLayout();
}

static getPanel({icon, title, closable, tooltip, renamable, manualClose, ...attrs}) {
static getPanel({icon, title, closable, tooltip, renamable, manualClose, bgcolor, fgcolor, ...attrs}) {
const internal = {
icon: icon,
title: title,
tooltip: tooltip,
closable: _.isUndefined(closable) ? manualClose : closable,
renamable: renamable,
manualClose: manualClose,
bgcolor: bgcolor,
fgcolor: fgcolor,
};
return {
cached: true,
Expand Down
23 changes: 21 additions & 2 deletions web/pgadmin/tools/debugger/static/js/DebuggerModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,13 +378,23 @@ export default class DebuggerModule {
let open_new_tab = browser_preferences.new_browser_tab_open;
const db_label = self.checkDbNameChange(data, dbNode, newTreeInfo);
let label = getAppropriateLabel(newTreeInfo);

// Extract bgcolor and fgcolor from server icon if available
let bgcolor = null;
let fgcolor = null;
if (newTreeInfo?.server?.icon) {
const iconParts = newTreeInfo.server.icon.split(' ');
bgcolor = iconParts[1] || null;
fgcolor = iconParts[2] || null;
}

pgAdmin.Browser.Events.trigger(
'pgadmin:tool:show',
`${BROWSER_PANELS.DEBUGGER_TOOL}_${trans_id}`,
url,
null,
{title: getDebuggerTitle(browser_preferences, label, newTreeInfo.schema.label, db_label, null, self.pgBrowser),
icon: 'fa fa-bug', manualClose: false, renamable: true},
icon: 'fa fa-bug', manualClose: false, renamable: true, bgcolor: bgcolor, fgcolor: fgcolor},
Boolean(open_new_tab?.includes('debugger'))
);
})
Expand Down Expand Up @@ -527,13 +537,22 @@ export default class DebuggerModule {

let label = getAppropriateLabel(treeInfo);

// Extract bgcolor and fgcolor from server icon if available
let bgcolor = null;
let fgcolor = null;
if (treeInfo?.server?.icon) {
const iconParts = treeInfo.server.icon.split(' ');
bgcolor = iconParts[1] || null;
fgcolor = iconParts[2] || null;
}

pgAdmin.Browser.Events.trigger(
'pgadmin:tool:show',
`${BROWSER_PANELS.DEBUGGER_TOOL}_${res.data.data.debuggerTransId}`,
url,
null,
{title: getDebuggerTitle(browser_preferences, label, db_label, db_label, null, self.pgBrowser),
icon: 'fa fa-bug', manualClose: false, renamable: true},
icon: 'fa fa-bug', manualClose: false, renamable: true, bgcolor: bgcolor, fgcolor: fgcolor},
Boolean(open_new_tab?.includes('debugger'))
);
})
Expand Down
11 changes: 10 additions & 1 deletion web/pgadmin/tools/erd/static/js/ERDModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,21 @@ export default class ERDModule {
const panelUrl = this.getPanelUrl(transId, parentData, gen);
const open_new_tab = usePreferences.getState().getPreferencesForModule('browser').new_browser_tab_open;

// Extract bgcolor and fgcolor from server icon if available
let bgcolor = null;
let fgcolor = null;
if (parentData?.server?.icon) {
const iconParts = parentData.server.icon.split(' ');
bgcolor = iconParts[1] || null;
fgcolor = iconParts[2] || null;
}

pgAdmin.Browser.Events.trigger(
'pgadmin:tool:show',
`${BROWSER_PANELS.ERD_TOOL}_${transId}`,
panelUrl,
{sql_id: toolDataId, connectionTitle: _.escape(panelTitle), db_name:parentData.database.label, server_name: parentData.server.label, user: parentData.server.user.name, server_type: parentData.server.server_type},
{title: 'Untitled', icon: 'fa fa-sitemap'},
{title: 'Untitled', icon: 'fa fa-sitemap', bgcolor: bgcolor, fgcolor: fgcolor},
Boolean(open_new_tab?.includes('erd_tool'))
);

Expand Down
11 changes: 10 additions & 1 deletion web/pgadmin/tools/psql/static/js/PsqlModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,21 @@ export default class Psql {

const open_new_tab = usePreferences.getState().getPreferencesForModule('browser').new_browser_tab_open;

// Extract bgcolor and fgcolor from server icon if available
let bgcolor = null;
let fgcolor = null;
if (parentData?.server?.icon) {
const iconParts = parentData.server.icon.split(' ');
bgcolor = iconParts[1] || null;
fgcolor = iconParts[2] || null;
}

pgAdmin.Browser.Events.trigger(
'pgadmin:tool:show',
`${BROWSER_PANELS.PSQL_TOOL}_${transId}`,
panelUrl,
{title: panelTitle, db: db_label, server_name: parentData.server.label, 'user': parentData.server.user.name },
{title: panelTitle, icon: 'pg-font-icon icon-terminal', manualClose: false, renamable: true},
{title: panelTitle, icon: 'pg-font-icon icon-terminal', manualClose: false, renamable: true, bgcolor: bgcolor, fgcolor: fgcolor},
Boolean(open_new_tab?.includes('psql_tool'))
);

Expand Down
15 changes: 14 additions & 1 deletion web/pgadmin/tools/schema_diff/static/js/SchemaDiffModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,25 @@ export default class SchemaDiff {
let browserPreferences = usePreferences.getState().getPreferencesForModule('browser');
let openInNewTab = browserPreferences.new_browser_tab_open;

// Extract bgcolor and fgcolor from selected server if available
let bgcolor = null;
let fgcolor = null;
const selectedItem = pgAdmin.Browser.tree?.selected();
if (selectedItem) {
const selectedNodeInfo = pgAdmin.Browser.tree?.getTreeNodeHierarchy(selectedItem);
if (selectedNodeInfo?.server?.icon) {
const iconParts = selectedNodeInfo.server.icon.split(' ');
bgcolor = iconParts[1] || null;
fgcolor = iconParts[2] || null;
}
}

pgAdmin.Browser.Events.trigger(
'pgadmin:tool:show',
`${BROWSER_PANELS.SCHEMA_DIFF_TOOL}_${trans_id}`,
baseUrl,
{...params},
{title: panelTitle, icon: 'pg-font-icon icon-compare', manualClose: false, renamable: true},
{title: panelTitle, icon: 'pg-font-icon icon-compare', manualClose: false, renamable: true, bgcolor: bgcolor, fgcolor: fgcolor},
Boolean(openInNewTab?.includes('schema_diff'))
);
return true;
Expand Down
11 changes: 10 additions & 1 deletion web/pgadmin/tools/sqleditor/static/js/SQLEditorModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,21 @@ export default class SQLEditor {
const [icon, tooltip] = panelTitleFunc.getQueryToolIcon(panel_title, is_query_tool);
let selectedNodeInfo = pgAdmin.Browser.tree?.selected() ? pgAdmin.Browser.tree?.getTreeNodeHierarchy(pgAdmin.Browser.tree.selected()) : null;

// Extract bgcolor and fgcolor from selectedNodeInfo if available
let bgcolor = null;
let fgcolor = null;
if (selectedNodeInfo?.server?.icon) {
const iconParts = selectedNodeInfo.server.icon.split(' ');
bgcolor = iconParts[1] || null;
fgcolor = iconParts[2] || null;
}

pgAdmin.Browser.Events.trigger(
'pgadmin:tool:show',
`${BROWSER_PANELS.QUERY_TOOL}_${trans_id}`,
panel_url,
{...params, title: panel_title, selectedNodeInfo: JSON.stringify(selectedNodeInfo)},
{title: panel_title, icon: icon, tooltip: tooltip, renamable: true},
{title: panel_title, icon: icon, tooltip: tooltip, renamable: true, bgcolor: bgcolor, fgcolor: fgcolor},
Boolean(open_new_tab?.includes('qt'))
);
return true;
Expand Down
Loading