Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Smithsonian/dpo-packrat i…
Browse files Browse the repository at this point in the history
…nto develop
  • Loading branch information
EMaslowskiQ committed Sep 23, 2024
2 parents 0e44f60 + 4e2356f commit 5cac3d3
Showing 1 changed file with 11 additions and 26 deletions.
37 changes: 11 additions & 26 deletions client/src/pages/Admin/components/AdminToolsView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -729,18 +729,8 @@ const AdminToolsBatchGeneration = (): React.ReactElement => {
// Helper function to handle null or undefined values and return 'N/A' as default
const handleNull = (value) => value != null ? value : 'N/A';

// handle characters that can mess up the outputted CSV
const escapeCsvValue = (value) => {
if (typeof value === 'string') {
const escapedValue = value.replace(/"/g, '""');
return /[",\n]/.test(escapedValue) ? `"${escapedValue}"` : escapedValue;
}
return value;
};

// Create CSV headers (clean names)
const headers = [
'Link',
'ID',
'Scene Name',
'Published',
Expand All @@ -766,34 +756,29 @@ const AdminToolsBatchGeneration = (): React.ReactElement => {
];

// Build CSV rows
const { protocol, host } = window.location;
const baseUrl = `${protocol}//${host}/repository/details/`;
const rows = projectScenes.map((scene, index) => {
const hyperlinkFormula = `=HYPERLINK("${baseUrl}/" & B${index + 2}, "url")`;

const rows = projectScenes.map(scene => {
return [
hyperlinkFormula,
escapeCsvValue(handleNull(scene.id)),
escapeCsvValue(handleNull(scene.name)),
escapeCsvValue(handleNull(scene.publishedState)),
handleNull(scene.id),
handleNull(scene.name),
handleNull(scene.publishedState),
// formatDate(scene.datePublished),
scene.isReviewed != null ? (scene.isReviewed ? 'Yes' : 'No') : 'N/A',
// handleNull(scene.project?.id),
escapeCsvValue(handleNull(scene.project?.name)),
handleNull(scene.project?.name),
// handleNull(scene.subject?.id),
escapeCsvValue(handleNull(scene.subject?.name)),
handleNull(scene.subject?.name),
// handleNull(scene.mediaGroup?.id),
escapeCsvValue(handleNull(scene.mediaGroup?.name)),
handleNull(scene.mediaGroup?.name),
formatDate(scene.dateCreated),
// handleNull(scene.derivatives.models?.status),
// handleNull(scene.derivatives.models?.items?.length),
escapeCsvValue(handleNull(scene.derivatives.downloads?.status)),
handleNull(scene.derivatives.downloads?.status),
// handleNull(scene.derivatives.downloads?.items?.length),
escapeCsvValue(handleNull(scene.derivatives.ar?.status)),
handleNull(scene.derivatives.ar?.status),
// handleNull(scene.derivatives.ar?.items?.length),
escapeCsvValue(handleNull(scene.sources.models?.status)),
handleNull(scene.sources.models?.status),
// handleNull(scene.sources.models?.items?.length),
escapeCsvValue(handleNull(scene.sources.captureData?.status)),
handleNull(scene.sources.captureData?.status),
// handleNull(scene.sources.captureData?.items?.length)
].join(','); // Join the row values with commas
});
Expand Down

0 comments on commit 5cac3d3

Please sign in to comment.