-
Notifications
You must be signed in to change notification settings - Fork 8
add depth check to oneNoteItemUtils #118
base: master
Are you sure you want to change the base?
Changes from 1 commit
d35c4b7
e826401
b249c39
a82758b
64f4fa3
408466c
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 |
|---|---|---|
|
|
@@ -6,6 +6,8 @@ import { Polyfills } from '../polyfills'; | |
|
|
||
| Polyfills.find(); | ||
|
|
||
| export type noteBookOrSectionGroup = Notebook | SectionGroup; | ||
|
|
||
| export class OneNoteItemUtils { | ||
| /** | ||
| * Given the id of the OneNoteItem, and a notebook or sectionGroup list, returns | ||
|
|
@@ -98,6 +100,38 @@ export class OneNoteItemUtils { | |
|
|
||
| return ancestry; | ||
| } | ||
|
|
||
| /** | ||
| * Finds the maximum depth of notebooks list, including sections | ||
| */ | ||
| getDepthOfNotebooks(notebooks: Notebook[]): number { | ||
|
||
| if (!notebooks || notebooks.length === 0) { | ||
| return 0; | ||
| } | ||
| return notebooks.map((notebook) => this.getDepthOfParent(notebook)).reduce((d1, d2) => Math.max(d1, d2)); | ||
| } | ||
|
|
||
| /** | ||
| * Finds the maximum depth of SectionGroup or Notebook, | ||
| * includes the number of sections below it | ||
| */ | ||
| getDepthOfParent(parent: noteBookOrSectionGroup ): number { | ||
|
||
| if (!parent) { | ||
| return 0; | ||
| } | ||
|
|
||
| let containsAtLeastOneSection = parent.sections && parent.sections.length > 0; | ||
| let maxDepth = containsAtLeastOneSection ? 1 : 0; | ||
|
|
||
| if (parent.sectionGroups) { | ||
| for (let i = 0; i < parent.sections.length; i++) { | ||
|
||
| maxDepth = Math.max(this.getDepthOfParent(parent.sectionGroups[i]), maxDepth); | ||
| } | ||
| } | ||
|
|
||
| // Include the parent itself | ||
| return maxDepth + 1; | ||
| } | ||
| } | ||
|
|
||
| export * from './oneNoteApiResponseTransformer'; | ||
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.
nit- notebook isn't two words, therefore noteBook -> notebook