Skip to content

Commit cd8f211

Browse files
jason-raitzanarchivistCopilot
authored
AP-529 tind references redesign (#92)
* references redesign * Update public/elements/tind-refs.jsx Co-authored-by: maría a. matienzo <[email protected]> * Update public/elements/tind-refs.jsx Co-authored-by: maría a. matienzo <[email protected]> * Update public/elements/tind-refs.jsx Co-authored-by: Copilot <[email protected]> * Update public/elements/tind-refs.jsx Co-authored-by: Copilot <[email protected]> * handling for empty reference keys --------- Co-authored-by: maría a. matienzo <[email protected]> Co-authored-by: Copilot <[email protected]>
1 parent 17aff8a commit cd8f211

File tree

2 files changed

+77
-3
lines changed

2 files changed

+77
-3
lines changed

public/elements/tind-refs.jsx

Lines changed: 76 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,87 @@ import {
66
} from "@/components/ui/accordion"
77

88
export default function TindRefs () {
9+
const parseTindReference = (msg) => {
10+
const ref = {
11+
title: null,
12+
interviewers: [],
13+
interviewees: [],
14+
project: null,
15+
link: null,
16+
};
17+
const lines = msg.split('\n').filter(line => line.trim() !== '');
18+
19+
lines.forEach(line => {
20+
const parts = line.split(':');
21+
const key = parts[0].trim();
22+
const value = parts.slice(1).join(':').trim();
23+
24+
switch (key) {
25+
case 'Title':
26+
ref.title = value;
27+
break;
28+
case 'Contributor':
29+
// if value ends in interviewee or interviewer, assign accordingly
30+
if (value.endsWith(' interviewer')) {
31+
ref.interviewers.push(value.replace(' interviewer', '').trim());
32+
} else if (value.endsWith(' interviewee')) {
33+
ref.interviewees.push(value.replace(' interviewee', '').trim());
34+
}
35+
break;
36+
case 'Project Name':
37+
ref.project = value;
38+
break;
39+
case 'Catalogue Link':
40+
ref.link = value;
41+
break;
42+
}
43+
});
44+
return ref;
45+
};
46+
47+
let count = 0;
48+
49+
50+
const buildTindMessage = () => {
51+
const originalMessage = props.tind_message || 'no references supplied';
52+
if (originalMessage === 'no references supplied') {
53+
return originalMessage;
54+
}
55+
// Split message into parts by '___________' separator
56+
const parts = originalMessage.split('___________');
57+
58+
const references = parts
59+
.filter(part => part.trim() !== '')
60+
.map(part => parseTindReference(part));
61+
62+
count = references.length;
63+
return (
64+
<div>
65+
{references.map((ref, index) => (
66+
<div key={index}>
67+
{ref.link && ref.link.trim() !== '' ? (
68+
<a href={ref.link} style={{ textDecoration: 'underline' }}>{ref.title}</a>
69+
) : (<span>{ref.title}</span>)}
70+
<p>
71+
Interviewee(s): {ref.interviewees.join(' | ') || 'not listed'}<br />
72+
Interviewer(s): {ref.interviewers.join(' | ') || 'not listed'}<br />
73+
Project Name: {ref.project || 'not listed'}<br />
74+
</p>
75+
___________
76+
</div>
77+
))}
78+
</div>
79+
);
80+
};
81+
const tindMessage = buildTindMessage();
82+
983
return (
1084
<Accordion type="single" collapsible className="w-full">
1185
<AccordionItem value="ref-1">
12-
<AccordionTrigger>Metadata</AccordionTrigger>
86+
<AccordionTrigger>References{count > 0 ? ` (${count})` : ''}</AccordionTrigger>
1387
<AccordionContent>
1488
<p className="mb-2" style={{ whiteSpace: 'pre-line' }}>
15-
{props.tind_message || 'no references supplied'}
89+
{tindMessage}
1690
</p>
1791
</AccordionContent>
1892
</AccordionItem>

willa/web/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ async def chat(message: cl.Message) -> None:
125125
)
126126
msg = cl.Message(
127127
author='TIND',
128-
content='References:',
128+
content='',
129129
elements=[tind_refs],
130130
metadata={'tind_message': reply['tind_message']}
131131
)

0 commit comments

Comments
 (0)