Skip to content
Merged
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
3 changes: 3 additions & 0 deletions src/components/AggregationPanel/AggregationPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const AggregationPanel = ({
cloudCodeFunction = null,
panelTitle = null,
style,
onContextMenu,
}) => {
const [isExpanded, setIsExpanded] = useState(false);
const [nestedData, setNestedData] = useState(null);
Expand Down Expand Up @@ -137,6 +138,7 @@ const AggregationPanel = ({
cloudCodeFunction={item.cloudCodeFunction}
panelTitle={item.title}
style={item.style}
onContextMenu={onContextMenu}
/>
</div>
);
Expand Down Expand Up @@ -205,6 +207,7 @@ const AggregationPanel = ({
return (
<div
onKeyDown={handleKeyDown}
onContextMenu={onContextMenu}
tabIndex={0}
>
{isLoadingInfoPanel ? (
Expand Down
44 changes: 44 additions & 0 deletions src/components/BrowserCell/BrowserCell.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,18 @@ export default class BrowserCell extends Component {
});
}

// Sort menu items alphabetically by text
contextMenuOptions.sort((a, b) => a.text.localeCompare(b.text));

// Add separator and "Add to config parameter..." after the sorted items
const addToConfigOption = this.getAddToConfigContextMenuOption();
if (addToConfigOption && contextMenuOptions.length > 0) {
contextMenuOptions.push({ type: 'separator' });
contextMenuOptions.push(addToConfigOption);
} else if (addToConfigOption) {
contextMenuOptions.push(addToConfigOption);
}

return contextMenuOptions;
}

Expand Down Expand Up @@ -618,6 +630,38 @@ export default class BrowserCell extends Component {
return relatedRecordsMenuItem.items.length ? relatedRecordsMenuItem : undefined;
}

getAddToConfigContextMenuOption() {
const { arrayConfigParams, onAddToArrayConfig, hidden } = this.props;

// Don't show for hidden cells to prevent leaking sensitive values
if (hidden) {
return;
}

// Only show if there are array config params and handler is available
if (!arrayConfigParams || arrayConfigParams.length === 0 || !onAddToArrayConfig) {
return;
}

// Get the cell's copyable value as string
const cellValue = this.copyableValue !== undefined ? String(this.copyableValue) : '';

// Don't show for empty or special values
if (!cellValue || cellValue === '(undefined)' || cellValue === '(null)' || cellValue === '(hidden)') {
return;
}

return {
text: 'Add to config parameter...',
items: arrayConfigParams.map(param => ({
text: param.name,
callback: () => {
onAddToArrayConfig(param.name, cellValue);
},
})),
};
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
}

pickFilter(constraint, addToExistingFilter) {
const definition = Filters.Constraints[constraint];
const { filters, type, value, field, className } = this.props;
Expand Down
2 changes: 2 additions & 0 deletions src/components/BrowserRow/BrowserRow.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ export default class BrowserRow extends Component {
setShowAggregatedData={this.props.setShowAggregatedData}
setErrorAggregatedData={this.props.setErrorAggregatedData}
firstSelectedCell={this.props.firstSelectedCell}
arrayConfigParams={this.props.arrayConfigParams}
onAddToArrayConfig={this.props.onAddToArrayConfig}
/>
);
})}
Expand Down
41 changes: 34 additions & 7 deletions src/components/ContextMenu/ContextMenu.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const getPositionToFitVisibleScreen = (ref, offset = 0) => {
const xLeft = prevElBox.left - elBox.left - elBox.width;

// Align submenu vertically with the hovered item in the parent menu
// offset is the pixel position of the hovered item (index * 30px item height)
// offset is the actual pixel position of the hovered item (via offsetTop)
// Subtract parent's scrollTop to account for scrolled position
const adjustedOffset = offset - prevEl.scrollTop;
let proposedTop = prevElBox.top + adjustedOffset;
Expand All @@ -59,14 +59,15 @@ const getPositionToFitVisibleScreen = (ref, offset = 0) => {
};
};

const MenuSection = ({ level, items, path, setPath, hide }) => {
const MenuSection = ({ level, items, path, setPath, hide, hoveredItemOffset }) => {
const sectionRef = useRef(null);
const [position, setPosition] = useState(null);
const basePosition = useRef(null);
const initialParentScrollTop = useRef(0);

useEffect(() => {
const newPosition = getPositionToFitVisibleScreen(sectionRef, path[level] * 30);
// Use the actual pixel offset of the hovered item instead of index-based calculation
const newPosition = getPositionToFitVisibleScreen(sectionRef, hoveredItemOffset);
if (newPosition) {
setPosition(newPosition);
basePosition.current = newPosition;
Expand All @@ -76,7 +77,7 @@ const MenuSection = ({ level, items, path, setPath, hide }) => {
initialParentScrollTop.current = prevEl.scrollTop;
}
}
}, []);
}, [hoveredItemOffset]);

// Listen for scroll events on the parent menu and adjust position
useEffect(() => {
Expand Down Expand Up @@ -114,12 +115,25 @@ const MenuSection = ({ level, items, path, setPath, hide }) => {
return (
<ul ref={sectionRef} className={styles.category} style={style}>
{items.map((item, index) => {
const handleHover = () => {
const handleHover = (event) => {
const newPath = path.slice(0, level + 1);
newPath.push(index);
setPath(newPath);
// Get the actual pixel offset of the hovered item relative to its parent
const itemElement = event.currentTarget;
const itemOffset = itemElement.offsetTop;
setPath(newPath, itemOffset);
};

// Handle separator items
if (item.type === 'separator') {
return (
<li
key={`menu-section-${level}-${index}`}
className={styles.separator}
/>
);
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

return (
<li
key={`menu-section-${level}-${index}`}
Expand All @@ -144,6 +158,8 @@ const MenuSection = ({ level, items, path, setPath, hide }) => {

const ContextMenu = ({ x, y, items }) => {
const [path, setPath] = useState([0]);
// Track the pixel offset of the hovered item for each level
const [hoveredOffsets, setHoveredOffsets] = useState([0]);
const [visible, setVisible] = useState(true);
const menuRef = useRef(null);

Expand All @@ -154,6 +170,16 @@ const ContextMenu = ({ x, y, items }) => {
const hide = () => {
setVisible(false);
setPath([0]);
setHoveredOffsets([0]);
};

// Combined setter that updates both path and offsets
const updatePath = (newPath, itemOffset) => {
setPath(newPath);
// Update offsets array to match the new path length
const newOffsets = hoveredOffsets.slice(0, newPath.length - 1);
newOffsets.push(itemOffset);
setHoveredOffsets(newOffsets);
};

useEffect(() => {
Expand Down Expand Up @@ -193,10 +219,11 @@ const ContextMenu = ({ x, y, items }) => {
<MenuSection
key={`section-${path[level]}-${level}`}
path={path}
setPath={setPath}
setPath={updatePath}
level={level}
items={itemsForLevel}
hide={hide}
hoveredItemOffset={hoveredOffsets[level] || 0}
/>
);
})}
Expand Down
13 changes: 13 additions & 0 deletions src/components/ContextMenu/ContextMenu.scss
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@
background: rgba(255, 255, 255, 0.1);
}

.separator {
height: 1px;
padding: 0;
margin: 5px 10px;
background: rgba(255, 255, 255, 0.2);
cursor: default;
pointer-events: none;

&:hover {
background: rgba(255, 255, 255, 0.2);
}
}

.category {
position: absolute;
// Keep above the toolbar (src/components/Toolbar/Toolbar.scss).
Expand Down
45 changes: 45 additions & 0 deletions src/components/StringEditor/StringEditor.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export default class StringEditor extends React.Component {

this.checkExternalClick = this.checkExternalClick.bind(this);
this.handleKey = this.handleKey.bind(this);
this.handleContextMenu = this.handleContextMenu.bind(this);
this.inputRef = React.createRef();
}

Expand Down Expand Up @@ -61,6 +62,48 @@ export default class StringEditor extends React.Component {
}
}

handleContextMenu(e) {
const { setContextMenu, arrayConfigParams, onAddToArrayConfig } = this.props;

// Only show custom context menu when Alt key is held
if (!e.altKey) {
return;
}

// Check if there are array config params available
if (!arrayConfigParams || arrayConfigParams.length === 0 || !onAddToArrayConfig || !setContextMenu) {
return;
}

// Get selected text from the input/textarea
const input = this.inputRef.current;
const selectedText = input.value.substring(input.selectionStart, input.selectionEnd).trim();

// Only show if there's selected text
if (!selectedText) {
return;
}

// Prevent default context menu
e.preventDefault();
e.stopPropagation();

// Build context menu items
const menuItems = [
{
text: 'Add to config parameter...',
items: arrayConfigParams.map(param => ({
text: param.name,
callback: () => {
onAddToArrayConfig(param.name, selectedText);
},
})),
},
];

setContextMenu(e.pageX, e.pageY, menuItems);
}

render() {
const classes = [styles.editor];
const onChange = this.props.readonly ? () => {} : e => this.setState({ value: e.target.value });
Expand All @@ -79,6 +122,7 @@ export default class StringEditor extends React.Component {
ref={this.inputRef}
value={this.state.value}
onChange={onChange}
onContextMenu={this.handleContextMenu}
style={style}
/>
</div>
Expand All @@ -90,6 +134,7 @@ export default class StringEditor extends React.Component {
ref={this.inputRef}
value={this.state.value}
onChange={onChange}
onContextMenu={this.handleContextMenu}
disabled={this.props.readonly}
/>
</div>
Expand Down
Loading
Loading