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

[GH-66] Improve date format selection UI. Fixes #66 #86

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 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
9 changes: 6 additions & 3 deletions server/meeting.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var (
type Meeting struct {
ChannelID string `json:"channelId"`
Schedule []time.Weekday `json:"schedule"`
HashtagFormat string `json:"hashtagFormat"` // Default: {ChannelName}-Jan02
HashtagFormat string `json:"hashtagFormat"` // Default: {ChannelName}-Jan-2
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did the default change here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hashtags with - were returning no results for me, after some digging found out:
Screenshot_1
ref
2/5, our plugin should be database agnostic but not sure if I should include these changes in this PR.
@mickmister

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not able to reproduce this issue using postgress using #foo-02. Is there anything more specific case that causes issues?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Case was same, but issue appeared randomly.

}

// GetMeeting returns a meeting
Expand All @@ -37,9 +37,10 @@ func (p *Plugin) GetMeeting(channelID string) (*Meeting, error) {
if err != nil {
return nil, err
}
paddedChannelName := strings.ReplaceAll(channel.Name, "-", "_")
meeting = &Meeting{
Schedule: []time.Weekday{time.Thursday},
HashtagFormat: strings.Join([]string{fmt.Sprintf("%.15s", channel.Name), "{{ Jan02 }}"}, "-"),
HashtagFormat: strings.Join([]string{fmt.Sprintf("%.15s", paddedChannelName), "{{ Jan 2 }}"}, "_"),
ChannelID: channelID,
}
}
Expand Down Expand Up @@ -92,8 +93,10 @@ func (p *Plugin) GenerateHashtag(channelID string, nextWeek bool, weekday int) (
prefix = matchGroups[1]
hashtagFormat = strings.TrimSpace(matchGroups[2])
postfix = matchGroups[3]
formattedDate := meetingDate.Format(hashtagFormat)
formattedDate = strings.ReplaceAll(formattedDate, " ", "_")

hashtag = fmt.Sprintf("#%s%v%s", prefix, meetingDate.Format(hashtagFormat), postfix)
hashtag = fmt.Sprintf("#%s%v%s", prefix, formattedDate, postfix)
} else {
hashtag = fmt.Sprintf("#%s", meeting.HashtagFormat)
}
Expand Down
22 changes: 11 additions & 11 deletions server/meeting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ func TestPlugin_GenerateHashtag(t *testing.T) {
meeting: &Meeting{
ChannelID: "QA",
Schedule: []time.Weekday{time.Wednesday},
HashtagFormat: "{{Jan02}}",
HashtagFormat: "{{Jan 2}}",
}},
want: "#" + assertNextWeekdayDate(time.Wednesday, true).Format("Jan02"),
want: "#" + strings.ReplaceAll(assertNextWeekdayDate(time.Wednesday, true).Format("Jan 2"), " ", "_"),
wantErr: false,
},
{
Expand All @@ -67,9 +67,9 @@ func TestPlugin_GenerateHashtag(t *testing.T) {
meeting: &Meeting{
ChannelID: "QA Backend",
Schedule: []time.Weekday{time.Monday},
HashtagFormat: "QA-{{January 02 2006}}",
HashtagFormat: "QA_{{January 02 2006}}",
}},
want: "#QA-" + assertNextWeekdayDate(time.Monday, true).Format("January 02 2006"),
want: "#QA_" + strings.ReplaceAll(assertNextWeekdayDate(time.Monday, true).Format("January 02 2006"), " ", "_"),
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems like a big drive of certain changes involve avoiding dashes and using underscores instead, which is an opinionated approach that is not backwards compatible with existing agenda settings. Why is this change required?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

wantErr: false,
},
{
Expand All @@ -81,7 +81,7 @@ func TestPlugin_GenerateHashtag(t *testing.T) {
Schedule: []time.Weekday{time.Monday},
HashtagFormat: "{{January 02 2006}}.vue",
}},
want: "#" + assertNextWeekdayDate(time.Monday, false).Format("January 02 2006") + ".vue",
want: "#" + strings.ReplaceAll(assertNextWeekdayDate(time.Monday, false).Format("January 02 2006"), " ", "_") + ".vue",
wantErr: false,
},
{
Expand All @@ -93,7 +93,7 @@ func TestPlugin_GenerateHashtag(t *testing.T) {
Schedule: []time.Weekday{time.Monday},
HashtagFormat: "React {{January 02 2006}} Born",
}},
want: "#React " + assertNextWeekdayDate(time.Monday, false).Format("January 02 2006") + " Born",
want: "#React " + strings.ReplaceAll(assertNextWeekdayDate(time.Monday, false).Format("January 02 2006"), " ", "_") + " Born",
wantErr: false,
},
{
Expand All @@ -105,7 +105,7 @@ func TestPlugin_GenerateHashtag(t *testing.T) {
Schedule: []time.Weekday{time.Monday},
HashtagFormat: "January 02 2006 {{January 02 2006}} January 02 2006",
}},
want: "#January 02 2006 " + assertNextWeekdayDate(time.Monday, false).Format("January 02 2006") + " January 02 2006",
want: "#January 02 2006 " + strings.ReplaceAll(assertNextWeekdayDate(time.Monday, false).Format("January 02 2006"), " ", "_") + " January 02 2006",
wantErr: false,
},
{
Expand All @@ -117,7 +117,7 @@ func TestPlugin_GenerateHashtag(t *testing.T) {
Schedule: []time.Weekday{time.Monday},
HashtagFormat: "{{ January 02 2006 }}",
}},
want: "#" + assertNextWeekdayDate(time.Monday, false).Format("January 02 2006"),
want: "#" + strings.ReplaceAll(assertNextWeekdayDate(time.Monday, false).Format("January 02 2006"), " ", "_"),
wantErr: false,
},
{
Expand All @@ -129,7 +129,7 @@ func TestPlugin_GenerateHashtag(t *testing.T) {
Schedule: []time.Weekday{time.Monday},
HashtagFormat: "{{ Mon Jan _2 }}",
}},
want: "#" + assertNextWeekdayDate(time.Monday, false).Format("Mon Jan _2"),
want: "#" + strings.ReplaceAll(assertNextWeekdayDate(time.Monday, false).Format("Mon Jan _2"), " ", "_"),
wantErr: false,
},
}
Expand Down Expand Up @@ -176,7 +176,7 @@ func TestPlugin_GetMeeting(t *testing.T) {
},
want: &Meeting{
Schedule: []time.Weekday{time.Thursday},
HashtagFormat: "Short-{{ Jan02 }}",
HashtagFormat: "Short_{{ Jan 2 }}",
ChannelID: "#short.name.channel",
},
wantErr: false,
Expand All @@ -190,7 +190,7 @@ func TestPlugin_GetMeeting(t *testing.T) {
},
want: &Meeting{
Schedule: []time.Weekday{time.Thursday},
HashtagFormat: "Very Long Chann-{{ Jan02 }}",
HashtagFormat: "Very Long Chann_{{ Jan 2 }}",
ChannelID: "#long.name.channel",
},
wantErr: false,
Expand Down
76 changes: 59 additions & 17 deletions webapp/src/components/meeting_settings/meeting_settings.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ export default class MeetingSettingsModal extends React.PureComponent {
super(props);

this.state = {
hashtag: '{{Jan02}}',
hashtagPrefix: 'Prefix',
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have a way for the user to define their own date format that is used, like the feature currently works?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no, as per issue. IMO it is end goal to limit that.

weekdays: [1],
dateFormat: '1-2',
Copy link
Contributor

Choose a reason for hiding this comment

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

What does 1-2 mean?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great catch, seems like I missed this while separating commits, will fix this.

};
}

Expand All @@ -28,20 +29,30 @@ export default class MeetingSettingsModal extends React.PureComponent {
}

if (this.props.meeting && this.props.meeting !== prevProps.meeting) {
const splitResult = this.props.meeting.hashtagFormat.split('{{');// we know, date Format is preceded by {{
const hashtagPrefix = splitResult[0];
const dateFormat = splitResult[1].substring(0, splitResult[1].length - 2); // remove trailing }}
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we trust that this.props.meeting.hashtagFormat is a correctly formatted string? i.e. it has {{ and }}

Also if it's an existing agenda setting that is made before this PR, do we know that dateFormat will be equal to one of the available options?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For the new ones, yes. Since we are assigning value from controlled values.
no, if any unknown value is there. 1st value from the list is used.

// eslint-disable-next-line react/no-did-update-set-state
this.setState({
hashtag: this.props.meeting.hashtagFormat,
hashtagPrefix,
dateFormat,
weekdays: this.props.meeting.schedule || [],
});
}
}

handleHashtagChange = (e) => {
this.setState({
hashtag: e.target.value,
hashtagPrefix: e.target.value,
});
}

handleDateFormat = (event) => {
this.setState({
dateFormat: event.target.value,
});
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we be consistent and use e in both of these cases, instead of using event here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure, will do that.


handleCheckboxChanged = (e) => {
const changeday = Number(e.target.value);
let changedWeekdays = Object.assign([], this.state.weekdays);
Expand All @@ -62,7 +73,7 @@ export default class MeetingSettingsModal extends React.PureComponent {
onSave = () => {
this.props.saveMeetingSettings({
channelId: this.props.channelId,
hashtagFormat: this.state.hashtag,
hashtagFormat: `${this.state.hashtagPrefix}{{${this.state.dateFormat}}}`,
schedule: this.state.weekdays.sort(),
});

Expand Down Expand Up @@ -118,19 +129,50 @@ export default class MeetingSettingsModal extends React.PureComponent {
</div>
</div>
<div className='form-group'>
<label className='control-label'>{'Hashtag Format'}</label>
<input
onChange={this.handleHashtagChange}
className='form-control'
value={this.state.hashtag ? this.state.hashtag : ''}
/>
<p className='text-muted pt-1'> {'Hashtag is formatted using the '}
<a
target='_blank'
rel='noopener noreferrer'
href='https://godoc.org/time#pkg-constants'
>{'Go time package.'}</a>
{' Embed a date by surrounding what January 2, 2006 would look like with double curly braces, i.e. {{Jan02}}'}
<div style={{display: 'flex'}}>
Copy link
Contributor

Choose a reason for hiding this comment

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

What does setting this value do in this case? It doesn't look like there are any alignItems, justifyContent, etc. rules being applied in the element's children.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, this expands items to fill available free space or shrinks them to prevent overflow.

<div
className='fifty'
style={{padding: '5px'}}
>
<label className='control-label'>{'Hashtag Prefix'}</label>
<input
onChange={this.handleHashtagChange}
className='form-control'
value={this.state.hashtagPrefix ? this.state.hashtagPrefix : ''}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
value={this.state.hashtagPrefix ? this.state.hashtagPrefix : ''}
value={this.state.hashtagPrefix || ''}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay

/>
</div>
<div
className='fifty'
style={{padding: '5px'}}
>
<label className='control-label'>{'Date Format'}</label>
<br/>
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we able to accomplish this with css instead of using <br/>?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure

Choose a reason for hiding this comment

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

@mickmister removed <br/> tag and there was no affect on design.

<select
name='format'
value={this.state.dateFormat}
onChange={this.handleDateFormat}
style={{height: '35px', border: '1px solid #ced4da'}}
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this be done using an scss file rather than using style directly? If you have questions on this, please ask on the Mattermost community server

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, will move all css to scss.

className='form-select'
>
<option value='Jan 2'>{'month_day'}</option>
<option value='2 Jan'>{'day_month'}</option>
<option value='1 2'>{'month_day'}</option>
<option value='2 1'>{'day_month'}</option>
<option value='2006 1 2'>{'year_month_day'}</option>
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do the values have spaces instead of underscores?

Copy link
Contributor Author

@sanjaydemansol sanjaydemansol Oct 5, 2021

Choose a reason for hiding this comment

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

because underscore has special significance for go time package, which we use. Hence we have this workaround for swapping _ with .


Copy link
Contributor

Choose a reason for hiding this comment

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

This empty line can be removed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure

</select>
</div>
</div>

<p className='text-muted pt-1'>
<div
className='alert alert-warning'
role='alert'
style={{marginBottom: '3px'}}
>
{'Prefixes may use underscore'}<code>{'_'}</code>{'.'} {'Other special characters including'} <code>{'-'}</code> {'are not allowed.'}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this a requirement?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

</div>
{'Date would be appended to Hashtag Prefix, according to the chosen format.'}
</p>
</div>
</Modal.Body>
Expand Down