Fixed: Add Delete Button to Custom Formats

pull/3843/head
Qstick 5 years ago
parent dd00c9b53e
commit fb4aa58a75

@ -118,7 +118,16 @@ class CustomFormat extends Component {
isOpen={this.state.isDeleteCustomFormatModalOpen}
kind={kinds.DANGER}
title="Delete Custom Format"
message={`Are you sure you want to delete the custom format '${name}'?`}
message={
<div>
<div>
Are you sure you want to delete custom format '{name}'?
</div>
<div>
This will remove all associations to this format in the DB. This may result in existing files being updated.
</div>
</div>
}
confirmLabel="Delete"
isSpinning={isDeleting}
onConfirm={this.onConfirmDeleteCustomFormat}

@ -0,0 +1,5 @@
.deleteButton {
composes: button from '~Components/Link/Button.css';
margin-right: auto;
}

@ -1,6 +1,6 @@
import PropTypes from 'prop-types';
import React, { Component } from 'react';
import { inputTypes } from 'Helpers/Props';
import { inputTypes, kinds } from 'Helpers/Props';
import Button from 'Components/Link/Button';
import SpinnerErrorButton from 'Components/Link/SpinnerErrorButton';
import LoadingIndicator from 'Components/Loading/LoadingIndicator';
@ -12,6 +12,7 @@ import Form from 'Components/Form/Form';
import FormGroup from 'Components/Form/FormGroup';
import FormLabel from 'Components/Form/FormLabel';
import FormInputGroup from 'Components/Form/FormInputGroup';
import styles from './EditCustomFormatModalContent.css';
class EditCustomFormatModalContent extends Component {
@ -28,6 +29,7 @@ class EditCustomFormatModalContent extends Component {
onInputChange,
onSavePress,
onModalClose,
onDeleteCustomFormatPress,
...otherProps
} = this.props;
@ -92,6 +94,17 @@ class EditCustomFormatModalContent extends Component {
</div>
</ModalBody>
<ModalFooter>
{
id &&
<Button
className={styles.deleteButton}
kind={kinds.DANGER}
onPress={onDeleteCustomFormatPress}
>
Delete
</Button>
}
<Button
onPress={onModalClose}
>
@ -120,7 +133,8 @@ EditCustomFormatModalContent.propTypes = {
onInputChange: PropTypes.func.isRequired,
onSavePress: PropTypes.func.isRequired,
onContentHeightChange: PropTypes.func.isRequired,
onModalClose: PropTypes.func.isRequired
onModalClose: PropTypes.func.isRequired,
onDeleteCustomFormatPress: PropTypes.func
};
export default EditCustomFormatModalContent;

@ -130,27 +130,14 @@ namespace NzbDrone.Core.CustomFormats
private void DeleteInRepo<TModel>(IBasicRepository<TModel> repository, Func<TModel, List<CustomFormat>> queryFunc,
Func<TModel, List<CustomFormat>, TModel> updateFunc, int customFormatId) where TModel : ModelBase, new()
{
var pagingSpec = new PagingSpec<TModel>
var allItems = repository.All();
var toUpdate = allItems.Where(r => queryFunc(r).Exists(c => c.Id == customFormatId)).Select(r =>
{
Page = 0,
PageSize = 2000
};
while (true)
{
var allItems = repository.GetPaged(pagingSpec);
var toUpdate = allItems.Records.Where(r => queryFunc(r).Exists(c => c.Id == customFormatId)).Select(r =>
{
return updateFunc(r, queryFunc(r).Where(c => c.Id != customFormatId).ToList());
});
repository.UpdateMany(toUpdate.ToList());
if (pagingSpec.Page * pagingSpec.PageSize >= allItems.TotalRecords)
{
break;
}
pagingSpec.Page += 1;
}
return updateFunc(r, queryFunc(r).Where(c => c.Id != customFormatId).ToList());
});
repository.UpdateMany(toUpdate.ToList());
}
private Dictionary<int, CustomFormat> AllDictionary()

Loading…
Cancel
Save