aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/views/collections/collectionSchema/CollectionSchemaView.tsx')
-rw-r--r--src/client/views/collections/collectionSchema/CollectionSchemaView.tsx69
1 files changed, 55 insertions, 14 deletions
diff --git a/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx b/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx
index d75f076d2..c66623bda 100644
--- a/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx
+++ b/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx
@@ -41,6 +41,7 @@ import { ContextMenuProps } from '../../ContextMenuItem';
import { truncate } from 'lodash';
import { DocumentManager } from '../../../util/DocumentManager';
import { TbHemispherePlus } from 'react-icons/tb';
+import { docs_v1 } from 'googleapis';
const { SCHEMA_NEW_NODE_HEIGHT } = require('../../global/globalCssVariables.module.scss'); // prettier-ignore
@@ -400,6 +401,7 @@ export class CollectionSchemaView extends CollectionSubView() {
@action
dragColumn = (e: PointerEvent, index: number) => {
+ this.closeColumnMenu();
this._draggedColIndex = index;
this._colBeingDragged = true;
const dragData = new DragManager.ColumnDragData(index);
@@ -584,6 +586,7 @@ export class CollectionSchemaView extends CollectionSubView() {
@action
selectCell = (doc: Doc, col: number, shiftKey: boolean, ctrlKey: boolean) => {
+ this.closeColumnMenu();
if (!shiftKey && !ctrlKey) this.clearSelection();
!this._selectedCells && (this._selectedCells = []);
!shiftKey && this._selectedCells.push(doc);
@@ -839,10 +842,28 @@ export class CollectionSchemaView extends CollectionSubView() {
const cm = ContextMenu.Instance;
cm.clearItems();
+ const fieldSortedAsc = (this.sortField === this.columnKeys[index] && !this.sortDesc);
+ const fieldSortedDesc = (this.sortField === this.columnKeys[index] && this.sortDesc);
const revealOptions = cm.findByDescription('Sort column')
const sortOptions: ContextMenuProps[] = revealOptions && revealOptions && 'subitems' in revealOptions ? revealOptions.subitems : [];
sortOptions.push({description: 'Sort A-Z', event: () => this.sortDocs(this._docs, this.columnKeys[index], false), icon: 'arrow-down-a-z',}); // prettier-ignore
sortOptions.push({description: 'Sort Z-A', event: () => this.sortDocs(this._docs, this.columnKeys[index], true), icon: 'arrow-up-z-a'}); // prettier-ignore
+ sortOptions.push({
+ description: 'Persistent Sort A-Z',
+ event: () => {
+ if (fieldSortedAsc){
+ this.setColumnSort(undefined)
+ } else this.setColumnSort(this.columnKeys[index], false)
+ },
+ icon: fieldSortedAsc ? 'lock' : 'lock-open'}); // prettier-ignore
+ sortOptions.push({
+ description: 'Persistent Sort Z-A',
+ event: () => {
+ if (fieldSortedDesc){
+ this.setColumnSort(undefined)
+ } else this.setColumnSort(this.columnKeys[index], true)
+ },
+ icon: fieldSortedDesc ? 'lock' : 'lock-open'}); // prettier-ignore
cm.addItem({
description: `Change field`,
@@ -1100,25 +1121,45 @@ export class CollectionSchemaView extends CollectionSubView() {
}
@computed get docsWithDrag() {
- const draggedDocs = this.isContentActive() ? DragManager.docsBeingDragged : [];
- let docs = [...this.docs];
- docs = docs.filter(d => !draggedDocs.includes(d));
- docs.splice(this.rowDropIndex, 0, ...draggedDocs);
+ let docs = this._docs;
+ if (this.sortField){
+ const field = StrCast(this.layoutDoc.sortField);
+ const desc = BoolCast(this.layoutDoc.sortDesc); // is this an ascending or descending sort
+ docs = this._docs.slice().sort((docA, docB) => {
+ // this sorts the documents based on the selected field. returning -1 for a before b, 0 for a = b, 1 for a > b
+ const aStr = Field.toString(docA[field] as FieldType);
+ const bStr = Field.toString(docB[field] as FieldType);
+ let out = 0;
+ if (aStr < bStr) out = -1;
+ if (aStr > bStr) out = 1;
+ if (desc) out *= -1;
+ return out;
+ });
+ } else {
+ const draggedDocs = this.isContentActive() ? DragManager.docsBeingDragged : [];
+ docs = docs.filter(d => !draggedDocs.includes(d));
+ docs.splice(this.rowDropIndex, 0, ...draggedDocs);
+ }
+
return { docs };
}
@action
sortDocs = (docs: Doc[], field: string, desc: boolean) => {
- this._docs = docs.sort((docA, docB) => {
- // this sorts the documents based on the selected field. returning -1 for a before b, 0 for a = b, 1 for a > b
- const aStr = Field.toString(docA[field] as FieldType);
- const bStr = Field.toString(docB[field] as FieldType);
- let out = 0;
- if (aStr < bStr) out = -1;
- if (aStr > bStr) out = 1;
- if (desc) out *= -1;
- return out;
- });
+ const collator = new Intl.Collator(undefined, {numeric: true, sensitivity: 'base'});
+ this._docs = this._docs.slice().sort((docA, docB) => collator.compare(Field.toString(docA[field] as FieldType), Field.toString(docB[field] as FieldType)));
+
+
+ // this._docs = docs.sort((docA, docB) => {
+ // // this sorts the documents based on the selected field. returning -1 for a before b, 0 for a = b, 1 for a > b
+ // const aStr = Field.toString(docA[field] as FieldType);
+ // const bStr = Field.toString(docB[field] as FieldType);
+ // let out = 0;
+ // if (aStr < bStr) out = -1;
+ // if (aStr > bStr) out = 1;
+ // if (desc) out *= -1;
+ // return out;
+ // });
}
rowHeightFunc = () => (BoolCast(this.layoutDoc._schema_singleLine) ? CollectionSchemaView._rowSingleLineHeight : CollectionSchemaView._rowHeight);