Skip to content

feat: lastModified and db for diagram list COMPASS-9398 #6951

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

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

paula-stacho
Copy link
Contributor

@paula-stacho paula-stacho commented May 22, 2025

Description

Note: I made the cards a bit smaller than the designs, they looked too empty with only the db.
Screenshot 2025-05-22 at 17 43 32

Overloads confusion

Hooks can't be called conditionally, so I made the hook useFormattedDate hook accept optional value. In that case the return type is of course optional too. This is represented with function overload. Unfortunately, the overloaded type is getting lost somewhere in the exports/imports, so in the end there is only one function signature.

Update:

I figured out what works - to repeat the overload signature. Looks like the last one is not transferred. I am still confused.

Checklist

  • New tests and/or benchmarks are included
  • Documentation is changed or added
  • If this change updates the UI, screenshots/videos are added and a design review is requested
  • I have signed the MongoDB Contributor License Agreement (https://www.mongodb.com/legal/contributor-agreement)

Motivation and Context

  • Bugfix
  • New feature
  • Dependency update
  • Misc

Open Questions

Dependents

Types of changes

  • Backport Needed
  • Patch (non-breaking change which fixes an issue)
  • Minor (non-breaking change which adds functionality)
  • Major (fix or feature that would cause existing functionality to change)

@paula-stacho paula-stacho added the feature flagged PRs labeled with this label will not be included in the release notes of the next release label May 22, 2025
@github-actions github-actions bot added the feat label May 22, 2025
@paula-stacho paula-stacho marked this pull request as ready for review May 23, 2025 09:12
Comment on lines +5 to +7
export function useFormattedDate(timestamp: number): string;
export function useFormattedDate(timestamp?: number): string | undefined;
export function useFormattedDate(timestamp?: number): string | undefined {
Copy link
Collaborator

@gribnoysup gribnoysup May 23, 2025

Choose a reason for hiding this comment

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

What you were running into here is a difference between overload signatures and overload implementation and is indeed a "common source of confusion" even mentioned as such in the TS documentation 🙂 The last function here, the overload implementation, is not "visible" to the outside

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oooh so I learned two TS lessons today

@@ -48,12 +78,16 @@ export function DiagramCard({
onRename,
onDelete,
}: {
diagram: MongoDBDataModelDescription;
diagram: MongoDBDataModelDescription & {
lastModified?: number;
Copy link
Collaborator

Choose a reason for hiding this comment

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

How is this value ever optional? Shouldn't the initial save count as "modified" too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

technically yeah the array should never be empty and so the derived value should always be there. I checked and looks like z.nonempty() could work here

Copy link
Contributor Author

@paula-stacho paula-stacho May 23, 2025

Choose a reason for hiding this comment

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

okay, typed the edits so that they are non empty. forcing us to ensure this in the reducer as well, which is good.
also good learning for me, I didn't expect that TS would understand this.

);
return {
...item,
lastModified: Date.parse(item.edits[item.edits.length - 1].timestamp),
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think when we usually refer to last modified we specifically mean when the file was saved by the storage, wouldn't it be easier to just write this value as part of the store logic instead of recalculating it here all the time?

Copy link
Contributor Author

@paula-stacho paula-stacho May 23, 2025

Choose a reason for hiding this comment

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

Yeah might be. Following the tech design here. We could achieve the same if we always save the last edit's timestamp also on the top level. But I'm actually not sure if lastModified should work like this with the undo. Shouldn't undo also count as modification? In that case we definitely need to store this. cc @Anemy - sorry that I didn't notice this when reviewing the design

Copy link
Collaborator

Choose a reason for hiding this comment

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

You also have a case of changing the name which counts as modification I think. Applying undo might also get confusing if we just use the timestamps (like imaging undoing to something that was timestamped a long time ago and the item that you might expect at the top is not at the bottom of the list). I really don't think we want to bind stored file modification action to edits themselves

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat feature flagged PRs labeled with this label will not be included in the release notes of the next release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants