-
Notifications
You must be signed in to change notification settings - Fork 842
Feat: Added a option to colorize panel/tab header based on server color #2431 #9799
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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, []) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can safely remove React.useCallback to simplify code. |
||
| ); | ||
| 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??''; | ||
|
|
@@ -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(); | ||
| } | ||
|
|
@@ -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) && ( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how does this work, if a tab is open and server color is changed? |
||
| <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); | ||
|
|
@@ -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, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what is this hack for? |
||
| } | ||
|
|
||
| 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')) | ||
| ); | ||
| }) | ||
|
|
@@ -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; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. repeated. |
||
| } | ||
|
|
||
| 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')) | ||
| ); | ||
| }) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. repeated |
||
| } | ||
|
|
||
| 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')) | ||
| ); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. repeated |
||
| } | ||
|
|
||
| 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')) | ||
| ); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i'm skeptical for this logic. kind of a hack, |
||
| } | ||
| } | ||
|
|
||
| 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; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. repeated. |
||
| } | ||
|
|
||
| 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; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix pycodestyle E501 on Line 106.
The new preference line exceeds the 79-char limit and is currently failing CI.
✂️ Suggested style-only fix
📝 Committable suggestion
🧰 Tools
🪛 GitHub Actions: Check Python style
[error] 106-106: pycodestyle reported E501: line too long (80 > 79 characters).
🤖 Prompt for AI Agents