-
Notifications
You must be signed in to change notification settings - Fork 7
Timespan component #2100
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
Closed
shreeyash07
wants to merge
15
commits into
project/early-action-protocols
from
feature/timespan-component
Closed
Timespan component #2100
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
02dd537
global(add-global-page): Add a global page
barshathakuri 916cd73
eap(add-eap-link): Add EAP Tab in account page
barshathakuri 9a765b7
eap(eap-translation): Add EAP translations
barshathakuri 39f9720
dref-process(tabs): Add tabs in dref process link
barshathakuri c7b0488
eap-table(table): Add eap development table
barshathakuri b523994
eap(eap-registration-form): Add EAP Registration Form
barshathakuri 4bc7988
eap-table(table): Add eap development table
barshathakuri ea21794
eap(lisitng): Add eap listing page
barshathakuri d46e199
feat(eap): update translation file
shreeyash07 6c9791a
fix(eap): update eap section according to new UI
shreeyash07 39a4657
fixup! fix(eap): update eap section according to new UI
shreeyash07 41eabdb
fixup! fix(eap): update eap section according to new UI
shreeyash07 b35db56
fixup! fix(eap): update eap section according to new UI
shreeyash07 3b86ec7
feat(eap): create timespan component
shreeyash07 1251d9f
fixup! feat(eap): create timespan component
shreeyash07 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
There are no files selected for viewing
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
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
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
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,7 @@ | ||
| { | ||
| "namespace": "common", | ||
| "strings": { | ||
| "timeframeLabel": "Timeframe", | ||
| "timespanLabel": "Time Span" | ||
| } | ||
| } |
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,128 @@ | ||
| import { useMemo } from 'react'; | ||
| import { | ||
| Checklist, | ||
| SelectInput, | ||
| } from '@ifrc-go/ui'; | ||
| import { useTranslation } from '@ifrc-go/ui/hooks'; | ||
| import { stringValueSelector } from '@ifrc-go/ui/utils'; | ||
| import { isNotDefined } from '@togglecorp/fujs'; | ||
|
|
||
| import i18n from './i18n.json'; | ||
|
|
||
| type Timeframe = 'hours' | 'days' | 'months' | 'years'; | ||
|
|
||
| type TimeframeOptions = { | ||
| key: Timeframe, | ||
| value: string, | ||
| } | ||
|
|
||
| type TimespanOptions = { | ||
| key: number, | ||
| value: string, | ||
| } | ||
|
|
||
| const timeframeOptions: TimeframeOptions[] = [ | ||
| { | ||
| key: 'hours', | ||
| value: 'Hours', | ||
| }, | ||
| { | ||
| key: 'days', | ||
| value: 'Days', | ||
| }, | ||
| { | ||
| key: 'months', | ||
| value: 'Months', | ||
| }, | ||
| { | ||
| key: 'years', | ||
| value: 'Years', | ||
| }, | ||
| ]; | ||
|
|
||
| function createTimespanOptions(range: number[]): TimespanOptions[] { | ||
| return range.map((num) => ({ | ||
| key: num, | ||
| value: String(num), | ||
| })); | ||
| } | ||
|
|
||
| const timespanOptionsMap: Record<Timeframe, TimespanOptions[]> = { | ||
| hours: createTimespanOptions(Array.from({ length: 25 }, (_, i) => i)), | ||
| days: createTimespanOptions(Array.from({ length: 31 }, (_, i) => i + 1)), | ||
| months: createTimespanOptions(Array.from({ length: 12 }, (_, i) => i + 1)), | ||
| years: createTimespanOptions(Array.from({ length: 10 }, (_, i) => i + 1)), | ||
| }; | ||
|
|
||
| function timeframeKeySelector(option: TimeframeOptions) { | ||
| return option.key; | ||
| } | ||
|
|
||
| function timeSpanKeySelector(option: TimespanOptions) { | ||
| return option.key; | ||
| } | ||
|
|
||
| export interface TimespanInputValue { | ||
| timeframe?: Timeframe; | ||
| timespan?: number[]; | ||
| } | ||
|
|
||
| interface Props { | ||
| value?: TimespanInputValue; | ||
| onChange: (value: TimespanInputValue) => void; | ||
| } | ||
|
|
||
| function TimespanInput(props: Props) { | ||
| const { | ||
| value, | ||
| onChange, | ||
| } = props; | ||
|
|
||
| const strings = useTranslation(i18n); | ||
|
|
||
| const timespanOptions = useMemo(() => { | ||
| if (isNotDefined(value?.timeframe)) { | ||
| return undefined; | ||
| } | ||
| return timespanOptionsMap[value?.timeframe]; | ||
tnagorra marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, [value?.timeframe]); | ||
|
|
||
| const handleTimeframeChange = (newTimeframe: Timeframe | undefined) => { | ||
| onChange({ | ||
| ...value, | ||
| timeframe: newTimeframe ?? 'months', | ||
| }); | ||
| }; | ||
|
|
||
| const handleTimespanChange = (newTimespan: number[] | undefined) => { | ||
| onChange({ | ||
| ...value, | ||
| timespan: newTimespan, | ||
| }); | ||
| }; | ||
|
|
||
| return ( | ||
| <> | ||
| <SelectInput | ||
| name="timeframe" | ||
| label={strings.timeframeLabel} | ||
| value={value?.timeframe} | ||
| onChange={handleTimeframeChange} | ||
| options={timeframeOptions} | ||
| keySelector={timeframeKeySelector} | ||
| labelSelector={stringValueSelector} | ||
| /> | ||
| <Checklist | ||
| name="timespan" | ||
| label={strings.timespanLabel} | ||
| value={value?.timespan} | ||
| options={timespanOptions} | ||
| keySelector={timeSpanKeySelector} | ||
| labelSelector={stringValueSelector} | ||
| onChange={handleTimespanChange} | ||
| /> | ||
| </> | ||
| ); | ||
| } | ||
|
|
||
| export default TimespanInput; | ||
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
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,9 @@ | ||
| { | ||
| "namespace":"accountMyFormsEap", | ||
| "strings":{ | ||
| "eapViewLabel": "View", | ||
| "eapEditLabel": "Edit", | ||
| "eapFormLink": "Start Full EAP", | ||
| "simplifiedEapLink": "Start sEAP" | ||
| } | ||
| } |
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.
The type of value does not match the type accepted by the backend.