Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(tablecard): file download timestamp mismatch from ui #3848

Merged
merged 2 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 25 additions & 17 deletions packages/react/src/components/TableCard/TableCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,24 @@ const TableCard = ({
.filter((i) => !isNil(i)),
[columns]
);

const updatedTableData = useMemo(() => {
return tableData.map((row) => {
const { values } = row;
Object.keys(values).forEach((column) => {
if (filteredTimestampColumns.includes(column) && !isEditable) {
values[column] = values[column]
? dayjs(values[column]).format(defaultDateFormatPattern)
: '';
}
});
return {
...row,
values,
};
});
}, [defaultDateFormatPattern, filteredTimestampColumns, isEditable, tableData]);

const columnsToRender = useMemo(
() =>
newColumns
Expand All @@ -320,19 +338,13 @@ const TableCard = ({
{ value } // default render function is to handle timestamp
) =>
// if it's a timestamp column type make sure to format it
filteredTimestampColumns.includes(i.dataSourceId) && !isEditable
? dayjs(value).format(defaultDateFormatPattern)
: isNil(value)
? ''
: value.toString(),
isNil(value) ? '' : value.toString(),
}))
.concat(hasActionColumn ? actionColumn : []),
[
actionColumn,
defaultDateFormatPattern,
filteredTimestampColumns,
hasActionColumn,
isEditable,
mergedI18n.defaultFilterStringPlaceholdText,
newColumns,
newSize,
Expand Down Expand Up @@ -377,7 +389,7 @@ const TableCard = ({
isEditable
? generateTableSampleValues(id, columns)
: hasActionColumn || filteredPrecisionColumns.length || thresholds
? tableData.map((i) => {
? updatedTableData.map((i) => {
// if has custom action
const action = hasActionColumn ? { actionColumn: i.actions || [] } : null;

Expand Down Expand Up @@ -426,15 +438,15 @@ const TableCard = ({
isSelectable: false,
};
})
: tableData,
: updatedTableData,
[
isEditable,
id,
columns,
hasActionColumn,
filteredPrecisionColumns,
thresholds,
tableData,
updatedTableData,
thresholdSeverityLabelsMap,
locale,
]
Expand All @@ -444,7 +456,7 @@ const TableCard = ({
const expandedRowsFormatted = useMemo(
() =>
expandedRows && expandedRows.length
? tableData.map((dataItem) => {
? updatedTableData.map((dataItem) => {
// filter the data keys and find the expandaded row exist for that key
const expandedItem = Object.keys(dataItem.values)
.map((value) => expandedRows.filter((item) => item.id === value)[0])
Expand Down Expand Up @@ -489,11 +501,7 @@ const TableCard = ({
{item?.label ? item.label : '--'}
</p>
<span key={`${item.id}-value`}>
{item
? item.type === 'TIMESTAMP'
? dayjs(dataItem.values[item.id]).format(defaultDateFormatPattern)
: dataItem.values[item.id]
: null}
{item ? dataItem.values[item.id] : null}
</span>
</>
)}
Expand All @@ -513,7 +521,7 @@ const TableCard = ({
};
})
: [],
[defaultDateFormatPattern, expandedRows, others.cardVariables, tableData]
[expandedRows, others.cardVariables, updatedTableData]
);

// is columns recieved is different from the columnsToRender show card expand
Expand Down
4 changes: 2 additions & 2 deletions packages/react/src/components/TableCard/TableCard.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ describe('TableCard', () => {
row: {
alert: 'AHI005 Asset failure',
count: 1.2039201932,
hour: 1563877570000,
hour: '07/23/2019 05:26',
long_description: 'long description for a given event payload',
pressure: 0,
},
Expand Down Expand Up @@ -1008,7 +1008,7 @@ describe('TableCard', () => {

userEvent.click(screen.getByRole('button', { name: /download/i }));
expect(fileDownload).toHaveBeenCalledWith(
`alert,count,hour,long_description,pressure\nAHI005 Asset failure,1.2039201932,1563877570000,long description for a given event payload,0\nAHI003 process need to optimize adjust X variables,1.10329291,1563873970000,long description for a given event payload,2\n`,
`alert,count,hour,long_description,pressure\nAHI005 Asset failure,1.2039201932,07/23/2019 05:26,long description for a given event payload,0\nAHI003 process need to optimize adjust X variables,1.10329291,07/23/2019 04:26,long description for a given event payload,2\n`,
'Open Alerts.csv'
);
});
Expand Down
Loading