aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbobzel <zzzman@gmail.com>2021-04-07 12:15:20 -0400
committerbobzel <zzzman@gmail.com>2021-04-07 12:15:20 -0400
commit797ebbe8a82c54104a96c6e570310fb1d02da69c (patch)
tree557aa21fd93bd2fc1f87d0bb5be293637589a1cb
parentc60be390a83520c0be1a5de2c4748b60aa15fd45 (diff)
removed scope option for filters in favor of selecting dashboard.
-rw-r--r--src/client/documents/Documents.ts4
-rw-r--r--src/client/util/CurrentUserUtils.ts2
-rw-r--r--src/client/views/PropertiesView.tsx56
-rw-r--r--src/client/views/nodes/FilterBox.tsx53
4 files changed, 38 insertions, 77 deletions
diff --git a/src/client/documents/Documents.ts b/src/client/documents/Documents.ts
index 3b40f0cc7..560806078 100644
--- a/src/client/documents/Documents.ts
+++ b/src/client/documents/Documents.ts
@@ -1005,7 +1005,7 @@ export namespace DocUtils {
return Field.toString(d[facetKey] as Field).includes(value);
});
// if we're ORing them together, the default return is false, and we return true for a doc if it satisfies any one set of criteria
- if (((FilterBox._filterScope === "Current Collection" ? parentCollection || CurrentUserUtils.ActiveDashboard : CurrentUserUtils.ActiveDashboard).currentFilter as Doc)?.filterBoolean === "OR") {
+ if ((parentCollection?.currentFilter as Doc)?.filterBoolean === "OR") {
if (satisfiesCheckFacets && !failsNotEqualFacets && satisfiesMatchFacets) return true;
}
// if we're ANDing them together, the default return is true, and we return false for a doc if it doesn't satisfy any set of criteria
@@ -1014,7 +1014,7 @@ export namespace DocUtils {
}
}
- return ((FilterBox._filterScope === "Current Collection" ? parentCollection || CurrentUserUtils.ActiveDashboard : CurrentUserUtils.ActiveDashboard).currentFilter as Doc)?.filterBoolean === "OR" ? false : true;
+ return (parentCollection?.currentFilter as Doc)?.filterBoolean === "OR" ? false : true;
}) : childDocs;
const rangeFilteredDocs = filteredDocs.filter(d => {
for (let i = 0; i < docRangeFilters.length; i += 3) {
diff --git a/src/client/util/CurrentUserUtils.ts b/src/client/util/CurrentUserUtils.ts
index 4b0a49180..417a1f405 100644
--- a/src/client/util/CurrentUserUtils.ts
+++ b/src/client/util/CurrentUserUtils.ts
@@ -806,7 +806,7 @@ export class CurrentUserUtils {
// setup Filter item
if (doc.currentFilter === undefined) {
doc.currentFilter = Docs.Create.FilterDocument({
- title: "FilterDoc", _height: 150,
+ title: "unnamed filter", _height: 150,
treeViewHideTitle: true, _xMargin: 5, _yMargin: 5, _gridGap: 5, _forceActive: true, childDropAction: "none",
treeViewTruncateTitleWidth: 150, ignoreClick: true,
_lockedPosition: true, boxShadow: "0 0", childDontRegisterViews: true, targetDropAction: "same", system: true, _autoHeight: true, _fitWidth: true
diff --git a/src/client/views/PropertiesView.tsx b/src/client/views/PropertiesView.tsx
index 92fe3acb5..bb0ad4c66 100644
--- a/src/client/views/PropertiesView.tsx
+++ b/src/client/views/PropertiesView.tsx
@@ -30,7 +30,6 @@ import { PropertiesDocContextSelector } from "./PropertiesDocContextSelector";
import "./PropertiesView.scss";
import { DefaultStyleProvider } from "./StyleProvider";
import { CurrentUserUtils } from "../util/CurrentUserUtils";
-import { FilterBox } from "./nodes/FilterBox";
import { List } from "../../fields/List";
const higflyout = require("@hig/flyout");
export const { anchorPoints } = higflyout;
@@ -49,10 +48,7 @@ export class PropertiesView extends React.Component<PropertiesViewProps> {
@computed get MAX_EMBED_HEIGHT() { return 200; }
- @computed get selectedDoc() { return SelectionManager.SelectedSchemaDoc() || this.selectedDocumentView?.rootDoc; }
- @computed get filterDoc() {
- return FilterBox._filterScope === "Current Collection" ? this.selectedDoc! : CurrentUserUtils.ActiveDashboard;
- }
+ @computed get selectedDoc() { return SelectionManager.SelectedSchemaDoc() || this.selectedDocumentView?.rootDoc || CurrentUserUtils.ActiveDashboard; }
@computed get selectedDocumentView() {
if (SelectionManager.Views().length) return SelectionManager.Views()[0];
if (PresBox.Instance?._selectedArray.size) return DocumentManager.Instance.getDocumentView(PresBox.Instance.rootDoc);
@@ -909,47 +905,47 @@ export class PropertiesView extends React.Component<PropertiesViewProps> {
* If it doesn't exist, it creates it.
*/
checkFilterDoc() {
- if (this.filterDoc.type === DocumentType.COL && !this.filterDoc.currentFilter) CurrentUserUtils.setupFilterDocs(this.filterDoc);
+ if (this.selectedDoc.type === DocumentType.COL && !this.selectedDoc.currentFilter) CurrentUserUtils.setupFilterDocs(this.selectedDoc);
}
/**
* Creates a new currentFilter for this.filterDoc,
*/
createNewFilterDoc = () => {
- const currentDocFilters = this.filterDoc._docFilters;
- const currentDocRangeFilters = this.filterDoc._docRangeFilters;
- this.filterDoc._docFilters = new List<string>();
- this.filterDoc._docRangeFilters = new List<string>();
- (this.filterDoc.currentFilter as Doc)._docFiltersList = currentDocFilters;
- (this.filterDoc.currentFilter as Doc)._docRangeFiltersList = currentDocRangeFilters;
- this.filterDoc.currentFilter = undefined;
- CurrentUserUtils.setupFilterDocs(this.filterDoc);
+ const currentDocFilters = this.selectedDoc._docFilters;
+ const currentDocRangeFilters = this.selectedDoc._docRangeFilters;
+ this.selectedDoc._docFilters = new List<string>();
+ this.selectedDoc._docRangeFilters = new List<string>();
+ (this.selectedDoc.currentFilter as Doc)._docFiltersList = currentDocFilters;
+ (this.selectedDoc.currentFilter as Doc)._docRangeFiltersList = currentDocRangeFilters;
+ this.selectedDoc.currentFilter = undefined;
+ CurrentUserUtils.setupFilterDocs(this.selectedDoc);
}
/**
* Updates this.filterDoc's currentFilter and saves the docFilters on the currentFilter
*/
updateFilterDoc = (doc: Doc) => {
- if (doc === this.filterDoc.currentFilter) return; // causes problems if you try to reapply the same doc
+ if (doc === this.selectedDoc.currentFilter) return; // causes problems if you try to reapply the same doc
const savedDocFilters = doc._docFiltersList;
- const currentDocFilters = this.filterDoc._docFilters;
- this.filterDoc._docFilters = new List<string>();
- (this.filterDoc.currentFilter as Doc)._docFiltersList = currentDocFilters;
- this.filterDoc.currentFilter = doc;
+ const currentDocFilters = this.selectedDoc._docFilters;
+ this.selectedDoc._docFilters = new List<string>();
+ (this.selectedDoc.currentFilter as Doc)._docFiltersList = currentDocFilters;
+ this.selectedDoc.currentFilter = doc;
doc._docFiltersList = new List<string>();
- this.filterDoc._docFilters = savedDocFilters;
+ this.selectedDoc._docFilters = savedDocFilters;
const savedDocRangeFilters = doc._docRangeFiltersList;
- const currentDocRangeFilters = this.filterDoc._docRangeFilters;
- this.filterDoc._docRangeFilters = new List<string>();
- (this.filterDoc.currentFilter as Doc)._docRangeFiltersList = currentDocRangeFilters;
- this.filterDoc.currentFilter = doc;
+ const currentDocRangeFilters = this.selectedDoc._docRangeFilters;
+ this.selectedDoc._docRangeFilters = new List<string>();
+ (this.selectedDoc.currentFilter as Doc)._docRangeFiltersList = currentDocRangeFilters;
+ this.selectedDoc.currentFilter = doc;
doc._docRangeFiltersList = new List<string>();
- this.filterDoc._docRangeFilters = savedDocRangeFilters;
+ this.selectedDoc._docRangeFilters = savedDocRangeFilters;
}
@computed get filtersSubMenu() {
- return !(this.filterDoc?.currentFilter instanceof Doc) ? (null) : <div className="propertiesView-filters">
+ return !(this.selectedDoc?.currentFilter instanceof Doc) ? (null) : <div className="propertiesView-filters">
<div className="propertiesView-filters-title"
onPointerDown={action(() => this.openFilters = !this.openFilters)}
style={{ backgroundColor: this.openFilters ? "black" : "" }}>
@@ -960,9 +956,9 @@ export class PropertiesView extends React.Component<PropertiesViewProps> {
</div>
{
!this.openFilters ? (null) :
- <div className="propertiesView-filters-content" style={{ height: this.filterDoc.currentFilter[HeightSym]() + 15 }}>
+ <div className="propertiesView-filters-content" style={{ height: this.selectedDoc.currentFilter[HeightSym]() + 15 }}>
<DocumentView
- Document={this.filterDoc.currentFilter}
+ Document={this.selectedDoc.currentFilter}
DataDoc={undefined}
addDocument={undefined}
addDocTab={returnFalse}
@@ -971,9 +967,9 @@ export class PropertiesView extends React.Component<PropertiesViewProps> {
removeDocument={returnFalse}
ScreenToLocalTransform={this.getTransform}
PanelWidth={() => this.props.width}
- PanelHeight={this.filterDoc.currentFilter[HeightSym]}
+ PanelHeight={this.selectedDoc.currentFilter[HeightSym]}
renderDepth={0}
- scriptContext={this.filterDoc.currentFilter}
+ scriptContext={this.selectedDoc.currentFilter}
focus={emptyFunction}
styleProvider={DefaultStyleProvider}
isContentActive={returnTrue}
diff --git a/src/client/views/nodes/FilterBox.tsx b/src/client/views/nodes/FilterBox.tsx
index d7f51c57b..05bb69d61 100644
--- a/src/client/views/nodes/FilterBox.tsx
+++ b/src/client/views/nodes/FilterBox.tsx
@@ -27,7 +27,6 @@ import Select from "react-select";
import { UserOptions } from "../../util/GroupManager";
import { DocumentViewProps } from "./DocumentView";
import { DefaultStyleProvider, StyleProp } from "../StyleProvider";
-import { CollectionViewType } from "../collections/CollectionView";
import { CurrentUserUtils } from "../../util/CurrentUserUtils";
import { EditableView } from "../EditableView";
import { undoBatch } from "../../util/UndoManager";
@@ -45,7 +44,6 @@ export class FilterBox extends ViewBoxBaseComponent<FieldViewProps, FilterBoxDoc
}
public static LayoutString(fieldKey: string) { return FieldView.LayoutString(FilterBox, fieldKey); }
- @observable static _filterScope = "Current Dashboard";
public _filterSelected = false;
public _filterMatch = "matched";
@@ -82,10 +80,10 @@ export class FilterBox extends ViewBoxBaseComponent<FieldViewProps, FilterBoxDoc
* @returns the relevant doc according to the value of FilterBox._filterScope i.e. either the Current Dashboard or the Current Collection
*/
@computed static get targetDoc() {
- if (FilterBox._filterScope === "Current Collection") {
+ if (SelectionManager.Views().length) {
return SelectionManager.Views()[0]?.Document.type === DocumentType.COL ? SelectionManager.Views()[0].Document : SelectionManager.Views()[0]?.props.ContainingCollectionDoc!;
}
- else return CurrentUserUtils.ActiveDashboard;
+ return CurrentUserUtils.ActiveDashboard;
}
@observable _loaded = false;
@@ -97,16 +95,17 @@ export class FilterBox extends ViewBoxBaseComponent<FieldViewProps, FilterBoxDoc
runInAction(() => this._loaded = true);
}, { fireImmediately: true });
}
+ @observable _allDocs = [] as Doc[];
@computed get allDocs() {
// trace();
- const allDocs = new Set<Doc>();
const targetDoc = FilterBox.targetDoc;
if (this._loaded && targetDoc) {
+ const allDocs = new Set<Doc>();
const activeTabs = DocListCast(targetDoc.data);
SearchBox.foreachRecursiveDoc(activeTabs, (doc: Doc) => allDocs.add(doc));
- setTimeout(() => targetDoc.allDocuments = new List<Doc>(Array.from(allDocs)));
+ setTimeout(action(() => this._allDocs = Array.from(allDocs)));
}
- return allDocs;
+ return this._allDocs;
}
@computed get _allFacets() {
@@ -271,34 +270,6 @@ export class FilterBox extends ViewBoxBaseComponent<FieldViewProps, FilterBoxDoc
}
/**
- * Changes the value of the variable that determines whether the filters should apply to the dashboard or the collection.
- *
- * Saves the Dashboard's filters (on its currentFilter filterdoc) when it shifts to Current Collection so it doesn't get passed into this.props.docFIlters() in CollectionSubView (in the docFilters function).
- */
- @action
- changeScope = (e: any) => {
- if (FilterBox._filterScope === "Current Dashboard" && e.currentTarget.value === "Current Collection") {
- const currentDashboardDocFilters = CurrentUserUtils.ActiveDashboard._docFilters;
- CurrentUserUtils.ActiveDashboard._docFilters = new List<string>();
- (CurrentUserUtils.ActiveDashboard.currentFilter as Doc)._docFilterList = currentDashboardDocFilters;
-
- const currentDashboardDocRangeFilters = CurrentUserUtils.ActiveDashboard._docRangeFilters;
- CurrentUserUtils.ActiveDashboard._docRangeFilters = new List<string>();
- (CurrentUserUtils.ActiveDashboard.currentFilter as Doc)._docRangeFilterList = currentDashboardDocRangeFilters;
- }
- else if (FilterBox._filterScope === "Current Collection" && e.currentTarget.value === "Current Dashboard") {
- const savedDashboardDocFilters = (CurrentUserUtils.ActiveDashboard.currentFilter as Doc)._docFilterList;
- (CurrentUserUtils.ActiveDashboard.currentFilter as Doc)._docFilterList = undefined;
- CurrentUserUtils.ActiveDashboard._docFilters = savedDashboardDocFilters;
-
- const savedDashboardDocRangeFilters = (CurrentUserUtils.ActiveDashboard.currentFilter as Doc)._docRangeFilterList;
- (CurrentUserUtils.ActiveDashboard.currentFilter as Doc)._docRangeFilterList = undefined;
- CurrentUserUtils.ActiveDashboard._docRangeFilters = savedDashboardDocRangeFilters;
- }
- FilterBox._filterScope = e.currentTarget.value;
- }
-
- /**
* Changes whether to select matched or unmatched documents
*/
@action
@@ -415,14 +386,6 @@ export class FilterBox extends ViewBoxBaseComponent<FieldViewProps, FilterBoxDoc
<option value="OR" key="OR" selected={(FilterBox.targetDoc.currentFilter as Doc)?.filterBoolean === "OR"}>OR</option>
</select>
<div className="filterBox-select-text">filters in </div>
- <select className="filterBox-selection" onChange={this.changeScope}>
- <option value="Current Dashboard" key="Current Dashboard" selected={"Current Dashboard" === FilterBox._filterScope}>Current Dashboard</option>
- {/* <option value="Current Tab" key="Current Tab">Current Tab</option> */}
- {SelectionManager.Views()?.[0].Document.type === DocumentType.COL ?
- <option value="Current Collection" key="Current Collection" selected={"Current Collection" === FilterBox._filterScope}>Current Collection</option>
- : (null)}
-
- </select>
</div>
<div className="filterBox-select">
@@ -526,7 +489,9 @@ Scripting.addGlobal(function determineCheckedState(layoutDoc: Doc, facetHeader:
return undefined;
});
Scripting.addGlobal(function readFacetData(layoutDoc: Doc, facetHeader: string) {
- const allCollectionDocs = DocListCast(layoutDoc.allDocuments);
+ const allCollectionDocs = new Set<Doc>();
+ const activeTabs = DocListCast(layoutDoc.data);
+ SearchBox.foreachRecursiveDoc(activeTabs, (doc: Doc) => allCollectionDocs.add(doc));
const set = new Set<string>();
if (facetHeader === "tags") allCollectionDocs.forEach(child => Field.toString(child[facetHeader] as Field).split(":").forEach(key => set.add(key)));
else allCollectionDocs.forEach(child => set.add(Field.toString(child[facetHeader] as Field)));