Skip to content
Open
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
56 changes: 50 additions & 6 deletions src/components/WebexActivity/WebexActivity.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,65 @@ import WebexAdaptiveCards from '../WebexAdaptiveCards/WebexAdaptiveCards';
* @param {object} props.style Custom style to apply
* @returns {object} JSX of the component
*/
export default function WebexActivity({activityID, className, style}) {
export default function WebexActivity({ activityID, className, style }) {
const activity = useActivity(activityID);
const adapter = useContext(AdapterContext);
const hasCards = adapter?.activitiesAdapter?.hasAdaptiveCards(activity);

const [cssClasses, sc] = webexComponentClasses('activity', className);
const [cssClasses, sc] = webexComponentClasses("activity", className);

function downloadFile(url, name) {
const link = document.createElement("a");
link.href = url;
link.download = name;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
Comment on lines +31 to +33
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should avoid using document.body, you can directly add this to component being returned

}
Comment on lines +27 to +34
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider error handling for the download functionality

The download function correctly creates and triggers a temporary link, but lacks error handling for potential failures.

function downloadFile(url, name) {
+  try {
    const link = document.createElement("a");
    link.href = url;
    link.download = name;
    document.body.appendChild(link);
    link.click();
    document.body.removeChild(link);
+  } catch (error) {
+    console.error('Failed to download file:', error);
+    // Consider showing user-friendly error notification
+  }
}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
function downloadFile(url, name) {
const link = document.createElement("a");
link.href = url;
link.download = name;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
function downloadFile(url, name) {
try {
const link = document.createElement("a");
link.href = url;
link.download = name;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
} catch (error) {
console.error('Failed to download file:', error);
// Consider showing user-friendly error notification
}
}


return (
<div className={cssClasses} key={activity.ID} style={style}>
{activity.displayHeader && (
<ActivityHeader personID={activity.personID} timestamp={activity.created} />
<ActivityHeader
personID={activity.personID}
timestamp={activity.created}
/>
)}
<div className={sc('content')}>
{!hasCards && activity.text && <div className={sc('message')}>{activity.text}</div>}
<div className={sc("content")}>
{!hasCards && activity.text && (
<div className={sc("message")}>{activity.text}</div>
)}
{hasCards && <WebexAdaptiveCards activityID={activity.ID} />}

{/* ✅ Accessible screenshot rendering for shared files */}
{activity?.object?.files?.length > 0 && (
<div className={sc("attachments")}>
{activity.object.files.map((file) => (
<div
className="share-file-wrapper"
tabIndex="0"
role="group"
key={file.url}
>
<img
src={file.url}
alt={file.displayName || "shared file"}
className="shared-screenshot"
/>
<div className="webex-share-item-actions">
<button
type="button"
className="md-button md-button--32"
aria-label={`Download ${file.displayName}`}
onClick={() => downloadFile(file.url, file.displayName)}
>
⬇️
</button>
</div>
</div>
))}
</div>
)}
</div>
</div>
);
Expand All @@ -46,4 +90,4 @@ WebexActivity.propTypes = {
WebexActivity.defaultProps = {
className: '',
style: undefined,
};
};
31 changes: 31 additions & 0 deletions src/components/WebexActivity/WebexActivity.scss
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,34 @@ $content-left-margin: 3.5rem; //avatar width + margin
}
}

.share-file-wrapper {
position: relative;
display: inline-block;
margin-top: 8px;
outline: none;
}

.shared-screenshot {
max-width: 100%;
border-radius: 4px;
display: block;
}

// Download button initially hidden, appears on hover or keyboard focus
.webex-share-item-actions {
position: absolute;
bottom: 8px;
right: 8px;
opacity: 0;
visibility: hidden;
transition: opacity 0.3s ease;
background: rgba(0, 0, 0, 0.5);
border-radius: 4px;
padding: 4px;
}

.share-file-wrapper:hover .webex-share-item-actions,
.share-file-wrapper:focus-within .webex-share-item-actions {
opacity: 1;
visibility: visible;
}