-
Notifications
You must be signed in to change notification settings - Fork 89
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
Allow strings for disabled days time picker #152
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 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 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
23 changes: 23 additions & 0 deletions
23
packages/pf3-component-mapper/src/form-fields/date-time-picker/helpers.js
This file contains 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,23 @@ | ||
const createDateObject = value => { | ||
if (value === 'today') { | ||
return new Date(); | ||
} | ||
|
||
if (typeof value === 'string') { | ||
return new Date(value); | ||
} | ||
|
||
return value; | ||
}; | ||
|
||
export const createDisabledDays = disabledDays => disabledDays.map(item => { | ||
if (typeof item === 'object' && !(item instanceof Date) && !Array.isArray(item)) { | ||
|
||
return Object.keys(item).reduce((acc, curr) => ({ | ||
...acc, | ||
[curr]: createDateObject(item[curr]), | ||
}), {}); | ||
} | ||
|
||
return createDateObject(item); | ||
}); |
56 changes: 56 additions & 0 deletions
56
packages/pf3-component-mapper/src/tests/form-fields/date-time-picker/helpers.test.js
This file contains 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,56 @@ | ||
import { createDisabledDays } from '../../../form-fields/date-time-picker/helpers'; | ||
|
||
describe('<DateTimePicker /> helpers', () => { | ||
it('should convert string into Date object', () => { | ||
const inputValue = [ | ||
'Tue Oct 08 2019 13:27:20 GMT+0200 (Central European Summer Time)', | ||
'1995-12-18T03:24:00', | ||
new Date(), | ||
]; | ||
const expectedValue = [ | ||
expect.any(Date), | ||
expect.any(Date), | ||
expect.any(Date), | ||
]; | ||
|
||
const output = createDisabledDays(inputValue); | ||
expect(output).toEqual(expectedValue); | ||
expect(output[0].getFullYear()).toEqual(2019); | ||
expect(output[1].getFullYear()).toEqual(1995); | ||
expect(output[1].getDay()).toEqual(1); | ||
expect(output[1].getMonth()).toEqual(11); | ||
}); | ||
|
||
it('should return Date object if used alias today', () => { | ||
const inputValue = [ | ||
'today', | ||
]; | ||
const expectedValue = [ | ||
expect.any(Date), | ||
]; | ||
|
||
const output = createDisabledDays(inputValue); | ||
expect(output).toEqual(expectedValue); | ||
}); | ||
|
||
it('should return range object with correct keys', () => { | ||
const inputValue = [ | ||
{ | ||
before: 'Tue Oct 08 2019 13:27:20 GMT+0200 (Central European Summer Time)', | ||
after: '1995-12-18T03:24:00', | ||
|
||
}, | ||
new Date(), | ||
]; | ||
const expectedValue = [ | ||
{ | ||
before: expect.any(Date), | ||
after: expect.any(Date), | ||
}, | ||
expect.any(Date), | ||
]; | ||
|
||
const output = createDisabledDays(inputValue); | ||
expect(output).toEqual(expectedValue); | ||
}); | ||
}); |
This file contains 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
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.
What this line actually means? Is it that you can't select today in the picker? Would it disable any date befor today if I write
before: 'today'
below?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.
http://react-day-picker.js.org/api/DayPicker#disabledDays
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.
We are using this component. There is a link in the componentApi docs for date time picker
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.
Yeah, this doesn't really answer my question, but I tested it and it works:
This doesn't allow me to select any date in the future and that's the thing I want the most from this PR 😉