refactor(ui): ♻ expect surrogate Language key

This commit is contained in:
Collin M. Barrett 2021-11-26 11:55:51 -06:00
parent 577c27aef1
commit f211ae4d30
6 changed files with 14 additions and 39 deletions

View file

@ -46,7 +46,7 @@ export const ListInfoDrawer = (props: RouteComponentProps & Props) => {
const list = useListDetails(props.listId);
const listLanguage = props.languages.filter((l) =>
list?.iso6391s.includes(l.iso6391)
list?.languageIds.includes(l.id)
);
const listTags = props.tags.filter((t) => list?.tagIds.includes(t.id));
const listLicense = props.licenses.find((l) => l.id === list?.licenseId);

View file

@ -22,7 +22,7 @@ import { Software } from "../../interfaces/Software";
import { Syntax } from "../../interfaces/Syntax";
import { TagCloud } from "../tagCloud";
import { Tag as TagInterface } from "../../interfaces/Tag";
import { arraySorter, languageArraySorter } from "./arraySorter";
import { arraySorter } from "./arraySorter";
import { nameof } from "../../utils";
import { TablePaginationConfig } from "antd/lib/table";
import { SyntaxTag } from "../SyntaxTag";
@ -225,9 +225,9 @@ export const ListsTable = (props: RouteComponentProps & Props) => {
<Table.Column<List>
title="Languages"
key="Languages"
dataIndex={nameof<List>("iso6391s")}
dataIndex={nameof<List>("languageIds")}
sorter={(a, b) =>
languageArraySorter(a.iso6391s, b.iso6391s, languages)
arraySorter(a.languageIds, b.languageIds, languages)
}
width={129}
filters={languages.map((l) => ({
@ -237,22 +237,24 @@ export const ListsTable = (props: RouteComponentProps & Props) => {
{l.name}&nbsp; (
{
visibleLists.filter(
(li) => li.iso6391s && li.iso6391s.includes(l.iso6391)
(li) => li.languageIds && li.languageIds.includes(l.id)
).length
}
)
</>
),
value: l.iso6391.toString(),
value: l.id,
}))}
onFilter={(value, record) =>
record.iso6391s ? record.iso6391s.includes(value as string) : false
record.languageIds
? record.languageIds.includes(value as number)
: false
}
render={(languageIds: string[]) =>
render={(languageIds: number[]) =>
languageIds ? (
<LanguageCloud
languages={languages.filter((l: Language) =>
languageIds.includes(l.iso6391)
languageIds.includes(l.id)
)}
/>
) : null

View file

@ -1,5 +1,3 @@
import { Language } from "../../interfaces/Language";
interface ArraySortableEntity {
id: number;
name: string;
@ -30,29 +28,3 @@ export const arraySorter = (
: 1
: -1
: 1;
export const languageArraySorter = (
a: string[],
b: string[],
entities: Language[]
) =>
a && a.length
? b && b.length
? a.length === b.length
? entities
.filter((e: Language) => a.includes(e.iso6391))
.map((e: Language) => e.name)
.join()
.toLowerCase() >
entities
.filter((e: Language) => b.includes(e.iso6391))
.map((e: Language) => e.name)
.join()
.toLowerCase()
? 1
: -1
: a.length > b.length
? -1
: 1
: -1
: 1;

View file

@ -1,4 +1,5 @@
export interface Language {
id: number;
iso6391: string;
name: string;
filterListIds: number[];

View file

@ -4,7 +4,7 @@
description?: string;
licenseId?: number;
syntaxIds: number[];
iso6391s: string[];
languageIds: number[];
tagIds: number[];
maintainerIds: number[];

View file

@ -4,7 +4,7 @@
description?: string;
licenseId?: number;
syntaxIds: number[];
iso6391s: string[];
languageIds: number[];
tagIds: number[];
viewUrls: ViewUrl[];
homeUrl?: string;