Changes to datagrid
This commit is contained in:
@ -1 +1 @@
|
|||||||
<?php return array('dependencies' => array('react', 'react-dom', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => '81e2f5a896da526cb195');
|
<?php return array('dependencies' => array('react', 'react-dom', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => '6c47b2075da54fd439aa');
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@ -45,6 +45,10 @@
|
|||||||
"type": "number",
|
"type": "number",
|
||||||
"default": 1
|
"default": 1
|
||||||
},
|
},
|
||||||
|
"dataTypes" :{
|
||||||
|
"type": "object",
|
||||||
|
"default" :{}
|
||||||
|
},
|
||||||
"gridColumnDefinitions": {
|
"gridColumnDefinitions": {
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"default": [
|
"default": [
|
||||||
|
|||||||
@ -64,12 +64,12 @@ export default function Edit({ attributes, setAttributes }) {
|
|||||||
help={__('Select the logic for setting the colors', 'lcp')}
|
help={__('Select the logic for setting the colors', 'lcp')}
|
||||||
value={hierarchicalSource || 'parent'}
|
value={hierarchicalSource || 'parent'}
|
||||||
options={[
|
options={[
|
||||||
{ label: 'Parent Column', value: 'parent' },
|
{ label: 'Color Column', value: 'colorColumn' },
|
||||||
{ label: 'Column Order', value: 'columnOrder' }
|
{ label: 'Swatch', value: 'swatch' }
|
||||||
]}
|
]}
|
||||||
onChange={(value) => setAttributes({ hierarchicalSource: value })}
|
onChange={(value) => setAttributes({ hierarchicalSource: value })}
|
||||||
/>
|
/>
|
||||||
{hierarchicalSource === 'columnOrder' && (
|
{hierarchicalSource === 'swatch' && (
|
||||||
<TextControl
|
<TextControl
|
||||||
label={__('Hierarchical Column Order', 'lcp')}
|
label={__('Hierarchical Column Order', 'lcp')}
|
||||||
value={hierarchicalColumnOrder}
|
value={hierarchicalColumnOrder}
|
||||||
|
|||||||
@ -77,11 +77,7 @@ function lcpCellRenderer(params) {
|
|||||||
console.log('Grid is not ready yet');
|
console.log('Grid is not ready yet');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
// let gridData = [
|
|
||||||
// { Department2: 'Sheriffs Office 2', Budget: '150000', MeetAt: '12/12/2025', PreferredColor: '#e0e0e0', PostContent: '<div> </div>' },
|
|
||||||
// { Department2: 'Treasurer2', Budget: '10000', MeetAt: '12-05', PreferredColor: '#232323', PostContent: '<p> </p>' },
|
|
||||||
// { Department2: 'Assessor2', Budget: '40000', MeetAt: 1737718512, PreferredColor: 'red', PostContent: '<h1> </h1>' },
|
|
||||||
// ];
|
|
||||||
|
|
||||||
const gridData = dataset;
|
const gridData = dataset;
|
||||||
// Helper function to detect the data type of a value
|
// Helper function to detect the data type of a value
|
||||||
@ -224,6 +220,15 @@ const isValidCSSColor = (value) => {
|
|||||||
|
|
||||||
return dataTypes;
|
return dataTypes;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Use useEffect to update dataTypes whenever data changes
|
||||||
|
useEffect(() => {
|
||||||
|
if (data && data.length > 0) {
|
||||||
|
const detectedDataTypes = detectDataTypes(data);
|
||||||
|
setAttributes({ dataTypes: detectedDataTypes });
|
||||||
|
}
|
||||||
|
}, [data, setAttributes]);
|
||||||
|
|
||||||
// Assuming gridData is already populated
|
// Assuming gridData is already populated
|
||||||
const gridDataTypes = detectDataTypes(gridData); // This will detect the types of each field
|
const gridDataTypes = detectDataTypes(gridData); // This will detect the types of each field
|
||||||
|
|
||||||
@ -315,11 +320,13 @@ const isValidCSSColor = (value) => {
|
|||||||
|
|
||||||
const columns = keys.map((key, index) => {
|
const columns = keys.map((key, index) => {
|
||||||
return {
|
return {
|
||||||
|
colId: getColumnLabel(index), // 'A', 'B', 'C', ...
|
||||||
headerName: getColumnLabel(index), // 'A', 'B', 'C', ...
|
headerName: getColumnLabel(index), // 'A', 'B', 'C', ...
|
||||||
field: key, // Field will match the key (Department2, Budget, etc.)
|
field: key, // Field will match the key (Department2, Budget, etc.)
|
||||||
valueParser: lcpDataTypeParser,
|
valueParser: lcpDataTypeParser,
|
||||||
cellRenderer: lcpCellRenderer, // Reference the custom cell renderer
|
cellRenderer: lcpCellRenderer, // Reference the custom cell renderer
|
||||||
headerComponent: LCPDataGridHeader
|
headerComponent: LCPDataGridHeader,
|
||||||
|
lcpDataType: 'myCustomDataType' // Add your custom parameter here
|
||||||
|
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
@ -427,10 +434,10 @@ const isValidCSSColor = (value) => {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Button outside the grid */}
|
{/* Grid Footer */}
|
||||||
<div>
|
<div style={{padding:'15px 0px',display:'flex', flexDirection:'row', justifyContent:'space-between', background:'white'}}>
|
||||||
{/* Input to add multiple rows */}
|
{/* Input to add multiple rows */}
|
||||||
<div>
|
<div style={{display:'flex', flexDirection:'row'}}>
|
||||||
<input
|
<input
|
||||||
type="number"
|
type="number"
|
||||||
value={rowsToAdd}
|
value={rowsToAdd}
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import {Icon, calendar } from '@wordpress/icons'; // Make sure to use the correc
|
|||||||
const LCPDataGridHeader = (props) => {
|
const LCPDataGridHeader = (props) => {
|
||||||
const { displayName, column, updateData, sort, menu } = props;
|
const { displayName, column, updateData, sort, menu } = props;
|
||||||
const colId = column.colId;
|
const colId = column.colId;
|
||||||
|
const lcpDataType = column.getColDef().customDataType; // Retrieve custom data type
|
||||||
|
|
||||||
// Sorting function
|
// Sorting function
|
||||||
const handleSort = () => {
|
const handleSort = () => {
|
||||||
@ -20,6 +21,7 @@ const LCPDataGridHeader = (props) => {
|
|||||||
{/* Calendar Icon */}
|
{/* Calendar Icon */}
|
||||||
<span style={{ marginRight: '8px', display: 'inline-block' }}>
|
<span style={{ marginRight: '8px', display: 'inline-block' }}>
|
||||||
<Icon icon={ calendar } />
|
<Icon icon={ calendar } />
|
||||||
|
{lcpDataType}
|
||||||
|
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
@ -28,7 +30,7 @@ const LCPDataGridHeader = (props) => {
|
|||||||
style={{ fontWeight: 'bold', fontSize: '16px' }}
|
style={{ fontWeight: 'bold', fontSize: '16px' }}
|
||||||
onClick={handleSort} // Click header for sorting
|
onClick={handleSort} // Click header for sorting
|
||||||
>
|
>
|
||||||
{displayName}
|
{colId}
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
{/* Sorting Indicators */}
|
{/* Sorting Indicators */}
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
import { useState, useEffect } from '@wordpress/element';
|
import { useState, useEffect } from '@wordpress/element';
|
||||||
|
import {Icon, chevronDownSmall} from '@wordpress/icons';
|
||||||
|
|
||||||
import { Button, Modal } from '@wordpress/components';
|
import { Button, Modal } from '@wordpress/components';
|
||||||
import { __ } from '@wordpress/i18n';
|
import { __ } from '@wordpress/i18n';
|
||||||
import LCPDataGrid from './LCPDataGrid';
|
import LCPDataGrid from './LCPDataGrid';
|
||||||
@ -49,7 +51,7 @@ const LCPDatasetBuilder = ({ attributes, setAttributes }) => {
|
|||||||
<Button
|
<Button
|
||||||
variant="secondary"
|
variant="secondary"
|
||||||
onClick={() => setIsOpen(true)}
|
onClick={() => setIsOpen(true)}
|
||||||
style={{ marginBottom: '10px', width: '100%' }}
|
style={{ marginBottom: '10px', width: '100%', }}
|
||||||
>
|
>
|
||||||
{__('Edit Dataset', 'lcp-visualize')}
|
{__('Edit Dataset', 'lcp-visualize')}
|
||||||
</Button>
|
</Button>
|
||||||
@ -58,27 +60,49 @@ const LCPDatasetBuilder = ({ attributes, setAttributes }) => {
|
|||||||
<Modal
|
<Modal
|
||||||
onRequestClose={() => setIsOpen(false)}
|
onRequestClose={() => setIsOpen(false)}
|
||||||
title={__('Dataset Builder', 'lcp-visualize')}
|
title={__('Dataset Builder', 'lcp-visualize')}
|
||||||
style={{ width: '90vw', height: '90vh' }}
|
style={{ width: '90vw', height: '90vh',
|
||||||
|
background:'#efefef',
|
||||||
|
padding:'0px',
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<div style={{ height: 'calc(90vh - 40px)', padding: '20px' }}>
|
<div style={{ height: 'calc(90vh - 40px)', padding: '0px' }}>
|
||||||
{/* Tabs */}
|
{/* Tabs */}
|
||||||
<div style={{ display: 'flex', marginBottom: '20px' }}>
|
<div style={{ display: 'flex' }}>
|
||||||
{datasets.map((dataset, index) => (
|
{datasets.map((dataset, index) => (
|
||||||
<button
|
<button
|
||||||
key={index}
|
key={index}
|
||||||
|
|
||||||
onClick={() => setActiveTab(index)} // Set the active tab
|
onClick={() => setActiveTab(index)} // Set the active tab
|
||||||
style={{
|
style={{
|
||||||
padding: '10px 20px',
|
display: 'flex',
|
||||||
margin: '0 5px',
|
alignItems:'center',
|
||||||
backgroundColor: activeTab === index ? '#007cba' : '#f1f1f1',
|
justifyContent:'center',
|
||||||
|
position: 'relative',
|
||||||
|
minWidth: '100px',
|
||||||
|
height: '35px',
|
||||||
|
lineHeight: '35px',
|
||||||
|
padding: '0 10px',
|
||||||
|
margin: '0 3px',
|
||||||
|
backgroundColor: '#fff',
|
||||||
|
border: '1px solid #ccc',
|
||||||
|
borderBottomColor: activeTab === index ? '#fff' : '#ccc',
|
||||||
|
borderRadius: '3px',
|
||||||
color: activeTab === index ? 'white' : 'black',
|
color: activeTab === index ? 'white' : 'black',
|
||||||
border: '1px solid #ccc',
|
border: '1px solid #ccc',
|
||||||
borderRadius: '5px',
|
borderRadius: '5px',
|
||||||
cursor: 'pointer',
|
cursor: 'pointer',
|
||||||
transition: 'background-color 0.3s ease',
|
transition: 'background-color 0.3s ease',
|
||||||
}}
|
}}
|
||||||
>
|
> <span style={{
|
||||||
|
display: 'inline-block',
|
||||||
|
marginRight: '5px',
|
||||||
|
color: activeTab === index ? '#333' : '#aaa',
|
||||||
|
fontWeight: 'bold'
|
||||||
|
}}>
|
||||||
{dataset.name}
|
{dataset.name}
|
||||||
|
</span>
|
||||||
|
<Icon icon={ chevronDownSmall } style={{position:'relative',top:'0px'}} />
|
||||||
|
|
||||||
</button>
|
</button>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user