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

Function SaveButton

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

Source from the content-addressed store, hash-verified

15
16
17export function SaveButton({
18 label, icon, checkDirtyOnEnableSave, onClick, mode,
19}) {
20 const [key, setKey] = useState(0);
21 const schemaState = useContext(SchemaStateContext);
22 const checkDisabled = (state) => {
23 const {isDirty, isSaving, errors} = state;
24 return (
25 isSaving ||
26 !(mode === 'edit' || checkDirtyOnEnableSave ? isDirty : true) ||
27 Boolean(errors.name)
28 );
29 };
30 const currState = schemaState.state();
31 const isDisabled = checkDisabled(currState);
32
33 useEffect(() => {
34 if (!schemaState) return;
35
36 const refreshOnDisableStateChanged = (newState) => {
37 if (isDisabled !== checkDisabled(newState)) setKey(Date.now());
38 };
39
40 return schemaState.subscribe([], refreshOnDisableStateChanged, 'states');
41 }, [key]);
42
43 return (
44 <PrimaryButton
45 data-test='Save' onClick={onClick} startIcon={icon}
46 disabled={isDisabled}
47 >
48 {label}
49 </PrimaryButton>
50 );
51}
52
53SaveButton.propTypes = {
54 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