Skip to content

FinceptTerminal is a modern finance application offering advanced market analytics, investment research, and economic data tools, designed for interactive exploration and data-driven decision-making in a user-friendly environment.

data mapping tab fixes

tilakpatel222a9b0461bdd8
diff --git a/.gitignore b/.gitignore
index a00d5ced0..d8252a34a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -17,6 +17,7 @@ fincept_env
# Allow specific markdown files
!README.md
!docs/**/*.md
+**/.claude/
!.github/**/*.md
# Allow embedded Python in resources (but exclude executables)
!fincept-terminal-desktop/src-tauri/resources/python/
diff --git a/fincept-terminal-desktop/.gitignore b/fincept-terminal-desktop/.gitignore
index 367d7613b..d1b9a0158 100644
--- a/fincept-terminal-desktop/.gitignore
+++ b/fincept-terminal-desktop/.gitignore
@@ -30,3 +30,4 @@ src-tauri/target
src-tauri/resources/python/
!src-tauri/resources/scripts/
fincept-terminal-desktop/nul
+"**/.claude/"
diff --git a/fincept-terminal-desktop/src/components/tabs/data-mapping/DataMappingTab.tsx b/fincept-terminal-desktop/src/components/tabs/data-mapping/DataMappingTab.tsx
index 87fbcdd47..0ef19f94c 100644
--- a/fincept-terminal-desktop/src/components/tabs/data-mapping/DataMappingTab.tsx
+++ b/fincept-terminal-desktop/src/components/tabs/data-mapping/DataMappingTab.tsx
@@ -160,6 +160,41 @@ export default function DataMappingTab() {
setIsTesting(true);
try {
+ // Detect if data has common array structure (only if not already configured from template)
+ const detectDataArray = (obj: any): { rootPath: string; isArray: boolean } => {
+ if (Array.isArray(obj)) return { rootPath: '', isArray: true };
+
+ // Common patterns: data, results, items, records
+ const arrayKeys = ['data', 'results', 'items', 'records', 'response'];
+ for (const key of arrayKeys) {
+ if (obj[key] && Array.isArray(obj[key]) && obj[key].length > 0) {
+ return { rootPath: key, isArray: true };
+ }
+ }
+
+ return { rootPath: '', isArray: false };
+ };
+
+ // Use existing extraction config if available (from template), otherwise auto-detect
+ let extractionConfig;
+ if (fieldMappings.length > 0 && fieldMappings[0].source?.path?.startsWith('$')) {
+ // Template has configured extraction, detect from sample data
+ const { rootPath, isArray } = detectDataArray(sampleData);
+ extractionConfig = {
+ engine: ParserEngine.JSONPATH,
+ rootPath: rootPath ? `$.${rootPath}[*]` : '',
+ isArray,
+ };
+ } else {
+ // No template, auto-detect
+ const { rootPath, isArray } = detectDataArray(sampleData);
+ extractionConfig = {
+ engine: ParserEngine.JSONPATH,
+ rootPath: rootPath ? `$.${rootPath}[*]` : '',
+ isArray,
+ };
+ }
+
const mappingConfig: DataMappingConfig = {
id: mappingId,
name: mappingName || apiConfig.name,
@@ -173,11 +208,7 @@ export default function DataMappingTab() {
schema: schemaType === 'predefined' ? selectedSchema : undefined,
customFields: schemaType === 'custom' ? customFields : undefined,
},
- extraction: {
- engine: ParserEngine.DIRECT,
- rootPath: '',
- isArray: Array.isArray(sampleData),
- },
+ extraction: extractionConfig,
fieldMappings,
postProcessing: undefined,
validation: {
@@ -229,6 +260,40 @@ export default function DataMappingTab() {
}
try {
+ // Detect if data has common array structure (same logic as test)
+ const detectDataArray = (obj: any): { rootPath: string; isArray: boolean } => {
+ if (Array.isArray(obj)) return { rootPath: '', isArray: true };
+
+ const arrayKeys = ['data', 'results', 'items', 'records', 'response'];
+ for (const key of arrayKeys) {
+ if (obj[key] && Array.isArray(obj[key]) && obj[key].length > 0) {
+ return { rootPath: key, isArray: true };
+ }
+ }
+
+ return { rootPath: '', isArray: false };
+ };
+
+ // Use existing extraction config if available (from template), otherwise auto-detect
+ let extractionConfig;
+ if (fieldMappings.length > 0 && fieldMappings[0].source?.path?.startsWith('$')) {
+ // Template has configured extraction, detect from sample data
+ const { rootPath, isArray } = detectDataArray(sampleData);
+ extractionConfig = {
+ engine: ParserEngine.JSONPATH,
+ rootPath: rootPath ? `$.${rootPath}[*]` : '',
+ isArray,
+ };
+ } else {
+ // No template, auto-detect
+ const { rootPath, isArray } = detectDataArray(sampleData);
+ extractionConfig = {
+ engine: ParserEngine.JSONPATH,
+ rootPath: rootPath ? `$.${rootPath}[*]` : '',
+ isArray,
+ };
+ }
+
const mappingConfig: DataMappingConfig = {
id: mappingId,
name: mappingName,
@@ -242,11 +307,7 @@ export default function DataMappingTab() {
schema: schemaType === 'predefined' ? selectedSchema : undefined,
customFields: schemaType === 'custom' ? customFields : undefined,
},
- extraction: {
- engine: ParserEngine.DIRECT,
- rootPath: '',
- isArray: Array.isArray(sampleData),
- },
+ extraction: extractionConfig,
fieldMappings,
postProcessing: undefined,
validation: {
@@ -338,12 +399,10 @@ export default function DataMappingTab() {
const canProceedToNextStep = () => {
switch (currentStep) {
case 'api-config':
- return apiConfig.baseUrl && apiConfig.endpoint && apiConfig.name;
+ return apiConfig.baseUrl && apiConfig.endpoint && apiConfig.name && sampleData !== null;
case 'schema-select':
return (schemaType === 'predefined' && selectedSchema) ||
(schemaType === 'custom' && customFields.length > 0);
- case 'fetch-sample':
- return sampleData !== null;
case 'field-mapping':
return fieldMappings.length > 0;
case 'cache-settings':
@@ -388,6 +447,14 @@ export default function DataMappingTab() {
onSchemaSelect={(schema) => setSelectedSchema(schema as UnifiedSchemaType)}
onCustomFieldsChange={setCustomFields}
sampleData={sampleData}
+ onFieldMappingsAutoCreate={(newMappings) => {
+ // Only add mappings for fields that don't already have mappings
+ const existingFields = new Set(fieldMappings.map(m => m.targetField));
+ const uniqueNewMappings = newMappings.filter(m => !existingFields.has(m.targetField));
+ if (uniqueNewMappings.length > 0) {
+ setFieldMappings([...fieldMappings, ...uniqueNewMappings]);
+ }
+ }}
/>
</div>
);
diff --git a/fincept-terminal-desktop/src/components/tabs/data-mapping/components/SchemaBuilder.tsx b/fincept-terminal-desktop/src/components/tabs/data-mapping/components/SchemaBuilder.tsx
index 79d92c4cf..44b063b6c 100644
--- a/fincept-terminal-desktop/src/components/tabs/data-mapping/components/SchemaBuilder.tsx
+++ b/fincept-terminal-desktop/src/components/tabs/data-mapping/components/SchemaBuilder.tsx
@@ -13,7 +13,8 @@ interface SchemaBuilderProps {
onSchemaTypeChange: (type: 'predefined' | 'custom') => void;
onSchemaSelect: (schema: string) => void;
onCustomFieldsChange: (fields: CustomField[]) => void;
- sampleData?: any; // NEW: Pass sample data for visual selection
+ sampleData?: any;
+ onFieldMappingsAutoCreate?: (mappings: any[]) => void; // NEW: Auto-create field mappings
}
export function SchemaBuilder({
@@ -24,6 +25,7 @@ export function SchemaBuilder({
onSchemaSelect,
onCustomFieldsChange,
sampleData,
+ onFieldMappingsAutoCreate,
}: SchemaBuilderProps) {
const [editingField, setEditingField] = useState<number | null>(null);
const [selectedJsonPath, setSelectedJsonPath] = useState<string[] | undefined>();
@@ -61,6 +63,34 @@ export function SchemaBuilder({
return cleanedSegments.join('_');
};
+ // Create field mapping from path
+ const createFieldMapping = (fieldName: string, path: string[], isRequired: boolean = false) => {
+ // Convert path to JSONPath expression
+ // For paths from auto-detection, we assume rootPath has already extracted the array
+ // So we just need the relative path from the current item
+ let jsonPathExpression: string;
+
+ if (path.length === 0) {
+ jsonPathExpression = '$';
+ } else if (path.length === 1) {
+ // Simple field at root level
+ jsonPathExpression = `$.${path[0]}`;
+ } else {
+ // Nested field - build path without root
+ jsonPathExpression = '$.' + path.join('.');
+ }
+
+ return {
+ targetField: fieldName,
+ source: {
+ type: 'path' as const,
+ path: jsonPathExpression,
+ },
+ parser: 'jsonpath' as const,
+ required: isRequired,
+ };
+ };
+
// Handle field selection from JSON tree
const handleFieldSelectFromJson = (path: string[], value: any) => {
const fullPath = path.join('.');
@@ -93,7 +123,15 @@ export function SchemaBuilder({
defaultValue: value === null || value === undefined ? undefined : value,
};
- onCustomFieldsChange([...customFields, newField]);
+ const updatedFields = [...customFields, newField];
+ onCustomFieldsChange(updatedFields);
+
+ // Auto-create field mapping
+ if (onFieldMappingsAutoCreate) {
+ const newMapping = createFieldMapping(fieldName, path, newField.required);
+ onFieldMappingsAutoCreate([newMapping]);
+ }
+
setEditingField(customFields.length);
setSelectedJsonPath(path);
};
@@ -113,22 +151,25 @@ export function SchemaBuilder({
const handleAutoAddAllFields = () => {
if (!sampleData) return;
+ // Store field paths for mapping creation
+ const fieldPaths: { field: CustomField; path: string[] }[] = [];
+
// Detect if data has a common array structure (e.g., data: [...])
- const detectDataArray = (obj: any): any => {
- if (Array.isArray(obj)) return obj;
+ const detectDataArray = (obj: any): { data: any; arrayKey: string | null } => {
+ if (Array.isArray(obj)) return { data: obj, arrayKey: null };
// Common patterns: data, results, items, records
const arrayKeys = ['data', 'results', 'items', 'records', 'response'];
for (const key of arrayKeys) {
if (obj[key] && Array.isArray(obj[key]) && obj[key].length > 0) {
- return obj[key];
+ return { data: obj[key], arrayKey: key };
}
}
- return obj;
+ return { data: obj, arrayKey: null };
};
- const extractFields = (obj: any, pathArray: string[] = ['root']): CustomField[] => {
+ const extractFields = (obj: any, pathArray: string[] = []): CustomField[] => {
const fields: CustomField[] = [];
if (typeof obj !== 'object' || obj === null) return fields;
@@ -136,7 +177,7 @@ export function SchemaBuilder({
// Handle array - use first item as template
if (Array.isArray(obj)) {
if (obj.length > 0) {
- return extractFields(obj[0], [...pathArray, '[0]']);
+ return extractFields(obj[0], pathArray);
}
return fields;
}
@@ -148,21 +189,29 @@ export function SchemaBuilder({
// Only add primitive fields (leaf nodes)
if (fieldType !== 'object' && fieldType !== 'array') {
- const fieldName = generateFieldNameFromPath(currentPath);
+ const fieldName = key; // Use simple key name for single-level fields
+ const nestedFieldName = currentPath.join('_'); // Use underscore for nested
+ const actualFieldName = currentPath.length === 1 ? fieldName : nestedFieldName;
const fullPath = currentPath.join('.');
- fields.push({
- name: fieldName,
+ const field: CustomField = {
+ name: actualFieldName,
type: fieldType,
description: `Path: ${fullPath}`,
required: false,
- });
+ };
+
+ fields.push(field);
+ fieldPaths.push({ field, path: currentPath });
} else if (fieldType === 'object' && value !== null) {
// Recursively extract from nested objects
fields.push(...extractFields(value, currentPath));
} else if (fieldType === 'array' && Array.isArray(value) && value.length > 0) {
- // Extract from first array item
- fields.push(...extractFields(value[0], [...currentPath, '[0]']));
+ // Extract from first array item if it's an array of objects
+ const firstItem = value[0];
+ if (typeof firstItem === 'object' && firstItem !== null) {
+ fields.push(...extractFields(firstItem, currentPath));
+ }
}
}
@@ -170,7 +219,7 @@ export function SchemaBuilder({
};
// Try to detect the main data array
- const dataToProcess = detectDataArray(sampleData);
+ const { data: dataToProcess } = detectDataArray(sampleData);
const autoFields = extractFields(dataToProcess);
// Remove duplicates based on field name
@@ -186,6 +235,15 @@ export function SchemaBuilder({
}
onCustomFieldsChange(limitedFields);
+
+ // Auto-create field mappings for all added fields
+ if (onFieldMappingsAutoCreate) {
+ const mappings = fieldPaths
+ .filter(({ field }) => limitedFields.some(f => f.name === field.name))
+ .map(({ field, path }) => createFieldMapping(field.name, path, field.required));
+
+ onFieldMappingsAutoCreate(mappings);
+ }
};
const handleRemoveField = (index: number) => {
@@ -470,7 +528,7 @@ export function SchemaBuilder({
{customFields.length > 0 && (
<div className="mt-3 text-xs text-green-500 bg-green-900/20 border border-green-700 rounded p-3">
<strong>✓ {customFields.length} field{customFields.length !== 1 ? 's' : ''} added!</strong>
- {' '}You can now proceed to the next step to map these fields.
+ {' '}Field mappings have been created automatically. You can review them in Step 3 (Field Mapping).
</div>
)}
</div>
diff --git a/fincept-terminal-desktop/src/components/tabs/data-mapping/engine/MappingEngine.ts b/fincept-terminal-desktop/src/components/tabs/data-mapping/engine/MappingEngine.ts
index 8404abbf1..2ab406a66 100644
--- a/fincept-terminal-desktop/src/components/tabs/data-mapping/engine/MappingEngine.ts
+++ b/fincept-terminal-desktop/src/components/tabs/data-mapping/engine/MappingEngine.ts
@@ -1,7 +1,7 @@
// Core Mapping Engine - Updated to use APIClient
import { DataMappingConfig, MappingExecutionContext, MappingExecutionResult, FieldMapping, ParserEngine } from '../types';
-import { getParser } from './parsers';
+import { getParser, BaseParser } from './parsers';
import { applyTransform } from '../utils/transformFunctions';
import { getSchema } from '../schemas';
import { apiClient } from '../services/APIClient';
@@ -172,9 +172,9 @@ export class MappingEngine {
}
}
- // Use default value if null/undefined and required
+ // Use default value if null/undefined
if ((value === null || value === undefined)) {
- if (fieldMapping.required && fieldMapping.defaultValue !== undefined) {
+ if (fieldMapping.defaultValue !== undefined) {
value = fieldMapping.defaultValue;
} else if (fieldMapping.required) {
throw new Error(`Required field ${fieldMapping.targetField} is missing`);
@@ -218,9 +218,24 @@ export class MappingEngine {
// Use field-specific parser if specified (legacy support), otherwise use parser from mapping
const parserType = fieldMapping.parserEngine || fieldMapping.parser;
- const parser = parserType
- ? (typeof parserType === 'string' ? getParser(ParserEngine.DIRECT) : getParser(parserType))
- : getParser(ParserEngine.DIRECT);
+ let parser: BaseParser;
+
+ if (typeof parserType === 'string') {
+ // Map string parser names to ParserEngine enum
+ const parserMap: Record<string, ParserEngine> = {
+ 'jsonpath': ParserEngine.JSONPATH,
+ 'jsonata': ParserEngine.JSONATA,
+ 'jmespath': ParserEngine.JMESPATH,
+ 'direct': ParserEngine.DIRECT,
+ 'javascript': ParserEngine.CUSTOM_JS,
+ };
+ const engine = parserMap[parserType.toLowerCase()] || ParserEngine.DIRECT;
+ parser = getParser(engine);
+ } else if (parserType !== undefined) {
+ parser = getParser(parserType);
+ } else {
+ parser = getParser(ParserEngine.DIRECT);
+ }
try {
// Use source.path (new) or sourceExpression (legacy)
diff --git a/fincept-terminal-desktop/src/components/tabs/data-mapping/engine/parsers/JSONPathParser.ts b/fincept-terminal-desktop/src/components/tabs/data-mapping/engine/parsers/JSONPathParser.ts
index be6f4e3ae..7bd20e99a 100644
--- a/fincept-terminal-desktop/src/components/tabs/data-mapping/engine/parsers/JSONPathParser.ts
+++ b/fincept-terminal-desktop/src/components/tabs/data-mapping/engine/parsers/JSONPathParser.ts
@@ -11,9 +11,20 @@ export class JSONPathParser extends BaseParser {
try {
const result = jp.query(data, expression);
- // If result is array with single element, unwrap it
- if (Array.isArray(result) && result.length === 1 && !expression.includes('[*]')) {
- return result[0];
+ // If result is array with single element, unwrap it (unless it's explicitly an array query)
+ if (Array.isArray(result)) {
+ // Keep as array if expression contains wildcards or is querying an array
+ if (expression.includes('[*]') || expression.includes('..')) {
+ return result;
+ }
+ // Unwrap single-element arrays for simple field access
+ if (result.length === 1) {
+ return result[0];
+ }
+ // Empty array returns undefined
+ if (result.length === 0) {
+ return undefined;
+ }
}
return result;
diff --git a/fincept-terminal-desktop/src/components/tabs/data-mapping/templates/indian-brokers.ts b/fincept-terminal-desktop/src/components/tabs/data-mapping/templates/indian-brokers.ts
index ad6ca2e9e..ca41a0f61 100644
--- a/fincept-terminal-desktop/src/components/tabs/data-mapping/templates/indian-brokers.ts
+++ b/fincept-terminal-desktop/src/components/tabs/data-mapping/templates/indian-brokers.ts
@@ -446,8 +446,8 @@ export const INDIAN_BROKER_TEMPLATES: MappingTemplate[] = [
schemaType: 'custom',
schema: 'PORT',
customFields: [
- { name: 'id', type: 'string', description: 'Unique port identifier', required: true },
- { name: 'name', type: 'string', description: 'Port name', required: true },
+ { name: 'id', type: 'string', description: 'Unique port identifier', required: false },
+ { name: 'name', type: 'string', description: 'Port name', required: false },
{ name: 'country', type: 'string', description: 'Country code', required: false },
{ name: 'code', type: 'string', description: 'Port code (e.g., LOCODE)', required: false },
{ name: 'latitude', type: 'number', description: 'Geographic latitude', required: false },
@@ -465,43 +465,50 @@ export const INDIAN_BROKER_TEMPLATES: MappingTemplate[] = [
targetField: 'id',
source: { type: 'path', path: '$._id' },
parser: 'jsonpath',
- required: true,
+ required: false,
+ defaultValue: '',
},
{
targetField: 'name',
source: { type: 'path', path: '$.name' },
parser: 'jsonpath',
- required: true,
+ required: false,
+ defaultValue: '',
},
{
targetField: 'country',
source: { type: 'path', path: '$.country.name' },
parser: 'jsonpath',
required: false,
+ defaultValue: '',
},
{
targetField: 'code',
source: { type: 'path', path: '$.unLoCode' },
parser: 'jsonpath',
required: false,
+ defaultValue: '',
},
{
targetField: 'latitude',
source: { type: 'path', path: '$.coordinates[1]' },
parser: 'jsonpath',
required: false,
+ defaultValue: 0,
},
{
targetField: 'longitude',
source: { type: 'path', path: '$.coordinates[0]' },
parser: 'jsonpath',
required: false,
+ defaultValue: 0,
},
{
targetField: 'type',
source: { type: 'path', path: '$.sefName' },
parser: 'jsonpath',
required: false,
+ defaultValue: '',
},
],
validation: {