-
Notifications
You must be signed in to change notification settings - Fork 273
feat(ui5-upload-collection): implement new webcomponent #1316
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
Conversation
ui5-upload-collection is new webcomponent located in fiori package, which benefits and brings some of ui5-list features, but it shows different items of type ui5-upload-collection-item. It is in the responsibility of the app developer to put ui5-file-uploader in the header, create and add new ui5-upload-collection-item(s) to the collection. Main features: - header slot - items slot (default) - items have special visualisation, suitable for files representation - items have "file" property, to allow app developers to set and get file object - drag and drop overlay
* Ensures that there is only 1 listener per type attached (drag, drop, leave). Event listeners will be only attached when | ||
* there is at least 1 UploadCollection registered in the set. | ||
*/ | ||
const bodyDnDHandler = { |
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.
Please move this to a separate module in main/src/upload-utils/ f.e. or whatever name you like
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.
main/src of fiori/src?
@@ -0,0 +1,35 @@ | |||
{{>include "../../main/src/ListItem.hbs"}} |
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.
|
||
onAfterRendering() { | ||
if (this.focused && this._editing) { | ||
const inp = this.shadowRoot.getElementById("ui5-uci-edit-input"); |
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.
Can you use our declarative focus dom ref and call focus()?
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.
Done.
} | ||
|
||
get _fileNameWithoutExtension() { | ||
return this.fileName.split(".")[0]; |
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.
Please create a more robust check, file may have dots inside the name too
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.
Done.
Does not render correctly on IE11 |
Fixed. They were caused by flex. |
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.
Looks really good!
- use events for body dnd class
- create a new message bundle
- bind all events in the template
@@ -0,0 +1,79 @@ | |||
|
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.
This is upload collection related. Please put that in the name somehow
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.
Renamed it to UploadCollectionBodyDnD
|
||
lastDragEnter = event.target; | ||
uploadCollections.forEach(uc => { | ||
if (uc._dndOverlayMode !== UploadCollectionDnDOverlayMode.Drop) { |
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.
The right pattern for this kind of behavior is: publish/subscribe. This file should not touch the private APIs of upload collections. They should register events and have this file fire the events, and they should do the work themselves.
See EventProvider.js in the base project. Use that as in OpenUI5
As a result, the methods this will export will be called something like attachDnDHandler, detachDnDHandler rather than add/remove upload collection instance
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.
Done
this._removeDragAndDropListeners(); | ||
} | ||
|
||
_addDragAndDropListeners() { |
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.
You should not register event listeners unless absolutely necessary. You should only bind events in the template and let lit handle the lifecycle. If you need to bind the events conditionally, just bind them and return early in the handlers if the condition is not met. Thus the whole onbefore/onafter rendering logic should go away
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.
Done. I was able to simplify the logic even further by adding the subscriptions not on the root div, but on the dedicated div for drag and drop overlay
Label.define(), | ||
List.define(), | ||
Title.define(), | ||
fetchI18nBundle("@ui5/webcomponents"), |
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.
"-fiori"
Each package should use its own bundle. These will be the first translations for this package :) so you get to create it
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.
Done
import litRender from "@ui5/webcomponents-base/dist/renderer/LitRenderer.js"; | ||
import { fetchI18nBundle, getI18nBundle } from "@ui5/webcomponents-base/dist/i18nBundle.js"; | ||
import Button from "@ui5/webcomponents/dist/Button.js"; | ||
import Icon from "@ui5/webcomponents/dist/Icon.js"; |
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.
if you don't have <ui5-icon tag in UploadCollectionitem.hbs, you don't need to import Icon.js
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.
Removed it
const metadata = { | ||
tag: "ui5-upload-collection-item", | ||
properties: /** @lends sap.ui.webcomponents.fiori.UploadCollectionItem.prototype */ { | ||
/** |
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.
make sure all the public properties have public, type and defaultvalue tags
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.
Done
* | ||
* @constructor | ||
* @author SAP SE | ||
* @alias sap.ui.webcomponents.fiori.UploadCollectionItem |
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.
add since 1.0.0-=rc.7
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.
Done
@@ -0,0 +1,123 @@ | |||
:host { |
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.
consider the "hidden" attribute, use some of the existing components for reference, but in general if the someone sets "hidden" to the component (to the host) the component should hide
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.
Done
@@ -0,0 +1,29 @@ | |||
import DataType from "@ui5/webcomponents-base/dist/types/DataType.js"; | |||
|
|||
/** |
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.
The enums should be documented as well. Use the AvatarShape.js for reference and it is ok to be public
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.
I added jsdoc to this type, but it is only used in a private property "_dndOverlayMode" and thats why I kept it private
import DataType from "@ui5/webcomponents-base/dist/types/DataType.js"; | ||
|
||
const UploadStates = { | ||
/** |
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.
same as previous
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.
Done
} | ||
|
||
get _progressText() { | ||
switch (this.uploadState) { |
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.
IMO switch is an overkill here:
`if (error) {
return "...";
}
if (warning) {
return "...";
}
return... "";`
If you insist on switch it's fine, just fix tabulation
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.
ESLint doesn't let me fix the indentation, but you are right that it is too much to use switch-case here. I have turned it to ifs
} | ||
|
||
get _fileExtension() { | ||
return this.fileName.includes(".") ? `.${this.fileName.split(".").pop()}` : ""; |
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.
this will have a problem with files such as .gitignore
that start with a dot and have no extension
Please research how to get the extension of a file safely and once you find the algorithm, implement it in: base/src/utils/getFileExtension.js
and let it export a single method
export default getFileExtension;
We might need it elsewhere in the future too :)
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.
Done
import DataType from "@ui5/webcomponents-base/dist/types/DataType.js"; | ||
|
||
/** | ||
* Different types of AvatarShape. |
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.
typo AvatarShape
@@ -94,21 +75,22 @@ <h3>UploadCollection</h3> | |||
return uci; | |||
} | |||
|
|||
fileUploader.addEventListener("ui5-change", function(event) { | |||
var files = event.detail.files; | |||
fileUploader.addEventListener("ui5-change", event => { |
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.
I don't think we transpile samples pages and this will not work on IE.
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.
Fixed it, now only the displayed code is in es6
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.
just the code that is displayed to the user should be es6 if possible
ui5-upload-collection is new webcomponent located in fiori package, which benefits and brings some of ui5-list features, but it shows different items of type ui5-upload-collection-item.
It is in the responsibility of the app developer to put ui5-file-uploader in the header, create and add new ui5-upload-collection-item(s) to the collection.
Main features: