Skip to content

Commit 223b098

Browse files
Merge pull request #177 from SingularityNET-Archive:development
feat: Enhance SelectTags component with debounced input handling and new option creation; update meeting summary state with username
2 parents 2a1c59b + 379b0cc commit 223b098

File tree

2 files changed

+69
-21
lines changed

2 files changed

+69
-21
lines changed

components/SelectTags.tsx

Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { useMemo } from 'react';
22
import { useMyVariable } from '../context/MyVariableContext';
33
import { debounce } from 'lodash';
44
import CreatableSelect from 'react-select/creatable';
5-
import { saveNewTags } from '../utils/saveNewTags'
5+
import { saveNewTags } from '../utils/saveNewTags';
66

77
interface SelectTagsProps {
88
onSelect: (names: string) => void;
@@ -11,39 +11,63 @@ interface SelectTagsProps {
1111
}
1212

1313
const SelectTags: React.FC<SelectTagsProps> = ({ onSelect, initialValue, type }) => {
14-
let initialOptions = initialValue ? initialValue.split(", ").map((val) => ({ label: val, value: val })) : [];
14+
const initialOptions = initialValue
15+
? initialValue.split(", ").map(val => ({ label: val, value: val }))
16+
: [];
1517
const [selectedLabels, setSelectedLabels] = React.useState(initialOptions);
1618
const { myVariable } = useMyVariable();
17-
const options = myVariable.tags[`${type}`] || [
18-
{ value: 'chocolate', label: 'Chocolate' },
19-
{ value: 'strawberry', label: 'Strawberry' },
20-
{ value: 'vanilla', label: 'Vanilla' }
21-
];
22-
19+
const options =
20+
myVariable.tags[type] ||
21+
[
22+
{ value: 'chocolate', label: 'Chocolate' },
23+
{ value: 'strawberry', label: 'Strawberry' },
24+
{ value: 'vanilla', label: 'Vanilla' }
25+
];
26+
2327
React.useEffect(() => {
24-
let initialOptions = initialValue ? initialValue.split(", ").map((val) => ({ label: val, value: val })) : [];
25-
setSelectedLabels(initialOptions);
28+
const initialOpts = initialValue
29+
? initialValue.split(", ").map(val => ({ label: val, value: val }))
30+
: [];
31+
setSelectedLabels(initialOpts);
2632
}, [initialValue]);
2733

34+
// Debounced update that saves tags
2835
const debouncedHandleInputChange = useMemo(
29-
() => debounce(async (selected: any) => {
30-
setSelectedLabels(selected); // Update local state
31-
const labs: string[] = selected.map((item: any) => item.label);
32-
const status = await saveNewTags(labs, type);
33-
onSelect(labs.join(", ")); // Update parent component's state
34-
}, 1000),
36+
() =>
37+
debounce(async (selected: any) => {
38+
setSelectedLabels(selected); // Update local state
39+
const labs: string[] = selected.map((item: any) => item.label);
40+
await saveNewTags(labs, type);
41+
onSelect(labs.join(", ")); // Update parent component's state
42+
}, 1000),
3543
[onSelect, type]
3644
);
37-
45+
46+
// Handle creation of new option (e.g., when user types comma separated tags)
47+
const handleCreateOption = (inputValue: string) => {
48+
// Split the input on commas, trim whitespace and remove empty strings
49+
const newTags = inputValue
50+
.split(',')
51+
.map(tag => tag.trim())
52+
.filter(tag => tag);
53+
// Map each tag to the option format
54+
const newOptions = newTags.map(tag => ({ label: tag, value: tag }));
55+
// Merge with the existing selected labels
56+
const updatedSelected = [...selectedLabels, ...newOptions];
57+
setSelectedLabels(updatedSelected);
58+
debouncedHandleInputChange(updatedSelected);
59+
};
60+
3861
return (
3962
<div title="When you type, hit enter to add item and start typing again to add another or select from the dropdown">
40-
<CreatableSelect
63+
<CreatableSelect
4164
isMulti
4265
options={options}
4366
value={selectedLabels}
4467
onChange={(selected) => {
4568
debouncedHandleInputChange(selected || []);
4669
}}
70+
onCreateOption={handleCreateOption}
4771
styles={{
4872
control: (baseStyles, state) => ({
4973
...baseStyles,

pages/submit-meeting-summary/index.tsx

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,15 +217,18 @@ const SubmitMeetingSummary: NextPage = () => {
217217
async function handleSelectChange2(e: any) {
218218
const newSelectedMeetingId = e.target.value;
219219
setSelectedMeetingId(newSelectedMeetingId);
220-
220+
221221
const selectedSummary = meetings.find((m: any) => m.meeting_id === newSelectedMeetingId);
222222
if (selectedSummary) {
223223
setMyVariable((prev) => ({
224224
...prev,
225-
summary: selectedSummary
225+
summary: {
226+
...selectedSummary,
227+
username: prev.currentUser,
228+
}
226229
}));
227230
}
228-
}
231+
}
229232

230233
// -----------------------------------------
231234
// Add New Workgroup logic
@@ -715,6 +718,27 @@ const SubmitMeetingSummary: NextPage = () => {
715718
</select>
716719
</div>
717720
)}
721+
{false && workgroups.length > 0 && meetings?.length > 0 && myVariable.roles?.isAdmin && (
722+
<>
723+
<div className={styles['column-flex']}>
724+
<label className={styles['form-label']} htmlFor="">Select previous meeting data</label>
725+
<select
726+
name="" id=""
727+
className={styles.select}
728+
value={selectedMeetingId} onChange={handleSelectChange2}
729+
title="Defaults to latest meeting, only change this when you want to use a previous meeting as template">
730+
{meetings.map((meeting: any) => (
731+
<option
732+
style={{ color: meeting.confirmed ? 'lightgreen' : 'black' }}
733+
key={`${meeting.meeting_id}-${meeting.updated_at}`}
734+
value={meeting.meeting_id}>
735+
{formatDate(meeting.date)} {meeting.username} {meeting.confirmed ? 'Archived' : ''}
736+
</option>
737+
))}
738+
</select>
739+
</div>
740+
</>
741+
)}
718742

719743
{showNewWorkgroupInput && (
720744
<>

0 commit comments

Comments
 (0)