This is an automated email from the ASF dual-hosted git repository. zjffdu pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/zeppelin.git
The following commit(s) were added to refs/heads/master by this push: new ceff31a [ZEPPELIN-4558] fix note list is not sorted by name in new web ui ceff31a is described below commit ceff31a7ef431757f223d89861356de0ae7b61d7 Author: vthinkxie <yadong....@alibaba-inc.com> AuthorDate: Thu Jan 16 13:10:03 2020 +0800 [ZEPPELIN-4558] fix note list is not sorted by name in new web ui ### What is this PR for? fix note list is not sorted by name in new web ui ### What type of PR is it? [Bug Fix] ### Todos * [ ] - Task ### What is the Jira issue? [ZEPPELIN-4558] ### How should this be tested? https://travis-ci.org/vthinkxie/zeppelin/builds/637915102 ### Screenshots (if appropriate) ### Questions: * Does the licenses files need update? no * Is there breaking changes for older versions? no * Does this needs documentation? no Author: vthinkxie <yadong....@alibaba-inc.com> Closes #3602 from vthinkxie/ZEPPELIN-4558 and squashes the following commits: a4d547205 [vthinkxie] [ZEPPELIN-4558] fix note list is not sorted by name in new web ui --- .../src/app/interfaces/node-list.ts | 1 + .../src/app/share/node-list/node-list.component.ts | 40 +++++++++++++++++++--- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/zeppelin-web-angular/src/app/interfaces/node-list.ts b/zeppelin-web-angular/src/app/interfaces/node-list.ts index 3330e03..55331a9 100644 --- a/zeppelin-web-angular/src/app/interfaces/node-list.ts +++ b/zeppelin-web-angular/src/app/interfaces/node-list.ts @@ -27,6 +27,7 @@ export interface NodeItem { expanded?: boolean; children?: NodeItem[]; isTrash: boolean; + nodeType?: string; path?: string; } diff --git a/zeppelin-web-angular/src/app/share/node-list/node-list.component.ts b/zeppelin-web-angular/src/app/share/node-list/node-list.component.ts index 5d9abb4..23a70c7 100644 --- a/zeppelin-web-angular/src/app/share/node-list/node-list.component.ts +++ b/zeppelin-web-angular/src/app/share/node-list/node-list.component.ts @@ -10,7 +10,8 @@ * limitations under the License. */ -import { ChangeDetectionStrategy, ChangeDetectorRef, Component, Input, OnInit } from '@angular/core'; +import { ChangeDetectionStrategy, ChangeDetectorRef, Component, Inject, Input, OnInit } from '@angular/core'; +import { TRASH_FOLDER_ID_TOKEN } from '@zeppelin/interfaces'; import { NzTreeNode } from 'ng-zorro-antd/core'; import { NzModalService } from 'ng-zorro-antd/modal'; @@ -96,15 +97,46 @@ export class NodeListComponent extends MessageListenersManager implements OnInit @MessageListener(OP.NOTES_INFO) getNotes(data: MessageReceiveDataTypeMap[OP.NOTES_INFO]) { this.noteListService.setNotes(data.notes); - this.nodes = this.noteListService.notes.root.children.map(item => { - return { ...item, key: item.id }; - }); + this.nodes = this.noteListService.notes.root.children + .sort((v1, v2) => this.noteComparator(v1, v2)) + .map(item => { + return { ...item, key: item.id }; + }); this.cdr.markForCheck(); } + getNoteName(note) { + if (note.title === undefined || note.title.trim() === '') { + return 'Note ' + note.id; + } else { + return note.title; + } + } + + noteComparator(v1, v2) { + const note1 = v1; + const note2 = v2; + if (note1.id === this.TRASH_FOLDER_ID) { + return 1; + } + if (note2.id === this.TRASH_FOLDER_ID) { + return -1; + } + if (note1.children === undefined && note2.children !== undefined) { + return 1; + } + if (note1.children !== undefined && note2.children === undefined) { + return -1; + } + const noteName1 = this.getNoteName(note1); + const noteName2 = this.getNoteName(note2); + return noteName1.localeCompare(noteName2); + } + constructor( private noteListService: NoteListService, public messageService: MessageService, + @Inject(TRASH_FOLDER_ID_TOKEN) public TRASH_FOLDER_ID: string, private nzModalService: NzModalService, private noteActionService: NoteActionService, private cdr: ChangeDetectorRef