themesberg / flowbite-react

Official React components built for Flowbite and Tailwind CSS
https://flowbite-react.com
MIT License
1.82k stars 406 forks source link

Feat/date value datepicker #1190

Open ddiasfront opened 8 months ago

ddiasfront commented 8 months ago

It was added a new property called dateValue, which directly modifies the date inside of the datepicker whenever it's necessary, also the view is set to this selected date, automatically, independently from the type of view.

It closes #1187 #1055 #1039 #1167

The prop added is merely optional and will not cause any breaking change, test coverage is basically set and documentation is covered as well.

Summary by CodeRabbit

vercel[bot] commented 8 months ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
flowbite-react ❌ Failed (Inspect) Aug 13, 2024 11:40am
flowbite-react-storybook ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 13, 2024 11:40am
codecov[bot] commented 8 months ago

Codecov Report

Attention: Patch coverage is 80.55556% with 7 lines in your changes are missing coverage. Please review.

Project coverage is 97.36%. Comparing base (7461173) to head (baed714). Report is 245 commits behind head on main.

:exclamation: Current head baed714 differs from pull request most recent head 2070c8b

Please upload reports for the commit 2070c8b to get more accurate results.

Files Patch % Lines
src/components/Datepicker/Datepicker.tsx 90.00% 3 Missing :warning:
src/components/Datepicker/Views/Decades.tsx 0.00% 2 Missing :warning:
src/components/Datepicker/Views/Months.tsx 0.00% 1 Missing :warning:
src/components/Datepicker/Views/Years.tsx 0.00% 1 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #1190 +/- ## ========================================== - Coverage 99.54% 97.36% -2.19% ========================================== Files 163 214 +51 Lines 6621 9091 +2470 Branches 401 542 +141 ========================================== + Hits 6591 8851 +2260 - Misses 30 240 +210 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

ddiasfront commented 8 months ago

Hey @rluders , I guess now it is ready for review, could please czech it out ?

SutuSebastian commented 8 months ago

@ddiasfront I see some formatting issues

ddiasfront commented 8 months ago

@SutuSebastian Can you describe it, please? I didn't see any formatting issues regarding the date itself, is it on the date or another stuff?

SutuSebastian commented 8 months ago

@SutuSebastian Can you describe it, please? I didn't see any formatting issues regarding the date itself, is it on the date or another stuff?

Apparently u fixed it with the last commits :D

The build failed, and inside the build fail output there was the formatting issue AFAIR.

ddiasfront commented 8 months ago

@rluders , @SutuSebastian Okay guys, now I've fixed the issues bellow as well, including the clear functionality:

1187 #1055 #1039 #1167

In the clear functionality scenario, I had to add a label property to be rendered whenever there's no date selected, and i set it to default "No date selected", please check it out.

bcostaaa01 commented 7 months ago

Thanks for looking at the issue I opened and hats off to you for the fix @ddiasfront 🚀

rluders commented 7 months ago

@ddiasfront could you rebase it with main branch?

ddiasfront commented 7 months ago

@ddiasfront could you rebase it with main branch?

Dun

tulup-conner commented 7 months ago

@ddiasfront Can you let us know when you're ready for a re-review? Just want to make sure before I dive in

ddiasfront commented 7 months ago

@ddiasfront Can you let us know when you're ready for a re-review? Just want to make sure before I dive in

It is all set @tulup-conner, @rluders , @SutuSebastian

ddiasfront commented 7 months ago

@tulup-conner Changes dun, check the last commit, please.

ddiasfront commented 7 months ago

Please check it out when you have some time @rluders? Would be glad to receive any feedback, or even pair if you want to :)

vipertecpro commented 7 months ago

It's been more than two weeks....Please help us

ddiasfront commented 7 months ago

@SutuSebastian @rluders @tulup-conner any comments ?

vipertecpro commented 7 months ago

i know that this issue is already been created here : https://github.com/themesberg/flowbite-react/issues/1187#issue-2041570898 Here is how i am using it and it is working great along with formik validation

<Datepicker
  id={'start_date'}
  name={'start_date'}
  minDate={new Date()}
  onSelectedDateChanged={(date) => {
      if(date) {
          setFormDefaultValues({
              ...formDefaultValues,
              start_date: date ? moment(date).format('YYYY-MM-DD') : ''
          });
          formik.setFieldValue('start_date', moment(date).format('YYYY-MM-DD'));
          formik.setFieldTouched('start_date');
      }
  }}
  defaultDate={formDefaultValues.start_date ? new Date(moment(formDefaultValues.start_date).format('YYYY-MM-DD')) : new Date()}
  className={`rounded-lg ${formik.touched.start_date && formik.errors.start_date ? 'bg-red-50 border border-red-500 text-red-900' : ''}`}
  value={formDefaultValues.start_date ? new Date(moment(formDefaultValues.start_date).format('YYYY-MM-DD')).toDateString() : new Date().toDateString()}
/>

Now here is the problem :

  1. datepicker popup doesn't select defaultValue as selected

Screenshot 2024-01-01 215521

  1. How do i setup date in a particular format like his YYYY-MM-DD

So is it possible for us to improve this interface

export interface DatepickerProps extends Omit<TextInputProps, 'theme'> {
    open?: boolean;
    inline?: boolean;
    autoHide?: boolean;
    showClearButton?: boolean;
    labelClearButton?: string;
    showTodayButton?: boolean;
    labelTodayButton?: string;
    defaultDate?: Date;
    minDate?: Date;
    maxDate?: Date;
    language?: string;
    weekStart?: WeekStart;
    theme?: DeepPartial<FlowbiteDatepickerTheme>;
    onSelectedDateChanged?: (date: Date) => void;
}

and add few more attribute like format which is the most conmanly used and it is DATE picker so there is has nothing to do with the time as well, here is the little tip to anyone who is using prisma ORM along with mysql and want to store only date then update this

  start_date                DateTime   @default(now()) @db.Date
  end_date                  DateTime   @default(now()) @db.Date
knom commented 6 months ago

This feature is super crucial.. seems we cannot set a VALUE otherwise (e.g. for update scenarios)?

PLEASE.. can you folks review /re-merge it? :-)

rluders commented 6 months ago

Hey, @knom this PR still needs some extra work before getting merged. Hopefully, @ddiasfront didn't drop it. :)

knom commented 6 months ago

Thanks @rluders.

Anything I can do to help? Like do some of the merges, fixes?

rnicholus commented 4 months ago

what's remaining here that's blocking a merge? the only unresolved comments don't appear to be blockers

ddiasfront commented 3 months ago

I'm catchin up with @vipertecpro and @SutuSebastian to close this one asap

changeset-bot[bot] commented 3 months ago

⚠️ No Changeset found

Latest commit: 2adc9694c05809308f7c474209bbd5897a7f854a

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

coderabbitai[bot] commented 3 months ago

Walkthrough

The Datepicker component has been enhanced to support controlled inputs via the value and defaultValue props, improving state management and customization options. These changes allow for programmatic updates to the selected date without requiring manual clicks, thus addressing various usability scenarios.

Changes

Files/Paths Change Summary
apps/web/content/docs/components/datepicker.mdx Added a section on controlled <Datepicker /> usage with value prop and handling of null values.
packages/ui/src/components/Datepicker/Datepicker.stories.tsx Improved Datepicker stories with new value, defaultValue, and label control types; adjusted logic for clarity and added new story variants.
packages/ui/src/components/Datepicker/Datepicker.tsx Introduced customValue and label props; optimized state management with useMemo and useEffect for better handling of selected and view dates.
packages/ui/src/components/Datepicker/DatepickerContext.tsx Changed selectedDate type to Date | null in DatepickerContextProps to allow representation of no date selected.
packages/ui/src/components/Datepicker/Views/Days.tsx Enhanced isSelected logic to check if selectedDate is truthy before comparison with currentDate.
packages/ui/src/components/Datepicker/Views/Decades.tsx Improved click handler to verify selectedDate exists before updating the view date.
packages/ui/src/components/Datepicker/Views/Months.tsx Updated month selection logic to ensure selectedDate is not null before comparison using isDateEqual.
packages/ui/src/components/Datepicker/Views/Years.tsx Enhanced year selection logic by checking if selectedDate is defined before comparison with newDate.
src/components/Datepicker/Datepicker.spec.tsx Introduced comprehensive unit tests for various date handling scenarios in the Datepicker component.

Assessment against linked issues

Objective Addressed Explanation
Datepicker only changes on manual click (#1187)

In fields of code, where dates now dance,
Controlled by props, they take their stance.
With value set, no click's demand,
The Datepicker's magic, at your command.
Null clears the way, like a gentle breeze,
A rabbit's touch, coding with ease. 🐇


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)
Tips ### Chat There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): - Review comments: Directly reply to a review comment made by CodeRabbit. Example: - `I pushed a fix in commit .` - `Generate unit testing code for this file.` - `Open a follow-up GitHub issue for this discussion.` - Files and specific lines of code (under the "Files changed" tab): Tag `@coderabbitai` in a new review comment at the desired location with your query. Examples: - `@coderabbitai generate unit testing code for this file.` - `@coderabbitai modularize this function.` - PR comments: Tag `@coderabbitai` in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples: - `@coderabbitai generate interesting stats about this repository and render them as a table.` - `@coderabbitai show all the console.log statements in this repository.` - `@coderabbitai read src/utils.ts and generate unit testing code.` - `@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.` - `@coderabbitai help me debug CodeRabbit configuration file.` Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. ### CodeRabbit Commands (invoked as PR comments) - `@coderabbitai pause` to pause the reviews on a PR. - `@coderabbitai resume` to resume the paused reviews. - `@coderabbitai review` to trigger an incremental review. This is useful when automatic reviews are disabled for the repository. - `@coderabbitai full review` to do a full review from scratch and review all the files again. - `@coderabbitai summary` to regenerate the summary of the PR. - `@coderabbitai resolve` resolve all the CodeRabbit review comments. - `@coderabbitai configuration` to show the current CodeRabbit configuration for the repository. - `@coderabbitai help` to get help. Additionally, you can add `@coderabbitai ignore` anywhere in the PR description to prevent this PR from being reviewed. ### CodeRabbit Configuration File (`.coderabbit.yaml`) - You can programmatically configure CodeRabbit by adding a `.coderabbit.yaml` file to the root of your repository. - Please see the [configuration documentation](https://docs.coderabbit.ai/guides/configure-coderabbit) for more information. - If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: `# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json` ### Documentation and Community - Visit our [Documentation](https://coderabbit.ai/docs) for detailed information on how to use CodeRabbit. - Join our [Discord Community](https://discord.com/invite/GsXnASn26c) to get help, request features, and share feedback. - Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.
ddiasfront commented 4 days ago

Hello @tulup-conner , @SutuSebastian , @rluders can you guys give the green light here ? I'm seeing tests failing at the main branch here, is that alright ?