-
Notifications
You must be signed in to change notification settings - Fork 504
dbeaver/pro#4999 Data editor icons to see pk details #4040
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: devel
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 | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,96 @@ | ||||||
| /* | ||||||
| * CloudBeaver - Cloud Database Manager | ||||||
| * Copyright (C) 2020-2026 DBeaver Corp and others | ||||||
| * | ||||||
| * Licensed under the Apache License, Version 2.0. | ||||||
| * you may not use this file except in compliance with the License. | ||||||
| */ | ||||||
| import type { SqlResultColumn } from '@cloudbeaver/core-sdk'; | ||||||
| import { observer } from 'mobx-react-lite'; | ||||||
| import { useContext } from 'react'; | ||||||
| import { clsx } from '@dbeaver/ui-kit'; | ||||||
|
|
||||||
| import { IconOrImage, useTranslate } from '@cloudbeaver/core-blocks'; | ||||||
|
|
||||||
| import { DataGridContext } from '../DataGridContext.js'; | ||||||
| import { TableDataContext } from '../TableDataContext.js'; | ||||||
|
|
||||||
| interface Props { | ||||||
| readOnlyConnection: boolean; | ||||||
| } | ||||||
|
|
||||||
| const STATUS_COLOR = 'status'; | ||||||
| const POSITIVE_COLOR = 'positive'; | ||||||
| const INFO_COLOR = 'info'; | ||||||
|
|
||||||
| export const TableStatusIndicator = observer<Props>(function TableStatusIndicator({ readOnlyConnection }) { | ||||||
| const dataGridContext = useContext(DataGridContext); | ||||||
| const tableDataContext = useContext(TableDataContext); | ||||||
| const translate = useTranslate(); | ||||||
|
|
||||||
| if (!tableDataContext || !dataGridContext) { | ||||||
| return null; | ||||||
| } | ||||||
|
|
||||||
| const hasRowIdentifier = dataGridContext.model.hasElementIdentifier(dataGridContext.resultIndex); | ||||||
|
|
||||||
| const firstColumn = tableDataContext.columns[1]; | ||||||
| const firstColumnData = | ||||||
| firstColumn?.key !== null && firstColumn?.key !== undefined | ||||||
|
Member
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.
Suggested change
|
||||||
| ? (tableDataContext.data.getColumn(firstColumn.key) as SqlResultColumn | undefined) | ||||||
| : undefined; | ||||||
| const readOnlyStatus = firstColumnData?.readOnlyStatus; | ||||||
|
|
||||||
| // TODO: Detect virtual keys when backend provides the information | ||||||
| const isVirtualKey = false; | ||||||
| const tooltipParts: string[] = []; | ||||||
|
|
||||||
| if (readOnlyConnection) { | ||||||
| tooltipParts.push(translate('data_grid_table_readonly_connection_tooltip')); | ||||||
| } | ||||||
|
|
||||||
| if (readOnlyStatus) { | ||||||
| if (!readOnlyConnection) { | ||||||
| tooltipParts.push(translate('data_grid_table_readonly_tooltip')); | ||||||
| } | ||||||
| tooltipParts.push(readOnlyStatus); | ||||||
| } | ||||||
|
|
||||||
| if (hasRowIdentifier) { | ||||||
| // TEMPORARY: Detect primary key by checking for required and not read-only columns | ||||||
| // TODO: Remove when backend provides the information | ||||||
| const pkColumn = tableDataContext.columns.find(col => { | ||||||
| const colData = col.key && (tableDataContext.data.getColumn(col.key) as SqlResultColumn | undefined); | ||||||
| return colData?.required && !colData?.readOnly; | ||||||
| })?.key; | ||||||
|
|
||||||
| if (pkColumn) { | ||||||
| tooltipParts.push(`Unique key: ${(tableDataContext.data.getColumn(pkColumn) as SqlResultColumn | undefined)?.name}`); | ||||||
| } | ||||||
| } | ||||||
|
Comment on lines
+48
to
+70
Member
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 not sure that it's good idea to try to implement this logic on frontend, because it might be different from dbeaver or incomplete |
||||||
|
|
||||||
| const tooltip = tooltipParts.join('\n'); | ||||||
|
|
||||||
| let themeColor = STATUS_COLOR; | ||||||
| if (hasRowIdentifier && !isVirtualKey) { | ||||||
| themeColor = POSITIVE_COLOR; | ||||||
| } else if (isVirtualKey) { | ||||||
| themeColor = INFO_COLOR; | ||||||
| } | ||||||
|
|
||||||
| return ( | ||||||
| <div | ||||||
| title={tooltip} | ||||||
| className="tw:absolute tw:top-1/2 tw:left-1 tw:-translate-y-1/2 tw:z-1 tw:pointer-events-auto tw:flex tw:items-center tw:gap-1 tw:cursor-help" | ||||||
| > | ||||||
| {readOnlyConnection && <IconOrImage icon="/icons/lock.png" className="tw:w-2.5 tw:cursor-help" />} | ||||||
| <div | ||||||
| className={clsx( | ||||||
| 'tw:w-3 tw:h-3 tw:rounded-full tw:shrink-0 tw:bg-transparent tw:border', | ||||||
| "tw:before:content-[''] tw:before:block tw:before:w-1.5 tw:before:h-1.5 tw:before:rounded-full tw:before:m-0.5", | ||||||
| `tw:border-(--theme-${themeColor}) tw:before:bg-(--theme-${themeColor})`, | ||||||
| )} | ||||||
| /> | ||||||
|
Comment on lines
+87
to
+93
Member
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. do we really need to always show this indicator? if table is normal table without restrictions and limitations, what the purpose of this indicator?
Contributor
Author
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. |
||||||
| </div> | ||||||
| ); | ||||||
| }); | ||||||

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.
seems like this prop not needed, component itself uses
dataGridContextand can retrieve this information by itself