Fix: (UI) Maintain search type and parameters on repeat search

pull/1747/head
Bogdan 2 years ago
parent 0de302ad48
commit b2b877a8c3

@ -76,7 +76,7 @@ function HistoryDetails(props) {
if (eventType === 'releaseGrabbed') { if (eventType === 'releaseGrabbed') {
const { const {
source, source,
title, grabTitle,
url url
} = data; } = data;
@ -101,8 +101,8 @@ function HistoryDetails(props) {
{ {
!!data && !!data &&
<DescriptionListItem <DescriptionListItem
title={translate('Title')} title={translate('GrabTitle')}
data={title ? title : '-'} data={grabTitle ? grabTitle : '-'}
/> />
} }

@ -8,10 +8,31 @@ import { icons } from 'Helpers/Props';
import CapabilitiesLabel from 'Indexer/Index/Table/CapabilitiesLabel'; import CapabilitiesLabel from 'Indexer/Index/Table/CapabilitiesLabel';
import translate from 'Utilities/String/translate'; import translate from 'Utilities/String/translate';
import HistoryDetailsModal from './Details/HistoryDetailsModal'; import HistoryDetailsModal from './Details/HistoryDetailsModal';
import * as historyDataTypes from './historyDataTypes';
import HistoryEventTypeCell from './HistoryEventTypeCell'; import HistoryEventTypeCell from './HistoryEventTypeCell';
import HistoryRowParameter from './HistoryRowParameter'; import HistoryRowParameter from './HistoryRowParameter';
import styles from './HistoryRow.css'; import styles from './HistoryRow.css';
const historyParameters = [
{ key: historyDataTypes.IMDB_ID, title: 'IMDb' },
{ key: historyDataTypes.TMDB_ID, title: 'TMDb' },
{ key: historyDataTypes.TVDB_ID, title: 'TVDb' },
{ key: historyDataTypes.TRAKT_ID, title: 'Trakt' },
{ key: historyDataTypes.R_ID, title: 'TvRage' },
{ key: historyDataTypes.TVMAZE_ID, title: 'TvMaze' },
{ key: historyDataTypes.SEASON, title: translate('Season') },
{ key: historyDataTypes.EPISODE, title: translate('Episode') },
{ key: historyDataTypes.ARTIST, title: translate('Artist') },
{ key: historyDataTypes.ALBUM, title: translate('Album') },
{ key: historyDataTypes.LABEL, title: translate('Label') },
{ key: historyDataTypes.TRACK, title: translate('Track') },
{ key: historyDataTypes.YEAR, title: translate('Year') },
{ key: historyDataTypes.GENRE, title: translate('Genre') },
{ key: historyDataTypes.AUTHOR, title: translate('Author') },
{ key: historyDataTypes.TITLE, title: translate('Title') },
{ key: historyDataTypes.PUBLISHER, title: translate('Publisher') }
];
class HistoryRow extends Component { class HistoryRow extends Component {
// //
@ -44,15 +65,52 @@ class HistoryRow extends Component {
data data
} = this.props; } = this.props;
const { query, queryType } = data;
let searchQuery = query;
let categories = []; let categories = [];
if (data.categories) { if (data.categories) {
categories = data.categories.split(',').map((item) => { categories = data.categories.split(',').map((item) => parseInt(item));
return parseInt(item); }
});
const searchParams = [
historyDataTypes.IMDB_ID,
historyDataTypes.TMDB_ID,
historyDataTypes.TVDB_ID,
historyDataTypes.TRAKT_ID,
historyDataTypes.R_ID,
historyDataTypes.TVMAZE_ID,
historyDataTypes.SEASON,
historyDataTypes.EPISODE,
historyDataTypes.ARTIST,
historyDataTypes.ALBUM,
historyDataTypes.LABEL,
historyDataTypes.TRACK,
historyDataTypes.YEAR,
historyDataTypes.GENRE,
historyDataTypes.AUTHOR,
historyDataTypes.TITLE,
historyDataTypes.PUBLISHER
]
.reduce((acc, key) => {
if (key in data && data[key].length > 0) {
const value = data[key];
acc.push({ key, value });
}
return acc;
}, [])
.map((item) => `{${item.key}:${item.value}}`)
.join('')
;
if (searchParams.length > 0) {
searchQuery += `${searchParams}`;
} }
this.props.onSearchPress(data.query, indexer.id, categories); this.props.onSearchPress(searchQuery, indexer.id, categories, queryType);
}; };
onDetailsPress = () => { onDetailsPress = () => {
@ -84,6 +142,8 @@ class HistoryRow extends Component {
return null; return null;
} }
const parameters = historyParameters.filter((parameter) => parameter.key in data && data[parameter.key]);
return ( return (
<TableRow> <TableRow>
{ {
@ -137,158 +197,16 @@ class HistoryRow extends Component {
key={name} key={name}
className={styles.parameters} className={styles.parameters}
> >
{ {parameters.map((parameter) => {
data.imdbId ? return (
<HistoryRowParameter
title='IMDb'
value={data.imdbId}
/> :
null
}
{
data.tmdbId ?
<HistoryRowParameter
title='TMDb'
value={data.tmdbId}
/> :
null
}
{
data.tvdbId ?
<HistoryRowParameter
title='TVDb'
value={data.tvdbId}
/> :
null
}
{
data.traktId ?
<HistoryRowParameter <HistoryRowParameter
title='Trakt' key={parameter.key}
value={data.traktId} title={parameter.title}
/> : value={data[parameter.key]}
null />
} );
{
data.rId ?
<HistoryRowParameter
title='TvRage'
value={data.rId}
/> :
null
}
{
data.tvMazeId ?
<HistoryRowParameter
title='TvMaze'
value={data.tvMazeId}
/> :
null
}
{
data.season ?
<HistoryRowParameter
title={translate('Season')}
value={data.season}
/> :
null
}
{
data.episode ?
<HistoryRowParameter
title={translate('Episode')}
value={data.episode}
/> :
null
}
{
data.artist ?
<HistoryRowParameter
title={translate('Artist')}
value={data.artist}
/> :
null
}
{
data.album ?
<HistoryRowParameter
title={translate('Album')}
value={data.album}
/> :
null
}
{
data.label ?
<HistoryRowParameter
title={translate('Label')}
value={data.label}
/> :
null
}
{
data.track ?
<HistoryRowParameter
title={translate('Track')}
value={data.track}
/> :
null
}
{
data.year ?
<HistoryRowParameter
title={translate('Year')}
value={data.year}
/> :
null
}
{
data.genre ?
<HistoryRowParameter
title={translate('Genre')}
value={data.genre}
/> :
null
}
{
data.author ?
<HistoryRowParameter
title={translate('Author')}
value={data.author}
/> :
null
}
{
data.bookTitle ?
<HistoryRowParameter
title={translate('Book')}
value={data.bookTitle}
/> :
null
}
{
data.publisher ?
<HistoryRowParameter
title={translate('Publisher')}
value={data.publisher}
/> :
null
} }
)}
</TableRowCell> </TableRowCell>
); );
} }
@ -300,8 +218,8 @@ class HistoryRow extends Component {
className={styles.indexer} className={styles.indexer}
> >
{ {
data.title ? data.grabTitle ?
data.title : data.grabTitle :
null null
} }
</TableRowCell> </TableRowCell>

@ -48,8 +48,8 @@ class HistoryRowConnector extends Component {
// //
// Listeners // Listeners
onSearchPress = (term, indexerId, categories) => { onSearchPress = (term, indexerId, categories, type) => {
this.props.setSearchDefault({ searchQuery: term, searchIndexerIds: [indexerId], searchCategories: categories }); this.props.setSearchDefault({ searchQuery: term, searchIndexerIds: [indexerId], searchCategories: categories, searchType: type });
this.props.push(`${window.Prowlarr.urlBase}/search`); this.props.push(`${window.Prowlarr.urlBase}/search`);
}; };

@ -0,0 +1,17 @@
export const IMDB_ID = 'imdbId';
export const TMDB_ID = 'tmdbId';
export const TVDB_ID = 'tvdbId';
export const TRAKT_ID = 'traktId';
export const R_ID = 'rId';
export const TVMAZE_ID = 'tvMazeId';
export const SEASON = 'season';
export const EPISODE = 'episode';
export const ARTIST = 'artist';
export const ALBUM = 'album';
export const LABEL = 'label';
export const TRACK = 'track';
export const YEAR = 'year';
export const GENRE = 'genre';
export const AUTHOR = 'author';
export const TITLE = 'title';
export const PUBLISHER = 'publisher';

@ -0,0 +1,91 @@
using System;
using System.Collections.Generic;
using System.Linq;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Common.Serializer;
using NzbDrone.Core.Datastore.Migration;
using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test.Datastore.Migration
{
[TestFixture]
public class history_fix_data_titlesFixture : MigrationTest<history_fix_data_titles>
{
[Test]
public void should_update_data_for_book_search()
{
var db = WithMigrationTestDb(c =>
{
c.Insert.IntoTable("History").Row(new
{
IndexerId = 1,
Date = DateTime.UtcNow,
Data = new
{
Author = "Fake Author",
BookTitle = "Fake Book Title",
Publisher = "",
Year = "",
Genre = "",
Query = "",
QueryType = "book",
Source = "Prowlarr",
Host = "localhost"
}.ToJson(),
EventType = 2,
Successful = true
});
});
var items = db.Query<HistoryDefinition34>("SELECT * FROM \"History\"");
items.Should().HaveCount(1);
items.First().Data.Should().NotContainKey("bookTitle");
items.First().Data.Should().ContainKey("title");
items.First().Data.GetValueOrDefault("title").Should().Be("Fake Book Title");
}
[Test]
public void should_update_data_for_release_grabbed()
{
var db = WithMigrationTestDb(c =>
{
c.Insert.IntoTable("History").Row(new
{
IndexerId = 1,
Date = DateTime.UtcNow,
Data = new
{
GrabMethod = "Proxy",
Title = "Fake Release Title",
Source = "Prowlarr",
Host = "localhost"
}.ToJson(),
EventType = 1,
Successful = true
});
});
var items = db.Query<HistoryDefinition34>("SELECT * FROM \"History\"");
items.Should().HaveCount(1);
items.First().Data.Should().NotContainKey("title");
items.First().Data.Should().ContainKey("grabTitle");
items.First().Data.GetValueOrDefault("grabTitle").Should().Be("Fake Release Title");
}
}
public class HistoryDefinition34
{
public int Id { get; set; }
public int IndexerId { get; set; }
public DateTime Date { get; set; }
public Dictionary<string, string> Data { get; set; }
public int EventType { get; set; }
public string DownloadId { get; set; }
public bool Successful { get; set; }
}
}

@ -0,0 +1,66 @@
using System.Collections.Generic;
using System.Data;
using Dapper;
using FluentMigrator;
using Newtonsoft.Json.Linq;
using NzbDrone.Common.Serializer;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(034)]
public class history_fix_data_titles : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Execute.WithConnection(MigrateHistoryDataTitle);
}
private void MigrateHistoryDataTitle(IDbConnection conn, IDbTransaction tran)
{
var updatedHistory = new List<object>();
using (var selectCommand = conn.CreateCommand())
{
selectCommand.Transaction = tran;
selectCommand.CommandText = "SELECT \"Id\", \"Data\" FROM \"History\"";
using var reader = selectCommand.ExecuteReader();
while (reader.Read())
{
var id = reader.GetInt32(0);
var data = reader.GetString(1);
if (!string.IsNullOrWhiteSpace(data))
{
var jsonObject = Json.Deserialize<JObject>(data);
if (jsonObject.ContainsKey("title"))
{
jsonObject.Add("grabTitle", jsonObject.Value<string>("title"));
jsonObject.Remove("title");
}
if (jsonObject.ContainsKey("bookTitle"))
{
jsonObject.Add("title", jsonObject.Value<string>("bookTitle"));
jsonObject.Remove("bookTitle");
}
data = jsonObject.ToJson();
updatedHistory.Add(new
{
Id = id,
Data = data
});
}
}
}
var updateHistorySql = "UPDATE \"History\" SET \"Data\" = @Data WHERE \"Id\" = @Id";
conn.Execute(updateHistorySql, updatedHistory, transaction: tran);
}
}
}

@ -164,7 +164,7 @@ namespace NzbDrone.Core.History
if (message.Query is BookSearchCriteria bookSearchCriteria) if (message.Query is BookSearchCriteria bookSearchCriteria)
{ {
history.Data.Add("Author", bookSearchCriteria.Author); history.Data.Add("Author", bookSearchCriteria.Author);
history.Data.Add("BookTitle", bookSearchCriteria.Title); history.Data.Add("Title", bookSearchCriteria.Title);
history.Data.Add("Publisher", bookSearchCriteria.Publisher); history.Data.Add("Publisher", bookSearchCriteria.Publisher);
history.Data.Add("Year", bookSearchCriteria.Year?.ToString()); history.Data.Add("Year", bookSearchCriteria.Year?.ToString());
history.Data.Add("Genre", bookSearchCriteria.Genre); history.Data.Add("Genre", bookSearchCriteria.Genre);
@ -199,7 +199,7 @@ namespace NzbDrone.Core.History
history.Data.Add("Source", message.Source ?? string.Empty); history.Data.Add("Source", message.Source ?? string.Empty);
history.Data.Add("Host", message.Host ?? string.Empty); history.Data.Add("Host", message.Host ?? string.Empty);
history.Data.Add("GrabMethod", message.Redirect ? "Redirect" : "Proxy"); history.Data.Add("GrabMethod", message.Redirect ? "Redirect" : "Proxy");
history.Data.Add("Title", message.Title); history.Data.Add("GrabTitle", message.Title);
history.Data.Add("Url", message.Url ?? string.Empty); history.Data.Add("Url", message.Url ?? string.Empty);
_historyRepository.Insert(history); _historyRepository.Insert(history);

Loading…
Cancel
Save