Skip to content

Commit f55a236

Browse files
committed
Fix dropdownLabel, correct formatting
Fix dropdownLabel, correct formatting
1 parent b095ee2 commit f55a236

File tree

6 files changed

+19
-37
lines changed

6 files changed

+19
-37
lines changed

.vs/OneNotePicker-JS/v15/.suo

-3.5 KB
Binary file not shown.

.vs/ProjectSettings.json

-3
This file was deleted.

.vs/slnx.sqlite

-148 KB
Binary file not shown.

sampleApp/sample.tsx

+18-20
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,17 @@ const render = (globalProps: GlobalProps, notebooks: Notebook[]) => {
2020
);
2121
};
2222

23-
const renderDropdown = (globalProps: GlobalProps, notebooks: Notebook[], label: string, popupVisible: boolean) => {
23+
const renderDropdown = (globalProps: GlobalProps, notebooks: Notebook[]) => {
24+
const dropdownLabel = !globalProps.globals.selectedId ?
25+
'Select Section' :
26+
findItemName(globalProps.globals.notebookListUpdater!.get(), globalProps.globals.selectedId);
27+
2428
ReactDOM.render(
25-
<OneNotePickerDropdown globals={globalProps.globals} notebooks={notebooks} dropdownLabel={label} popupDirection={'bottom'} popupVisible={popupVisible}/>,
29+
<OneNotePickerDropdown globals={globalProps.globals} notebooks={notebooks} dropdownLabel={dropdownLabel} popupDirection={'bottom'} />,
2630
document.getElementById('oneNotePickerDropdown') as HTMLElement
2731
);
2832
};
2933

30-
export let defaultDropdownLabel = "";
3134

3235
oneNoteDataProvider.getNotebooks().then((notebooks) => {
3336
for (let i = 0; i < notebooks.length; i++) {
@@ -38,6 +41,7 @@ oneNoteDataProvider.getNotebooks().then((notebooks) => {
3841

3942
const initialSelectedId = '0-752C1AAF7737895C!515';
4043
OneNoteItemUtils.expandTo(notebooks, item => item.id === initialSelectedId);
44+
let dropdownLabel = '';
4145

4246
const globalProps: GlobalProps = {
4347
globals: {
@@ -46,39 +50,34 @@ oneNoteDataProvider.getNotebooks().then((notebooks) => {
4650
notebookListUpdater: updater,
4751
callbacks: {
4852
onNotebookHierarchyUpdated: (newNotebookHierarchy) => {
49-
let latestNotebook = newNotebookHierarchy[newNotebookHierarchy.length - 1].name;
50-
if(defaultDropdownLabel === "")
51-
defaultDropdownLabel = latestNotebook;
53+
5254
render(globalProps, newNotebookHierarchy);
53-
renderDropdown(globalProps, newNotebookHierarchy, defaultDropdownLabel, true);
55+
renderDropdown(globalProps, newNotebookHierarchy);
5456
},
5557
onSectionSelected: (section, breadcrumbs) => {
5658
globalProps.globals.selectedId = section.id;
57-
defaultDropdownLabel = section.name;
59+
5860
// tslint:disable-next-line:no-console
5961
console.log(breadcrumbs.map(x => x.name).join(' > '));
6062

6163
render(globalProps, globalProps.globals.notebookListUpdater!.get());
62-
renderDropdown(globalProps, globalProps.globals.notebookListUpdater!.get(), defaultDropdownLabel, false);
64+
renderDropdown(globalProps, globalProps.globals.notebookListUpdater!.get());
6365
},
6466
onPageSelected: (page, breadcrumbs) => {
6567
globalProps.globals.selectedId = page.id;
66-
defaultDropdownLabel = page.name;
68+
6769
// tslint:disable-next-line:no-console
6870
console.log(breadcrumbs.map(x => x.name).join(' > '));
69-
console.log(breadcrumbs[breadcrumbs.length -1].name)
7071

7172
render(globalProps, globalProps.globals.notebookListUpdater!.get());
72-
renderDropdown(globalProps, globalProps.globals.notebookListUpdater!.get(), defaultDropdownLabel, false);
73+
renderDropdown(globalProps, globalProps.globals.notebookListUpdater!.get());
7374
},
7475
onAccessibleSelection: (selectedItemId: string) => {
7576
globalProps.globals.ariaSelectedId = selectedItemId;
76-
let notebookName = findNotebook(notebooks, selectedItemId);
77-
if (defaultDropdownLabel === "")
78-
defaultDropdownLabel = notebookName;
77+
7978
// todo this changes the label but you can't click to make a selection?
8079
render(globalProps, globalProps.globals.notebookListUpdater!.get());
81-
renderDropdown(globalProps, globalProps.globals.notebookListUpdater!.get(), defaultDropdownLabel, true);
80+
renderDropdown(globalProps, globalProps.globals.notebookListUpdater!.get());
8281
},
8382
onNotebookCreated: (notebook: Notebook) => {
8483
// Allow max one creation
@@ -111,15 +110,14 @@ oneNoteDataProvider.getNotebooks().then((notebooks) => {
111110
ariaSelectedId: initialSelectedId
112111
}
113112
};
114-
let notebookName = findNotebook(notebooks, initialSelectedId)
115113
render(globalProps, notebooks);
116-
renderDropdown(globalProps, notebooks, notebookName, false);
114+
renderDropdown(globalProps, notebooks);
117115
}).catch((value) => {
118116
// tslint:disable-next-line:no-console
119117
console.error(value);
120118
});
121119

122-
export function findNotebook(notebooks, itemid) {
120+
export function findItemName(notebooks, itemid) {
123121
let notebook = OneNoteItemUtils.find(notebooks, item => item.id === itemid);
124-
return notebook ? notebook.name : "";
122+
return notebook ? notebook.name : '';
125123
}

src/oneNotePickerDropdown.tsx

+1-13
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ export interface OneNotePickerDropdownState {
88
popupVisible: boolean;
99
}
1010

11-
1211
export interface PickerProperties extends GlobalProps {
13-
popupVisible: boolean;
1412
dropdownLabel: string;
1513
popupDirection: 'bottom' | 'top';
1614
popupContentOverride?: JSX.Element;
@@ -22,18 +20,12 @@ export abstract class GenericOneNotePickerDropdown<T extends PickerProperties> e
2220
constructor(props: T) {
2321
super(props);
2422
this.state = {
25-
popupVisible: props.popupVisible
23+
popupVisible: false
2624
};
2725
this.handleClickOutside = this.handleClickOutside.bind(this);
2826
this.setWrapperRef = this.setWrapperRef.bind(this);
2927
}
3028

31-
componentWillReceiveProps(nextProps: T) {
32-
this.state = {
33-
popupVisible: nextProps.popupVisible
34-
}
35-
}
36-
3729
onClick() {
3830
this.setState({
3931
popupVisible: !this.state.popupVisible
@@ -66,7 +58,6 @@ export abstract class GenericOneNotePickerDropdown<T extends PickerProperties> e
6658
document.removeEventListener('mousedown', this.handleClickOutside);
6759
}
6860

69-
7061
abstract createTag(arg: T): JSX.Element;
7162

7263
render() {
@@ -112,10 +103,7 @@ export abstract class GenericOneNotePickerDropdown<T extends PickerProperties> e
112103
undefined}
113104
</div>
114105
);
115-
116-
117106
}
118-
119107
}
120108

121109
export class OneNotePickerDropdown extends GenericOneNotePickerDropdown<OneNotePickerProps & PickerProperties> {

src/props/globalProps.ts

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ export interface GlobalProps {
1616
export interface InnerGlobals {
1717
focusOnMount: boolean;
1818

19-
2019
oneNoteDataProvider: OneNoteDataProvider | undefined;
2120
notebookListUpdater: NotebookListUpdater | undefined;
2221
callbacks: OneNotePickerCallbacks;

0 commit comments

Comments
 (0)