Skip to content

Commit 4ecc1d4

Browse files
committed
fix: Fixed show descriptors per category on edit
1 parent b905dff commit 4ecc1d4

File tree

3 files changed

+39
-10
lines changed

3 files changed

+39
-10
lines changed

src/components/statementWizard/EditStatementModal.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,17 @@ export const EditStatementModal: React.FC<EditStatementModalProps> = ({
8888
return (
8989
<SubjectStep
9090
username={username}
91-
// For editing mode, it doesn't need a preset question
92-
presetQuestion={undefined}
91+
// Create a mock preset question with the statement's category
92+
presetQuestion={{
93+
id: 'editing',
94+
category: statement.category || 'wellbeing',
95+
question: '', // Not needed for editing
96+
steps: {
97+
subject: {
98+
allowDescriptors: true
99+
}
100+
}
101+
}}
93102
selection={localValue as string}
94103
onUpdate={(val) => setLocalValue(val)}
95104
/>

src/components/statementWizard/StatementWizard.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,23 @@ const StatementWizard: React.FC<StatementWizardProps> = ({
6666
});
6767
const [isSubmitting, setIsSubmitting] = useState(false);
6868

69+
// Initialize default values based on whether this is a preset or custom statement
6970
useEffect(() => {
71+
// For preset questions, set the subject if a preset is specified
7072
if (presetQuestion?.steps?.subject?.preset) {
7173
setSelection((prev) => ({
7274
...prev,
7375
atoms: { ...prev.atoms, subject: username },
7476
}));
7577
}
78+
79+
// For custom statements, set the default category to 'uncategorised'
80+
if (!presetQuestion) {
81+
setSelection((prev) => ({
82+
...prev,
83+
category: 'uncategorised',
84+
}));
85+
}
7686
}, [presetQuestion, username]);
7787

7888
const currentStep = steps[currentStepIndex];
@@ -92,8 +102,11 @@ const StatementWizard: React.FC<StatementWizardProps> = ({
92102
id: Date.now().toString(),
93103
input: fullInput,
94104
presetId: presetQuestion ? presetQuestion.id : undefined,
105+
// Ensure consistent casing for uncategorized - capital 'U'
95106
category:
96-
presetQuestion?.category || selection.category || 'Uncategorized',
107+
presetQuestion?.category ||
108+
(selection.category === 'uncategorised' ? 'Uncategorized' : selection.category) ||
109+
'Uncategorized',
97110
};
98111

99112
try {

src/components/statementWizard/selectors/SubjectSelector.tsx

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,32 @@ interface SubjectSelectorProps {
1616
onChange: (value: string) => void;
1717
onAddDescriptor: (descriptor: string) => void;
1818
username: string;
19+
category?: string; // Add category prop
1920
}
2021

2122
const SubjectSelector: React.FC<SubjectSelectorProps> = ({
2223
value,
2324
onChange,
2425
onAddDescriptor,
2526
username,
27+
category = 'wellbeing', // Default to wellbeing if no category provided
2628
}) => {
2729
const subjectTiles: SubjectOption[] = useMemo(() => {
2830
const baseOption = { label: username, value: username };
29-
const descriptorOptions = descriptorsData.descriptors.flatMap(
30-
(descriptor) =>
31-
descriptor.options.map((option) => ({
32-
label: `${username}'s ${option}`,
33-
value: `${username}'s ${option}`,
34-
}))
31+
32+
// Find the category in the descriptors data
33+
const categoryData = descriptorsData.descriptors.find(
34+
(descriptor) => descriptor.name.toLowerCase() === category.toLowerCase()
3535
);
36+
37+
// Use the category's options if found, otherwise use an empty array
38+
const descriptorOptions = (categoryData?.options || []).map((option) => ({
39+
label: `${username}'s ${option}`,
40+
value: `${username}'s ${option}`,
41+
}));
42+
3643
return [baseOption, ...descriptorOptions];
37-
}, [username]);
44+
}, [username, category]);
3845
const [open, setOpen] = useState(false);
3946
const [search, setSearch] = useState('');
4047
const [isAddingNew, setIsAddingNew] = useState(false);

0 commit comments

Comments
 (0)