API & Client: can't delete a sport w/ activities
This commit is contained in:
parent
ff45b5982e
commit
608319386b
@ -20,7 +20,8 @@ class Sport(db.Model):
|
||||
def serialize(self):
|
||||
return {
|
||||
'id': self.id,
|
||||
'label': self.label
|
||||
'label': self.label,
|
||||
'_can_be_deleted': len(self.activities) == 0
|
||||
}
|
||||
|
||||
|
||||
|
@ -45,8 +45,9 @@ class AdminDetail extends React.Component {
|
||||
<form onSubmit={event =>
|
||||
event.preventDefault()}
|
||||
>
|
||||
{ results.map(result => (
|
||||
Object.keys(result).map(key => (
|
||||
{ Object.keys(results[0])
|
||||
.filter(key => key.charAt(0) !== '_')
|
||||
.map(key => (
|
||||
<div className="form-group" key={key}>
|
||||
<label>
|
||||
{key}:
|
||||
@ -54,12 +55,12 @@ class AdminDetail extends React.Component {
|
||||
className="form-control input-lg"
|
||||
name={key}
|
||||
readOnly={key === 'id' || !isInEdition}
|
||||
defaultValue={result[key]}
|
||||
defaultValue={results[0][key]}
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
))
|
||||
))}
|
||||
}
|
||||
{isInEdition ? (
|
||||
<div>
|
||||
<input
|
||||
@ -93,7 +94,11 @@ class AdminDetail extends React.Component {
|
||||
<input
|
||||
type="submit"
|
||||
className="btn btn-danger btn-lg btn-block"
|
||||
disabled={!results[0]._can_be_deleted}
|
||||
onClick={event => onDataDelete(event, target)}
|
||||
title={results[0]._can_be_deleted
|
||||
? ''
|
||||
: 'Can\'t be deleted, associated data exist'}
|
||||
value="Delete"
|
||||
/>
|
||||
<input
|
||||
|
@ -11,7 +11,9 @@ export default function AdminPage(props) {
|
||||
const results = data.data
|
||||
const tbKeys = []
|
||||
if (results.length > 0) {
|
||||
Object.keys(results[0]).map(key => tbKeys.push(key))
|
||||
Object.keys(results[0])
|
||||
.filter(key => key.charAt(0) !== '_')
|
||||
.map(key => tbKeys.push(key))
|
||||
}
|
||||
const title = target.charAt(0).toUpperCase() + target.slice(1)
|
||||
|
||||
@ -43,7 +45,9 @@ export default function AdminPage(props) {
|
||||
{ results.map((result, idx) => (
|
||||
// eslint-disable-next-line react/no-array-index-key
|
||||
<tr key={idx}>
|
||||
{ Object.keys(result).map(key => {
|
||||
{ Object.keys(result)
|
||||
.filter(key => key.charAt(0) !== '_')
|
||||
.map(key => {
|
||||
if (key === 'id') {
|
||||
return (
|
||||
<th key={key} scope="row">
|
||||
|
Loading…
Reference in New Issue
Block a user