-
Notifications
You must be signed in to change notification settings - Fork 18
Snapshot scheduler #97
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
Conversation
|
| @@ -1,4 +1,4 @@ | |||
| import { AEM_ORIGIN } from '../../../public/utils/constants.js'; | |||
| import { AEM_ORIGIN, SNAPSHOT_SCHEDULER_URL } from '../../../public/utils/constants.js'; | |||
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.
If nothing else is using this, I would keep this internal to this file.
| if (!utcDate) return ''; | ||
| const d = new Date(utcDate); | ||
| return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}T${String(d.getHours()).padStart(2, '0')}:${String(d.getMinutes()).padStart(2, '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.
We have functions that already do this in our preferred formats that are also international friendly.
export function formatDate(timestamp) {
const rawDate = timestamp ? new Date(timestamp) : new Date();
const date = rawDate.toLocaleDateString([], { year: 'numeric', month: 'short', day: 'numeric' });
const time = rawDate.toLocaleTimeString([], { hour: 'numeric', minute: '2-digit' });
return { date, time };
}
EDIT: I just realized you may be doing this to get into a format you need for datatime-local input. For some reason all the string concating rubs me the wrong way, but it's not a hill I would die on.
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 would probably return null.
Loosely:
- If DA / NX gives you
nullwe purposefully did this based on input supplied. - If DA / NX gives you
undefined"something" in the machine is truly undefined. - If DA / NX gives you an empty string... it's fairly rare and likely only because we need to concat a 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.
Same addition as above... if the input cannot take a null, it's a totally valid and good usecase to have it be an empty string.
| _message: { state: true }, | ||
| _isOpen: { state: true }, | ||
| _action: { state: true }, | ||
| _isRegisteredForSnapshotScheduler: { state: true, type: Boolean }, |
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.
_isScheduled is fine. No need for the type, either. If these micro frontends become so big we cannot figure out that this is a boolean, we can pivot.
|
|
||
| async connectedCallback() { | ||
| super.connectedCallback(); | ||
| this._isRegisteredForSnapshotScheduler = false; |
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'd avoid doing setters unless absolutely necessary. Especially for booleans where lazy falsey checks (!this._isRegisteredForSnapshotScheduler) will result in the same outcome.
|
|
||
| async firstUpdated() { | ||
| // Check if registered for snapshot scheduler after first render | ||
| this._isRegisteredForSnapshotScheduler = await isRegisteredForSnapshotScheduler(); |
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.
If you're not waiting on DOM to render, you can do this in connectedCallback which should only run once.
firstUpdated is for use cases where you need to know the DOM inside the web component.
https://lit.dev/docs/components/lifecycle/#firstupdated (this whole page on lifecycle is great, btw)
| // Set the name if it isn't already set | ||
| if (!this.basics.name) this.basics.name = name; | ||
|
|
||
| // Validate scheduled publish time before saving |
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 try to leave these lifecycle events as trim as possible and kick out to other functions.
This way, as a fellow developer, I do not have to digest all of your code below when simply trying to see what's being fired off when this lifecycle function loads.
|
|
||
| // Validate scheduled publish time before saving | ||
| const scheduledPublish = this.getValue('[name="scheduler"]'); | ||
| if (scheduledPublish) { |
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 like early returns.
|
This is great. We could probably use a bit of vocabulary clarifications... I'm going to make some assumptions on the feature...
In this light, I would reconsider these function names: and because I am overly brief... Unless a snapshot can be registered with the scheduler, but not have a scheduled date, I would avoid the ambiguity of the term We are also leaning into the fact that schedule === publish, and we can infer that when we talk about scheduling: publishing is implied. |
auniverseaway
left a comment
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.
Minor things. When you address we can pull it into a scheduler branch so we can run this on some production-ish snapshots.
Thanks for doing this. You may not realize it, but this unlocks a few things we want to do on the security front for DA.
|
One clarification -
|
Fix #96
Test URLs: