pgadmin4/web/pgadmin/static/js/components/SelectRefresh.jsx
Yogesh Mahajan 102e0a9839
- Update MUI v4 to v5
- Remove the SCSS dependency completely and use MUI for theming.
- Update - date-fns, @date-io, notistack. Remove - popper.js, sass-loader.
- Cleanup webpack config.
- Port PSQL tool to use MUI themes instead of SCSS theme.
- Theme change will reflect realtime without refreshing pgAdmin.
2024-04-09 08:21:14 +05:30

55 lines
1.8 KiB
JavaScript

import React, { useState } from 'react';
import { Box} from '@mui/material';
import {InputSelect, FormInput} from './FormComponents';
import PropTypes from 'prop-types';
import CustomPropTypes from '../custom_prop_types';
import RefreshIcon from '@mui/icons-material/Refresh';
import { PgIconButton } from './Buttons';
function ChildContent({cid, helpid, onRefreshClick, label, ...props}) {
return <Box display="flex" >
<Box flexGrow="1">
<InputSelect {...props} cid={cid} helpid={helpid} />
</Box>
<Box>
<PgIconButton onClick={onRefreshClick} icon={<RefreshIcon />} title={label||''}/>
</Box>
</Box>;
}
ChildContent.propTypes = {
cid: PropTypes.string,
helpid: PropTypes.string,
onRefreshClick: PropTypes.func,
label: PropTypes.string,
};
export function SelectRefresh({ required, className, label, helpMessage, testcid, controlProps, ...props }){
const [options, setOptions] = useState([]);
const [optionsReloadBasis, setOptionsReloadBasis] = useState(false);
const {getOptionsOnRefresh, ...selectControlProps} = controlProps;
const onRefreshClick = ()=>{
getOptionsOnRefresh?.()
.then((res)=>{
setOptions(res);
setOptionsReloadBasis((prevVal)=>!prevVal);
});
};
return (
<FormInput required={required} label={label} className={className} helpMessage={helpMessage} testcid={testcid}>
<ChildContent options={options} optionsReloadBasis={optionsReloadBasis}
onRefreshClick={onRefreshClick} controlProps={selectControlProps} label={label} {...props} />
</FormInput>
);
}
SelectRefresh.propTypes = {
required: PropTypes.bool,
label: PropTypes.string,
className: CustomPropTypes.className,
helpMessage: PropTypes.string,
testcid: PropTypes.string,
controlProps: PropTypes.object,
};