aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormehekj <mehek.jethani@gmail.com>2023-02-28 21:15:37 -0500
committermehekj <mehek.jethani@gmail.com>2023-02-28 21:15:37 -0500
commit4137fa5fedae84aa781f3ba22ddfb2410a0cad9a (patch)
tree100f24dd02103a486242fbdb45a412ded6a2ef33
parent027c89584d087ada9d45a46cb620b157ae29d0b9 (diff)
preserve sort when adding docs, break sort when rearranging
-rw-r--r--src/client/views/collections/collectionSchema/CollectionSchemaView.tsx45
-rw-r--r--src/client/views/collections/collectionSchema/SchemaRowBox.tsx6
2 files changed, 33 insertions, 18 deletions
diff --git a/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx b/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx
index a0e1ae8b2..1a26f1178 100644
--- a/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx
+++ b/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx
@@ -8,7 +8,7 @@ import { RichTextField } from '../../../../fields/RichTextField';
import { listSpec } from '../../../../fields/Schema';
import { BoolCast, Cast, DocCast, NumCast, StrCast } from '../../../../fields/Types';
import { ImageField } from '../../../../fields/URLField';
-import { emptyFunction, returnEmptyDoclist, returnEmptyFilter, returnEmptyString, returnFalse, returnTrue, setupMoveUpEvents, smoothScroll, Utils } from '../../../../Utils';
+import { emptyFunction, returnEmptyDoclist, returnEmptyFilter, returnEmptyString, returnFalse, returnTransparent, returnTrue, setupMoveUpEvents, smoothScroll, Utils } from '../../../../Utils';
import { Docs, DocUtils } from '../../../documents/Documents';
import { DragManager } from '../../../util/DragManager';
import { SelectionManager } from '../../../util/SelectionManager';
@@ -69,7 +69,7 @@ export class CollectionSchemaView extends CollectionSubView() {
}
@computed get previewWidth() {
- return NumCast(this.props.Document.schemaPreviewWidth);
+ return NumCast(this.layoutDoc.schemaPreviewWidth);
}
@computed get tableWidth() {
@@ -103,7 +103,7 @@ export class CollectionSchemaView extends CollectionSubView() {
}
@computed get sortField() {
- return StrCast(this.layoutDoc.sortField, 'creationDate');
+ return StrCast(this.layoutDoc.sortField);
}
@computed get sortDesc() {
@@ -149,10 +149,14 @@ export class CollectionSchemaView extends CollectionSubView() {
@undoBatch
@action
- setSort = (field: string, desc: boolean) => {
+ setSort = (field: string | undefined, desc: boolean = false) => {
this.layoutDoc.sortField = field;
this.layoutDoc.sortDesc = desc;
+ console.log(field, desc);
+
+ if (field === undefined) return;
+
this.childDocs.sort((docA, docB) => {
const aStr = Field.toString(docA[field] as Field);
const bStr = Field.toString(docB[field] as Field);
@@ -164,6 +168,12 @@ export class CollectionSchemaView extends CollectionSubView() {
});
};
+ addRow = (doc: Doc | Doc[]) => {
+ const result: boolean = this.addDocument(doc);
+ this.setSort(this.sortField, this.sortDesc);
+ return result;
+ };
+
@undoBatch
@action
changeColumnKey = (index: number, newKey: string, defaultVal?: any) => {
@@ -316,6 +326,9 @@ export class CollectionSchemaView extends CollectionSubView() {
if (this._selectedDocs.has(doc)) this._selectedDocs.delete(doc);
const rowDocView = DocumentManager.Instance.getDocumentView(doc);
if (rowDocView) SelectionManager.DeselectView(rowDocView);
+ if (this._selectedDocs.size === 0) {
+ this._lastSelectedRow = undefined;
+ }
};
@action
@@ -340,10 +353,8 @@ export class CollectionSchemaView extends CollectionSubView() {
this._lastSelectedRow = index;
} else if (ctrl) {
if (!this._selectedDocs.has(doc)) {
- console.log('add');
this.addDocToSelection(doc, true, index);
} else {
- console.log('remove');
this.removeDocFromSelection(doc);
}
} else {
@@ -370,6 +381,7 @@ export class CollectionSchemaView extends CollectionSubView() {
this.props.removeDocument?.(this._selectedDocSortedArray);
this.addDocument(this._selectedDocSortedArray);
this.addDocument(pushedDocs);
+ this.setSort(undefined);
return true;
}
return false;
@@ -383,10 +395,13 @@ export class CollectionSchemaView extends CollectionSubView() {
undoBatch(
action(docus => {
this._isDragging = false;
- docus.map((doc: Doc) => this.addDocument(doc));
+ docus.map((doc: Doc) => {
+ this.addDocument(doc);
+ });
})
)
);
+ this.setSort(undefined);
};
@action
@@ -422,7 +437,7 @@ export class CollectionSchemaView extends CollectionSubView() {
const maxWidth = 1000;
const movedWidth = this.props.ScreenToLocalTransform().transformDirection(nativeWidth.right - e.clientX, 0)[0];
const width = movedWidth < minWidth ? minWidth : movedWidth > maxWidth ? maxWidth : movedWidth;
- this.props.Document.schemaPreviewWidth = width;
+ this.layoutDoc.schemaPreviewWidth = width;
return false;
};
@@ -432,7 +447,7 @@ export class CollectionSchemaView extends CollectionSubView() {
const newDoc = Docs.Create.TextDocument(value, { title: value, _autoHeight: true });
FormattedTextBox.SelectOnLoad = newDoc[Id];
FormattedTextBox.SelectOnLoadChar = forceEmptyNote ? '' : ' ';
- return this.props.addDocument?.(newDoc) || false;
+ return this.addRow(newDoc) || false;
};
menuCallback = (x: number, y: number) => {
@@ -444,9 +459,9 @@ export class CollectionSchemaView extends CollectionSubView() {
DocUtils.addDocumentCreatorMenuItems(
doc => {
FormattedTextBox.SelectOnLoad = StrCast(doc[Id]);
- return this.addDocument(doc);
+ return this.addRow(doc);
},
- this.addDocument,
+ this.addRow,
x,
y,
true
@@ -463,7 +478,7 @@ export class CollectionSchemaView extends CollectionSubView() {
if (this.props.Document.isTemplateDoc) {
Doc.MakeMetadataFieldTemplate(created, this.props.Document);
}
- return this.props.addDocument?.(created);
+ return this.addRow(created);
}
},
icon: 'compress-arrows-alt',
@@ -482,7 +497,7 @@ export class CollectionSchemaView extends CollectionSubView() {
Doc.MakeMetadataFieldTemplate(created, container);
return Doc.AddDocToList(container, Doc.LayoutFieldKey(container), created);
}
- return this.props.addDocument?.(created) || false;
+ return this.addRow(created) || false;
}
},
icon: 'compress-arrows-alt',
@@ -497,7 +512,7 @@ export class CollectionSchemaView extends CollectionSubView() {
if (this.props.Document.isTemplateDoc) {
Doc.MakeMetadataFieldTemplate(created, this.props.Document);
}
- this.props.addDocument?.(created);
+ this.addRow(created);
}
});
ContextMenu.Instance.displayMenu(x, y, undefined, true);
@@ -621,7 +636,7 @@ export class CollectionSchemaView extends CollectionSubView() {
ContainingCollectionDoc={this.props.CollectionView?.props.Document}
ContainingCollectionView={this.props.CollectionView}
moveDocument={this.props.moveDocument}
- addDocument={this.props.addDocument}
+ addDocument={this.addRow}
removeDocument={this.props.removeDocument}
whenChildContentsActiveChanged={this.props.whenChildContentsActiveChanged}
addDocTab={this.props.addDocTab}
diff --git a/src/client/views/collections/collectionSchema/SchemaRowBox.tsx b/src/client/views/collections/collectionSchema/SchemaRowBox.tsx
index 0ed5f2df4..d6a00966d 100644
--- a/src/client/views/collections/collectionSchema/SchemaRowBox.tsx
+++ b/src/client/views/collections/collectionSchema/SchemaRowBox.tsx
@@ -113,7 +113,7 @@ export class SchemaRowBox extends ViewBoxBaseComponent<FieldViewProps>() {
className="schema-row-button"
onPointerDown={undoBatch(e => {
e.stopPropagation();
- this.props.removeDocument?.(this.props.Document);
+ this.props.removeDocument?.(this.rootDoc);
})}>
<FontAwesomeIcon icon="times" />
</div>
@@ -121,14 +121,14 @@ export class SchemaRowBox extends ViewBoxBaseComponent<FieldViewProps>() {
className="schema-row-button"
onPointerDown={e => {
e.stopPropagation();
- this.props.addDocTab(this.props.Document, OpenWhere.addRight);
+ this.props.addDocTab(this.rootDoc, OpenWhere.addRight);
}}>
<FontAwesomeIcon icon="external-link-alt" />
</div>
</div>
<div className="row-cells">
{this.schemaView?.columnKeys?.map((key, index) => (
- <SchemaTableCell key={key} Document={this.props.Document} fieldKey={key} columnWidth={this.schemaView?.displayColumnWidths[index] ?? CollectionSchemaView._minColWidth} />
+ <SchemaTableCell key={key} Document={this.rootDoc} fieldKey={key} columnWidth={this.schemaView?.displayColumnWidths[index] ?? CollectionSchemaView._minColWidth} />
))}
</div>
</div>