Skip to content

Commit

Permalink
Merge pull request #3293 from bcgov/NDT-329-History-for-Template-1-an…
Browse files Browse the repository at this point in the history
…d-Template-2-upload-for-RFI

fix: history files not showing properly
  • Loading branch information
RRanath authored May 23, 2024
2 parents 3b56bca + 237cdfc commit ecf463b
Showing 1 changed file with 97 additions and 95 deletions.
192 changes: 97 additions & 95 deletions app/components/Analyst/History/HistoryFile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,103 +32,105 @@ const HistoryFile = ({
keepUnchangedValues: true,
full: true,
});
return filesDiff && filesDiff?.length > 0
? (filesDiff[0][0] === '+' ||
filesDiff[0][0] === '-' ||
filesDiff[0][0] === '~') && (
<StyledTable>
<thead style={{ borderBottom: '2px solid #CCC' }}>
{tableTitle && (
<tr>
<th>Files</th>
</tr>
)}
</thead>
<tbody>
<tr data-testid={testId}>
<td style={tableTitle ? { paddingTop: '8px' } : {}}>{title}</td>
<td style={tableTitle ? { paddingTop: '8px' } : {}}>
<div>
{filesDiff &&
filesDiff.map((file) => {
// A file was added
if (file[0] === '+') {
return (
<div key={file[1].uuid}>
Added file{' '}

const hasFileChanges =
filesDiff?.filter(
(file) => file[0] === '+' || file[0] === '-' || file[0] === '~'
).length > 0;

return hasFileChanges ? (
<StyledTable>
<thead style={{ borderBottom: '2px solid #CCC' }}>
{tableTitle && (
<tr>
<th>Files</th>
</tr>
)}
</thead>
<tbody>
<tr data-testid={testId}>
<td style={tableTitle ? { paddingTop: '8px' } : {}}>{title}</td>
<td style={tableTitle ? { paddingTop: '8px' } : {}}>
<div>
{filesDiff &&
filesDiff.map((file) => {
// A file was added
if (file[0] === '+') {
return (
<div key={file[1].uuid}>
Added file{' '}
<DownloadLink
uuid={file[1].uuid}
fileName={file[1].name}
/>
</div>
);
}
// A file was removed
if (file[0] === '-') {
return (
<div key={file[1].uuid}>
Deleted file{' '}
<del>
<DownloadLink
uuid={file[1].uuid}
fileName={file[1].name}
/>
</del>
</div>
);
}
// The object was modified (file replacement)
if (file[0] === '~') {
if (filesDiff.length === 1) {
return (
<div key={file[1].uuid}>
Replaced file{' '}
<del>
<DownloadLink
uuid={file[1].uuid.__old}
fileName={file[1].name.__old || file[1].name}
/>
</del>{' '}
with file{' '}
<DownloadLink
uuid={file[1].uuid.__new}
fileName={file[1].name.__new || file[1].name}
/>
</div>
);
}
return (
<>
<div key={file[1].uuid}>
Deleted file{' '}
<del>
<DownloadLink
uuid={file[1].uuid.__old}
fileName={file[1].name.__old}
/>
</del>{' '}
</div>
<div key={file[1].uuid}>
Added file{' '}
<del>
<DownloadLink
uuid={file[1].uuid}
fileName={file[1].name}
uuid={file[1].uuid.__new}
fileName={file[1].name.__new}
/>
</div>
);
}
// A file was removed
if (file[0] === '-') {
return (
<div key={file[1].uuid}>
Deleted file{' '}
<del>
<DownloadLink
uuid={file[1].uuid}
fileName={file[1].name}
/>
</del>
</div>
);
}
// The object was modified (file replacement)
if (file[0] === '~') {
if (filesDiff.length === 1) {
return (
<div key={file[1].uuid}>
Replaced file{' '}
<del>
<DownloadLink
uuid={file[1].uuid.__old}
fileName={file[1].name.__old || file[1].name}
/>
</del>{' '}
with file{' '}
<DownloadLink
uuid={file[1].uuid.__new}
fileName={file[1].name.__new || file[1].name}
/>
</div>
);
}
return (
<>
<div key={file[1].uuid}>
Deleted file{' '}
<del>
<DownloadLink
uuid={file[1].uuid.__old}
fileName={file[1].name.__old}
/>
</del>{' '}
</div>
<div key={file[1].uuid}>
Added file{' '}
<del>
<DownloadLink
uuid={file[1].uuid.__new}
fileName={file[1].name.__new}
/>
</del>{' '}
</div>
</>
);
}
return null;
})}
</div>
</td>
</tr>
</tbody>
</StyledTable>
)
: null;
</del>{' '}
</div>
</>
);
}
return null;
})}
</div>
</td>
</tr>
</tbody>
</StyledTable>
) : null;
};

export default HistoryFile;

0 comments on commit ecf463b

Please sign in to comment.