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

Allow editing of DayOne entries #1001

Merged
merged 4 commits into from
Jul 18, 2020

Conversation

wren
Copy link
Member

@wren wren commented Jul 11, 2020

Fixes #955

DayOneJournal previously reimplemented Journal._parse inside of DayOneJournal.parse_editable_string, and in doing so caused issues between the two classes (the body was being reparsed for a title, overwriting the title, and essentially dropping the first line of each edited entry). This commit fixes the issue by moving the UUID to be in the body of the entry, rather than above it. Doing this allows us to use Journal._parse like normal (it still finds the correct boundaries between entries), and then DayOneJournal parses the UUID afterward.

Co-authored-by: MinchinWeb
Co-authored-by: Micah Jerome Ellison

Checklist

  • I have read the contributing doc.
  • I have included a link to the relevant issue number.
  • I have tested this code locally.
  • I have checked to ensure there aren't other open pull requests
    for the same issue.
  • I have written new tests for these changes, as needed.
  • All tests pass.

wren and others added 4 commits July 2, 2020 00:14
Add test for editing Dayone entries (this test currently fails)

Co-authored-by: Jonathan Wren <jonathan@nowandwren.com>
DayOneJournal previously reimplemented Journal._parse inside of
DayOneJournal.parse_editable_string, and in doing so caused issues
between itself and the class it was inheriting from. This commit fixes
the issue by moving the UUID to be in the body of the entry, rather than
above it. So, then Journal._parse still finds the correct boundaries
between entries, and DayOneJournal then parses the UUID afterward.

Co-authored-by: Micah Jerome Ellison <micah.jerome.ellison@gmail.com>
@wren
Copy link
Member Author

wren commented Jul 11, 2020

Well, that took longer than expected, but I think this is all working now.

@MinchinWeb @micahellison Would y'all mind taking a look over this?

@MinchinWeb
Copy link
Contributor

MinchinWeb commented Jul 12, 2020

I haven't had the chance to test drive this yet, but it we're using a regex match:

  • UUID's should all be the same length. Should the regex enforce that?
  • should we be more explicit with our inserted text, perhaps by prefacing it with "UUID:"?
  • "#" is used for Level 1 headings in Markdown, but this is now at the bottom of the entry. Would it make sense to to move to an HTML comment style? Like <!-- 3547D0580346804689 -->
    • I realize not everyone writes their entries in Markdown, but I do. If for some reason the comment got included in the output, it would automatically just not be rendered in HTML, which I think it a good default.
    • if you combine these two, you'd get <!-- UUID: 3547D0580346804689 -->
  • should we think about extend-ability of this for other DayOne metadata? That doesn't have to be dealt with now, but (for example) currently you can't edit the tags on an entry in a straightforward, deterministic manner. If we went with the HTML comment style, it could be extended for tags, and potentially other metadata. So add another line like: <!-- tags: test_tag, awesome project -->

@wren
Copy link
Member Author

wren commented Jul 12, 2020

@MinchinWeb I think those are all very good questions, and we should definitely discuss if and how to handle extended metadata on entries for certain journal types, but I would consider that out of scope for issue #955.

I was also very tempted to change the # to something more friendly, but I decided against it in order to keep the format as close to its current look. That way, we can take some time to plan any upcoming changes in a different issue.

@wren wren changed the title Fix Dayone editing Allow editing of DayOne entries Jul 12, 2020
# merge existing tags with tags pulled from the entry body
entry.tags = list(set(entry.tags + match.tags))

# extended Dayone metadata
Copy link
Contributor

Choose a reason for hiding this comment

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

How is this extended metadata being preserved? or is it being dropped when the entry is edited?

Copy link
Member

Choose a reason for hiding this comment

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

It is being preserved: it is read when the journal is opened, it remains in memory as the entry is being edited, then it's saved back. And it still creates the metadata when writing a new entry.

@@ -37,18 +39,30 @@ def title(self):
self._parse_text()
return self._title

@title.setter
Copy link
Contributor

Choose a reason for hiding this comment

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

These setters I don't think are being used by your solution. Would it make sense to drop them?

Copy link
Member

Choose a reason for hiding this comment

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

I think it's good to leave them in. It sends a nudge to future contributors that they should use entry's accessors rather than underscore-prefixed internals.

@MinchinWeb
Copy link
Contributor

Simple local testing seems to show that it works! Extended metadata stays in place. The behave test suite passes locally.

In regards to this PR, should we remove the setter code I added, as it's not being used?

In regards to future work:

  • we should look at expanding this to support editing entry tags
  • we should look at the format of the UUID within the editing output
  • the "Device Agent" is currently being set to a empty string, which is less than ideal (this is not new)

I'm excited to see this merged. Thank for everyone's help!

LGTM!

Copy link
Member

@micahellison micahellison left a comment

Choose a reason for hiding this comment

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

Looks good! Nice collaboration!

@micahellison micahellison added bug Something isn't working day one Issues related to Day One (dayoneapp.com) labels Jul 18, 2020
@micahellison micahellison merged commit 9ccb0b9 into jrnl-org:develop Jul 18, 2020
wren added a commit that referenced this pull request Jul 25, 2020
* add test to repro issue #955

* Allow editing of DayOne entries

* Add broken test for Dayone

Add test for editing Dayone entries (this test currently fails)

Co-authored-by: Jonathan Wren <jonathan@nowandwren.com>

* Fix editing logic for DayOneJournal

DayOneJournal previously reimplemented Journal._parse inside of
DayOneJournal.parse_editable_string, and in doing so caused issues
between itself and the class it was inheriting from. This commit fixes
the issue by moving the UUID to be in the body of the entry, rather than
above it. So, then Journal._parse still finds the correct boundaries
between entries, and DayOneJournal then parses the UUID afterward.

Co-authored-by: MinchinWeb <w_minchin@hotmail.com>
Co-authored-by: Micah Jerome Ellison <micah.jerome.ellison@gmail.com>
@wren wren deleted the dayone-edit-fix-955 branch October 18, 2020 21:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working day one Issues related to Day One (dayoneapp.com)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[DayOne] Editing an entry shows AttributeError
3 participants