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

editor: fix issues #338

Merged
merged 1 commit into from
Feb 10, 2021
Merged

editor: fix issues #338

merged 1 commit into from
Feb 10, 2021

Conversation

jma
Copy link
Contributor

@jma jma commented Jan 7, 2021

Co-Authored-by: Johnny Mariéthoz [email protected]

Why are you opening this PR?

  • To solve several issue on SONAR.

How to test?

-Start the demo server and go to http://localhost:4200/editor.

Code review check list

  • Commit message template compliance.
  • Commit message without typos.
  • File names.
  • Functions names.
  • Functions docstrings.
  • Unnecessary commited files?
  • Extracted translations?

@jma jma force-pushed the maj-fix-editor-issues branch 3 times, most recently from a2e12a6 to 1a803ec Compare January 11, 2021 09:42
@jma jma changed the title Maj fix editor issues editor: fix issues Jan 11, 2021
@jma jma force-pushed the maj-fix-editor-issues branch from 1a803ec to 7bed2d2 Compare January 11, 2021 10:23
@jma jma marked this pull request as ready for review January 11, 2021 12:22
@jma jma requested review from sebdeleze and zannkukai January 11, 2021 12:22
Copy link

@sebdeleze sebdeleze left a comment

Choose a reason for hiding this comment

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

There's a typo in commit message: routing instead of rooting.

And you can reference the solved issues to close them automatically.

Comment on lines +21 to +32
@each $breakpoint in map-keys($grid-breakpoints) {
@include media-breakpoint-up($breakpoint) {
$infix: breakpoint-infix($breakpoint, $grid-breakpoints);
@each $prop, $abbrev in (width: w, height: h) {
@each $size, $length in $sizes {
.#{$abbrev}#{$infix}-#{$size} { #{$prop}: $length !important; }
}
}
}
}

Choose a reason for hiding this comment

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

Be careful, I think it can create a black hole 🤣

Copy link
Contributor

Choose a reason for hiding this comment

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

an after that, @jma tells me that he isn't a CSS king .... What's the truth ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is just a copy/paste from the web.

Comment on lines 254 to 258
// },
// (error) => {
// this.error = error;
// this._spinner.hide();
// }

Choose a reason for hiding this comment

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

Better to remove instead of commenting, Git have the history!

@@ -30,6 +30,7 @@
</li>
</ul>
<div class="main-content">
{{types}}

Choose a reason for hiding this comment

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

Must be removed

Comment on lines 117 to 122
// /**
// * Hide the array and remove all the elements
// */
// hide() {
// this.field.hide = true;
// }

Choose a reason for hiding this comment

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

Better to remove instead of commenting

<div>
<legend *ngIf="to.label" [tooltip]="to.description">{{ to.label }} </legend>
<div class="{{field.parent.templateOptions.cssClass}}">
<legend *ngIf="to.label" [tooltip]="to.description">label {{ to.label }}</legend>

Choose a reason for hiding this comment

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

label should be removed.

class="dropdown-menu"
role="menu"
aria-labelledby="button-basic">
<div id="dropdown-basic" *dropdownMenu class="dropdown-menu" role="menu" aria-labelledby="button-basic">

Choose a reason for hiding this comment

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

aria-labelledby should be removed as it refer to a non-existing ID.

Comment on lines 48 to 57
constructor(private _editorService: EditorService) {
super();
}

getIndex() {

Choose a reason for hiding this comment

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

Doc block is missing for constructor and getIndex

Comment on lines 55 to 76
getIndex() {
if (this.field.parent.type === 'array') {
return Number(this.field.key);
}
return null;
}

getFieldGroup(field: FormlyFieldConfig) {

Choose a reason for hiding this comment

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

doc blocks are missing for getIndex and getFieldGroup

add() {
if (this.field.parent.type === 'array') {
const i = this.getIndex() + 1;
console.log('i:', i);

Choose a reason for hiding this comment

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

Remove console log

@sebdeleze
Copy link

I tested the issues and some of them seem not to be corrected:

@jma jma marked this pull request as draft January 13, 2021 20:03
@jma jma force-pushed the maj-fix-editor-issues branch 2 times, most recently from 2601da7 to e411862 Compare January 14, 2021 14:15
@jma jma marked this pull request as ready for review January 14, 2021 14:31
Copy link
Contributor

@zannkukai zannkukai left a comment

Choose a reason for hiding this comment

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

Most of comments are cosmetics ;-) you can skip them

Comment on lines +109 to +119
if (!field.templateOptions.longMode) {
return false;
}
return (
!field.templateOptions.required &&
!field.hide &&
field.hideExpression == null
);
Copy link
Contributor

Choose a reason for hiding this comment

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

I like (me and myself) ternary instruction. In this case

return (!field.templateOptions.longMode)
    ? false
    : ( !field.templateOptions.required &&
        !field.hide &&
        field.hideExpression == null
      );

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seem to me more difficult to read. @sebastiendeleze any advises?

Copy link

@sebdeleze sebdeleze Jan 19, 2021

Choose a reason for hiding this comment

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

+1 for use ternary, but only if expression is quite simple. In this case, it is difficult to read in my opinion. But I would suggest to merge statements, like this:

return (
      field.templateOptions.longMode &&
      !field.templateOptions.required &&
      !field.hide &&
      field.hideExpression == null
    );

Comment on lines +125 to +131
if (!field) {
return false;
}
return field.templateOptions && field.templateOptions.isRoot && field.templateOptions.isRoot === true;
Copy link
Contributor

Choose a reason for hiding this comment

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

ternary is cosmetic ;-)

return (!field)
    ? false
    : field.templateOptions && field.templateOptions.isRoot && field.templateOptions.isRoot === true;

<!-- section title -->
<ng-template #title let-f="f">
<div class="header">
<label class="mb-0" *ngIf="f.templateOptions.label" [attr.for]="f.id" [tooltip]="f.templateOptions.description">
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

* @param field - FormlyFieldConfig, the correspondig form field config
* @returns boolean, true if the menu should be displayed
*/
hasMenu(field: FormlyFieldConfig) {
Copy link
Contributor

Choose a reason for hiding this comment

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

ternary ?

Comment on lines +61 to +65
getIndex() {
if (this.field.parent.type === 'array') {
return Number(this.field.key);
}
return null;
Copy link
Contributor

Choose a reason for hiding this comment

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

This one is the perfect one for a ternary return :
return (this.field.parent.type === 'array') ? Number(this.field.key) : null;

Comment on lines +161 to +187
if (this.field.parent.type === 'array') {
return this.field.parent.templateOptions.canAdd();
}
return false;
Copy link
Contributor

Choose a reason for hiding this comment

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

ternary ?

Comment on lines 173 to 174
const i = this.getIndex() + 1;
return this.field.parent.templateOptions.add(this.getIndex() + 1);
Copy link
Contributor

Choose a reason for hiding this comment

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

Either use i, either delete line 173

Comment on lines 82 to 88
if (this.field.parent.type === 'object') {
return this._editorService.canHide(this.field);
}
if (this.field.parent.type === 'array') {
return this.field.parent.templateOptions.canRemove();
}
return false;
Copy link
Contributor

Choose a reason for hiding this comment

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

switch ?

Comment on lines +96 to +100
if (this.field.parent.type === 'array') {
return this.field.parent.templateOptions.canAdd();
}
return false;
Copy link
Contributor

Choose a reason for hiding this comment

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

ternary again ?

Comment on lines 107 to 108
const i = this.getIndex() + 1;
return this.field.parent.templateOptions.add(this.getIndex() + 1);
Copy link
Contributor

Choose a reason for hiding this comment

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

use i or delete the line 107

@jma jma force-pushed the maj-fix-editor-issues branch 4 times, most recently from 3f40ac9 to 51f4a19 Compare January 18, 2021 15:48
@jma jma requested review from sebdeleze and zannkukai January 18, 2021 15:48
@sebdeleze
Copy link

When I tried the editor on SONAR, the main field wrapper and labels are appearing twice. I noticed this problem in ng-core-tester, too.

Capture d’écran 2021-01-19 à 14 15 54

@sebdeleze
Copy link

When I try to create a new document, some fields appear both in the left side and in the editor.

collection

@sebdeleze
Copy link

sebdeleze commented Jan 19, 2021

Based on the schema property here https://github.com/rero/sonar/blob/staging/sonar/modules/documents/jsonschemas/documents/document-v1.0.0_src.json#L313, I think the subtitles must not be present in the editor by default:

Capture d’écran 2021-01-19 à 14 44 22

I think this is related to #338 (comment) and the hideExpression management, because when the document type is changed, the field subtitles is shown or hidden, even though it has no hideExpression property.

@jma jma force-pushed the maj-fix-editor-issues branch 3 times, most recently from dab1625 to 75f2990 Compare January 19, 2021 20:14
@jma jma force-pushed the maj-fix-editor-issues branch 5 times, most recently from d3a0de3 to 2955b8e Compare January 20, 2021 14:05
@jma
Copy link
Contributor Author

jma commented Jan 20, 2021

When I tried the editor on SONAR, the main field wrapper and labels are appearing twice. I noticed this problem in ng-core-tester, too.

Capture d’écran 2021-01-19 à 14 15 54

It should be solved

@iGormilhit iGormilhit added the f: editor Concerns editor based on JSON schema AND custom editor label Jan 25, 2021
@jma jma force-pushed the maj-fix-editor-issues branch 3 times, most recently from ba2a45f to 0529063 Compare January 27, 2021 13:14
@jma jma force-pushed the maj-fix-editor-issues branch from 0529063 to 3c53cb3 Compare January 27, 2021 13:47
@jma jma force-pushed the maj-fix-editor-issues branch from 3c53cb3 to f289992 Compare January 27, 2021 15:32
Copy link

@iGormilhit iGormilhit left a comment

Choose a reason for hiding this comment

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

Commit message approved.

* Fixes tester document search routing.
* Removes useless log messages.
* Fixes import paths.
* Replaces the css classes such as `editor-title` by a `card` wrapper.
* Moves some common code lines in the editor service.
* Moves the field label html code into a specific component.
* Adds new `containerCSSClass`, `itemCSSClass` and `cssClass` to allow
  field grid positions.
* Renders the hide/show/clone button in the children field instead of
  the parent (array, object) component.
* Adds external link support for remote typeahead editor component.
* Closes rero#328.
* Closes rero#327.
* Closes rero#325.
* Closes rero#248.
* Closes rero#242.
* Closes rero/rero-ils#1604.
* Closes rero/rero-ils#1601.

Co-Authored-by: Johnny Mariéthoz <[email protected]>
@jma jma force-pushed the maj-fix-editor-issues branch from f289992 to 4198063 Compare January 28, 2021 10:22
@@ -14,14 +14,14 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { Component } from '@angular/core';
import { Component, OnInit } from '@angular/core';

Choose a reason for hiding this comment

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

On Init is not used.

@jma jma merged commit ca9caf8 into rero:dev Feb 10, 2021
@jma jma deleted the maj-fix-editor-issues branch December 13, 2021 10:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
f: editor Concerns editor based on JSON schema AND custom editor
Projects
None yet
4 participants