-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Add incident column for when an incident occurred at #2212
Conversation
@@ -110,7 +110,7 @@ | |||
'component_status' => 'nullable|required_with:component_id|int|min:0|max:4', | |||
'notify' => 'nullable|bool', | |||
'stickied' => 'required|bool', | |||
'incident_date' => 'nullable|string', | |||
'occurredAt' => 'nullable|string', |
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.
I reckon we should move to camelCase
but I also reckon it should be done in it's own PR rather than just leaving random bits here and there.
if ($occurredAt = $command->occurredAt) { | ||
if ($date = $this->dates->create('Y-m-d H:i', $occurredAt)) { | ||
$incident->fill(['occurred_at' => $date]); | ||
} else { |
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.
Guard > else
- looks messy imo
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.
Also, the exception doesn't do anything here, because create
will throw, so we need to catch.
])->orderBy('created_at', 'desc')->get()->groupBy(function (Incident $incident) { | ||
return (new Date($incident->created_at)) | ||
])->orderBy('occurred_at', 'desc')->get()->groupBy(function (Incident $incident) { | ||
return (new Date($incident->occurred_at)) |
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.
Could we not use the presenter here?
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.
I was thinking this when I was looking at it this morning.
@@ -80,12 +85,12 @@ private function feedAction(ComponentGroup &$group, $isRss) | |||
{ | |||
if ($group->exists) { | |||
$group->components->map(function ($component) use ($isRss) { | |||
$component->incidents()->visible()->orderBy('created_at', 'desc')->get()->map(function ($incident) use ($isRss) { | |||
$component->incidents()->visible()->orderBy('occurred_at', 'desc')->get()->map(function ($incident) use ($isRss) { |
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.
Long line is long 😛
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.
I should add a better scope for this.
@@ -109,7 +109,7 @@ public function showIndex() | |||
->withDaysToShow($daysToShow) | |||
->withAllIncidents($allIncidents) | |||
->withCanPageForward((bool) $today->gt($startDate)) | |||
->withCanPageBackward(Incident::notScheduled()->where('created_at', '<', $startDate->format('Y-m-d'))->count() > 0) | |||
->withCanPageBackward(Incident::notScheduled()->where('occurred_at', '<', $startDate->format('Y-m-d'))->count() > 0) |
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.
Do we even need to format $startDate
?
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.
Dunno.
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.
Yes, because occurred_at
might contain a time, but we're only interested in whole days.
*/ | ||
public function occurred_at() | ||
{ | ||
return app(DateFactory::class)->make($this->wrappedObject->occurred_at)->toDateTimeString(); |
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.
Off topic but is there any reason we don't just inject the DateFactory?
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.
Laziness.
{ | ||
return ucfirst(app(DateFactory::class)->make($this->wrappedObject->created_at)->format(Config::get('setting.incident_date_format', 'l jS F Y H:i:s'))); | ||
return ucfirst(app(DateFactory::class)->make($this->wrappedObject->occurred_at)->format(Config::get('setting.incident_date_format', 'l jS F Y H:i:s'))); |
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.
This seems overly complex / long. QoL goes down.
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.
👍
*/ | ||
public function created_at_formatted() | ||
{ | ||
return ucfirst(app(DateFactory::class)->make($this->wrappedObject->created_at)->format(Config::get('setting.incident_date_format', 'l jS F Y H:i:s'))); |
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.
Same as previous.
*/ | ||
function datetime_to_moment($format) | ||
{ | ||
$replacements = [ |
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.
This is just bizarre. I see it's point tho 😆
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.
I didn't end up using this, but I like it, so I'm keeping it because I probably will use this at some point.
@@ -7,7 +7,7 @@ | |||
@stop | |||
|
|||
@section('content') | |||
<h1>{{ $incident->name }} <small>{{ formatted_date($incident->created_at) }}</small></h1> | |||
<h1>{{ $incident->name }} <small>{{ formatted_date($incident->occurred_at) }}</small></h1> |
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.
Why are we not using the presenter here?
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.
I noticed this too, dunno why.
Let's merge and see what happens 👍 there might be an edge-case I've missed. |
Closes #2208
This does change the API requests, as we're now looking for a field called
occurred_at
instead ofincident_date
, or whatever.