Skip to content

Commit

Permalink
Merge pull request #129 from ligangty/cache
Browse files Browse the repository at this point in the history
Add confirm dialog popup for cache delete page
  • Loading branch information
ligangty authored Dec 20, 2023
2 parents 799be72 + d8b5db3 commit 5d4a6b3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
18 changes: 15 additions & 3 deletions src/main/webui/src/app/components/content/addons/Cache.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import React, {useState} from 'react';
import {useForm} from 'react-hook-form';
import {ConfirmDialog} from '../common/PopupDialogs.jsx';

import {IndyRest} from '#utils/RestClient.js';

Expand All @@ -37,13 +38,21 @@ export default function Cache() {
const {
register,
handleSubmit,
trigger,
formState: {errors}
} = useForm();
const submit = e => {
e.preventDefault();
const [showConfirmBox, setShowConfirm] = useState(false);
const showConfirmLog = () =>{
trigger().then(valid => valid && setShowConfirm(true));
};
const cancelConfirmLog = ()=>{
setShowConfirm(false);
};
const submit = () => {
handleSubmit(data=>{
deleteCache(data.path);
})();
setShowConfirm(false);
};
return <form onSubmit={e => e.preventDefault()}>
<div className="control-panel">
Expand All @@ -57,7 +66,10 @@ export default function Cache() {
{errors.path?.type === "required" && <span className="alert">Metadata url is required</span>}
</div>
<div className="cp-row">
<button onClick={submit}>Delete</button>
<button onClick={showConfirmLog}>Delete</button>
<ConfirmDialog showBox={showConfirmBox}
title={`Do you really want to delete this file?`}
handleCancel={cancelConfirmLog} handleConfirm={submit} />
</div>
</div>
<div className="content-panel">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ ChangeLogDialog.propTypes={
changelog: PropTypes.object
};

const ConfirmDialog = ({showBox, handleConfirm, handleCancel}) => <Modal show={showBox} onHide={handleCancel}>
const ConfirmDialog = ({showBox, title, handleConfirm, handleCancel}) => <Modal show={showBox} onHide={handleCancel}>
<Modal.Header>
<Modal.Title><b>Are you sure to delete this repository?</b></Modal.Title>
<Modal.Title><b>{title}</b></Modal.Title>
</Modal.Header>
<Modal.Footer>
<Button variant="secondary" onClick={handleCancel}>
Expand All @@ -59,6 +59,7 @@ const ConfirmDialog = ({showBox, handleConfirm, handleCancel}) => <Modal show={s

ConfirmDialog.propTypes={
showBox: PropTypes.bool,
title: PropTypes.string.isRequired,
handleConfirm: PropTypes.func,
handleCancel: PropTypes.func
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ const StoreViewControlPanel = function({store}){
<button name="delete" onClick={showConfirmLog} className="del-button cp-button">
Delete
</button>
<ConfirmDialog showBox={showConfirmBox} handleCancel={cancelConfirmLog} handleConfirm={handleRemove} />
<ConfirmDialog showBox={showConfirmBox}
title="Are you sure to delete this repository?"
handleCancel={cancelConfirmLog} handleConfirm={handleRemove} />
</div>
</div>
);
Expand Down Expand Up @@ -175,7 +177,9 @@ const StoreEditControlPanel = ({mode, store, handleSubmit, validate, changelog})
<button name="delete" onClick={showConfirmLog} className="del-button cp-button">
Delete
</button>
<ConfirmDialog showBox={showConfirmBox} handleCancel={cancelConfirmLog} handleConfirm={handleRemove} />
<ConfirmDialog showBox={showConfirmBox}
title="Are you sure to delete this repository?"
handleCancel={cancelConfirmLog} handleConfirm={handleRemove} />
</React.Fragment>
}
<ChangeLogDialog showBox={showChangeBox} handleCancel={cancelCommitMsg} handleSave={handleSave} changelog={changelog} />
Expand Down

0 comments on commit 5d4a6b3

Please sign in to comment.