-
Notifications
You must be signed in to change notification settings - Fork 2
Migrate editing, polling and resizing functionality #2
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
jreineckearm
merged 2 commits into
eclipse-cdt-cloud:main
from
haydar-metin:migrate-peripheral-inspector-v2
Mar 31, 2025
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,21 +1,23 @@ | ||
| /********************************************************************************** | ||
| * Copyright (c) 2025 Company and others. | ||
| * Copyright (c) 2025 EclipseSource and others. | ||
| * | ||
| * This program and the accompanying materials are made available under the | ||
| * terms of the MIT License as outlined in the LICENSE file. | ||
| **********************************************************************************/ | ||
|
|
||
| export function classNames(...classes: (string | Record<string, boolean>)[]): string { | ||
| export function classNames(...classes: (string | Record<string, boolean> | undefined)[]): string { | ||
| return classes | ||
| .filter(c => c !== undefined) | ||
| .map(c => { | ||
| if (typeof c === 'string') { | ||
| return c; | ||
| .map(className => { | ||
| if (!className) { | ||
| return ''; | ||
| } | ||
|
|
||
| return Object.entries(c) | ||
| if (typeof className === 'string') { | ||
| return className; | ||
| } | ||
| return Object.entries(className) | ||
| .filter(([, value]) => value) | ||
| .map(([key]) => key); | ||
| }) | ||
| .filter(className => className.length > 0) | ||
| .join(' '); | ||
| } |
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 |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| /********************************************************************************** | ||
| * Copyright (c) 2025 EclipseSource and others. | ||
| * | ||
| * This program and the accompanying materials are made available under the | ||
| * terms of the MIT License as outlined in the LICENSE file. | ||
| **********************************************************************************/ | ||
|
|
||
| import React from 'react'; | ||
| import { CommandDefinition } from '../../../../vscode/webview-types'; | ||
| import { CDTTreeItem, CDTTreeItemResource, CDTTreeTableActionColumn, CDTTreeTableActionColumnCommand } from '../../../common'; | ||
|
|
||
| export interface ActionCellProps<T extends CDTTreeItemResource> { | ||
| column: CDTTreeTableActionColumn; | ||
| record: CDTTreeItem<T>; | ||
| actions: CDTTreeTableActionColumnCommand[]; | ||
| onAction?: (event: React.UIEvent, command: CommandDefinition, value: unknown, record: CDTTreeItem<T>) => void; | ||
| } | ||
|
|
||
| const ActionCell = <T extends CDTTreeItemResource>({ record, actions, onAction }: ActionCellProps<T>) => { | ||
| return ( | ||
| <div className='tree-actions'> | ||
| {actions.map(action => { | ||
| const handleAction = (e: React.MouseEvent | React.KeyboardEvent) => { | ||
| e.stopPropagation(); | ||
| e.preventDefault(); | ||
| onAction?.(e, action, action.value, record); | ||
| }; | ||
| return ( | ||
| <i | ||
| key={action.commandId} | ||
| title={action.title} | ||
| className={`codicon codicon-${action.icon}`} | ||
| onClick={handleAction} | ||
| role='button' | ||
| tabIndex={0} | ||
| onKeyDown={e => e.key === 'Enter' && handleAction(e)} | ||
| /> | ||
| ); | ||
| })} | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default ActionCell; |
157 changes: 157 additions & 0 deletions
157
src/tree/browser/components/cells/EditableStringCell.tsx
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 |
|---|---|---|
| @@ -0,0 +1,157 @@ | ||
| /********************************************************************************** | ||
| * Copyright (c) 2025 EclipseSource and others. | ||
| * | ||
| * This program and the accompanying materials are made available under the | ||
| * terms of the MIT License as outlined in the LICENSE file. | ||
| **********************************************************************************/ | ||
|
|
||
| import '../../../../../style/tree/editable-string-cell.css'; | ||
|
|
||
| import { Checkbox, Input, Select } from 'antd'; | ||
| import type { CheckboxChangeEvent } from 'antd/lib/checkbox'; | ||
| import React, { useCallback, useEffect, useRef } from 'react'; | ||
| import { CDTTreeItem, CDTTreeItemResource, EditableCDTTreeTableStringColumn } from '../../../common'; | ||
| import LabelCell from './LabelCell'; | ||
|
|
||
| interface EditableLabelCellProps<T extends CDTTreeItemResource> { | ||
| column: EditableCDTTreeTableStringColumn; | ||
| record: CDTTreeItem<T>; | ||
| editing: boolean; | ||
| autoFocus: boolean; | ||
| onSubmit: (newValue: string) => void; | ||
| onCancel: () => void; | ||
| onEdit?: (edit: boolean) => void; | ||
| } | ||
|
|
||
| const EditableLabelCell = <T extends CDTTreeItemResource>({ | ||
| column, | ||
| record, | ||
| editing, | ||
| autoFocus, | ||
| onSubmit, | ||
| onCancel, | ||
| onEdit | ||
| }: EditableLabelCellProps<T>) => { | ||
| const containerRef = useRef<HTMLDivElement>(null); | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| const editorRef = useRef<any>(null); | ||
|
|
||
| const commitEdit = useCallback( | ||
| (newValue: string, event?: { stopPropagation: () => void; preventDefault: () => void }) => { | ||
| event?.stopPropagation(); | ||
| event?.preventDefault(); | ||
| onSubmit(newValue); | ||
| onEdit?.(false); | ||
| }, | ||
| [onSubmit] | ||
| ); | ||
|
|
||
| const cancelEdit = useCallback(() => { | ||
| onCancel(); | ||
| onEdit?.(false); | ||
| }, [column.edit.value, onCancel, onEdit]); | ||
|
|
||
| // Cancel the edit only if focus leaves the entire container. | ||
| const handleBlur = useCallback(() => { | ||
| setTimeout(() => { | ||
| if (containerRef.current && document.activeElement && !containerRef.current.contains(document.activeElement)) { | ||
| cancelEdit(); | ||
| } | ||
| }, 0); | ||
| }, [cancelEdit]); | ||
|
|
||
| const handleKeyDown = useCallback( | ||
| (e: React.KeyboardEvent) => { | ||
| if (e.key === 'Escape') { | ||
| cancelEdit(); | ||
| } | ||
| e.stopPropagation(); | ||
| }, | ||
| [cancelEdit] | ||
| ); | ||
|
|
||
| // Consume the double-click event so no other handler is triggered. | ||
| const handleDoubleClick = useCallback( | ||
| (e: React.MouseEvent) => { | ||
| e.preventDefault(); | ||
| e.stopPropagation(); | ||
| onEdit?.(true); | ||
| }, | ||
| [column, onEdit] | ||
| ); | ||
|
|
||
| // Focus the editor when entering edit mode. | ||
| useEffect(() => { | ||
| if (editing && editorRef.current && autoFocus) { | ||
| editorRef.current.focus(); | ||
| } | ||
| }, [editing, autoFocus]); | ||
|
|
||
| if (editing) { | ||
| return ( | ||
| <div className='edit-field-container' ref={containerRef}> | ||
| {(() => { | ||
| switch (column.edit.type) { | ||
| case 'text': | ||
| return ( | ||
| <Input | ||
| ref={editorRef} | ||
| className={'text-field-cell'} | ||
| defaultValue={column.edit.value} | ||
| onPressEnter={e => commitEdit(e.currentTarget.value, e)} | ||
| onBlur={handleBlur} | ||
| onClick={e => e.stopPropagation()} | ||
| onKeyDown={handleKeyDown} | ||
| /> | ||
| ); | ||
| case 'boolean': { | ||
| const checked = column.edit.value === '1'; | ||
| return ( | ||
| <Checkbox | ||
| ref={editorRef} | ||
| checked={checked} | ||
| onChange={(e: CheckboxChangeEvent) => commitEdit(e.target.checked ? '1' : '0', e)} | ||
| onBlur={handleBlur} | ||
| onClick={e => e.stopPropagation()} | ||
| onKeyDown={handleKeyDown} | ||
| /> | ||
| ); | ||
| } | ||
| case 'enum': { | ||
| return ( | ||
| <Select | ||
| ref={editorRef} | ||
| className={'enum-field-cell'} | ||
| placeholder={column.label} | ||
| value={column.label} // we want to use 'Write Only' as value even if it is not an option | ||
| onChange={newValue => commitEdit(newValue)} | ||
| onBlur={handleBlur} | ||
| onClick={e => e.stopPropagation()} | ||
| onKeyDown={handleKeyDown} | ||
| > | ||
| {column.edit.options.map(opt => { | ||
| return ( | ||
| <Select.Option key={opt.value} value={opt.value}> | ||
| {opt.label} | ||
| </Select.Option> | ||
| ); | ||
| })} | ||
| </Select> | ||
| ); | ||
| } | ||
| default: | ||
| return null; | ||
| } | ||
| })()} | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <div className='editable-string-cell' onDoubleClick={handleDoubleClick}> | ||
| <LabelCell record={record} column={column} /> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default React.memo(EditableLabelCell); |
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 |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| /********************************************************************************** | ||
| * Copyright (c) 2025 EclipseSource and others. | ||
| * | ||
| * This program and the accompanying materials are made available under the | ||
| * terms of the MIT License as outlined in the LICENSE file. | ||
| **********************************************************************************/ | ||
|
|
||
| import classNames from 'classnames'; | ||
| import React from 'react'; | ||
| import { createHighlightedText, createLabelWithTooltip } from '../../../../label/label-helpers'; | ||
| import { CDTTreeItem, CDTTreeItemResource, CDTTreeTableStringColumn } from '../../../common'; | ||
|
|
||
| export interface LabelCellProps<T extends CDTTreeItemResource> { | ||
| column: CDTTreeTableStringColumn; | ||
| record: CDTTreeItem<T>; | ||
| } | ||
|
|
||
| const LabelCell = <T extends CDTTreeItemResource>({ column }: LabelCellProps<T>) => { | ||
| const icon = column.icon && <i className={classNames('cell-icon', column.icon)} />; | ||
|
|
||
| const content = column.tooltip | ||
| ? createLabelWithTooltip(<span>{createHighlightedText(column.label, column.highlight)}</span>, column.tooltip) | ||
| : createHighlightedText(column.label, column.highlight); | ||
|
|
||
| return ( | ||
| <div className='tree-cell ant-table-cell-ellipsis' tabIndex={0}> | ||
| {icon} | ||
| {content} | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default React.memo(LabelCell); |
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 |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| /********************************************************************************** | ||
| * Copyright (c) 2025 EclipseSource and others. | ||
| * | ||
| * This program and the accompanying materials are made available under the | ||
| * terms of the MIT License as outlined in the LICENSE file. | ||
| **********************************************************************************/ | ||
|
|
||
| import React, { useCallback } from 'react'; | ||
| import { CDTTreeItem, CDTTreeItemResource, CDTTreeTableStringColumn, EditableCDTTreeTableStringColumn } from '../../../common'; | ||
| import EditableStringCell from './EditableStringCell'; | ||
| import LabelCell from './LabelCell'; | ||
|
|
||
| interface StringCellProps<T extends CDTTreeItemResource> { | ||
| column: CDTTreeTableStringColumn; | ||
| record: CDTTreeItem<T>; | ||
| editing?: boolean; | ||
| autoFocus?: boolean; | ||
| onSubmit?: (record: CDTTreeItem<T>, newValue: string) => void; | ||
| onCancel?: (record: CDTTreeItem<T>) => void; | ||
| onEdit?: (record: CDTTreeItem<T>, edit: boolean) => void; | ||
| } | ||
|
|
||
| const StringCell = <T extends CDTTreeItemResource>({ | ||
| column, | ||
| record, | ||
| editing = false, | ||
| autoFocus = false, | ||
| onSubmit, | ||
| onCancel, | ||
| onEdit | ||
| }: StringCellProps<T>) => { | ||
| const handleSubmit = useCallback((newValue: string) => onSubmit?.(record, newValue), [record, onSubmit]); | ||
|
|
||
| const handleCancel = useCallback(() => onCancel?.(record), [record, onCancel]); | ||
|
|
||
| const handleEdit = useCallback((edit: boolean) => onEdit?.(record, edit), [record, onEdit]); | ||
|
|
||
| return column.edit && onSubmit ? ( | ||
| <EditableStringCell | ||
| record={record} | ||
| column={column as EditableCDTTreeTableStringColumn} | ||
| onSubmit={handleSubmit} | ||
| onCancel={handleCancel} | ||
| onEdit={handleEdit} | ||
| editing={editing} | ||
| autoFocus={autoFocus} | ||
| /> | ||
| ) : ( | ||
| <LabelCell record={record} column={column} /> | ||
| ); | ||
| }; | ||
|
|
||
| export default StringCell; |
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.
Uh oh!
There was an error while loading. Please reload this page.