MCPcopy Create free account
hub / github.com/pgadmin-org/pgadmin4 / ResetButton

Function ResetButton

web/pgadmin/static/js/SchemaView/ResetButton.jsx:17–43  ·  view source on GitHub ↗
({label, icon, onClick})

Source from the content-addressed store, hash-verified

15
16
17export function ResetButton({label, icon, onClick}) {
18 const [key, setKey] = useState(0);
19 const schemaState = useContext(SchemaStateContext);
20 const checkDisabled = (state) => (state.isSaving || !state.isDirty);
21 const currState = schemaState.state();
22 const isDisabled = checkDisabled(currState);
23
24 useEffect(() => {
25 if (!schemaState) return;
26
27 const refreshOnDisableStateChanged = (newState) => {
28 if (isDisabled !== checkDisabled(newState)) setKey(Date.now());
29 };
30
31 return schemaState.subscribe([], refreshOnDisableStateChanged, 'states');
32 }, [key]);
33
34 return (
35 <DefaultButton
36 data-test='Reset' onClick={onClick}
37 startIcon={icon}
38 disabled={isDisabled}
39 className='Dialog-buttonMargin'>
40 { label }
41 </DefaultButton>
42 );
43}
44
45ResetButton.propTypes = {
46 label: PropTypes.string,

Callers

nothing calls this directly

Calls 3

subscribeMethod · 0.80
checkDisabledFunction · 0.70
stateMethod · 0.45

Tested by

no test coverage detected