Skip to content

Commit

Permalink
Instead of skipping alias fields rendering them correctly using the a…
Browse files Browse the repository at this point in the history
…ctual column they are representing

Signed-off-by: Ravi Thaluru <thalurur@users.noreply.github.com>
  • Loading branch information
thalurur committed Apr 19, 2022
1 parent 324b1ce commit 7ddd7e7
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
1 change: 1 addition & 0 deletions models/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ export interface MetricItem {
export interface FieldItem {
label: string;
type: string | undefined;
path: string | undefined;
}

interface DateHistogramItem {
Expand Down
2 changes: 1 addition & 1 deletion public/pages/CreateRollup/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export const isNumericMapping = (fieldType: string | undefined): boolean => {
};

export const compareFieldItem = (itemA: FieldItem, itemB: FieldItem): boolean => {
return itemB.label == itemA.label && itemA.type == itemB.type;
return itemB.label == itemA.label && itemA.type == itemB.type && itemA.path == itemB.path;
};

export const parseFieldOptions = (prefix: string, mappings: any): FieldItem[] => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,21 +142,29 @@ export default function DefineTransforms({

const renderCellValue = ({ rowIndex, columnId }) => {
if (!loading && data.hasOwnProperty(rowIndex)) {
if (columns?.find((column) => column.id == columnId).schema == "keyword") {
// Remove the keyword postfix for getting correct data from array
const correspondingTextColumnId = columnId.replace(".keyword", "");
return data[rowIndex]._source[correspondingTextColumnId] ? data[rowIndex]._source[correspondingTextColumnId] : "-";
} else if (columns?.find((column) => column.id == columnId).schema == "date") {
return data[rowIndex]._source[columnId] ? renderTime(data[rowIndex]._source[columnId]) : "-";
} else if (columns?.find((column) => column.id == columnId).schema == "boolean") {
return data[rowIndex]._source[columnId] == null ? "-" : data[rowIndex]._source[columnId] ? "true" : "false";
let lookupId = columnId;
if (columns?.find((column) => column.id == columnId).schema == "alias") {
lookupId = columns?.find((column) => column.id == columnId).path;
}
const val = data[rowIndex]._source[columnId];
return val !== undefined ? JSON.stringify(val) : "-";
return getColumnValue(rowIndex, lookupId);
}
return "-";
};

const getColumnValue = (rowIndex, columnId) => {
if (columns?.find((column) => column.id == columnId).schema == "keyword") {
// Remove the keyword postfix for getting correct data from array
const correspondingTextColumnId = columnId.replace(".keyword", "");
return data[rowIndex]._source[correspondingTextColumnId] ? data[rowIndex]._source[correspondingTextColumnId] : "-";
} else if (columns?.find((column) => column.id == columnId).schema == "date") {
return data[rowIndex]._source[columnId] ? renderTime(data[rowIndex]._source[columnId]) : "-";
} else if (columns?.find((column) => column.id == columnId).schema == "boolean") {
return data[rowIndex]._source[columnId] == null ? "-" : data[rowIndex]._source[columnId] ? "true" : "false";
}
const val = data[rowIndex]._source[columnId];
return val !== undefined ? JSON.stringify(val) : "-";
}

//TODO: remove duplicate code here after extracting the first table as separate component
if (isReadOnly)
return (
Expand Down
2 changes: 1 addition & 1 deletion public/pages/CreateTransform/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const parseFieldOptions = (prefix: string, mappings: any): FieldItem[] =>
for (let field in mappings) {
if (mappings.hasOwnProperty(field)) {
if (mappings[field].type != "object" && mappings[field].type != null && mappings[field].type != "nested")
fieldsOption.push({ label: prefix + field, type: mappings[field].type });
fieldsOption.push({ label: prefix + field, type: mappings[field].type, path: mappings[field].path});
if (mappings[field].fields != null)
fieldsOption = fieldsOption.concat(parseFieldOptions(prefix + field + ".", mappings[field].fields));
if (mappings[field].properties != null)
Expand Down

0 comments on commit 7ddd7e7

Please sign in to comment.