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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
import * as React from "react";
import { CollectionView } from "./CollectionView";
import "./CollectionViewChromes.scss";
import { CollectionViewType } from "./CollectionBaseView";
import { undoBatch } from "../../util/UndoManager";
import { action, observable, runInAction, computed } from "mobx";
import { observer } from "mobx-react";
import { Doc, DocListCast } from "../../../new_fields/Doc";
import { DocLike } from "../MetadataEntryMenu";
const higflyout = require("@hig/flyout");
export const Flyout = higflyout.default;
import * as Autosuggest from 'react-autosuggest';
import { EditableView } from "../EditableView";
import { StrCast } from "../../../new_fields/Types";
interface CollectionViewChromeProps {
CollectionView: CollectionView;
}
class CollectionViewBaseChrome extends React.Component<CollectionViewChromeProps> {
@undoBatch
viewChanged = (e: React.ChangeEvent) => {
//@ts-ignore
switch (e.target.selectedOptions[0].value) {
case "freeform":
this.props.CollectionView.props.Document.viewType = CollectionViewType.Freeform;
break;
case "schema":
this.props.CollectionView.props.Document.viewType = CollectionViewType.Schema;
break;
case "treeview":
this.props.CollectionView.props.Document.viewType = CollectionViewType.Tree;
break;
case "stacking":
this.props.CollectionView.props.Document.viewType = CollectionViewType.Stacking;
break;
case "masonry":
this.props.CollectionView.props.Document.viewType = CollectionViewType.Masonry;
break;
default:
break;
}
}
render() {
return (
<div className="collectionViewBaseChrome">
<select onChange={this.viewChanged}>
<option value="freeform" selected={this.props.CollectionView.props.Document.viewType === CollectionViewType.Freeform}>Freeform View</option>
<option value="schema" selected={this.props.CollectionView.props.Document.viewType === CollectionViewType.Schema}>Schema View</option>
<option value="treeview" selected={this.props.CollectionView.props.Document.viewType === CollectionViewType.Tree}>Tree View</option>
<option value="stacking" selected={this.props.CollectionView.props.Document.viewType === CollectionViewType.Stacking}>Stacking View</option>
<option value="masonry" selected={this.props.CollectionView.props.Document.viewType === CollectionViewType.Masonry}>Masonry View</option>
</select>
</div>
)
}
}
@observer
export class CollectionStackingViewChrome extends React.Component<CollectionViewChromeProps> {
@observable private _currentKey: string = "";
@observable private suggestions: string[] = [];
@computed get sectionFilter() { return StrCast(this.props.CollectionView.props.Document.sectionFilter); }
getKeySuggestions = async (value: string): Promise<string[]> => {
value = value.toLowerCase();
let docs: Doc | Doc[] | Promise<Doc> | Promise<Doc[]> | (() => DocLike)
= () => DocListCast(this.props.CollectionView.props.Document[this.props.CollectionView.props.fieldExt ? this.props.CollectionView.props.fieldExt : this.props.CollectionView.props.fieldKey]);
if (typeof docs === "function") {
docs = docs();
}
docs = await docs;
if (docs instanceof Doc) {
return Object.keys(docs).filter(key => key.toLowerCase().startsWith(value));
} else {
const keys = new Set<string>();
docs.forEach(doc => Doc.allKeys(doc).forEach(key => keys.add(key)));
return Array.from(keys).filter(key => key.toLowerCase().startsWith(value));
}
}
@action
onKeyChange = (e: React.ChangeEvent, { newValue }: { newValue: string }) => {
this._currentKey = newValue;
}
getSuggestionValue = (suggestion: string) => suggestion;
renderSuggestion = (suggestion: string) => {
return <p>{suggestion}</p>;
}
onSuggestionFetch = async ({ value }: { value: string }) => {
const sugg = await this.getKeySuggestions(value);
runInAction(() => {
this.suggestions = sugg;
});
}
@action
onSuggestionClear = () => {
this.suggestions = [];
}
setValue = (value: string) => {
this.props.CollectionView.props.Document.sectionFilter = value;
return true;
}
@action resetValue = () => { this._currentKey = this.sectionFilter; };
render() {
return (
<div className="collectionStackingViewChrome">
<CollectionViewBaseChrome CollectionView={this.props.CollectionView} />
<div className="collectionStackingViewChrome-sectionFilter-cont">
<div className="collectionStackingViewChrome-sectionFilter-label">
Group items by:
</div>
<div className="collectionStackingViewChrome-sectionFilter">
<EditableView
GetValue={() => this.sectionFilter}
autosuggestProps={
{
resetValue: this.resetValue,
value: this._currentKey,
onChange: this.onKeyChange,
autosuggestProps: {
inputProps:
{
value: this._currentKey,
onChange: this.onKeyChange
},
getSuggestionValue: this.getSuggestionValue,
suggestions: this.suggestions,
alwaysRenderSuggestions: true,
renderSuggestion: this.renderSuggestion,
onSuggestionsFetchRequested: this.onSuggestionFetch,
onSuggestionsClearRequested: this.onSuggestionClear
}
}}
SetValue={this.setValue}
contents={this.sectionFilter ? this.sectionFilter : "N/A"}
/>
</div>
</div>
</div>
)
}
}
|