removed id and _vehicle objects from editor dropdown, json is made procramatically instead of hardcored, so when entity changed, json is auto updated
This commit is contained in:
@@ -1,9 +1,11 @@
|
|||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
import { useReportData } from './DataContext';
|
import { useReportData } from './DataContext';
|
||||||
|
import { useNomenclatureData } from '../../contexts/NomenclatureDataContext';
|
||||||
import './ConfigPanel.css';
|
import './ConfigPanel.css';
|
||||||
|
|
||||||
function ConfigPanel({ apiEndpoint, onApiEndpointChange, isOpen, onClose }) {
|
function ConfigPanel({ apiEndpoint, onApiEndpointChange, isOpen, onClose }) {
|
||||||
const { reportData, isLoading, error, fetchData, setData, clearData } = useReportData();
|
const { reportData, isLoading, error, fetchData, setData, clearData } = useReportData();
|
||||||
|
const { definitions, entries } = useNomenclatureData();
|
||||||
const [localEndpoint, setLocalEndpoint] = useState(apiEndpoint || '');
|
const [localEndpoint, setLocalEndpoint] = useState(apiEndpoint || '');
|
||||||
const [manualDataInput, setManualDataInput] = useState('');
|
const [manualDataInput, setManualDataInput] = useState('');
|
||||||
const [showManualInput, setShowManualInput] = useState(false);
|
const [showManualInput, setShowManualInput] = useState(false);
|
||||||
@@ -84,153 +86,49 @@ function ConfigPanel({ apiEndpoint, onApiEndpointChange, isOpen, onClose }) {
|
|||||||
className="config-button"
|
className="config-button"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
if (!showManualInput && !manualDataInput) {
|
if (!showManualInput && !manualDataInput) {
|
||||||
// Pre-fill with example data when opening for the first time
|
// Build extra sample from actual nomenclature definitions
|
||||||
|
// Lookup fields become nested objects with all their sub-fields
|
||||||
|
const extra = {};
|
||||||
|
for (const def of Object.values(definitions)) {
|
||||||
|
if (def.kind === 'lookup') {
|
||||||
|
const activeEntries = (entries[def.code] || []).filter(e => e.is_active);
|
||||||
|
const firstEntry = activeEntries[0];
|
||||||
|
if (firstEntry?.data && Object.keys(firstEntry.data).length > 0) {
|
||||||
|
// Use actual field values from the first active entry
|
||||||
|
extra[def.name] = { ...firstEntry.data };
|
||||||
|
} else if (def.fields?.length > 0) {
|
||||||
|
// No entries yet — build placeholders from field definitions
|
||||||
|
const sample = {};
|
||||||
|
for (const field of def.fields) {
|
||||||
|
if (field.field_type === 'number') sample[field.key] = 0;
|
||||||
|
else if (field.field_type === 'bool') sample[field.key] = false;
|
||||||
|
else sample[field.key] = 'Sample';
|
||||||
|
}
|
||||||
|
extra[def.name] = sample;
|
||||||
|
} else {
|
||||||
|
extra[def.name] = {};
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
extra[def.name] = 'Sample Text';
|
||||||
|
}
|
||||||
|
}
|
||||||
setManualDataInput(JSON.stringify({
|
setManualDataInput(JSON.stringify({
|
||||||
"reportTitle": "Weight Measurements Report",
|
vehicle: {
|
||||||
"reportDate": "2026-01-26",
|
vehicle_number: 'АА1234ВВ',
|
||||||
"owner": {
|
trailer1_number: 'ПВ5678ВВ',
|
||||||
"name": "John Doe",
|
trailer2_number: null,
|
||||||
"contact": {
|
driver_pid: '123456789',
|
||||||
"phone": "555-1234",
|
tare: 8500,
|
||||||
"email": "john.doe@example.com"
|
tare_date: '2026-02-22T08:00:00Z',
|
||||||
}
|
tare_user_name: 'operator',
|
||||||
},
|
gross: 28500,
|
||||||
"vessel": {
|
gross_date: '2026-02-22T10:30:00Z',
|
||||||
"id": "ABC123",
|
gross_user_name: 'operator',
|
||||||
"type": "Truck",
|
net: 20000,
|
||||||
"capacity": 5000
|
net_date: '2026-02-22T10:30:00Z',
|
||||||
},
|
net_user_name: 'operator',
|
||||||
"measurements": [
|
doc_number: '2026-001',
|
||||||
{
|
extra,
|
||||||
"id": 1,
|
|
||||||
"weight": 1500,
|
|
||||||
"timestamp": "2026-01-26T08:00:00",
|
|
||||||
"operator": "Alice",
|
|
||||||
"items": [
|
|
||||||
{ "name": "Box A", "quantity": 10, "unitWeight": 50 },
|
|
||||||
{ "name": "Box B", "quantity": 20, "unitWeight": 25 }
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": 2,
|
|
||||||
"weight": 1650,
|
|
||||||
"timestamp": "2026-01-26T09:30:00",
|
|
||||||
"operator": "Bob",
|
|
||||||
"items": [
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Pallet D", "quantity": 15, "unitWeight": 30 }
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": 3,
|
|
||||||
"weight": 1820,
|
|
||||||
"timestamp": "2026-01-26T11:15:00",
|
|
||||||
"operator": "Charlie",
|
|
||||||
"items": [
|
|
||||||
{ "name": "Container E", "quantity": 8, "unitWeight": 75 }
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": 4,
|
|
||||||
"weight": 41820,
|
|
||||||
"timestamp": "2026-01-26T11:15:00",
|
|
||||||
"operator": "4Charlie",
|
|
||||||
"items": [
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Crate C", "quantity": 5, "unitWeight": 100 },
|
|
||||||
{ "name": "Container E", "quantity": 8, "unitWeight": 75 }
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
],
|
|
||||||
"summary": {
|
|
||||||
"totalMeasurements": 3,
|
|
||||||
"averageWeight": 1656.67,
|
|
||||||
"maxWeight": 1820,
|
|
||||||
"minWeight": 1500
|
|
||||||
}
|
}
|
||||||
}, null, 2));
|
}, null, 2));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -91,12 +91,14 @@ export function getAvailableFields(obj, prefix = '') {
|
|||||||
const fields = [];
|
const fields = [];
|
||||||
|
|
||||||
for (const key of Object.keys(obj)) {
|
for (const key of Object.keys(obj)) {
|
||||||
|
// Skip raw id/FK fields — only human-readable fields are useful for binding
|
||||||
|
if (key === 'id' || (key.endsWith('_user') && !key.endsWith('_user_name'))) continue;
|
||||||
|
|
||||||
const fullPath = prefix ? `${prefix}.${key}` : key;
|
const fullPath = prefix ? `${prefix}.${key}` : key;
|
||||||
const value = obj[key];
|
const value = obj[key];
|
||||||
|
|
||||||
if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
|
if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
|
||||||
// Nested object - add this key and recurse
|
// Nested object - recurse into children only (don't add the object itself)
|
||||||
fields.push(fullPath);
|
|
||||||
fields.push(...getAvailableFields(value, fullPath));
|
fields.push(...getAvailableFields(value, fullPath));
|
||||||
} else {
|
} else {
|
||||||
// Primitive or array - add this key
|
// Primitive or array - add this key
|
||||||
|
|||||||
Reference in New Issue
Block a user