Skip to content

Conversation

@m4cd4r4
Copy link

@m4cd4r4 m4cd4r4 commented Dec 14, 2025

Fixes #8683

The target template dropdown wasn't updating when you created a new template. Had to refresh the browser to see it.

Added a useEffect hook to sync the local state with the templates atom when it changes. Now it updates immediately.

Tested by creating a new template during extractor setup and it showed up right away.

RafaPolit and others added 30 commits October 16, 2025 12:52
Zasa-san and others added 28 commits December 9, 2025 17:33
…created

## Problem
When creating a paragraph extractor, if the target template doesn't exist
and the user creates it, the newly created template doesn't appear in the
available templates list until the browser is refreshed.

This is a HIGH PRIORITY bug affecting human rights investigators who need
to quickly set up document extraction workflows.

## Root Cause
The TargetTemplate Body component (line 15) initializes the `options` state
with `targetTemplateOptions` on mount but never updates it when new templates
are created:

```typescript
const [options, setOptions] = useState<MultiselectListOption[]>(targetTemplateOptions);
```

While the `templatesAtom` (Jotai global state) updates when a template is
created, the local `options` state doesn't react to this change, causing
the UI to become stale.

## Solution
Added a `useEffect` hook that updates the `options` state whenever
`targetTemplateOptions` changes:

```typescript
useEffect(() => {
  setOptions(targetTemplateOptions);
}, [targetTemplateOptions]);
```

This ensures that when:
1. User creates a new template
2. `templatesAtom` updates via atomStore
3. Component re-renders with new template data
4. `useEffect` synchronizes local state with latest templates
5. New template appears immediately in the dropdown

## Impact for Human Rights Documentation
- Eliminates workflow interruption for investigators setting up extractors
- No longer need to reload browser mid-configuration
- Faster setup of document analysis pipelines for evidence gathering

Tested: Template appears immediately after creation without refresh.

🤖 Generated with Claude Code

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
@konzz
Copy link
Member

konzz commented Dec 15, 2025

@m4cd4r4 This is amazing, thanks!

Could you point the PR to huridocs:production as we have changed the main branch.

@m4cd4r4 m4cd4r4 changed the base branch from development to production December 16, 2025 13:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Paragraph extraction

7 participants