Skip to content

Commit 6225d84

Browse files
committed
Do a little refactoring
1 parent f5f5cda commit 6225d84

2 files changed

Lines changed: 39 additions & 42 deletions

File tree

src/components/EditableConfigList.tsx

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,42 @@ export abstract class GenericEditableConfigList<
242242
: `${count} libraries`;
243243
}
244244

245+
protected getAssociatedEntries(
246+
item: any
247+
): Array<{ label: string; suffix?: string; href?: string }> {
248+
const libraries: Array<{ short_name: string }> = item?.libraries || [];
249+
const allLibraries: Array<{
250+
short_name: string;
251+
name?: string;
252+
uuid?: string;
253+
}> = (this.props.data as any)?.allLibraries || [];
254+
return libraries.map((lib) => {
255+
const libraryData = allLibraries.find(
256+
(l) => l.short_name === lib.short_name
257+
);
258+
return {
259+
label: libraryData?.name || lib.short_name,
260+
href: libraryData?.uuid
261+
? `/admin/web/config/libraries/edit/${libraryData.uuid}`
262+
: undefined,
263+
};
264+
});
265+
}
266+
245267
protected renderAssociatedSection(item: any): JSX.Element {
246-
return this.renderAssociatedLibraries(item);
268+
const entries = this.getAssociatedEntries(item).sort((a, b) =>
269+
a.label.localeCompare(b.label)
270+
);
271+
return (
272+
<ul className="associated-libraries">
273+
{entries.map((entry, i) => (
274+
<li key={i}>
275+
{entry.href ? <a href={entry.href}>{entry.label}</a> : entry.label}
276+
{entry.suffix}
277+
</li>
278+
))}
279+
</ul>
280+
);
247281
}
248282

249283
renderLi(item, index): JSX.Element {
@@ -355,34 +389,6 @@ export abstract class GenericEditableConfigList<
355389
this.setState({ expandedItems: newExpandedItems });
356390
}
357391

358-
renderAssociatedLibraries(item: any): JSX.Element {
359-
const libraries: Array<{ short_name: string }> = item.libraries;
360-
const allLibraries: Array<{
361-
short_name: string;
362-
name?: string;
363-
uuid?: string;
364-
}> = (this.props.data as any)?.allLibraries || [];
365-
366-
return (
367-
<ul className="associated-libraries">
368-
{libraries.map((lib) => {
369-
const libraryData = allLibraries.find(
370-
(l) => l.short_name === lib.short_name
371-
);
372-
const name = libraryData?.name || lib.short_name;
373-
const href = libraryData?.uuid
374-
? `/admin/web/config/libraries/edit/${libraryData.uuid}`
375-
: null;
376-
return (
377-
<li key={lib.short_name}>
378-
{href ? <a href={href}>{name}</a> : name}
379-
</li>
380-
);
381-
})}
382-
</ul>
383-
);
384-
}
385-
386392
label(item): string {
387393
return item[this.labelKey];
388394
}

src/components/IndividualAdmins.tsx

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ export class IndividualAdmins extends EditableConfigList<
8787
});
8888
}
8989

90-
result.sort((a, b) => a.label.localeCompare(b.label));
9190
return result;
9291
}
9392

@@ -102,18 +101,10 @@ export class IndividualAdmins extends EditableConfigList<
102101
return count === 0 ? "no roles" : count === 1 ? "1 role" : `${count} roles`;
103102
}
104103

105-
protected renderAssociatedSection(item: IndividualAdminData): JSX.Element {
106-
const summary = this.getRolesSummary(item);
107-
return (
108-
<ul className="associated-libraries">
109-
{summary.map((entry, i) => (
110-
<li key={i}>
111-
{entry.href ? <a href={entry.href}>{entry.label}</a> : entry.label}
112-
{entry.suffix}
113-
</li>
114-
))}
115-
</ul>
116-
);
104+
protected getAssociatedEntries(
105+
item: IndividualAdminData
106+
): Array<{ label: string; suffix?: string; href?: string }> {
107+
return this.getRolesSummary(item);
117108
}
118109

119110
canCreate() {

0 commit comments

Comments
 (0)