From 9b83472e2d972b216feeb4ea2c32c96acf011f6a Mon Sep 17 00:00:00 2001 From: loi Date: Tue, 27 Feb 2024 16:05:51 -0800 Subject: [PATCH] TableOptionPanel: revert show/hide toggle to checkboxes --- .../js/tables/ui/TablePanelOptions.jsx | 67 ++++++++----------- src/firefly/js/ui/SimpleComponent.jsx | 14 ++++ src/firefly/js/ui/Stacker.jsx | 21 ++++-- 3 files changed, 56 insertions(+), 46 deletions(-) diff --git a/src/firefly/js/tables/ui/TablePanelOptions.jsx b/src/firefly/js/tables/ui/TablePanelOptions.jsx index 385da6a871..b8833128d8 100644 --- a/src/firefly/js/tables/ui/TablePanelOptions.jsx +++ b/src/firefly/js/tables/ui/TablePanelOptions.jsx @@ -2,9 +2,9 @@ * License information at https://github.com/Caltech-IPAC/firefly/blob/master/License.txt */ -import React, {useEffect} from 'react'; +import React, {useCallback, useEffect} from 'react'; import PropTypes from 'prop-types'; -import {Box, Button, Stack, ToggleButtonGroup, Typography} from '@mui/joy'; +import {Box, Button, Checkbox, Divider, Stack, Typography} from '@mui/joy'; import {badgeClasses} from '@mui/joy/Badge'; import {cloneDeep, get, isEmpty} from 'lodash'; @@ -82,22 +82,23 @@ export const TablePanelOptions = React.memo(({tbl_ui_id, tbl_id, onChange, onOpt }; const onSqlFilterChanged = ({op, sql}) => onChange({sqlFilter: sql ? `${op}::${sql}` : ''}); + const actions = useCallback(() => , [ctm_tbl_id]); return ( - + - }> - - - - {showAdvFilter && + + + + + + {showAdvFilter && -
- -
+
- } -
+ } +
+
{showTblPrefMsg && } }> @@ -133,7 +134,7 @@ function OptionsFilterStats({tbl_id}) { ); } -function Options({uiState, tbl_id, tbl_ui_id, ctm_tbl_id, onOptionReset, onChange}) { +function Options({uiState, onChange}) { const {pageSize, showPaging=true, showUnits, allowUnits=true, showTypes, allowTypes=true, showFilters} = uiState || {}; const onPageSize = (pageSize) => { @@ -141,33 +142,19 @@ function Options({uiState, tbl_id, tbl_ui_id, ctm_tbl_id, onOptionReset, onChang onChange && onChange({pageSize: pageSize.value}); } }; - const [value, setValue] = React.useState([ - showUnits && 'showUnits', - showTypes && 'showTypes', - showFilters && 'showFilters' - ].filter((v) => v)); + const handleChange =(ev) => { + const bname = ev.target?.value; + onChange({[bname]: ev.target.checked}); + }; return ( - + Show/Hide: - { - setValue(val); - const bname = ev.target?.value; - onChange({[bname]: val.includes(bname)}); - }} - > - {allowUnits && - - } - {allowUnits && - - } - - + + {allowUnits && <> } + {allowTypes && <> } + + {showPaging && pageSize !== MAX_ROW && + undefined} /> - + ); }); diff --git a/src/firefly/js/ui/SimpleComponent.jsx b/src/firefly/js/ui/SimpleComponent.jsx index f9e4d539cb..090773df90 100644 --- a/src/firefly/js/ui/SimpleComponent.jsx +++ b/src/firefly/js/ui/SimpleComponent.jsx @@ -240,3 +240,17 @@ export function useWatcher(actions, callback, params) { }; },[]); } + +export function useDebugCycle({id, render=true, mount=true}) { + + useEffect(() => { + mount && console.log(id, 'mounting'); + return () => { + mount && console.log(id, 'unmounting'); + }; + },[]); + + useEffect(() => { + render && console.log(id, 'rendering'); + }); +} diff --git a/src/firefly/js/ui/Stacker.jsx b/src/firefly/js/ui/Stacker.jsx index 03500deb43..5863b0ae3a 100644 --- a/src/firefly/js/ui/Stacker.jsx +++ b/src/firefly/js/ui/Stacker.jsx @@ -1,22 +1,31 @@ -import {Stack} from '@mui/joy'; +import {Sheet, Stack} from '@mui/joy'; import React from 'react'; -import {node, shape, object, number} from 'prop-types'; +import {node, shape, object, number, string} from 'prop-types'; - -export function Stacker({endDecorator, startDecorator, gap=1, slotProps, children, ...props}) { +/* + * A convenience component built around Sheet and Stack to provide a layout + * with support for variant and color. Use slopProps to customize + */ +export function Stacker({variant, color, endDecorator, startDecorator, gap=1, slotProps, children, ...props}) { return ( - + + {startDecorator} {children} {endDecorator} - + + ); } Stacker.propTypes = { + variant: string, + color: string, endDecorator: node, startDecorator: node, gap: number, // spacing between decorators and the main child