This repository was archived by the owner on Sep 9, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathoneNotePicker.tsx
More file actions
118 lines (102 loc) · 6.41 KB
/
oneNotePicker.tsx
File metadata and controls
118 lines (102 loc) · 6.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import * as React from 'react';
import './index.css';
import { OneNotePickerBase } from './oneNotePickerBase';
import { NotebookRenderStrategy } from './components/notebookRenderStrategy';
import { SharedNotebookRenderStrategy } from './components/sharedNotebookRenderStrategy';
import { ExpandableNode } from './components/treeView/expandableNode';
import { LeafNode } from './components/treeView/leafNode';
import { GlobalProps } from './props/globalProps';
import { Notebook } from './oneNoteDataStructures/notebook';
import { SharedNotebook } from './oneNoteDataStructures/sharedNotebook';
import { CreateNewNotebookNode } from './components/createNewNotebook/createNewNotebookNode';
import { Section } from './oneNoteDataStructures/section';
import { RecentSectionsNode } from './components/recentSections/recentSectionsNode';
import { RecentSectionHeaderRenderStrategy } from './components/recentSections/recentSectionHeaderRenderStrategy';
export interface OneNotePickerProps extends GlobalProps {
notebooks: Notebook[];
sharedNotebooks?: SharedNotebook[];
recentSections?: Section[];
}
export interface OneNotePickerState {
recentSectionsExpanded: boolean;
}
export class OneNotePicker extends OneNotePickerBase<OneNotePickerProps, OneNotePickerState> {
constructor(props: OneNotePickerProps) {
super(props);
this.state = {
recentSectionsExpanded: true
};
}
protected rootNodes(): JSX.Element[] {
const { notebooks, sharedNotebooks, recentSections, globals } = this.props;
const { focusOnMount, ariaSelectedId } = globals;
const { recentSectionsExpanded } = this.state;
// Sort both personal and shared notebooks by last modified time (last accessed time for shared notebooks)
let allNotebooks: (Notebook | SharedNotebook)[] = notebooks || [];
if (sharedNotebooks) {
allNotebooks = allNotebooks.concat(sharedNotebooks);
}
allNotebooks.sort(this.sortNotebooksByLastModifiedTime);
const noPersonalNotebooks = !notebooks || notebooks.length === 0;
// The key here is guaranteed to be unique as there is only one max 'Create notebook' affordance
const createNewNotebookExists = this.props.globals.callbacks.onNotebookCreated || this.props.globals.shouldShowCreateEntityInputs;
const createNewNotebook = createNewNotebookExists ?
[<CreateNewNotebookNode key='createnewnotebooknode' {...this.props.globals} level={1} tabbable={true} focusOnMount={focusOnMount}></CreateNewNotebookNode>] :
[];
let recentSectionRenderStrategy, recentSectionsExists = false;
if (recentSections && recentSections.length > 0) {
recentSectionRenderStrategy = new RecentSectionHeaderRenderStrategy(recentSections, recentSectionsExpanded, globals, this.onRecentSectionsClick.bind(this));
recentSectionsExists = true;
}
const recentSectionNodes = recentSectionRenderStrategy ?
[<RecentSectionsNode key={recentSectionRenderStrategy.getId()} globals={this.props.globals} level={1} tabbable={true}
focusOnMount={!createNewNotebookExists && focusOnMount} sections={recentSections || []}
treeViewId={this.treeViewId()} id={recentSectionRenderStrategy.getId()}
ariaSelected={ariaSelectedId ? recentSectionRenderStrategy.isAriaSelected() : true}
node={recentSectionRenderStrategy} expanded={recentSectionRenderStrategy.isExpanded()}
onRecentSectionsClick={this.onRecentSectionsClick.bind(this)}></RecentSectionsNode>] : [];
const allNotebookNodes = allNotebooks.map((notebook, i) => {
if ((notebook as SharedNotebook).sourceService) {
const renderStrategy = new SharedNotebookRenderStrategy(notebook as SharedNotebook, globals);
return !!this.props.globals.callbacks.onSectionSelected || !!this.props.globals.callbacks.onPageSelected ?
<ExpandableNode globals={this.props.globals} expanded={renderStrategy.isExpanded()} node={renderStrategy}
treeViewId={this.treeViewId()} key={renderStrategy.getId()}
id={renderStrategy.getId()} tabbable={!createNewNotebookExists && noPersonalNotebooks && i === 0}
focusOnMount={!createNewNotebookExists && !recentSectionsExists && focusOnMount && i === 0}
ariaSelected={ariaSelectedId ? renderStrategy.isAriaSelected() : !recentSectionsExists && i === 0} selected={renderStrategy.isSelected()}
setsize={allNotebooks.length} posinset={i + 1}></ExpandableNode> :
<LeafNode globals={this.props.globals} node={renderStrategy} treeViewId={this.treeViewId()} key={renderStrategy.getId()}
id={renderStrategy.getId()} tabbable={!createNewNotebookExists && noPersonalNotebooks && i === 0}
focusOnMount={!createNewNotebookExists && !recentSectionsExists && focusOnMount && i === 0}
ariaSelected={ariaSelectedId ? renderStrategy.isAriaSelected() : !recentSectionsExists && i === 0}></LeafNode>;
} else {
const renderStrategy = new NotebookRenderStrategy(notebook, globals);
return !!this.props.globals.callbacks.onSectionSelected || !!this.props.globals.callbacks.onPageSelected ?
<ExpandableNode globals={this.props.globals} expanded={renderStrategy.isExpanded()} node={renderStrategy}
treeViewId={this.treeViewId()} key={renderStrategy.getId()}
id={renderStrategy.getId()} tabbable={!createNewNotebookExists && !recentSectionsExists && i === 0} focusOnMount={!createNewNotebookExists && !recentSectionsExists && focusOnMount && i === 0}
ariaSelected={ariaSelectedId ? renderStrategy.isAriaSelected() : !recentSectionsExists && i === 0} selected={renderStrategy.isSelected()}
setsize={allNotebooks.length} posinset={i + 1}></ExpandableNode> :
<LeafNode globals={this.props.globals} node={renderStrategy} treeViewId={this.treeViewId()} key={renderStrategy.getId()}
id={renderStrategy.getId()} tabbable={!createNewNotebookExists && i === 0} focusOnMount={!createNewNotebookExists && !recentSectionsExists && focusOnMount && i === 0}
ariaSelected={ariaSelectedId ? renderStrategy.isAriaSelected() : !recentSectionsExists && i === 0}></LeafNode>;
}
})
return [...recentSectionNodes, ...createNewNotebook, ...allNotebookNodes];
}
private onRecentSectionsClick(expanded: boolean) {
this.setState({
recentSectionsExpanded: expanded
});
}
private sortNotebooksByLastModifiedTime(notebook1: Notebook | SharedNotebook, notebook2: Notebook | SharedNotebook) {
if (notebook1.lastModifiedTime && notebook2.lastModifiedTime) {
if (notebook1.lastModifiedTime > notebook2.lastModifiedTime) {
return -1;
} else if (notebook2.lastModifiedTime > notebook1.lastModifiedTime) {
return 1;
}
}
return 0;
}
}