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