-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c289c46
commit bdab991
Showing
11 changed files
with
206 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import * as React from 'react' | ||
|
||
export interface CheckboxInputProps { | ||
label?: string | ||
name: string | ||
checked: boolean | ||
onChange: (name: string, checked: any) => void | ||
} | ||
|
||
const CheckboxInput: React.FunctionComponent<CheckboxInputProps> = ({ label, name, checked, onChange }) => { | ||
const labelColor = 'primary' | ||
return ( | ||
<> | ||
<div className='checkbox-input-container'> | ||
<input | ||
id={name} | ||
name={name} | ||
type='checkbox' | ||
className='checkbox-input' | ||
checked={checked} | ||
onChange={ () => { onChange(name, !checked) }} | ||
/> | ||
{label && <span className={labelColor}>{label}</span>} | ||
</div> | ||
</> | ||
) | ||
} | ||
|
||
export default CheckboxInput |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import * as React from 'react' | ||
|
||
import CheckboxInput from '../form/CheckboxInput' | ||
import Modal from './Modal' | ||
import { ApiAction } from '../../store/api' | ||
import Error from './Error' | ||
import Buttons from './Buttons' | ||
|
||
interface RemoveDatasetProps { | ||
peername: string | ||
name: string | ||
linkpath: string | ||
onDismissed: () => void | ||
onSubmit: (peername: string, name: string, dir: string) => Promise<ApiAction> | ||
} | ||
|
||
const RemoveDataset: React.FunctionComponent<RemoveDatasetProps> = ({ peername, name, onDismissed, onSubmit, linkpath }) => { | ||
const [shouldRemoveFiles, setShouldRemoveFiles] = React.useState(false) | ||
|
||
const [dismissable, setDismissable] = React.useState(true) | ||
|
||
const [error, setError] = React.useState('') | ||
const [loading, setLoading] = React.useState(false) | ||
|
||
const handleChanges = (name: string, value: any) => { | ||
setShouldRemoveFiles(value) | ||
} | ||
|
||
const handleSubmit = () => { | ||
setDismissable(false) | ||
setLoading(true) | ||
error && setError('') | ||
if (!onSubmit) return | ||
onSubmit(peername, name, linkpath) | ||
.then(onDismissed) | ||
.catch((action) => { | ||
setLoading(false) | ||
setDismissable(true) | ||
setError(action.payload.err.message) | ||
}) | ||
} | ||
|
||
return ( | ||
<Modal | ||
id='RemoveDataset' | ||
title={`Remove Dataset`} | ||
onDismissed={onDismissed} | ||
onSubmit={() => {}} | ||
dismissable={dismissable} | ||
setDismissable={setDismissable} | ||
> | ||
<div className='content-wrap'> | ||
<div className='content'> | ||
<p>Are you sure you want to remove the dataset "{peername}/{name}"?</p> | ||
{ linkpath.length > 0 && | ||
<CheckboxInput | ||
name='shouldRemoveFiles' | ||
checked={shouldRemoveFiles} | ||
onChange={handleChanges} | ||
label={'Also remove the dataset\'s files'} | ||
/> | ||
} | ||
</div> | ||
</div> | ||
<p className='submit-message'> | ||
{ linkpath.length > 0 && shouldRemoveFiles && `Qri will delete dataset files in "${linkpath}"`} | ||
</p> | ||
<Error text={error} /> | ||
<Buttons | ||
cancelText='cancel' | ||
onCancel={onDismissed} | ||
submitText='Remove' | ||
onSubmit={handleSubmit} | ||
disabled={false} | ||
loading={loading} | ||
/> | ||
</Modal> | ||
) | ||
} | ||
|
||
export default RemoveDataset |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,7 @@ | |
} | ||
|
||
.submit-message { | ||
min-height: 35px; | ||
font-size: .8rem; | ||
color: #777; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -99,3 +99,14 @@ | |
} | ||
} | ||
} | ||
|
||
.checkbox-input-container { | ||
display: flex; | ||
|
||
input { | ||
margin-right: 5px; | ||
} | ||
|
||
span { | ||
font-size: 0.8rem; | ||
} |