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

chore(release-overlay-previews): add simple release overlay previews #2084

Merged
merged 4 commits into from
Nov 4, 2024

Conversation

georgedoescode
Copy link
Contributor

@georgedoescode georgedoescode commented Nov 4, 2024

No description provided.

@georgedoescode georgedoescode requested a review from a team as a code owner November 4, 2024 14:22
Copy link

vercel bot commented Nov 4, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
live-visual-editing-next ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 4, 2024 3:41pm
visual-editing-astro ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 4, 2024 3:41pm
visual-editing-next ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 4, 2024 3:41pm
visual-editing-next-with-i18n ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 4, 2024 3:41pm
visual-editing-nuxt ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 4, 2024 3:41pm
visual-editing-page-builder-demo ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 4, 2024 3:41pm
visual-editing-remix ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 4, 2024 3:41pm
visual-editing-storybook ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 4, 2024 3:41pm
visual-editing-svelte ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 4, 2024 3:41pm
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
visual-editing-studio ⬜️ Skipped (Inspect) 💬 Add feedback Nov 4, 2024 3:41pm

bundlesPerspective: string[]
}

const PostMessageReleases: FC<PostMessageReleasesProps> = (props) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

This component will be used only inside the studio right? In PresentationTool

Maybe we could reuse here the releases from import {useReleases} from 'sanity' , what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

in that case, the studio will be responsible for providing the list of releases, which will change a bit in the near future. And you won't need to do this here.

If it's inside the context of the studio the hook should work

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah awesome — this works! I initially used a simple query as eventually we would like to try this out in custom overlay components and it was good research, but we don't need it here. Have updated :)

Comment on lines 352 to 365
if (overlayDocumentReleases.length > 0) {
const asapReleases = overlayDocumentReleases.filter((r) => r.metadata.releaseType === 'asap')

const scheduledReleases = overlayDocumentReleases.filter(
(r) => r.metadata.releaseType === 'scheduled',
)

if (asapReleases.length > 0) {
const asapReleasesSorted = asapReleases.sort(
(a, b) => new Date(a._createdAt).getTime() - new Date(b._createdAt).getTime(),
)

nearestUpcomingRelease = asapReleasesSorted[0]
} else if (scheduledReleases.length > 0) {
const scheduledReleasesSorted = scheduledReleases.sort(
(a, b) =>
new Date(a.metadata.intendedPublishAt).getTime() -
new Date(b.metadata.intendedPublishAt).getTime(),
)

nearestUpcomingRelease = scheduledReleasesSorted[0]

timeTilNextRelease = getTimeDifferenceInDays(
nearestUpcomingRelease.metadata.intendedPublishAt,
)
Copy link
Contributor

Choose a reason for hiding this comment

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

for sorting we also need to consider the release.publishAt date, which will be added once the release is scheduled.
So

   const scheduledReleasesSorted = scheduledReleases.sort(
          (a, b) =>
            new Date(a.publishAt || a.metadata.intendedPublishAt).getTime() -
            new Date(b.publishAt || b.metadata.intendedPublishAt).getTime(),
        )

And we could also have releases that are neither asap or scheduled, which are the undecided

Maybe it's easier for now to copy this from sanity to use the same sort mechanism. https://github.com/sanity-io/sanity/blob/corel/packages/sanity/src/core/releases/hooks/utils.ts#L6-L49

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, if you are using releases from useReleases you can trust that they will be sorted, so you could use the first match found.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am using useReleases now so all sorting logic is removed. Great call out!

}

run()
}, [comlink, perspective, bundlesPerspective])
Copy link
Contributor

Choose a reason for hiding this comment

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

You will probably want here releases.data as a dependency ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oops sorry good catch 👍

Copy link
Contributor

@pedrobonamin pedrobonamin left a comment

Choose a reason for hiding this comment

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

Thanks for this @georgedoescode ! It is amazing to see the releases in the overlays.

@pedrobonamin pedrobonamin merged commit ed5f3a5 into corel Nov 4, 2024
17 of 18 checks passed
@pedrobonamin pedrobonamin deleted the corel-add-releaes-overlay-previews branch November 4, 2024 15:45
stipsan pushed a commit that referenced this pull request Nov 5, 2024
…2084)

* chore(release-overlay-previews): add simple release overlay previews

wip improve data fetching

wip ui

tidy up comments

tidy up postmessagereleases

ensure preview is only shown when data attribute is set

* chore(release-overlay-previews): use useReleases hook

* chore(release-overlay-previews): add releases.data to comlink useEffect deps

* fix: update how the nearestRelease is obtained

---------

Co-authored-by: pedrobonamin <[email protected]>
rdunk pushed a commit that referenced this pull request Nov 6, 2024
…2084)

* chore(release-overlay-previews): add simple release overlay previews

wip improve data fetching

wip ui

tidy up comments

tidy up postmessagereleases

ensure preview is only shown when data attribute is set

* chore(release-overlay-previews): use useReleases hook

* chore(release-overlay-previews): add releases.data to comlink useEffect deps

* fix: update how the nearestRelease is obtained

---------

Co-authored-by: pedrobonamin <[email protected]>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 11, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants