-
Notifications
You must be signed in to change notification settings - Fork 539
dbeaver/pro#9522 integrate profile selector to connection form #4440
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
Open
sergeyteleshev
wants to merge
20
commits into
devel
Choose a base branch
from
9522-cb-network-profiles---add-to-connection-settings
base: devel
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
5a90238
dbeaver/pro#9522 integrate profile selector to connection form
sergeyteleshev c9c9029
Merge branch 'devel' into 9522-cb-network-profiles---add-to-connectio…
sergeyteleshev f5f1fcb
dbeaver/pro#9522 handles edge cases
sergeyteleshev 602fa49
dbeaver/pro#9522 uses rest instead of default getter
sergeyteleshev 2122b08
dbeaver/pro#9522 adds preprocessing to handle null/undefined differen…
sergeyteleshev dbbb1ee
Merge branch 'devel' into 9522-cb-network-profiles---add-to-connectio…
sergeyteleshev c02175d
dbeaver/pro#9522 eslint fix
sergeyteleshev cecfe28
Merge branch 'devel' into 9522-cb-network-profiles---add-to-connectio…
sergeyteleshev 40a9e72
dbeaver/pro#9522 refactors profiles
sergeyteleshev c43512c
dbeaver/pro#9522 removes preprocess
sergeyteleshev 8c279c5
Merge branch 'devel' into 9522-cb-network-profiles---add-to-connectio…
sergeyteleshev b7a3e9b
Merge branch 'devel' into 9522-cb-network-profiles---add-to-connectio…
sergeyteleshev ebdd022
Merge branch 'devel' into 9522-cb-network-profiles---add-to-connectio…
sergeyteleshev a9a596c
Merge branch 'devel' into 9522-cb-network-profiles---add-to-connectio…
EvgeniaBzzz c334149
Merge branch 'devel' into 9522-cb-network-profiles---add-to-connectio…
sergeyteleshev 0be4844
dbeaver/pro#9522 adds header & footer items
sergeyteleshev aaec613
dbeaver/pro#9522 truncates items values
sergeyteleshev 1aee6dc
dbeaver/pro#9522 fix retrieving creds from profiles
yagudin10 057ca95
Merge branch 'devel' into 9522-cb-network-profiles---add-to-connectio…
sergeyteleshev 7c8f6a9
Merge branch 'devel' into 9522-cb-network-profiles---add-to-connectio…
EvgeniaBzzz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,18 +8,18 @@ | |
|
|
||
| import { useState } from 'react'; | ||
| import clsx from 'clsx'; | ||
| import { SelectProvider, Select, SelectPopover, SelectItem, SelectLabel, type SelectProviderProps } from './Select.js'; | ||
| import { SelectProvider, Select, SelectPopover, SelectItem, SelectLabel, SelectGroup, type SelectProviderProps } from './Select.js'; | ||
| import './SelectField.css'; | ||
|
|
||
| export interface SelectItem<T> { | ||
| export interface ISelectItem<T> { | ||
| value: T; | ||
| label: string; | ||
| disabled?: boolean; | ||
| } | ||
|
|
||
| type PropertyGetter<ItemType, ValueType> = (item: ItemType) => ValueType; | ||
|
|
||
| export interface SelectFieldProps<T, ItemType = SelectItem<T>> { | ||
| export interface ISelectFieldProps<T, ItemType = ISelectItem<T>> { | ||
| /** Options array - can be SelectOption objects or arbitrary objects */ | ||
| items: ItemType[]; | ||
|
|
||
|
|
@@ -47,6 +47,12 @@ | |
| */ | ||
| itemDisabled?: PropertyGetter<ItemType, boolean>; | ||
|
|
||
| /** | ||
| * When true for an item, it acts as a group boundary — items are split into | ||
| * SelectGroup chunks separated by a CSS border. Separator items are not rendered. | ||
| */ | ||
| isSeparator?: PropertyGetter<ItemType, boolean>; | ||
|
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. please use SelectSeparator as separator
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. |
||
|
|
||
| value?: T; | ||
|
|
||
| onChange?: (value: T) => void; | ||
|
|
@@ -65,6 +71,18 @@ | |
|
|
||
| noItemsPlaceholder?: React.ReactNode; | ||
|
|
||
| /** | ||
| * Items pinned above the scrollable list, always visible at the top of the popover. | ||
| * Uses the same item API (itemValue, itemRender, itemDisabled) as the main items list. | ||
| */ | ||
| headerItems?: ItemType[]; | ||
|
|
||
| /** | ||
| * Items pinned below the scrollable list, always visible at the bottom of the popover. | ||
| * Uses the same item API (itemValue, itemRender, itemDisabled) as the main items list. | ||
| */ | ||
| footerItems?: ItemType[]; | ||
|
|
||
| /** | ||
| * Custom renderer for the selected value, overrides itemRenderer for the selected state | ||
| * Only needed for special formatting of the selected value different from list items | ||
|
|
@@ -94,16 +112,31 @@ | |
| return getter ? getter(item) : defaultGetter(item); | ||
| } | ||
|
|
||
| export function SelectField<T, ItemType extends {} = SelectItem<T>>({ | ||
| function splitIntoGroups<ItemType>(items: ItemType[], isSeparator: PropertyGetter<ItemType, boolean>): ItemType[][] { | ||
| const groups: ItemType[][] = [[]]; | ||
| for (const item of items) { | ||
| if (isSeparator(item)) { | ||
| groups.push([]); | ||
| } else { | ||
| groups[groups.length - 1]!.push(item); | ||
| } | ||
| } | ||
| return groups.filter(g => g.length > 0); | ||
| } | ||
|
|
||
| export function SelectField<T, ItemType extends {} = ISelectItem<T>>({ | ||
| items, | ||
| value, | ||
| onChange, | ||
| itemValue, | ||
| itemValueSerialized, | ||
| itemRender, | ||
| itemDisabled, | ||
| isSeparator, | ||
| label, | ||
| noItemsPlaceholder = 'No items', | ||
| headerItems, | ||
| footerItems, | ||
| description, | ||
| disabled, | ||
| required, | ||
|
|
@@ -115,18 +148,18 @@ | |
| autoFocusItemsOnShow, | ||
| name, | ||
| id, | ||
| }: SelectFieldProps<T, ItemType>) { | ||
| }: ISelectFieldProps<T, ItemType>) { | ||
| const getItemValue = (item: ItemType): T => | ||
| getValueByPath<ItemType, T>(item, itemValue, i => ('value' in i ? (i as unknown as SelectItem<T>).value : (i as unknown as T))); | ||
| getValueByPath<ItemType, T>(item, itemValue, i => ('value' in i ? (i as unknown as ISelectItem<T>).value : (i as unknown as T))); | ||
|
|
||
| const getItemValueSerialized = (item: ItemType): string => | ||
| getValueByPath<T, string>(getItemValue(item), itemValueSerialized, key => JSON.stringify(key)); | ||
|
|
||
| const renderItem = (item: ItemType): React.ReactNode => | ||
| getValueByPath<ItemType, React.ReactNode>(item, itemRender, i => ('label' in i ? (i as unknown as SelectItem<T>).label : String(i))); | ||
| getValueByPath<ItemType, React.ReactNode>(item, itemRender, i => ('label' in i ? (i as unknown as ISelectItem<T>).label : String(i))); | ||
|
|
||
| const isItemDisabled = (item: ItemType): boolean => | ||
| getValueByPath<ItemType, boolean>(item, itemDisabled, i => ('disabled' in i ? Boolean((i as unknown as SelectItem<T>).disabled) : false)); | ||
| getValueByPath<ItemType, boolean>(item, itemDisabled, i => ('disabled' in i ? Boolean((i as unknown as ISelectItem<T>).disabled) : false)); | ||
|
|
||
| const [selectedValue, setSelectedValue] = useState<T | undefined>(() => { | ||
| if (value !== undefined) { | ||
|
|
@@ -140,7 +173,8 @@ | |
| const handleChange = (newValue: string | readonly string[]) => { | ||
| // TODO: add support for multi-select | ||
|
|
||
| const newItem = items.find(item => getItemValueSerialized(item) === newValue); | ||
| const allItems = [...(headerItems ?? []), ...items, ...(footerItems ?? [])]; | ||
| const newItem = allItems.find(item => getItemValueSerialized(item) === newValue); | ||
| if (!newItem) { | ||
| return; | ||
| } | ||
|
|
@@ -157,8 +191,30 @@ | |
| } | ||
|
|
||
| const selectedItem = currentValue !== undefined ? items.find(item => getItemValueSerialized(item) === currentValueSerialized) : undefined; | ||
| const displayValue = selectedRender ? selectedRender(currentValue, selectedItem) : selectedItem ? renderItem(selectedItem) : ''; | ||
|
|
||
| function renderSelectItem(item: ItemType) { | ||
| return ( | ||
| <SelectItem key={getItemValueSerialized(item)} value={getItemValueSerialized(item)} disabled={isItemDisabled(item)}> | ||
| {renderItem(item)} | ||
| </SelectItem> | ||
| ); | ||
| } | ||
|
|
||
| function renderItems(): React.ReactNode { | ||
| if (items.length === 0) { | ||
| return <div className="dbv-kit-select__empty">{noItemsPlaceholder}</div>; | ||
| } | ||
|
|
||
| if (isSeparator) { | ||
| return splitIntoGroups(items, isSeparator).map(group => ( | ||
| <SelectGroup key={getItemValueSerialized(group[0]!)}>{group.map(renderSelectItem)}</SelectGroup> | ||
| )); | ||
| } | ||
|
|
||
| return items.map(renderSelectItem); | ||
| } | ||
|
|
||
| return ( | ||
| <div className={clsx('dbv-kit-select-field', className)}> | ||
| <SelectProvider value={currentValueSerialized} setValue={val => handleChange(val)} store={store}> | ||
|
|
@@ -171,14 +227,12 @@ | |
| {description && <span className="dbv-kit-select__description">{description}</span>} | ||
|
|
||
| <SelectPopover autoFocusOnShow={autoFocusItemsOnShow} portal={portal} gutter={4} unmountOnHide> | ||
| {items.length === 0 ? ( | ||
| <div className="dbv-kit-select__empty">{noItemsPlaceholder}</div> | ||
| ) : ( | ||
| items.map(item => ( | ||
| <SelectItem key={getItemValueSerialized(item)} value={getItemValueSerialized(item)} disabled={isItemDisabled(item)}> | ||
| {renderItem(item)} | ||
| </SelectItem> | ||
| )) | ||
| {headerItems && headerItems.length > 0 && ( | ||
| <SelectGroup className="dbv-kit-select__popover-header">{headerItems.map(renderSelectItem)}</SelectGroup> | ||
| )} | ||
| <div className="dbv-kit-select__popover-items">{renderItems()}</div> | ||
| {footerItems && footerItems.length > 0 && ( | ||
| <SelectGroup className="dbv-kit-select__popover-footer">{footerItems.map(renderSelectItem)}</SelectGroup> | ||
| )} | ||
| </SelectPopover> | ||
| </SelectProvider> | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.

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.
have you checked ellipsis after this fix?
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.
all cool
