Add support for deprecated values in field select options

(cherry picked from commit d9786887f3fe30ef60ad9c50b3272bf60dfef309)
pull/1794/head v1.7.3.3764
Bogdan 1 year ago
parent 1697cee680
commit cea6aae9e1

@ -108,7 +108,7 @@ namespace Prowlarr.Http.ClientSchema
Placeholder = fieldAttribute.Placeholder
};
if (fieldAttribute.Type == FieldType.Select || fieldAttribute.Type == FieldType.TagSelect)
if (fieldAttribute.Type is FieldType.Select or FieldType.TagSelect)
{
if (fieldAttribute.SelectOptionsProviderAction.IsNotNullOrWhiteSpace())
{
@ -157,23 +157,26 @@ namespace Prowlarr.Http.ClientSchema
{
if (selectOptions.IsEnum)
{
var options = selectOptions.GetFields().Where(v => v.IsStatic).Select(v =>
{
var name = v.Name.Replace('_', ' ');
var value = Convert.ToInt32(v.GetRawConstantValue());
var attrib = v.GetCustomAttribute<FieldOptionAttribute>();
if (attrib != null)
var options = selectOptions
.GetFields()
.Where(v => v.IsStatic && !v.GetCustomAttributes(false).OfType<ObsoleteAttribute>().Any())
.Select(v =>
{
return new SelectOption
var name = v.Name.Replace('_', ' ');
var value = Convert.ToInt32(v.GetRawConstantValue());
var attrib = v.GetCustomAttribute<FieldOptionAttribute>();
if (attrib != null)
{
Value = value,
Name = attrib.Label ?? name,
Order = attrib.Order,
Hint = attrib.Hint ?? $"({value})"
};
}
else
{
return new SelectOption
{
Value = value,
Name = attrib.Label ?? name,
Order = attrib.Order,
Hint = attrib.Hint ?? $"({value})"
};
}
return new SelectOption
{
Value = value,
@ -181,8 +184,7 @@ namespace Prowlarr.Http.ClientSchema
Order = value,
Hint = $"({value})"
};
}
});
});
return options.OrderBy(o => o.Order).ToList();
}

Loading…
Cancel
Save