Skip to content
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

feat(ui5-upload-collection): implement new webcomponent #1316

Merged
merged 47 commits into from
Apr 3, 2020
Merged

feat(ui5-upload-collection): implement new webcomponent #1316

merged 47 commits into from
Apr 3, 2020

Conversation

dimovpetar
Copy link
Contributor

@dimovpetar dimovpetar commented Mar 19, 2020

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
  • progress indicator

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
packages/fiori/src/UploadCollection.hbs Show resolved Hide resolved
* 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 = {
Copy link
Contributor

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

Copy link
Contributor Author

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?

packages/fiori/src/UploadCollection.js Show resolved Hide resolved
packages/fiori/src/UploadCollection.js Outdated Show resolved Hide resolved
@@ -0,0 +1,35 @@
{{>include "../../main/src/ListItem.hbs"}}
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure how we can proceed here. We need to import a template from another package
@ilhan007 @pskelin @MapTo0 @fifoosid
Opinions?
Should we modify the plugin to understand node_modules/ and write here a full @ui5/webcomponents/dist..../ path?


onAfterRendering() {
if (this.focused && this._editing) {
const inp = this.shadowRoot.getElementById("ui5-uci-edit-input");
Copy link
Contributor

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()?

Copy link
Contributor Author

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];
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@vladitasev
Copy link
Contributor

Does not render correctly on IE11

@dimovpetar
Copy link
Contributor Author

Does not render correctly on IE11

Fixed. They were caused by flex.

@dimovpetar dimovpetar changed the title WIP(ui5-upload-collection): implement new webcomponent feat(ui5-upload-collection): implement new webcomponent Mar 26, 2020
Copy link
Contributor

@vladitasev vladitasev left a 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 @@

Copy link
Contributor

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

Copy link
Contributor Author

@dimovpetar dimovpetar Apr 1, 2020

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) {
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

packages/fiori/src/UploadCollection.js Show resolved Hide resolved
this._removeDragAndDropListeners();
}

_addDragAndDropListeners() {
Copy link
Contributor

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

Copy link
Contributor Author

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"),
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

packages/fiori/src/UploadCollection.js Show resolved Hide resolved
packages/fiori/src/UploadCollection.js Show resolved Hide resolved
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";
Copy link
Member

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

Copy link
Contributor Author

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 */ {
/**
Copy link
Member

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

Copy link
Contributor Author

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
Copy link
Member

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

Copy link
Contributor Author

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 {
Copy link
Member

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

Copy link
Contributor Author

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";

/**
Copy link
Member

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

Copy link
Contributor Author

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 = {
/**
Copy link
Member

Choose a reason for hiding this comment

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

same as previous

Copy link
Contributor Author

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) {
Copy link
Contributor

@vladitasev vladitasev Apr 3, 2020

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

Copy link
Contributor Author

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()}` : "";
Copy link
Contributor

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 :)

Copy link
Contributor Author

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.
Copy link
Member

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 => {
Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Member

@ilhan007 ilhan007 left a 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

@ilhan007 ilhan007 merged commit 54038e4 into SAP:master Apr 3, 2020
@dimovpetar dimovpetar deleted the uploadcollection branch October 29, 2020 16:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants