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

feat(datepicker): Add initial view setting #221

Closed

Conversation

trevordaniels
Copy link
Contributor

@trevordaniels trevordaniels commented Aug 8, 2017

Partially addresses #165
Not sure if you want to expose CalendarViewType, or create a new export type similar to DatepickerMode

@harogaston
Copy link
Contributor

Did you check what happens if initialView is not in the keys of config.mappings.changed?
What I mean is the initialVIew must be part of the views asociated with the datepicker mode. For instance initialView=minute is not compatible with datepicker mode=year.

Does it behave well under those conditions? Otherwise a check must be added.

@trevordaniels
Copy link
Contributor Author

Added a check to ensure the view exists in mappings.changed

@harogaston
Copy link
Contributor

Nice, I mentioned it because I had already been thinking about implementing this. Keep it up!

@trevordaniels
Copy link
Contributor Author

I appreciate your feedback, hope you hadn't started on it!

Copy link
Owner

@edcarroll edcarroll left a comment

Choose a reason for hiding this comment

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

Thank you for the PR 🎉 Just a couple of things I've highlighted in the review comments 😄

@@ -112,6 +119,13 @@ export class DatepickerPage {
defaultValue: "0"
},
{
name: "pickerInitialView",
type: "CalendarViewType",
description: "Specifies the initial view for the datepicker. Options are: <code>CalendarViewType.Year</code>, " +
Copy link
Owner

Choose a reason for hiding this comment

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

For the options list, use their string values rather than the enum references

Copy link
Contributor Author

Choose a reason for hiding this comment

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

From my understanding, because CalendarViewType is an enum

export enum CalendarViewType {
    Year = 0, ... 
}

there are no string equivalent values to use. For eg. this is not allowed

<suiDatepicker pickerInitialView="year">

To use string values instead of enums, a new type would need to be created similar to DatepickerMode

export type DatepickerMode = "year" | "month" | "date" | "datetime" | "time";
export const DatepickerMode = {
    Year: "year" as DatepickerMode, ...
}

What is your preferred option?

Copy link
Owner

Choose a reason for hiding this comment

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

Ahh I see, sorry completely forgot the fact that it was just an enum! Turning it into a string enum is definitely the way foward, as then it can be easily used in HTML

Copy link
Owner

Choose a reason for hiding this comment

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

alas TS 2.4.1 support still isn't in Angular when using strict null checks so the "enum" solution is still the best way

public set initialView(view:CalendarViewType) {
if (this.changed && this.changed.has(view)) {
this._initialView = view;
}
Copy link
Owner

Choose a reason for hiding this comment

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

Perhaps throw an error here?

@@ -32,6 +33,19 @@ export class SuiDatepickerDirective
this.onSelectedDateChange.emit(date);
}

private _initialView:CalendarViewType;
Copy link
Owner

Choose a reason for hiding this comment

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

Should be nullable

@@ -60,6 +74,9 @@ export class SuiDatepickerDirective
this.config = new TimeConfig();
break;
}
if (this._initialView != undefined) {
Copy link
Owner

Choose a reason for hiding this comment

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

Thoughts on making initialView?:CalendarViewType a constructor parameter of CalendarMapping?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean a parameter on CalendarMappings? so it can be used like

export class DateMappings extends CalendarMappings {
    constructor(initialView?:CalendarViewType) {
        super(initialView || CalendarViewType.Date);

Copy link
Owner

Choose a reason for hiding this comment

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

Exactly, though do this instead:

export class DateMappings extends CalendarMappings {
    constructor(initialView:CalendarViewType = CalendarViewType.Date) {
        super(initialView);

@@ -1,4 +1,5 @@
export {
SuiDatepickerModule,
DatepickerMode
DatepickerMode,
CalendarViewType
Copy link
Owner

Choose a reason for hiding this comment

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

Export as DatepickerViewType for consistency

@@ -1,6 +1,6 @@
import { Component } from "@angular/core";
import { ApiDefinition } from "../../../components/api/api.component";
import { DatepickerMode } from "../../../../../../src/public";
import { DatepickerMode, CalendarViewType } from "../../../../../../src/public";
Copy link
Owner

Choose a reason for hiding this comment

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

DatepickerViewType (see bottom)

@@ -112,6 +119,13 @@ export class DatepickerPage {
defaultValue: "0"
},
{
name: "pickerInitialView",
type: "CalendarViewType",
Copy link
Owner

Choose a reason for hiding this comment

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

DatepickerViewType (see bottom)

@edcarroll edcarroll modified the milestone: 0.9.5 Aug 11, 2017
@edcarroll edcarroll modified the milestones: 0.9.6, 0.9.5 Aug 14, 2017
@trevordaniels trevordaniels closed this by deleting the head repository Apr 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants