aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/FilterPanel.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/views/FilterPanel.tsx')
-rw-r--r--src/client/views/FilterPanel.tsx285
1 files changed, 244 insertions, 41 deletions
diff --git a/src/client/views/FilterPanel.tsx b/src/client/views/FilterPanel.tsx
index 332a89a96..e5f9fdb51 100644
--- a/src/client/views/FilterPanel.tsx
+++ b/src/client/views/FilterPanel.tsx
@@ -28,6 +28,19 @@ import { CurrentUserUtils } from '../util/CurrentUserUtils';
import { DocumentOptions } from '../documents/Documents';
import { DocUtils } from '../documents/DocUtils';
import { dropActionType } from '../util/DropActionTypes';
+import { Toggle } from 'browndash-components';
+import { SettingsManager } from '../util/SettingsManager';
+import { StrCast } from '../../fields/Types';
+import { ToggleType } from 'browndash-components';
+import { MultiToggle } from 'browndash-components';
+import { Type } from 'browndash-components';
+import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
+import { DocData } from '../../fields/DocSymbols';
+import { DocumentType } from '../documents/DocumentTypes';
+import { Tooltip } from '@mui/material';
+import { useLocalObservable } from 'mobx-react';
+import { useRef } from 'react';
+import { useEffect } from 'react';
interface filterProps {
@@ -228,11 +241,14 @@ export class FilterPanel extends ObservableReactComponent<filterProps> {
};
addHotkey() {
-
const buttons = DocCast(Doc.UserDoc().myContextMenuBtns);
- const filter = buttons['Filter']
- const filter2 = DocCast(filter)
- const but2 = Doc.UserDoc().myContextMenuBtns
+ const filter = DocCast(buttons.Filter);
+ const filter2 = DocCast(filter);
+ const but2 = Doc.UserDoc().myContextMenuBtns;
+
+ console.log(DocCast(filter).data);
+
+ //[idToDoc("0bec0963-95ac-4978-8606-8af4c7b9badd"),idToDoc("f740e910-bf83-4ee3-b13a-1e63c49dd254"),idToDoc("61db82b0-025a-4cb9-937b-97b1290e8f1a"),idToDoc("1046859f-34ac-4421-bc07-ee2f2cf812e2"),idToDoc("badaff47-3c3a-4b78-a7d6-f2cbc8e45ba0")]
// const newCol = Docs.Create.CarouselDocument(DocListCast(doc[Doc.LayoutFieldKey(doc)]), {
// _width: 250,
@@ -251,59 +267,135 @@ export class FilterPanel extends ObservableReactComponent<filterProps> {
// DocumentView.getDocumentView(DocCast(buttons['Card']))?.ComponentView?.addDocument?.(hm)
- const hi = CurrentUserUtils.contextMenuTools()
-
- const newKey: Button = { title: "Cloud", icon: "cloud", toolTip:"Click to toggle the cloud group's visibility", btnType: ButtonType.ToggleButton, expertMode: false, toolType:"cloud", funcs: {}, scripts: { onClick: '{ return handleTags(this.toolType, _readOnly_);}'}}
-
-
- const heyy = [...hi, newKey]
-
- Doc.UserDoc().myFilterHotKeyIcons = "palette"
- Doc.UserDoc().myFilterHotKeyTitles = "hi"
-
- CurrentUserUtils.setupContextMenuButtons(Doc.UserDoc());
-
-
-
- Doc.UserDoc().hi = Docs.Create.FontIconDocument(
- { title: '',
- icon: 'map-pin',
-
- backgroundColor: '#ACCEF7',
- layout_hideAllLinks: true,
- _width: 15,
- _height: 15,
- _xPadding: 0,
- }
- )
-
-
- // buttons['Filter']
+ // const hi = CurrentUserUtils.contextMenuTools()
+
+ const newKey: Button = {
+ title: 'Bob',
+ icon: 'cloud',
+ toolTip: "Click to toggle the cloud group's visibility",
+ btnType: ButtonType.ToggleButton,
+ expertMode: false,
+ toolType: 'cloud',
+ funcs: {},
+ scripts: { onClick: '{ return handleTags(this.toolType, _readOnly_);}' },
+ };
+
+ // const heyy = [...hi, newKey]
+
+ Doc.UserDoc().myFilterHotKeyTitles = new List<string>(['hi hi', 'supppp'])
+
+ Doc.UserDoc()['hi hi'] = 'heart'
+ Doc.UserDoc()['supppp'] = 'star'
+
+ // CurrentUserUtils.setupContextMenuButtons(Doc.UserDoc());
+
+ // Doc.UserDoc().hi = Docs.Create.FontIconDocument(
+ // { title: '',
+ // icon: 'map-pin',
+
+ // backgroundColor: '#ACCEF7',
+ // layout_hideAllLinks: true,
+ // _width: 15,
+ // _height: 15,
+ // _xPadding: 0,
+ // }
+ // )
+
+ // // buttons['Filter']
+
+ // const reqdCtxtOpts: DocumentOptions = {
+ // title: 'Filter',
+ // undoIgnoreFields: new List<string>(['width', 'linearView_IsOpen']),
+ // flexGap: 0,
+ // childDragAction: dropActionType.embed,
+ // childDontRegisterViews: true,
+ // linearView_IsOpen: true,
+ // ignoreClick: true,
+ // linearView_Expandable: false,
+ // _height: 35,
+ // };
+ const ctxtMenuBtn = CurrentUserUtils.setupContextMenuBtn(newKey, filter);
+ ctxtMenuBtn.isSystem = ctxtMenuBtn[DocData].isSystem = undefined;
+ Doc.AddDocToList(filter, 'data', ctxtMenuBtn);
+ // // // DocUtils.AssignOpts(buttons, reqdCtxtOpts, ctxtMenuBtns);
+
+ // DocUtils.AssignOpts(DocCast(buttons['Filter']), reqdCtxtOpts, [ctxtMenuBtns]);
+ // newCol && dv.ComponentView?.addDocument?.(newCol);
+ // console.log(but2 + "omgg")
+ // doc.cardSort_activeIcons = new List<string>(list.includes(icon) ? list.filter(d => d !== icon) : [...list, icon]);
- const reqdCtxtOpts:DocumentOptions = { title: "hi", undoIgnoreFields:new List<string>(['width', "linearView_IsOpen"]), flexGap: 0, childDragAction: dropActionType.embed, childDontRegisterViews: true, linearView_IsOpen: true, ignoreClick: true, linearView_Expandable: false, _height: 35 };
- const ctxtMenuBtns = CurrentUserUtils.setupContextMenuBtn(newKey, buttons);
- // DocUtils.AssignOpts(buttons, reqdCtxtOpts, ctxtMenuBtns);
+ // Doc.UserDoc().myContextMenuBtns = new List<Doc>([...buttons, newKey as Doc])
+ }
+ hotKeyButtons() {
+ const selected = DocumentView.SelectedDocs().lastElement();
- DocUtils.AssignOpts(DocCast(buttons['Filter']), reqdCtxtOpts, [ctxtMenuBtns]);
+ function isAttrFiltered(attr: string) {
+ if (selected && selected._childFilters != undefined && selected.type === DocumentType.COL) {
+ return StrListCast(selected._childFilters).some(filter => filter.includes(attr));
+ } else {
+ return false;
+ }
+ // return selected._childFilters ? StrListCast(selected._childFilters).some(filter => filter.includes(attr)) : false;
+ }
+ const hotKeys = StrListCast(Doc.UserDoc().myFilterHotKeyTitles);
- // newCol && dv.ComponentView?.addDocument?.(newCol);
+ console.log(hotKeys + 'hiihihi');
- // console.log(but2 + "omgg")
+ const hi = ['star', 'heart', 'bolt'];
+
- // doc.cardSort_activeIcons = new List<string>(list.includes(icon) ? list.filter(d => d !== icon) : [...list, icon]);
+ //selecting a button should make t so that the the icon on the top filter panel becomes said icon
+ const buttons = hotKeys.map((hotKey, i) => (
+ // <div key={i} className={`filterHotKey-button ${isAttrFiltered(hotKey) ? 'active' : ''} ` }
+
+ // onClick={undoable((e: React.MouseEvent) => {
+ // // if (e.target === e.currentTarget){
+ // isAttrFiltered(hotKey) ? Doc.setDocFilter(selected, hotKey, true, 'remove') : Doc.setDocFilter(selected, hotKey, true, 'match');
+ // // }
+ // }, hotKey)}
- // Doc.UserDoc().myContextMenuBtns = new List<Doc>([...buttons, newKey as Doc])
+ // // style = {{backgroundColor: `${isAttrFiltered(hotKey) ? '#878484' : SettingsManager.userBackgroundColor}`}}
+
+
+ // >
+ {/* <Toggle
+ toggleStatus={isAttrFiltered(hotKey)}
+ tooltip={'toggle filter'}
+ text={hotKey}
+ color={SettingsManager.userColor}
+ icon={<FontAwesomeIcon icon={Doc.UserDoc()[hotKey] as any}/>}
+ iconPlacement="left"
+ align="flex-start"
+ fillWidth
+ toggleType={ToggleType.BUTTON}
+ onClick={undoable(() => {
+ isAttrFiltered(hotKey) ? Doc.setDocFilter(selected, hotKey, true, 'remove') : Doc.setDocFilter(selected, hotKey, true, 'match');
+ }, hotKey)}
+ /> */}
+ <>
+
+ <Tooltip key={i} title={<div className="dash-tooltip">Click to customize this hotkey's icon</div>}>
+ <HotKeyIconButton hotKey = {hotKey} />
+
+ </Tooltip>
+
+ </>
+ ));
+
+ return buttons;
}
+ // @observable iconPanelMap: Map<string, number> = new Map();
+
render() {
return (
<div className="filterBox-treeView">
@@ -376,8 +468,9 @@ export class FilterPanel extends ObservableReactComponent<filterProps> {
<FieldsDropdown Document={this.Document} selectFunc={this.addHotkey} showPlaceholder placeholder="add a hotkey" addedFields={['acl_Guest', LinkedTo, 'Star', 'Heart', 'Bolt', 'Cloud']} />
</div>
</div>
-
</div>
+
+ <div>{this.hotKeyButtons()}</div>
</div>
);
}
@@ -486,3 +579,113 @@ export class FilterPanel extends ObservableReactComponent<filterProps> {
return undefined;
}
}
+
+
+
+interface HotKeyButtonProps {
+ hotKey: string;
+ selected?: Doc
+}
+
+const HotKeyIconButton: React.FC<HotKeyButtonProps> = observer(({ hotKey, selected}) => {
+ const state = useLocalObservable(() => ({
+ isActive: false,
+ toggleActive() {
+ this.isActive = !this.isActive;
+ },
+ deactivate() {
+ this.isActive = false;
+ }
+ }));
+
+ const panelRef = useRef<HTMLDivElement>(null);
+
+ const handleClick = () => {
+ state.toggleActive();
+
+ console.log(state.isActive + "hmmm")
+ };
+
+ const handleClickOutside = (event: MouseEvent) => {
+ if (panelRef.current && !panelRef.current.contains(event.target as Node)) {
+ state.deactivate();
+ }
+ };
+
+ useEffect(() => {
+ document.addEventListener('mousedown', handleClickOutside);
+ return () => {
+ document.removeEventListener('mousedown', handleClickOutside);
+ };
+ }, []);
+
+ const iconOpts = ['star', 'heart', 'bolt'];
+
+ const iconPanel = iconOpts.map((icon, i) => (
+ <button key={i} onClick={() => Doc.UserDoc()[hotKey] = icon}>
+ <FontAwesomeIcon icon={icon as any} />
+ </button>
+ ));
+
+ const hotKeys = StrListCast(Doc.UserDoc().myFilterHotKeyTitles)
+
+ return (
+ <>
+
+ <div className={`filterHotKey-button ${isAttrFiltered(hotKey) ? 'active' : ''} ` }
+
+ onClick={undoable((e: React.MouseEvent) => {
+
+ // if (e.target === e.currentTarget){
+ isAttrFiltered(hotKey) ? Doc.setDocFilter(selected, hotKey, true, 'remove') : Doc.setDocFilter(selected, hotKey, true, 'match');
+ // }
+ }, hotKey)}
+
+ // style = {{backgroundColor: `${isAttrFiltered(hotKey) ? '#878484' : SettingsManager.userBackgroundColor}`}}
+
+
+ >
+ <div className={`hotKey-icon-button ${state.isActive ? 'active' : ''}`} ref={panelRef}>
+ <Tooltip title={<div className="dash-tooltip">Click to customize this hotkey's icon</div>}>
+ <button
+ type="button"
+ onClick={(e: React.MouseEvent) => {
+ console.log('hiii')
+ e.stopPropagation();
+ handleClick();
+
+ }}
+
+ >
+ <FontAwesomeIcon icon={Doc.UserDoc()[hotKey] as any} size="2xl"/>
+ </button>
+ </Tooltip>
+ {state.isActive && (
+ <div className="icon-panel" >
+ {iconPanel}
+ </div>
+ )}
+
+
+ </div>
+
+ <p> {hotKey.toUpperCase()} </p>
+
+
+ <button onClick={(e: React.MouseEvent) => {
+ e.stopPropagation();
+ Doc.UserDoc().myFilterHotKeyTitles = new List<string>(hotKeys.filter(k => k !== hotKey));
+ }}>
+ <FontAwesomeIcon icon={'x' as any} />
+ </button>
+
+ </div>
+
+
+ </>
+
+
+ );
+});
+
+