Skip to content
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

fix: range without end #63

Merged
merged 3 commits into from
Jun 25, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions src/js/timepicker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -732,24 +732,32 @@ var TimePicker = defineClass(
*/
setRangeMinute: function(beginHour, beginMin, endHour, endMin) {
var disabledMinRanges = [];

if (!beginHour && !beginMin) {
return;
}

disabledMinRanges.push({
begin: START_NUMBER_OF_TIME,
end: beginMin
});

if (endMin) {
if (endHour && endMin) {
disabledMinRanges.push({
begin: endMin,
end: END_NUMBER_OF_MINUTE
});
}

if (disabledMinRanges.length > 1 && beginHour === endHour) {
this.disabledMinutes[beginHour] = util.getDisabledMinuteArr(disabledMinRanges).concat();
} else {
this.disabledMinutes[beginHour] = util.getDisabledMinuteArr([disabledMinRanges[0]]).concat();
if (beginHour === endHour) {
this.disabledMinutes[beginHour] = util.getDisabledMinuteArr(disabledMinRanges).concat();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

concat()을 μ‚¬μš©ν•œ μ΄μœ κ°€.. 배열을 λ³΅μ‚¬ν•˜κΈ° μœ„ν•œ μš©λ„λ‘œ μ‚¬μš©λœ κ²ƒμΈκ°€μš”~?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

볡사 μš©λ„κ°€ λ§žλ‹€λ©΄ concat() λ³΄λ‹€λŠ” slice(0)을 μ‚¬μš©ν•˜λŠ” 것이 쒋을 것 κ°™μŠ΅λ‹ˆλ‹€. concat()은 배열을 μ—°κ²°ν•˜λŠ” λͺ©μ μ˜ ν•¨μˆ˜μ΄κΈ° ν˜„μž¬ μ‚¬μš© μ˜λ„μ™€λŠ” λ§žμ§€ μ•Šμ•„λ³΄μ—¬μš”~

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

λ‹€λ₯Έ μ½”λ“œμ—μ„œ μ €λ ‡κ²Œ μ‚¬μš©ν•˜λŠ” 것을 보고 λ°°μ—΄ 볡사 μ‹œ concat()을 μ‚¬μš©ν•˜λŠ” κ²ƒμœΌλ‘œ μ˜€ν•΄ν–ˆμŠ΅λ‹ˆλ‹€.
λ°°μ—΄ 볡사λ₯Ό λͺ©μ μœΌλ‘œ ν•˜λŠ” κ΅¬λ¬Έμ—μ„œλŠ” slice(0)λ₯Ό μ‚¬μš©ν•˜λŠ” κ²ƒμœΌλ‘œ μˆ˜μ •ν•˜κ² μŠ΅λ‹ˆλ‹€!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

참고둜 λ°°μ—΄ 전체 λ³΅μ‚¬λŠ” κ·Έλƒ₯ slice() 만 해도 λΌμš”


return;
}

this.disabledMinutes[endHour] = util.getDisabledMinuteArr([disabledMinRanges[1]]).concat();
}

this.disabledMinutes[beginHour] = util.getDisabledMinuteArr([disabledMinRanges[0]]).concat();
},

/**
Expand Down
23 changes: 23 additions & 0 deletions test/timepicker/timepicker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,29 @@ describe('Set selectable range', function() {
});
});

it('should set selectable range with only begin', function() {
var start = makeRangeObj(9, 30);
var selector, hourSelect, minSelect, selectOption;

timepickerNoMeridiem.setRange(start);

selector = timepickerNoMeridiem.element.querySelectorAll('select[aria-label="Time"]');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

μ‹€μ œ λ³€μˆ˜μ— ν• λ‹Ήλ˜λŠ” 결과물을 μƒκ°ν•˜λ©΄ selectBoxes 정도가 λ³€μˆ˜ μ΄λ¦„μœΌλ‘œ μ μ ˆν•΄λ³΄μ΄λ„€μš”.

hourSelect = selector[0];
minSelect = selector[1];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[hourSelect, minSelect] = selector둜 쀄이면 쒋을 것 κ°™μŠ΅λ‹ˆλ‹€.


selectOption = hourSelect.querySelector('option[value="8"]');
expect(selectOption.disabled).toBe(true);
selectOption = hourSelect.querySelector('option[value="9"]');
expect(selectOption.disabled).toBe(false);

timepickerNoMeridiem.setTime(9, 0);

selectOption = minSelect.querySelector('option[value="30"]');
expect(selectOption.disabled).toBe(true);
selectOption = minSelect.querySelector('option[value="31"]');
expect(selectOption.disabled).toBe(false);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ν…ŒμŠ€νŠΈλ‘œ μ»€λ²„ν•˜κ³ μž ν•˜λŠ” λ²”μœ„κ°€ 더 λͺ…ν™•ν–ˆμœΌλ©΄ μ’‹κ² μŠ΅λ‹ˆλ‹€.
μš°λ¦¬κ°€ μ•Œκ³ μž ν•˜λŠ” 것은 '(μ‹œκ°„ μ„ νƒμ˜ 경우) 8κΉŒμ§€λŠ” λͺ¨λ‘ disabled 이고, 9λΆ€ν„°λŠ” λͺ¨λ‘ enabled 이닀' μž…λ‹ˆλ‹€.
그런데 λ‹¨μˆœνžˆ 뢄기점 ν•˜λ‚˜λ§Œ 두고 이게 μ •μƒμ μœΌλ‘œ λ™μž‘ν•˜λŠ”μ§€ 보μž₯ν•˜λŠ” 것은 어폐가 μžˆμ–΄ λ³΄μ΄λ„€μš”.

querySelectorAll 을 톡해 λͺ¨λ“  μ˜΅μ…˜μ„ κ°€μ Έμ˜¨ λ’€, 1 ~ 8κΉŒμ§€ 자λ₯΄κ³ , 9 ~ 12κΉŒμ§€ 자λ₯Έ λ‹€μŒ 각각의 배열이 μ›ν•˜λŠ” disabled 값을 가지고 μžˆλŠ”μ§€ toMatchObject 단언을 ν™œμš©ν•΄λ³΄λ©΄ μ’‹κ² μŠ΅λ‹ˆλ‹€.

Copy link

@js87zz js87zz Jun 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hourSelectκ°€ minSelect λ‘˜λ‹€ 같이 κ²€μ¦λ˜μ–΄μ•Ό ν•˜λŠ”κ±΄κ°€μš”? λ§Œμ•½ 그게 μ•„λ‹ˆλΌλ©΄ λ‚˜λˆ„μ–΄μ„œ κ²€μ¦ν•˜λŠ”κ²Œ 쒋을 것 κ°™μŠ΅λ‹ˆλ‹€. 그리고 μ‹œκ°„μ΄λ‚˜ 뢄을 λ²”μœ„ λ³„λ‘œ 검증(disabled κ°’)ν•΄μ•Ό ν•œλ‹€λ©΄, μœ„μ˜ 리뷰처럼 λ²”μœ„ 전체λ₯Ό 검증해야 μ •ν™•ν•˜κ² λ„€μš”~! ν…ŒμŠ€νŠΈμ—μ„œ ν΄λž˜μŠ€λ‚˜ 속성에 μ˜ν•΄ 자주 λ³€κ²½λ˜λŠ” μš”μ†Œκ°€ μ•„λ‹ˆλΌλ©΄ jest μŠ€λƒ…μƒ· ν…ŒμŠ€νŠΈλ₯Ό μ μš©ν•˜λŠ” 것도 쒋을 것 κ°™μ•„μš”.(λ§Œμ•½ 그렇지 μ•Šλ‹€λ©΄, toMatchObjectλ₯Ό μ“°λŠ”κ²Œ μ’‹κ² κ΅¬μš”)

});

it('should disable a meridiem selector when range included in the other', function() {
var start = makeRangeObj(6, 30);
var end = makeRangeObj(11, 30);
Expand Down