Skip to content

Commit

Permalink
Fixed function to retrieve fields from deeper arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
mamartinezmejia committed Feb 25, 2025
1 parent 4559a1c commit b6efb09
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions frontend/src/services/ForestClientService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,17 +281,29 @@ export const getActionLabel = (action: string) => {
export const getOldValue = (path: string, data: Ref<ClientDetails> | ClientDetails) => {
if (!data) {
console.warn("Old value was called with undefined data!", path);
return 'N/A';
return "N/A";
}

const clientData = unref(data);
const fieldName = path.split('/').pop() || "";
const fieldName = path.split("/").pop() || "";

const clientKeys = Object.keys(clientData) as (keyof ClientDetails)[];
if (fieldName in clientData) {
return clientData[fieldName as keyof ClientDetails] || "N/A";
}

if (clientKeys.includes(fieldName as keyof ClientDetails)) {
return clientData[fieldName as keyof ClientDetails] || 'N/A';
for (const [key, value] of Object.entries(clientData)) {
if (Array.isArray(value)) {
for (const item of value) {
if (fieldName in item) {
if (Array.isArray(item[fieldName])) {
const arrayValue = item[fieldName as keyof typeof item];
return arrayValue?.[0] || "N/A";
}
return item[fieldName as keyof typeof item] || "N/A";
}
}
}
}

return 'N/A';
return "N/A";
};

0 comments on commit b6efb09

Please sign in to comment.