diff options
author | Nathan-SR <144961007+Nathan-SR@users.noreply.github.com> | 2024-06-18 00:44:37 -0400 |
---|---|---|
committer | Nathan-SR <144961007+Nathan-SR@users.noreply.github.com> | 2024-06-18 00:44:37 -0400 |
commit | 3b838e251d4c626c30ef9fa507e68f6839b5cfd7 (patch) | |
tree | e67ad131825c5e4b51621c0738c3b36e9d1d1a13 | |
parent | 50021902948840e87da1faf74f6403e25e667580 (diff) |
work on sort
-rw-r--r-- | src/ClientUtils.ts | 2 | ||||
-rw-r--r-- | src/client/views/collections/collectionSchema/CollectionSchemaView.tsx | 56 |
2 files changed, 28 insertions, 30 deletions
diff --git a/src/ClientUtils.ts b/src/ClientUtils.ts index cd2b9b3a9..a72e3ffaa 100644 --- a/src/ClientUtils.ts +++ b/src/ClientUtils.ts @@ -352,6 +352,8 @@ export namespace ClientUtils { return undefined; } + + export function GetClipboardText(): string { const textArea = document.createElement('textarea'); document.body.appendChild(textArea); diff --git a/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx b/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx index c66623bda..b1284fe31 100644 --- a/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx +++ b/src/client/views/collections/collectionSchema/CollectionSchemaView.tsx @@ -846,8 +846,8 @@ export class CollectionSchemaView extends CollectionSubView() { 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: 'Sort A-Z', event: () => this._docs = this.sortDocs(this.columnKeys[index], false), icon: 'arrow-down-a-z',}); // prettier-ignore + sortOptions.push({description: 'Sort Z-A', event: () => this._docs = this.sortDocs(this.columnKeys[index], true), icon: 'arrow-up-z-a'}); // prettier-ignore sortOptions.push({ description: 'Persistent Sort A-Z', event: () => { @@ -1119,22 +1119,36 @@ export class CollectionSchemaView extends CollectionSubView() { return docs; } + + @action + sortDocs = (field: string, desc: boolean) => { + console.log('called') + const numbers: Doc[] = this.docs.filter(doc => !isNaN(Number(Field.toString(doc[field] as FieldType)))); + const strings = this.docs.filter(doc => !numbers.includes(doc)); + + const sortedNums = numbers.sort((numOne, numTwo) => { + const numA = Number(Field.toString(numOne[field] as FieldType)); + const numB = Number(Field.toString(numTwo[field] as FieldType)); + return desc? numA - numB : numB - numA; + }); + + const collator = new Intl.Collator(undefined, {sensitivity: 'base'}); + let sortedStrings; + if (!desc) {sortedStrings = strings.slice().sort((docA, docB) => collator.compare(Field.toString(docA[field] as FieldType), Field.toString(docB[field] as FieldType))); + } else sortedStrings = strings.slice().sort((docB, docA) => collator.compare(Field.toString(docA[field] as FieldType), Field.toString(docB[field] as FieldType))); + + const sortedDocs = desc ? sortedNums.concat(sortedStrings) : sortedStrings.concat(sortedNums); + return sortedDocs; + } @computed get docsWithDrag() { let docs = this._docs; + console.log('docrender called') if (this.sortField){ + console.log(true) 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; - }); + docs = this.sortDocs(field, desc); } else { const draggedDocs = this.isContentActive() ? DragManager.docsBeingDragged : []; docs = docs.filter(d => !draggedDocs.includes(d)); @@ -1144,24 +1158,6 @@ export class CollectionSchemaView extends CollectionSubView() { return { docs }; } - @action - sortDocs = (docs: Doc[], field: string, desc: boolean) => { - 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); isContentActive = () => this._props.isSelected() || this._props.isContentActive(); screenToLocal = () => this.ScreenToLocalBoxXf().translate(-this.tableWidth, 0); |