42 lines
1.1 KiB
JavaScript
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;
|