feat(web): re-enable langs column sort

This commit is contained in:
Collin M. Barrett 2020-08-30 13:56:32 -05:00
parent cecf44a8ec
commit 8a1e608f3e
2 changed files with 36 additions and 4 deletions

View file

@ -25,7 +25,7 @@ import { Software } from "../../interfaces/Software";
import { Syntax } from "../../interfaces/Syntax";
import { TagCloud } from "../tagCloud";
import { Tag as TagInterface } from "../../interfaces/Tag";
import { arraySorter } from "./arraySorter";
import { arraySorter, languageArraySorter } from "./arraySorter";
import { nameof } from "../../utils";
import styles from "./ListsTable.module.css";
import { TablePaginationConfig } from "antd/lib/table";
@ -228,9 +228,13 @@ export const ListsTable = (props: RouteComponentProps & Props) => {
title="Languages"
key="Languages"
dataIndex={nameof<List>("languageIso6391s")}
// sorter={(a, b) =>
// arraySorter(a.languageIso6391s, b.languageIso6391s, languages)
// }
sorter={(a, b) =>
languageArraySorter(
a.languageIso6391s,
b.languageIso6391s,
languages
)
}
width={129}
className={styles.nogrow}
filters={languages.map((l) => ({

View file

@ -1,3 +1,5 @@
import { Language } from "../../interfaces/Language";
interface ArraySortableEntity {
id: number;
name: string;
@ -28,3 +30,29 @@ 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;