Skip to content

Commit

Permalink
display parent category name in category selects (fixes #1045)
Browse files Browse the repository at this point in the history
  • Loading branch information
Athou committed Mar 7, 2023
1 parent 10bfbbe commit 5003c17
Show file tree
Hide file tree
Showing 33 changed files with 132 additions and 15 deletions.
1 change: 1 addition & 0 deletions commafeed-client/src/app/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export interface ApplicationSettings {
export interface Category {
id: string
parentId?: string
parentName?: string
name: string
children: Category[]
feeds: Subscription[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions commafeed-client/src/locales/ar/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
4 changes: 4 additions & 0 deletions commafeed-client/src/locales/ca/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
4 changes: 4 additions & 0 deletions commafeed-client/src/locales/cs/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
4 changes: 4 additions & 0 deletions commafeed-client/src/locales/cy/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
4 changes: 4 additions & 0 deletions commafeed-client/src/locales/da/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
4 changes: 4 additions & 0 deletions commafeed-client/src/locales/de/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
4 changes: 4 additions & 0 deletions commafeed-client/src/locales/en/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -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})"
4 changes: 4 additions & 0 deletions commafeed-client/src/locales/es/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
4 changes: 4 additions & 0 deletions commafeed-client/src/locales/fa/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
4 changes: 4 additions & 0 deletions commafeed-client/src/locales/fi/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
4 changes: 4 additions & 0 deletions commafeed-client/src/locales/fr/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
4 changes: 4 additions & 0 deletions commafeed-client/src/locales/gl/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
4 changes: 4 additions & 0 deletions commafeed-client/src/locales/hu/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
4 changes: 4 additions & 0 deletions commafeed-client/src/locales/id/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
4 changes: 4 additions & 0 deletions commafeed-client/src/locales/it/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
4 changes: 4 additions & 0 deletions commafeed-client/src/locales/ja/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
4 changes: 4 additions & 0 deletions commafeed-client/src/locales/ko/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
4 changes: 4 additions & 0 deletions commafeed-client/src/locales/ms/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
4 changes: 4 additions & 0 deletions commafeed-client/src/locales/nb/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
4 changes: 4 additions & 0 deletions commafeed-client/src/locales/nl/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
4 changes: 4 additions & 0 deletions commafeed-client/src/locales/nn/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
4 changes: 4 additions & 0 deletions commafeed-client/src/locales/pl/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
4 changes: 4 additions & 0 deletions commafeed-client/src/locales/pt/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
4 changes: 4 additions & 0 deletions commafeed-client/src/locales/ru/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
4 changes: 4 additions & 0 deletions commafeed-client/src/locales/sk/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
4 changes: 4 additions & 0 deletions commafeed-client/src/locales/sv/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
4 changes: 4 additions & 0 deletions commafeed-client/src/locales/tr/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
4 changes: 4 additions & 0 deletions commafeed-client/src/locales/zh/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
7 changes: 6 additions & 1 deletion commafeed-client/src/pages/app/CategoryDetailsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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} />
</>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -454,17 +454,13 @@ private Category buildCategory(Long id, List<FeedCategory> categories, List<Feed
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
Expand All @@ -474,12 +470,8 @@ public int compare(Category o1, Category o2) {
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;
}

Expand Down

0 comments on commit 5003c17

Please sign in to comment.