@tekkare/romulus 0.1.252 → 0.1.253
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/module.json
CHANGED
|
@@ -49,6 +49,12 @@ export interface RmProjectGroup {
|
|
|
49
49
|
export interface RmProjectKind<S = any> {
|
|
50
50
|
/** Valeur de `resourceType` cote API. */
|
|
51
51
|
type: string;
|
|
52
|
+
/**
|
|
53
|
+
* La famille sous laquelle la ligne s'affiche, quand deux types designent
|
|
54
|
+
* les memes documents (un essai range depuis deux apps, sous deux cles) :
|
|
55
|
+
* une seule puce, un seul filtre. Absent : le type lui-meme.
|
|
56
|
+
*/
|
|
57
|
+
group?: string;
|
|
52
58
|
index: string;
|
|
53
59
|
label: Record<RmProjectLang, string>;
|
|
54
60
|
/** Rubrique de l'app d'ou vient la famille (Essais, Publications...). */
|
|
@@ -82,6 +88,8 @@ export interface RmProjectResource {
|
|
|
82
88
|
path?: string;
|
|
83
89
|
/** Libelle de la famille. */
|
|
84
90
|
family: string;
|
|
91
|
+
/** Cle de la famille affichee (cf. RmProjectKind.group) ; `type` reste celui de l'API. */
|
|
92
|
+
group?: string;
|
|
85
93
|
section?: string;
|
|
86
94
|
icon: string;
|
|
87
95
|
createdAt?: string;
|
|
@@ -74,8 +74,9 @@ export async function rmProjectHydrate(items, kinds, search) {
|
|
|
74
74
|
return out;
|
|
75
75
|
}
|
|
76
76
|
export function rmProjectRows(items, documents, kinds, lang = "fr") {
|
|
77
|
+
const groupOf = (type) => kinds.find((kind) => kind.type === type)?.group ?? type;
|
|
77
78
|
const rank = (type) => {
|
|
78
|
-
const index = kinds.findIndex((kind) => kind.type === type);
|
|
79
|
+
const index = kinds.findIndex((kind) => kind.type === groupOf(type));
|
|
79
80
|
return index < 0 ? kinds.length : index;
|
|
80
81
|
};
|
|
81
82
|
return [...items].sort((a, b) => rank(a.resourceType) - rank(b.resourceType)).map((item) => {
|
|
@@ -88,6 +89,7 @@ export function rmProjectRows(items, documents, kinds, lang = "fr") {
|
|
|
88
89
|
subtitle: kind && source ? kind.subtitle?.(source, lang) ?? "" : "",
|
|
89
90
|
path: kind && source ? kind.path?.(source, item.resourceId) ?? "" : "",
|
|
90
91
|
family: kind ? kind.label[lang] : item.resourceType,
|
|
92
|
+
group: kind?.group ?? item.resourceType,
|
|
91
93
|
section: kind?.section?.[lang],
|
|
92
94
|
icon: kind?.icon ?? "Question",
|
|
93
95
|
createdAt: item.createdAt,
|
|
@@ -100,9 +102,10 @@ export function rmProjectRows(items, documents, kinds, lang = "fr") {
|
|
|
100
102
|
export function rmProjectFamilies(rows) {
|
|
101
103
|
const out = [];
|
|
102
104
|
for (const row of rows) {
|
|
103
|
-
const
|
|
105
|
+
const key = row.group ?? row.type;
|
|
106
|
+
const found = out.find((family) => family.type === key);
|
|
104
107
|
if (found) found.count++;
|
|
105
|
-
else out.push({ type:
|
|
108
|
+
else out.push({ type: key, label: row.family, icon: row.icon, count: 1 });
|
|
106
109
|
}
|
|
107
110
|
return out;
|
|
108
111
|
}
|
|
@@ -110,14 +113,14 @@ export function rmProjectFilterRows(rows, filter, lang = "fr") {
|
|
|
110
113
|
const words = fold(filter.search).split(/\s+/).filter(Boolean);
|
|
111
114
|
const family = filter.family && filter.family !== "all" ? filter.family : "";
|
|
112
115
|
const order = rmProjectFamilies(rows).map((f) => f.type);
|
|
113
|
-
const list = rows.filter((row) => !family || row.type === family).filter((row) => !filter.onlyCommented || (row.comments ?? 0) > 0).filter((row) => !words.length || words.every((word) => fold([row.title, row.subtitle, row.family, row.section, row.id].join(" ")).includes(word)));
|
|
116
|
+
const list = rows.filter((row) => !family || (row.group ?? row.type) === family).filter((row) => !filter.onlyCommented || (row.comments ?? 0) > 0).filter((row) => !words.length || words.every((word) => fold([row.title, row.subtitle, row.family, row.section, row.id].join(" ")).includes(word)));
|
|
114
117
|
const byDate = (a, b) => String(a.createdAt ?? "").localeCompare(String(b.createdAt ?? ""));
|
|
115
118
|
const byTitle = (a, b) => (a.title || a.id).localeCompare(b.title || b.id, lang);
|
|
116
119
|
const sort = filter.sort ?? "date-desc";
|
|
117
120
|
return [...list].sort((a, b) => {
|
|
118
121
|
if (sort === "date-asc") return byDate(a, b);
|
|
119
122
|
if (sort === "title") return byTitle(a, b);
|
|
120
|
-
if (sort === "family") return order.indexOf(a.type) - order.indexOf(b.type) || byTitle(a, b);
|
|
123
|
+
if (sort === "family") return order.indexOf(a.group ?? a.type) - order.indexOf(b.group ?? b.type) || byTitle(a, b);
|
|
121
124
|
return byDate(b, a);
|
|
122
125
|
});
|
|
123
126
|
}
|