diff --git a/mpwo_api/mpwo_api/activities/models.py b/mpwo_api/mpwo_api/activities/models.py index 4e9a0e4a..e12bebd3 100644 --- a/mpwo_api/mpwo_api/activities/models.py +++ b/mpwo_api/mpwo_api/activities/models.py @@ -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 } diff --git a/mpwo_client/src/components/Admin/generic/AdminDetail.jsx b/mpwo_client/src/components/Admin/generic/AdminDetail.jsx index 77cb9bd8..6950aa8a 100644 --- a/mpwo_client/src/components/Admin/generic/AdminDetail.jsx +++ b/mpwo_client/src/components/Admin/generic/AdminDetail.jsx @@ -45,8 +45,9 @@ class AdminDetail extends React.Component {
event.preventDefault()} > - { results.map(result => ( - Object.keys(result).map(key => ( + { Object.keys(results[0]) + .filter(key => key.charAt(0) !== '_') + .map(key => (
)) - ))} + } {isInEdition ? (
onDataDelete(event, target)} + title={results[0]._can_be_deleted + ? '' + : 'Can\'t be deleted, associated data exist'} value="Delete" /> 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 - { Object.keys(result).map(key => { + { Object.keys(result) + .filter(key => key.charAt(0) !== '_') + .map(key => { if (key === 'id') { return (