Files
lcp-visualizer/blocks/components/ParentCellRenderer.js
Jeremy Rangel dd4bd0caf5 Initial
2025-01-21 18:41:51 -08:00

42 lines
1.1 KiB
JavaScript

import { SelectControl } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
const ParentCellRenderer = (props) => {
if (!props.data || !props.data.ID) {
return null;
}
// Create options from all available rows except current
const options = [
{ label: __('None', 'lcp-visualize'), value: '' }
];
// Get all rows from the grid
props.api.forEachNode(node => {
if (node.data &&
node.data.ID &&
node.data.ID !== props.data.ID) {
options.push({
label: node.data.Label || node.data.ID,
value: node.data.ID
});
}
});
const handleChange = (newValue) => {
if (props.context && props.context.handleParentChange) {
props.context.handleParentChange(props.data, newValue);
}
};
return (
<SelectControl
value={props.data.Parent || ''}
options={options}
onChange={handleChange}
/>
);
};
export default ParentCellRenderer;