display parent category name in category selects (fixes #1045)

This commit is contained in:
Athou
2023-03-07 08:40:02 +01:00
parent 10bfbbec17
commit 5003c176a2
33 changed files with 132 additions and 15 deletions

View File

@@ -38,6 +38,7 @@ export interface ApplicationSettings {
export interface Category {
id: string
parentId?: string
parentName?: string
name: string
children: Category[]
feeds: Subscription[]

View File

@@ -4,16 +4,20 @@ import { Constants } from "app/constants"
import { useAppSelector } from "app/store"
import { flattenCategoryTree } from "app/utils"
type CategorySelectProps = Partial<SelectProps> & { withAll?: boolean }
type CategorySelectProps = Partial<SelectProps> & {
withAll?: boolean
withoutCategoryIds?: string[]
}
export function CategorySelect(props: CategorySelectProps) {
const rootCategory = useAppSelector(state => state.tree.rootCategory)
const categories = rootCategory && flattenCategoryTree(rootCategory)
const selectData: SelectItem[] | undefined = categories
?.filter(c => c.id !== Constants.categories.all.id)
.filter(c => !props.withoutCategoryIds || !props.withoutCategoryIds.includes(c.id))
.sort((c1, c2) => c1.name.localeCompare(c2.name))
.map(c => ({
label: c.name,
label: c.parentName ? t`${c.name} (in ${c.parentName})` : c.name,
value: c.id,
}))
if (props.withAll) {

View File

@@ -795,3 +795,7 @@ msgstr ""
#: src/components/content/add/ImportOpml.tsx
msgid "file is required"
msgstr "الملف مطلوب"
#: src/components/content/add/CategorySelect.tsx
msgid "{0} (in {1})"
msgstr ""

View File

@@ -795,3 +795,7 @@ msgstr ""
#: src/components/content/add/ImportOpml.tsx
msgid "file is required"
msgstr "el fitxer és necessari"
#: src/components/content/add/CategorySelect.tsx
msgid "{0} (in {1})"
msgstr ""

View File

@@ -795,3 +795,7 @@ msgstr ""
#: src/components/content/add/ImportOpml.tsx
msgid "file is required"
msgstr ""
#: src/components/content/add/CategorySelect.tsx
msgid "{0} (in {1})"
msgstr ""

View File

@@ -795,3 +795,7 @@ msgstr ""
#: src/components/content/add/ImportOpml.tsx
msgid "file is required"
msgstr "mae angen y ffeil"
#: src/components/content/add/CategorySelect.tsx
msgid "{0} (in {1})"
msgstr ""

View File

@@ -795,3 +795,7 @@ msgstr ""
#: src/components/content/add/ImportOpml.tsx
msgid "file is required"
msgstr "fil er påkrævet"
#: src/components/content/add/CategorySelect.tsx
msgid "{0} (in {1})"
msgstr ""

View File

@@ -795,3 +795,7 @@ msgstr ""
#: src/components/content/add/ImportOpml.tsx
msgid "file is required"
msgstr "Datei ist erforderlich"
#: src/components/content/add/CategorySelect.tsx
msgid "{0} (in {1})"
msgstr ""

View File

@@ -795,3 +795,7 @@ msgstr "Your feeds have been queued for refresh."
#: src/components/content/add/ImportOpml.tsx
msgid "file is required"
msgstr "file is required"
#: src/components/content/add/CategorySelect.tsx
msgid "{0} (in {1})"
msgstr "{0} (in {1})"

View File

@@ -795,3 +795,7 @@ msgstr ""
#: src/components/content/add/ImportOpml.tsx
msgid "file is required"
msgstr "archivo requerido"
#: src/components/content/add/CategorySelect.tsx
msgid "{0} (in {1})"
msgstr ""

View File

@@ -795,3 +795,7 @@ msgstr ""
#: src/components/content/add/ImportOpml.tsx
msgid "file is required"
msgstr "فایل مورد نیاز است"
#: src/components/content/add/CategorySelect.tsx
msgid "{0} (in {1})"
msgstr ""

View File

@@ -795,3 +795,7 @@ msgstr ""
#: src/components/content/add/ImportOpml.tsx
msgid "file is required"
msgstr "tiedosto vaaditaan"
#: src/components/content/add/CategorySelect.tsx
msgid "{0} (in {1})"
msgstr ""

View File

@@ -795,3 +795,7 @@ msgstr ""
#: src/components/content/add/ImportOpml.tsx
msgid "file is required"
msgstr "fichier requis"
#: src/components/content/add/CategorySelect.tsx
msgid "{0} (in {1})"
msgstr ""

View File

@@ -795,3 +795,7 @@ msgstr ""
#: src/components/content/add/ImportOpml.tsx
msgid "file is required"
msgstr "é necesario o ficheiro"
#: src/components/content/add/CategorySelect.tsx
msgid "{0} (in {1})"
msgstr ""

View File

@@ -795,3 +795,7 @@ msgstr ""
#: src/components/content/add/ImportOpml.tsx
msgid "file is required"
msgstr "fájl szükséges"
#: src/components/content/add/CategorySelect.tsx
msgid "{0} (in {1})"
msgstr ""

View File

@@ -795,3 +795,7 @@ msgstr ""
#: src/components/content/add/ImportOpml.tsx
msgid "file is required"
msgstr "file diperlukan"
#: src/components/content/add/CategorySelect.tsx
msgid "{0} (in {1})"
msgstr ""

View File

@@ -795,3 +795,7 @@ msgstr ""
#: src/components/content/add/ImportOpml.tsx
msgid "file is required"
msgstr "è richiesto il file"
#: src/components/content/add/CategorySelect.tsx
msgid "{0} (in {1})"
msgstr ""

View File

@@ -795,3 +795,7 @@ msgstr ""
#: src/components/content/add/ImportOpml.tsx
msgid "file is required"
msgstr "ファイルが必要です"
#: src/components/content/add/CategorySelect.tsx
msgid "{0} (in {1})"
msgstr ""

View File

@@ -795,3 +795,7 @@ msgstr ""
#: src/components/content/add/ImportOpml.tsx
msgid "file is required"
msgstr "파일이 필요합니다"
#: src/components/content/add/CategorySelect.tsx
msgid "{0} (in {1})"
msgstr ""

View File

@@ -795,3 +795,7 @@ msgstr ""
#: src/components/content/add/ImportOpml.tsx
msgid "file is required"
msgstr "fail diperlukan"
#: src/components/content/add/CategorySelect.tsx
msgid "{0} (in {1})"
msgstr ""

View File

@@ -795,3 +795,7 @@ msgstr ""
#: src/components/content/add/ImportOpml.tsx
msgid "file is required"
msgstr "fil kreves"
#: src/components/content/add/CategorySelect.tsx
msgid "{0} (in {1})"
msgstr ""

View File

@@ -795,3 +795,7 @@ msgstr ""
#: src/components/content/add/ImportOpml.tsx
msgid "file is required"
msgstr "bestand is vereist"
#: src/components/content/add/CategorySelect.tsx
msgid "{0} (in {1})"
msgstr ""

View File

@@ -795,3 +795,7 @@ msgstr ""
#: src/components/content/add/ImportOpml.tsx
msgid "file is required"
msgstr "fil kreves"
#: src/components/content/add/CategorySelect.tsx
msgid "{0} (in {1})"
msgstr ""

View File

@@ -795,3 +795,7 @@ msgstr ""
#: src/components/content/add/ImportOpml.tsx
msgid "file is required"
msgstr "plik jest wymagany"
#: src/components/content/add/CategorySelect.tsx
msgid "{0} (in {1})"
msgstr ""

View File

@@ -795,3 +795,7 @@ msgstr ""
#: src/components/content/add/ImportOpml.tsx
msgid "file is required"
msgstr "o arquivo é obrigatório"
#: src/components/content/add/CategorySelect.tsx
msgid "{0} (in {1})"
msgstr ""

View File

@@ -795,3 +795,7 @@ msgstr ""
#: src/components/content/add/ImportOpml.tsx
msgid "file is required"
msgstr "требуется файл"
#: src/components/content/add/CategorySelect.tsx
msgid "{0} (in {1})"
msgstr ""

View File

@@ -795,3 +795,7 @@ msgstr ""
#: src/components/content/add/ImportOpml.tsx
msgid "file is required"
msgstr ""
#: src/components/content/add/CategorySelect.tsx
msgid "{0} (in {1})"
msgstr ""

View File

@@ -795,3 +795,7 @@ msgstr ""
#: src/components/content/add/ImportOpml.tsx
msgid "file is required"
msgstr "fil krävs"
#: src/components/content/add/CategorySelect.tsx
msgid "{0} (in {1})"
msgstr ""

View File

@@ -795,3 +795,7 @@ msgstr ""
#: src/components/content/add/ImportOpml.tsx
msgid "file is required"
msgstr "dosya gerekli"
#: src/components/content/add/CategorySelect.tsx
msgid "{0} (in {1})"
msgstr ""

View File

@@ -795,3 +795,7 @@ msgstr ""
#: src/components/content/add/ImportOpml.tsx
msgid "file is required"
msgstr "文件是必需的"
#: src/components/content/add/CategorySelect.tsx
msgid "{0} (in {1})"
msgstr ""

View File

@@ -109,7 +109,12 @@ export function CategoryDetailsPage() {
{editable && (
<>
<TextInput label={t`Name`} {...form.getInputProps("name")} required />
<CategorySelect label={t`Parent Category`} {...form.getInputProps("parentId")} clearable />
<CategorySelect
label={t`Parent Category`}
{...form.getInputProps("parentId")}
clearable
withoutCategoryIds={[id]}
/>
<NumberInput label={t`Position`} {...form.getInputProps("position")} required min={0} />
</>
)}

View File

@@ -19,6 +19,9 @@ public class Category implements Serializable {
@ApiModelProperty(value = "parent category id")
private String parentId;
@ApiModelProperty(value = "parent category name")
private String parentName;
@ApiModelProperty(value = "category id", required = true)
private String name;

View File

@@ -454,17 +454,13 @@ public class CategoryREST {
child.setPosition(c.getPosition());
if (c.getParent() != null && c.getParent().getId() != null) {
child.setParentId(String.valueOf(c.getParent().getId()));
child.setParentName(c.getParent().getName());
}
child.setExpanded(!c.isCollapsed());
category.getChildren().add(child);
}
}
Collections.sort(category.getChildren(), new Comparator<Category>() {
@Override
public int compare(Category o1, Category o2) {
return ObjectUtils.compare(o1.getPosition(), o2.getPosition());
}
});
Collections.sort(category.getChildren(), (o1, o2) -> ObjectUtils.compare(o1.getPosition(), o2.getPosition()));
for (FeedSubscription subscription : subscriptions) {
if (id == null && subscription.getCategory() == null
@@ -474,12 +470,8 @@ public class CategoryREST {
category.getFeeds().add(sub);
}
}
Collections.sort(category.getFeeds(), new Comparator<Subscription>() {
@Override
public int compare(Subscription o1, Subscription o2) {
return ObjectUtils.compare(o1.getPosition(), o2.getPosition());
}
});
Collections.sort(category.getFeeds(), (o1, o2) -> ObjectUtils.compare(o1.getPosition(), o2.getPosition()));
return category;
}