New: Ensure all unmapped folders are fetched when importing from a root folder

Closes #3751
This commit is contained in:
Mark McDowall 2020-06-13 12:15:58 -07:00
parent b642c3acfd
commit 11cdf13148
5 changed files with 37 additions and 23 deletions

View File

@ -102,24 +102,30 @@ class ImportSeries extends Component {
onScroll={this.onScroll} onScroll={this.onScroll}
> >
{ {
rootFoldersFetching && !rootFoldersPopulated && rootFoldersFetching ? <LoadingIndicator /> : null
<LoadingIndicator />
} }
{ {
!rootFoldersFetching && !!rootFoldersError && !rootFoldersFetching && !!rootFoldersError ?
<div>Unable to load root folders</div> <div>Unable to load root folders</div> :
null
} }
{ {
!rootFoldersError && rootFoldersPopulated && !unmappedFolders.length && !rootFoldersError &&
!rootFoldersFetching &&
!unmappedFolders.length ?
<div> <div>
All series in {path} have been imported All series in {path} have been imported
</div> </div> :
null
} }
{ {
!rootFoldersError && rootFoldersPopulated && !!unmappedFolders.length && scroller && !rootFoldersError &&
!rootFoldersFetching &&
!!unmappedFolders.length &&
scroller ?
<ImportSeriesTableConnector <ImportSeriesTableConnector
rootFolderId={rootFolderId} rootFolderId={rootFolderId}
unmappedFolders={unmappedFolders} unmappedFolders={unmappedFolders}
@ -131,18 +137,22 @@ class ImportSeries extends Component {
onSelectAllChange={this.onSelectAllChange} onSelectAllChange={this.onSelectAllChange}
onSelectedChange={this.onSelectedChange} onSelectedChange={this.onSelectedChange}
onRemoveSelectedStateItem={this.onRemoveSelectedStateItem} onRemoveSelectedStateItem={this.onRemoveSelectedStateItem}
/> /> :
null
} }
</PageContentBody> </PageContentBody>
{ {
!rootFoldersError && rootFoldersPopulated && !!unmappedFolders.length && !rootFoldersError &&
!rootFoldersFetching &&
!!unmappedFolders.length ?
<ImportSeriesFooterConnector <ImportSeriesFooterConnector
selectedIds={this.getSelectedIds()} selectedIds={this.getSelectedIds()}
showLanguageProfile={showLanguageProfile} showLanguageProfile={showLanguageProfile}
onInputChange={this.onInputChange} onInputChange={this.onInputChange}
onImportPress={this.onImportPress} onImportPress={this.onImportPress}
/> /> :
null
} }
</PageContent> </PageContent>
); );

View File

@ -76,6 +76,7 @@ class ImportSeriesConnector extends Component {
componentDidMount() { componentDidMount() {
const { const {
rootFolderId,
qualityProfiles, qualityProfiles,
languageProfiles, languageProfiles,
defaultQualityProfileId, defaultQualityProfileId,
@ -84,9 +85,7 @@ class ImportSeriesConnector extends Component {
dispatchSetAddSeriesDefault dispatchSetAddSeriesDefault
} = this.props; } = this.props;
if (!this.props.rootFoldersPopulated) { dispatchFetchRootFolders({ id: rootFolderId, timeout: false });
dispatchFetchRootFolders();
}
let setDefaults = false; let setDefaults = false;
const setDefaultPayload = {}; const setDefaultPayload = {};
@ -154,6 +153,8 @@ const routeMatchShape = createRouteMatchShape({
ImportSeriesConnector.propTypes = { ImportSeriesConnector.propTypes = {
match: routeMatchShape.isRequired, match: routeMatchShape.isRequired,
rootFolderId: PropTypes.number.isRequired,
rootFoldersFetching: PropTypes.bool.isRequired,
rootFoldersPopulated: PropTypes.bool.isRequired, rootFoldersPopulated: PropTypes.bool.isRequired,
qualityProfiles: PropTypes.arrayOf(PropTypes.object).isRequired, qualityProfiles: PropTypes.arrayOf(PropTypes.object).isRequired,
languageProfiles: PropTypes.arrayOf(PropTypes.object).isRequired, languageProfiles: PropTypes.arrayOf(PropTypes.object).isRequired,

View File

@ -43,7 +43,7 @@ namespace NzbDrone.Api.RootFolders
private RootFolderResource GetRootFolder(int id) private RootFolderResource GetRootFolder(int id)
{ {
return _rootFolderService.Get(id).ToResource(); return _rootFolderService.Get(id, true).ToResource();
} }
private int CreateRootFolder(RootFolderResource rootFolderResource) private int CreateRootFolder(RootFolderResource rootFolderResource)

View File

@ -2,7 +2,6 @@ using System.Linq;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using NLog; using NLog;
using NzbDrone.Common; using NzbDrone.Common;
@ -18,7 +17,7 @@ namespace NzbDrone.Core.RootFolders
List<RootFolder> AllWithUnmappedFolders(); List<RootFolder> AllWithUnmappedFolders();
RootFolder Add(RootFolder rootDir); RootFolder Add(RootFolder rootDir);
void Remove(int id); void Remove(int id);
RootFolder Get(int id); RootFolder Get(int id, bool timeout);
string GetBestRootFolderPath(string path); string GetBestRootFolderPath(string path);
} }
@ -71,7 +70,7 @@ namespace NzbDrone.Core.RootFolders
{ {
if (folder.Path.IsPathValid()) if (folder.Path.IsPathValid())
{ {
GetDetails(folder); GetDetails(folder, true);
} }
} }
//We don't want an exception to prevent the root folders from loading in the UI, so they can still be deleted //We don't want an exception to prevent the root folders from loading in the UI, so they can still be deleted
@ -111,7 +110,7 @@ namespace NzbDrone.Core.RootFolders
_rootFolderRepository.Insert(rootFolder); _rootFolderRepository.Insert(rootFolder);
GetDetails(rootFolder); GetDetails(rootFolder, true);
return rootFolder; return rootFolder;
} }
@ -155,10 +154,10 @@ namespace NzbDrone.Core.RootFolders
return results.OrderBy(u => u.Name, StringComparer.InvariantCultureIgnoreCase).ToList(); return results.OrderBy(u => u.Name, StringComparer.InvariantCultureIgnoreCase).ToList();
} }
public RootFolder Get(int id) public RootFolder Get(int id, bool timeout)
{ {
var rootFolder = _rootFolderRepository.Get(id); var rootFolder = _rootFolderRepository.Get(id);
GetDetails(rootFolder); GetDetails(rootFolder, timeout);
return rootFolder; return rootFolder;
} }
@ -177,7 +176,7 @@ namespace NzbDrone.Core.RootFolders
return possibleRootFolder.Path; return possibleRootFolder.Path;
} }
private void GetDetails(RootFolder rootFolder) private void GetDetails(RootFolder rootFolder, bool timeout)
{ {
Task.Run(() => Task.Run(() =>
{ {
@ -188,7 +187,7 @@ namespace NzbDrone.Core.RootFolders
rootFolder.TotalSpace = _diskProvider.GetTotalSize(rootFolder.Path); rootFolder.TotalSpace = _diskProvider.GetTotalSize(rootFolder.Path);
rootFolder.UnmappedFolders = GetUnmappedFolders(rootFolder.Path); rootFolder.UnmappedFolders = GetUnmappedFolders(rootFolder.Path);
} }
}).Wait(5000); }).Wait(timeout ? 5000 : -1);
} }
} }
} }

View File

@ -1,9 +1,11 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading;
using FluentValidation; using FluentValidation;
using NzbDrone.Core.RootFolders; using NzbDrone.Core.RootFolders;
using NzbDrone.Core.Validation.Paths; using NzbDrone.Core.Validation.Paths;
using NzbDrone.SignalR; using NzbDrone.SignalR;
using Sonarr.Http; using Sonarr.Http;
using Sonarr.Http.Extensions;
namespace Sonarr.Api.V3.RootFolders namespace Sonarr.Api.V3.RootFolders
{ {
@ -42,7 +44,9 @@ namespace Sonarr.Api.V3.RootFolders
private RootFolderResource GetRootFolder(int id) private RootFolderResource GetRootFolder(int id)
{ {
return _rootFolderService.Get(id).ToResource(); var timeout = Request.GetBooleanQueryParameter("timeout", true);
return _rootFolderService.Get(id, timeout).ToResource();
} }
private int CreateRootFolder(RootFolderResource rootFolderResource) private int CreateRootFolder(RootFolderResource rootFolderResource)