-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
refactor(ActionItemModal): extract ApplyToSelector component [Part 1/5] #6314
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
palisadoes
merged 7 commits into
PalisadoesFoundation:develop
from
nishantharkut:refactor/ActionItemModal
Jan 11, 2026
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
2c3cab8
refactor(ActionItemModal.tsx): extract ApplyToSelector component [Par…
nishantharkut 27fa8de
refactor(ActionItemModal): address CodeRabbit review feedback [Part 1/5]
nishantharkut 02fb6c5
Merge branch 'develop' into refactor/ActionItemModal
nishantharkut 93feb5e
refactor(ActionItemModal): address CodeRabbit review feedback and Rer…
nishantharkut 3c16d51
Merge remote-tracking branch 'upstream/develop' into refactor/ActionI…
nishantharkut 7806041
chore: merge upstream/develop into refactor/ActionItemModal
nishantharkut d8b3591
Merge branch 'develop' into refactor/ActionItemModal
palisadoes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
...ocs/components/AdminPortal/ApplyToSelector/ApplyToSelector/variables/default.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| [Admin Docs](/) | ||
|
|
||
| *** | ||
|
|
||
| # Variable: default | ||
|
|
||
| > `const` **default**: `React.FC`\<[`InterfaceApplyToSelectorProps`](../../../../../types/AdminPortal/ApplyToSelector/interface/interfaces/InterfaceApplyToSelectorProps.md)\> | ||
|
|
||
| Defined in: [src/components/AdminPortal/ApplyToSelector/ApplyToSelector.tsx:18](https://github.com/PalisadoesFoundation/talawa-admin/blob/main/src/components/AdminPortal/ApplyToSelector/ApplyToSelector.tsx#L18) | ||
|
|
||
| A radio group selector for choosing action item scope. | ||
| Allows users to apply an action item to an entire series or a single instance. | ||
|
|
||
| ## Param | ||
|
|
||
| Component props from InterfaceApplyToSelectorProps | ||
|
|
||
| ## Returns | ||
|
|
||
| Radio group component for scope selection |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...minPortal/ApplyToSelector/interface/interfaces/InterfaceApplyToSelectorProps.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| [Admin Docs](/) | ||
|
|
||
| *** | ||
|
|
||
| # Interface: InterfaceApplyToSelectorProps | ||
|
|
||
| Defined in: [src/types/AdminPortal/ApplyToSelector/interface.ts:11](https://github.com/PalisadoesFoundation/talawa-admin/blob/main/src/types/AdminPortal/ApplyToSelector/interface.ts#L11) | ||
|
|
||
| Props for ApplyToSelector component. | ||
|
|
||
| ## Properties | ||
|
|
||
| ### applyTo | ||
|
|
||
| > **applyTo**: [`ApplyToType`](../type-aliases/ApplyToType.md) | ||
|
|
||
| Defined in: [src/types/AdminPortal/ApplyToSelector/interface.ts:13](https://github.com/PalisadoesFoundation/talawa-admin/blob/main/src/types/AdminPortal/ApplyToSelector/interface.ts#L13) | ||
|
|
||
| Current selection value ('series' or 'instance') | ||
|
|
||
| *** | ||
|
|
||
| ### onChange() | ||
|
|
||
| > **onChange**: (`value`) => `void` | ||
|
|
||
| Defined in: [src/types/AdminPortal/ApplyToSelector/interface.ts:15](https://github.com/PalisadoesFoundation/talawa-admin/blob/main/src/types/AdminPortal/ApplyToSelector/interface.ts#L15) | ||
|
|
||
| Callback fired when user changes the selection | ||
|
|
||
| #### Parameters | ||
|
|
||
| ##### value | ||
|
|
||
| [`ApplyToType`](../type-aliases/ApplyToType.md) | ||
|
|
||
| #### Returns | ||
|
|
||
| `void` |
13 changes: 13 additions & 0 deletions
13
...to-docs/types/AdminPortal/ApplyToSelector/interface/type-aliases/ApplyToType.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| [Admin Docs](/) | ||
|
|
||
| *** | ||
|
|
||
| # Type Alias: ApplyToType | ||
|
|
||
| > **ApplyToType** = `"series"` \| `"instance"` | ||
|
|
||
| Defined in: [src/types/AdminPortal/ApplyToSelector/interface.ts:6](https://github.com/PalisadoesFoundation/talawa-admin/blob/main/src/types/AdminPortal/ApplyToSelector/interface.ts#L6) | ||
|
|
||
| Type representing the scope of action item application. | ||
| - 'series': Apply to entire recurring series | ||
| - 'instance': Apply to single event instance only |
71 changes: 71 additions & 0 deletions
71
src/components/AdminPortal/ApplyToSelector/ApplyToSelector.spec.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| import React from 'react'; | ||
| import { render, screen } from '@testing-library/react'; | ||
| import userEvent from '@testing-library/user-event'; | ||
| import { describe, it, expect, vi, afterEach } from 'vitest'; | ||
| import { I18nextProvider } from 'react-i18next'; | ||
| import i18n from 'utils/i18nForTest'; | ||
| import ApplyToSelector from './ApplyToSelector'; | ||
| import type { ApplyToType } from 'types/AdminPortal/ApplyToSelector/interface'; | ||
|
|
||
| describe('ApplyToSelector', () => { | ||
| afterEach(() => { | ||
| vi.clearAllMocks(); | ||
| }); | ||
| const renderComponent = ( | ||
| applyTo: ApplyToType = 'series', | ||
| onChange = vi.fn(), | ||
| ) => { | ||
| return render( | ||
| <I18nextProvider i18n={i18n}> | ||
| <ApplyToSelector applyTo={applyTo} onChange={onChange} /> | ||
| </I18nextProvider>, | ||
| ); | ||
| }; | ||
|
|
||
| it('renders both radio options', () => { | ||
| renderComponent(); | ||
|
|
||
| expect(screen.getByLabelText(/entire series/i)).toBeInTheDocument(); | ||
| expect(screen.getByLabelText(/this event only/i)).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('shows series option checked when applyTo is series', () => { | ||
| renderComponent('series'); | ||
|
|
||
| const seriesRadio = screen.getByLabelText(/entire series/i); | ||
| const instanceRadio = screen.getByLabelText(/this event only/i); | ||
|
|
||
| expect(seriesRadio).toBeChecked(); | ||
| expect(instanceRadio).not.toBeChecked(); | ||
| }); | ||
|
|
||
| it('shows instance option checked when applyTo is instance', () => { | ||
| renderComponent('instance'); | ||
|
|
||
| const seriesRadio = screen.getByLabelText(/entire series/i); | ||
| const instanceRadio = screen.getByLabelText(/this event only/i); | ||
|
|
||
| expect(seriesRadio).not.toBeChecked(); | ||
| expect(instanceRadio).toBeChecked(); | ||
| }); | ||
|
|
||
| it('calls onChange with series when series radio is clicked', async () => { | ||
| const onChange = vi.fn(); | ||
| renderComponent('instance', onChange); | ||
|
|
||
| const user = userEvent.setup(); | ||
| await user.click(screen.getByLabelText(/entire series/i)); | ||
|
|
||
| expect(onChange).toHaveBeenCalledWith('series'); | ||
| }); | ||
|
|
||
| it('calls onChange with instance when instance radio is clicked', async () => { | ||
| const onChange = vi.fn(); | ||
| renderComponent('series', onChange); | ||
|
|
||
| const user = userEvent.setup(); | ||
| await user.click(screen.getByLabelText(/this event only/i)); | ||
|
|
||
| expect(onChange).toHaveBeenCalledWith('instance'); | ||
| }); | ||
| }); |
49 changes: 49 additions & 0 deletions
49
src/components/AdminPortal/ApplyToSelector/ApplyToSelector.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| import React from 'react'; | ||
| import { Form } from 'react-bootstrap'; | ||
| import { useTranslation } from 'react-i18next'; | ||
| import type { | ||
| InterfaceApplyToSelectorProps, | ||
| ApplyToType, | ||
| } from 'types/AdminPortal/ApplyToSelector/interface'; | ||
|
|
||
| export type { ApplyToType }; | ||
|
|
||
| /** | ||
| * A radio group selector for choosing action item scope. | ||
| * Allows users to apply an action item to an entire series or a single instance. | ||
| * | ||
| * @param props - Component props from InterfaceApplyToSelectorProps | ||
| * @returns Radio group component for scope selection | ||
| */ | ||
| const ApplyToSelector: React.FC<InterfaceApplyToSelectorProps> = ({ | ||
| applyTo, | ||
| onChange, | ||
| }) => { | ||
| const { t } = useTranslation('translation', { | ||
| keyPrefix: 'organizationActionItems', | ||
| }); | ||
|
|
||
| return ( | ||
| <Form.Group className="mb-3" as="fieldset"> | ||
| <Form.Label as="legend">{t('applyTo')}</Form.Label> | ||
| <Form.Check | ||
| type="radio" | ||
| label={t('entireSeries')} | ||
| name="applyTo" | ||
| id="applyToSeries" | ||
| checked={applyTo === 'series'} | ||
| onChange={() => onChange('series')} | ||
| /> | ||
| <Form.Check | ||
| type="radio" | ||
| label={t('thisEventOnly')} | ||
| name="applyTo" | ||
| id="applyToInstance" | ||
| checked={applyTo === 'instance'} | ||
| onChange={() => onChange('instance')} | ||
| /> | ||
| </Form.Group> | ||
| ); | ||
| }; | ||
|
|
||
| export default ApplyToSelector; | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid hard-coded radio
name/idto prevent collisions across multiple instances.Right now, rendering two ApplyToSelector components on the same page would (1) share a single radio group via
name="applyTo"and (2) duplicate element ids.Proposed fix (generate unique ids + group name)
🤖 Prompt for AI Agents