Renames in Frontend

This commit is contained in:
Qstick
2020-05-15 23:32:52 -04:00
committed by ta264
parent ee4e44b81a
commit ee43ccf620
387 changed files with 4036 additions and 4364 deletions
@@ -0,0 +1,45 @@
import PropTypes from 'prop-types';
import React from 'react';
import TableRow from 'Components/Table/TableRow';
import TableRowCell from 'Components/Table/Cells/TableRowCell';
import TableSelectCell from 'Components/Table/Cells/TableSelectCell';
import BookQuality from 'Book/BookQuality';
function BookFileEditorRow(props) {
const {
id,
path,
quality,
isSelected,
onSelectedChange
} = props;
return (
<TableRow>
<TableSelectCell
id={id}
isSelected={isSelected}
onSelectedChange={onSelectedChange}
/>
<TableRowCell>
{path}
</TableRowCell>
<TableRowCell>
<BookQuality
quality={quality}
/>
</TableRowCell>
</TableRow>
);
}
BookFileEditorRow.propTypes = {
id: PropTypes.number.isRequired,
path: PropTypes.string.isRequired,
quality: PropTypes.object.isRequired,
isSelected: PropTypes.bool,
onSelectedChange: PropTypes.func.isRequired
};
export default BookFileEditorRow;
@@ -0,0 +1,16 @@
import React from 'react';
import BookFileEditorTableContentConnector from './BookFileEditorTableContentConnector';
function BookFileEditorTable(props) {
const {
...otherProps
} = props;
return (
<BookFileEditorTableContentConnector
{...otherProps}
/>
);
}
export default BookFileEditorTable;
@@ -0,0 +1,8 @@
.actions {
display: flex;
margin-right: auto;
}
.selectInput {
margin-left: 10px;
}
@@ -0,0 +1,236 @@
import _ from 'lodash';
import PropTypes from 'prop-types';
import React, { Component } from 'react';
import hasDifferentItems from 'Utilities/Object/hasDifferentItems';
import getSelectedIds from 'Utilities/Table/getSelectedIds';
import removeOldSelectedState from 'Utilities/Table/removeOldSelectedState';
import selectAll from 'Utilities/Table/selectAll';
import toggleSelected from 'Utilities/Table/toggleSelected';
import { kinds } from 'Helpers/Props';
import ConfirmModal from 'Components/Modal/ConfirmModal';
import LoadingIndicator from 'Components/Loading/LoadingIndicator';
import SpinnerButton from 'Components/Link/SpinnerButton';
import SelectInput from 'Components/Form/SelectInput';
import Table from 'Components/Table/Table';
import TableBody from 'Components/Table/TableBody';
import BookFileEditorRow from './BookFileEditorRow';
import styles from './BookFileEditorTableContent.css';
const columns = [
{
name: 'path',
label: 'Path',
isVisible: true
},
{
name: 'quality',
label: 'Quality',
isVisible: true
}
];
class BookFileEditorTableContent extends Component {
//
// Lifecycle
constructor(props, context) {
super(props, context);
this.state = {
allSelected: false,
allUnselected: false,
lastToggled: null,
selectedState: {},
isConfirmDeleteModalOpen: false
};
}
componentDidUpdate(prevProps) {
if (hasDifferentItems(prevProps.items, this.props.items)) {
this.setState((state) => {
return removeOldSelectedState(state, prevProps.items);
});
}
}
//
// Control
getSelectedIds = () => {
const selectedIds = getSelectedIds(this.state.selectedState);
return selectedIds.reduce((acc, id) => {
const matchingItem = this.props.items.find((item) => item.id === id);
if (matchingItem && !acc.includes(matchingItem.bookFileId)) {
acc.push(matchingItem.bookFileId);
}
return acc;
}, []);
}
//
// Listeners
onSelectAllChange = ({ value }) => {
this.setState(selectAll(this.state.selectedState, value));
}
onSelectedChange = ({ id, value, shiftKey = false }) => {
this.setState((state) => {
return toggleSelected(state, this.props.items, id, value, shiftKey);
});
}
onDeletePress = () => {
this.setState({ isConfirmDeleteModalOpen: true });
}
onConfirmDelete = () => {
this.setState({ isConfirmDeleteModalOpen: false });
this.props.onDeletePress(this.getSelectedIds());
}
onConfirmDeleteModalClose = () => {
this.setState({ isConfirmDeleteModalOpen: false });
}
onQualityChange = ({ value }) => {
const selectedIds = this.getSelectedIds();
if (!selectedIds.length) {
return;
}
this.props.onQualityChange(selectedIds, parseInt(value));
}
//
// Render
render() {
const {
isDeleting,
isFetching,
isPopulated,
error,
items,
qualities
} = this.props;
const {
allSelected,
allUnselected,
selectedState,
isConfirmDeleteModalOpen
} = this.state;
const qualityOptions = _.reduceRight(qualities, (acc, quality) => {
acc.push({
key: quality.id,
value: quality.name
});
return acc;
}, [{ key: 'selectQuality', value: 'Select Quality', disabled: true }]);
const hasSelectedFiles = this.getSelectedIds().length > 0;
return (
<>
{
isFetching && !isPopulated ?
<LoadingIndicator /> :
null
}
{
!isFetching && error ?
<div>{error}</div> :
null
}
{
isPopulated && !items.length ?
<div>
No book files to manage.
</div> :
null
}
{
isPopulated && items.length ?
<Table
columns={columns}
selectAll={true}
allSelected={allSelected}
allUnselected={allUnselected}
onSelectAllChange={this.onSelectAllChange}
>
<TableBody>
{
items.map((item) => {
return (
<BookFileEditorRow
key={item.id}
isSelected={selectedState[item.id]}
{...item}
onSelectedChange={this.onSelectedChange}
/>
);
})
}
</TableBody>
</Table> :
null
}
<div className={styles.actions}>
<SpinnerButton
kind={kinds.DANGER}
isSpinning={isDeleting}
isDisabled={!hasSelectedFiles}
onPress={this.onDeletePress}
>
Delete
</SpinnerButton>
<div className={styles.selectInput}>
<SelectInput
name="quality"
value="selectQuality"
values={qualityOptions}
isDisabled={!hasSelectedFiles}
onChange={this.onQualityChange}
/>
</div>
</div>
<ConfirmModal
isOpen={isConfirmDeleteModalOpen}
kind={kinds.DANGER}
title="Delete Selected Book Files"
message={'Are you sure you want to delete the selected book files?'}
confirmLabel="Delete"
onConfirm={this.onConfirmDelete}
onCancel={this.onConfirmDeleteModalClose}
/>
</>
);
}
}
BookFileEditorTableContent.propTypes = {
isDeleting: PropTypes.bool.isRequired,
isFetching: PropTypes.bool.isRequired,
isPopulated: PropTypes.bool.isRequired,
error: PropTypes.object,
items: PropTypes.arrayOf(PropTypes.object).isRequired,
qualities: PropTypes.arrayOf(PropTypes.object).isRequired,
onDeletePress: PropTypes.func.isRequired,
onQualityChange: PropTypes.func.isRequired
};
export default BookFileEditorTableContent;
@@ -0,0 +1,125 @@
/* eslint max-params: 0 */
import _ from 'lodash';
import PropTypes from 'prop-types';
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { createSelector } from 'reselect';
import getQualities from 'Utilities/Quality/getQualities';
import createAuthorSelector from 'Store/Selectors/createAuthorSelector';
import { deleteBookFiles, updateBookFiles } from 'Store/Actions/bookFileActions';
import { fetchQualityProfileSchema } from 'Store/Actions/settingsActions';
import BookFileEditorTableContent from './BookFileEditorTableContent';
function createSchemaSelector() {
return createSelector(
(state) => state.settings.qualityProfiles,
(qualityProfiles) => {
const qualities = getQualities(qualityProfiles.schema.items);
let error = null;
if (qualityProfiles.schemaError) {
error = 'Unable to load qualities';
}
return {
isFetching: qualityProfiles.isSchemaFetching,
isPopulated: qualityProfiles.isSchemaPopulated,
error,
qualities
};
}
);
}
function createMapStateToProps() {
return createSelector(
(state, { bookId }) => bookId,
(state) => state.bookFiles,
createSchemaSelector(),
createAuthorSelector(),
(
bookId,
bookFiles,
schema,
author
) => {
return {
...schema,
items: bookFiles.items,
authorType: author.authorType,
isDeleting: bookFiles.isDeleting,
isSaving: bookFiles.isSaving
};
}
);
}
function createMapDispatchToProps(dispatch, props) {
return {
dispatchFetchQualityProfileSchema(name, path) {
dispatch(fetchQualityProfileSchema());
},
dispatchUpdateBookFiles(updateProps) {
dispatch(updateBookFiles(updateProps));
},
onDeletePress(bookFileIds) {
dispatch(deleteBookFiles({ bookFileIds }));
}
};
}
class BookFileEditorTableContentConnector extends Component {
//
// Lifecycle
componentDidMount() {
this.props.dispatchFetchQualityProfileSchema();
}
//
// Listeners
onQualityChange = (bookFileIds, qualityId) => {
const quality = {
quality: _.find(this.props.qualities, { id: qualityId }),
revision: {
version: 1,
real: 0
}
};
this.props.dispatchUpdateBookFiles({ bookFileIds, quality });
}
//
// Render
render() {
const {
dispatchFetchQualityProfileSchema,
dispatchUpdateBookFiles,
...otherProps
} = this.props;
return (
<BookFileEditorTableContent
{...otherProps}
onQualityChange={this.onQualityChange}
/>
);
}
}
BookFileEditorTableContentConnector.propTypes = {
authorId: PropTypes.number.isRequired,
bookId: PropTypes.number,
qualities: PropTypes.arrayOf(PropTypes.object).isRequired,
dispatchFetchQualityProfileSchema: PropTypes.func.isRequired,
dispatchUpdateBookFiles: PropTypes.func.isRequired
};
export default connect(createMapStateToProps, createMapDispatchToProps)(BookFileEditorTableContentConnector);