-
Notifications
You must be signed in to change notification settings - Fork 57
Fix/spark 564418 fixing download button for shared files and screenshot #853
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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
+27
to
+34
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| 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> | ||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -46,4 +90,4 @@ WebexActivity.propTypes = { | |||||||||||||||||||||||||||||||||||||||||||
| WebexActivity.defaultProps = { | ||||||||||||||||||||||||||||||||||||||||||||
| className: '', | ||||||||||||||||||||||||||||||||||||||||||||
| style: undefined, | ||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
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