Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@amol-anand
Copy link
Contributor

@amol-anand amol-anand commented Oct 5, 2025

@aem-code-sync
Copy link

aem-code-sync bot commented Oct 5, 2025

Page Scores Audits Google
📱 /drafts/amol/scheduler PERFORMANCE A11Y SEO BEST PRACTICES SI FCP LCP TBT CLS PSI
🖥️ /drafts/amol/scheduler PERFORMANCE A11Y SEO BEST PRACTICES SI FCP LCP TBT CLS PSI

@@ -1,4 +1,4 @@
import { AEM_ORIGIN } from '../../../public/utils/constants.js';
import { AEM_ORIGIN, SNAPSHOT_SCHEDULER_URL } from '../../../public/utils/constants.js';
Copy link
Member

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')}`;
}
Copy link
Member

@auniverseaway auniverseaway Oct 6, 2025

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.

Copy link
Member

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:

  1. If DA / NX gives you null we purposefully did this based on input supplied.
  2. If DA / NX gives you undefined "something" in the machine is truly undefined.
  3. If DA / NX gives you an empty string... it's fairly rare and likely only because we need to concat a string.

Copy link
Member

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 },
Copy link
Member

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;
Copy link
Member

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();
Copy link
Member

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
Copy link
Member

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) {
Copy link
Member

Choose a reason for hiding this comment

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

We like early returns.

@auniverseaway auniverseaway changed the base branch from main to scheduler October 6, 2025 22:12
@auniverseaway
Copy link
Member

auniverseaway commented Oct 6, 2025

This is great. We could probably use a bit of vocabulary clarifications...

I'm going to make some assumptions on the feature...

  1. Snapshot Scheduler - the service that orchestrates a scheduled publish of a snapshot.
  2. Scheduled Snapshot - Whether or not the snapshot is scheduled for publish.

In this light, I would reconsider these function names:

isRegisteredForSnapshotScheduler
updateScheduledPublish

and because I am overly brief...

isScheduled
updateSchedule

Unless a snapshot can be registered with the scheduler, but not have a scheduled date, I would avoid the ambiguity of the term register. When we introduce the word register, it makes me think you can register, but not have a date... maybe that's the case?

We are also leaning into the fact that schedule === publish, and we can infer that when we talk about scheduling: publishing is implied.

Copy link
Member

@auniverseaway auniverseaway left a 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.

@amol-anand
Copy link
Contributor Author

One clarification - isRegisteredForSnapshotScheduler is checking if this org/site has registered to USE the new service. If not we don't even show the option for scheduling a publish.

updatePublish sounds fine to me. I'll leave the other one to isRegistered (to confirm this org/site is registered for the entire scheduler service which is a one time setup step per org/site combo)

@auniverseaway auniverseaway merged commit 65b0b4d into adobe:scheduler Oct 7, 2025
4 checks passed
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.

Add Scheduled Publish to DA Snapshot UI

2 participants