From 9e809f8748d1812bb03ec6471aa6f97467f8f75a Mon Sep 17 00:00:00 2001
From: bobzel <zzzman@gmail.com>
Date: Tue, 23 Apr 2024 16:20:08 -0400
Subject: fixes for rich text menu updates and setting parameters on text doc
 vs within in RTF. Lots of lint cleanup.

---
 src/client/views/collections/CollectionMenu.tsx | 73 ++++++++++++++++---------
 1 file changed, 46 insertions(+), 27 deletions(-)

(limited to 'src/client/views/collections/CollectionMenu.tsx')

diff --git a/src/client/views/collections/CollectionMenu.tsx b/src/client/views/collections/CollectionMenu.tsx
index 5a509128d..6dba9e155 100644
--- a/src/client/views/collections/CollectionMenu.tsx
+++ b/src/client/views/collections/CollectionMenu.tsx
@@ -1,3 +1,9 @@
+/* eslint-disable jsx-a11y/label-has-associated-control */
+/* eslint-disable jsx-a11y/no-static-element-interactions */
+/* eslint-disable jsx-a11y/click-events-have-key-events */
+/* eslint-disable jsx-a11y/control-has-associated-label */
+/* eslint-disable react/no-unused-class-component-methods */
+/* eslint-disable react/sort-comp */
 import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
 import { Tooltip } from '@mui/material';
 import { Toggle, ToggleType, Type } from 'browndash-components';
@@ -312,8 +318,6 @@ export class CollectionViewBaseChrome extends React.Component<CollectionViewMenu
     }
     private get _buttonizableCommands() {
         switch (this.props.type) {
-            default:
-                return this._doc_commands;
             case CollectionViewType.Freeform:
                 return this._freeform_commands;
             case CollectionViewType.Tree:
@@ -332,6 +336,8 @@ export class CollectionViewBaseChrome extends React.Component<CollectionViewMenu
                 return this._freeform_commands;
             case CollectionViewType.Carousel3D:
                 return this._freeform_commands;
+            default:
+                return this._doc_commands;
         }
     }
     private _commandRef = React.createRef<HTMLInputElement>();
@@ -345,11 +351,13 @@ export class CollectionViewBaseChrome extends React.Component<CollectionViewMenu
     @undoBatch
     viewChanged = (e: React.ChangeEvent) => {
         const target = this.document !== Doc.MyLeftSidebarPanel ? this.document : DocCast(this.document.proto);
-        target._type_collection = e.target.selectedOptions[0].value;
+        target._type_collection = (e.target as any).selectedOptions[0].value;
     };
 
     commandChanged = (e: React.ChangeEvent) => {
-        runInAction(() => (this._currentKey = e.target.selectedOptions[0].value));
+        runInAction(() => {
+            this._currentKey = (e.target as any).selectedOptions[0].value;
+        });
     };
 
     @action closeViewSpecs = () => {
@@ -367,7 +375,7 @@ export class CollectionViewBaseChrome extends React.Component<CollectionViewMenu
     @undoBatch
     @action
     protected drop(e: Event, de: DragManager.DropEvent): boolean {
-        const docDragData = de.complete.docDragData;
+        const { docDragData } = de.complete;
         if (docDragData?.draggedDocuments.length) {
             this._buttonizableCommands?.filter(c => c.title === this._currentKey).map(c => c.immediate(docDragData.draggedDocuments || []));
             e.stopPropagation();
@@ -420,11 +428,11 @@ export class CollectionViewBaseChrome extends React.Component<CollectionViewMenu
             <div className="collectionViewBaseChrome-template" ref={this.createDropTarget}>
                 <Tooltip title={<div className="dash-tooltip">drop document to apply or drag to create button</div>} placement="bottom">
                     <div className="commandEntry-outerDiv" ref={this._commandRef} onPointerDown={this.dragCommandDown}>
-                        <button className={'antimodeMenu-button'}>
+                        <button type="button" className="antimodeMenu-button">
                             <FontAwesomeIcon icon="bullseye" size="lg" />
                         </button>
                         <select className="collectionViewBaseChrome-cmdPicker" onPointerDown={stopPropagation} onChange={this.commandChanged} value={this._currentKey}>
-                            <option className="collectionViewBaseChrome-viewOption" onPointerDown={stopPropagation} key={'empty'} value={''} />
+                            <option className="collectionViewBaseChrome-viewOption" onPointerDown={stopPropagation} key="empty" value="" />
                             {this._buttonizableCommands?.map(cmd => (
                                 <option className="collectionViewBaseChrome-viewOption" onPointerDown={stopPropagation} key={cmd.title} value={cmd.title}>
                                     {cmd.title}
@@ -471,23 +479,19 @@ export class CollectionNoteTakingViewChrome extends React.Component<CollectionVi
             if (docs instanceof Doc) {
                 const keys = Object.keys(docs).filter(key => key.indexOf('title') >= 0 || key.indexOf('author') >= 0 || key.indexOf('author_date') >= 0 || key.indexOf('modificationDate') >= 0 || (key[0].toUpperCase() === key[0] && key[0] !== '_'));
                 return keys.filter(key => key.toLowerCase().indexOf(val) > -1);
-            } else {
-                const keys = new Set<string>();
-                docs.forEach(doc => Doc.allKeys(doc).forEach(key => keys.add(key)));
-                const noviceKeys = Array.from(keys).filter(
-                    key => key.indexOf('title') >= 0 || key.indexOf('author') >= 0 || key.indexOf('author_date') >= 0 || key.indexOf('modificationDate') >= 0 || (key[0]?.toUpperCase() === key[0] && key[0] !== '_')
-                );
-                return noviceKeys.filter(key => key.toLowerCase().indexOf(val) > -1);
             }
+            const keys = new Set<string>();
+            docs.forEach(doc => Doc.allKeys(doc).forEach(key => keys.add(key)));
+            const noviceKeys = Array.from(keys).filter(key => key.indexOf('title') >= 0 || key.indexOf('author') >= 0 || key.indexOf('author_date') >= 0 || key.indexOf('modificationDate') >= 0 || (key[0]?.toUpperCase() === key[0] && key[0] !== '_'));
+            return noviceKeys.filter(key => key.toLowerCase().indexOf(val) > -1);
         }
 
         if (docs instanceof Doc) {
             return Object.keys(docs).filter(key => key.toLowerCase().indexOf(val) > -1);
-        } 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().indexOf(val) > -1);
         }
+        const keys = new Set<string>();
+        docs.forEach(doc => Doc.allKeys(doc).forEach(key => keys.add(key)));
+        return Array.from(keys).filter(key => key.toLowerCase().indexOf(val) > -1);
     };
 
     @action
@@ -497,9 +501,7 @@ export class CollectionNoteTakingViewChrome extends React.Component<CollectionVi
 
     getSuggestionValue = (suggestion: string) => suggestion;
 
-    renderSuggestion = (suggestion: string) => {
-        return <p>{suggestion}</p>;
-    };
+    renderSuggestion = (suggestion: string) => <p>{suggestion}</p>;
 
     onSuggestionFetch = async ({ value }: { value: string }) => {
         const sugg = await this.getKeySuggestions(value);
@@ -587,12 +589,16 @@ export class CollectionGridViewChrome extends React.Component<CollectionViewMenu
     }
 
     componentDidMount() {
-        runInAction(() => (this.resize = this.props.docView.props.PanelWidth() < 700));
+        runInAction(() => {
+            this.resize = this.props.docView.props.PanelWidth() < 700;
+        });
 
         // listener to reduce text on chrome resize (panel resize)
         this.resizeListenerDisposer = reaction(
             () => this.panelWidth,
-            newValue => (this.resize = newValue < 700)
+            newValue => {
+                this.resize = newValue < 700;
+            }
         );
     }
 
@@ -608,7 +614,10 @@ export class CollectionGridViewChrome extends React.Component<CollectionViewMenu
      * Sets the value of `numCols` on the grid's Document to the value entered.
      */
     onNumColsChange = (e: React.ChangeEvent<HTMLInputElement>) => {
-        if (e.currentTarget.valueAsNumber > 0) undoBatch(() => (this.document.gridNumCols = e.currentTarget.valueAsNumber))();
+        if (e.currentTarget.valueAsNumber > 0)
+            undoBatch(() => {
+                this.document.gridNumCols = e.currentTarget.valueAsNumber;
+            })();
     };
 
     /**
@@ -637,7 +646,9 @@ export class CollectionGridViewChrome extends React.Component<CollectionViewMenu
     onIncrementButtonClick = () => {
         this.clicked = true;
         this.entered && (this.document.gridNumCols as number)--;
-        undoBatch(() => (this.document.gridNumCols = this.numCols + 1))();
+        undoBatch(() => {
+            this.document.gridNumCols = this.numCols + 1;
+        })();
         this.entered = false;
     };
 
@@ -648,7 +659,9 @@ export class CollectionGridViewChrome extends React.Component<CollectionViewMenu
         this.clicked = true;
         if (this.numCols > 1 && !this.decrementLimitReached) {
             this.entered && (this.document.gridNumCols as number)++;
-            undoBatch(() => (this.document.gridNumCols = this.numCols - 1))();
+            undoBatch(() => {
+                this.document.gridNumCols = this.numCols - 1;
+            })();
             if (this.numCols === 1) this.decrementLimitReached = true;
         }
         this.entered = false;
@@ -741,7 +754,13 @@ export class CollectionGridViewChrome extends React.Component<CollectionViewMenu
                     <label className="flexLabel">{this.resize ? 'Flex' : 'Flexible'}</label>
                 </span>
 
-                <button onClick={() => (this.document.gridResetLayout = true)}>{!this.resize ? 'Reset' : <FontAwesomeIcon icon="redo-alt" size="1x" />}</button>
+                <button
+                    type="button"
+                    onClick={() => {
+                        this.document.gridResetLayout = true;
+                    }}>
+                    {!this.resize ? 'Reset' : <FontAwesomeIcon icon="redo-alt" size="1x" />}
+                </button>
             </div>
         );
     }
-- 
cgit v1.2.3-70-g09d2

