-
Notifications
You must be signed in to change notification settings - Fork 565
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add note's tags to history screen (#2817)
* Add interactive prop to Tag chip interactive prop determines if the tag should display the remove button and pointer cursor * Add note revisions component This component displays a preview of the content and the tags of the current selected revision. * Add note revisions in app layout * Update tag chip component test snapshot * Add unit tests for interactive state * Add note tags selectors This selector is now used in tag-field and note-revisions components to simplify the rendering of tags. * Add deleted state to tag chip component * Add restore tags action This action will be executed when a revision that contains tags that don't exist is restored. It also triggers updates in tags bucket in Simperium. * Improve a11y in note revision The div that wraps the note revision content is now the one that controls the ARIA visibility. * Move tags restoration logic into note revision restoration * Refactor noteTags selector to return an array of tags Since we don't really need the tag's hash, now this selector simply return an array of tags. * Update noteTags selector to include email tags When restoring a note revision, email tags are included so we should display them too in the note's history. * Remove unused tagNameOf import * Use name instead of un-hashed value for tag restore * Update deleted style of tag chip component * Add deleted tags toggle * Calculate tag list when restoring a note revision When restoring a revision, the tag list has to be calculated having the following rules in mind: 1. New email tags shouldn't be included because they might grant undesired users permission. 2. Email tags of current note should be kept to prevent modify user permissions, therefore all of them have to be included. 3. Depending on user selection, tags that were previously deleted could be included. * Remove email tag condition from tag-field component The noteTags selector is already filtering them so it's not needed. * Use checkbox instead of toggle in deleted tags * Add getRevision selector This selector will return the revision object to be passed to the restore note revision Redux action. * Keep note system tags when restoring a revision * Remove deleted property from Tag type noteTags selector has been refactored due to this change, now it only returns the canonical tag names. * Rename toggle deleted tags action and reducer * Remove restoreNoteRevision action creator * Remove isEmailTag import from data middleware * Rename tags class name to be less generic
- Loading branch information
Showing
19 changed files
with
364 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import React, { Component } from 'react'; | ||
import { connect } from 'react-redux'; | ||
|
||
import NotePreview from '../components/note-preview'; | ||
import TagChip from '../components/tag-chip'; | ||
import { noteCanonicalTags } from '../state/selectors'; | ||
import { tagHashOf } from '../utils/tag-hash'; | ||
|
||
import type * as S from '../state'; | ||
import type * as T from '../types'; | ||
|
||
type OwnProps = { | ||
noteId: T.EntityId; | ||
note?: T.Note; | ||
}; | ||
|
||
type StateProps = { | ||
tags: Array<{ name: T.TagName; deleted: boolean }>; | ||
noteId: T.EntityId | null; | ||
note: T.Note | null; | ||
}; | ||
|
||
type Props = OwnProps & | ||
StateProps & | ||
Pick<React.HTMLProps<HTMLDivElement>, 'aria-hidden'>; | ||
|
||
export class NoteRevisions extends Component<Props> { | ||
static displayName = 'NoteRevisions'; | ||
|
||
render() { | ||
const { note, noteId, tags, 'aria-hidden': ariaHidden } = this.props; | ||
|
||
return ( | ||
<div aria-hidden={ariaHidden} className="note-revisions"> | ||
<NotePreview noteId={noteId} note={note} /> | ||
<div className="note-revisions-tag-list"> | ||
{tags.map(({ name, deleted }) => ( | ||
<TagChip | ||
key={name} | ||
tagName={name} | ||
interactive={false} | ||
deleted={deleted} | ||
/> | ||
))} | ||
</div> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
const mapStateToProps: S.MapState<StateProps, OwnProps> = (state, props) => { | ||
const noteId = props.noteId ?? state.ui.openedNote; | ||
const note = props.note ?? state.data.notes.get(noteId); | ||
const restoreDeletedTags = state.ui.restoreDeletedTags; | ||
|
||
const tags = noteCanonicalTags(state, note) | ||
.map((tagName) => { | ||
const tagHash = tagHashOf(tagName); | ||
return { name: tagName, deleted: !state.data.tags.has(tagHash) }; | ||
}) | ||
.filter((tag) => { | ||
return restoreDeletedTags || !tag.deleted; | ||
}); | ||
|
||
return { | ||
tags, | ||
noteId, | ||
note, | ||
}; | ||
}; | ||
|
||
export default connect(mapStateToProps)(NoteRevisions); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
.note-revisions { | ||
display: flex; | ||
flex-direction: column; | ||
flex: 1 1 auto; | ||
padding-top: 20px; | ||
|
||
.note-revisions-tag-list { | ||
display: flex; | ||
justify-content: flex-start; | ||
flex-wrap: wrap; | ||
line-height: 1.75em; | ||
white-space: nowrap; | ||
overflow: auto; | ||
max-height: calc(2.5 * 1.75em + 16px); // about 2.5 rows | ||
padding: 8px 12px; | ||
} | ||
} |
Oops, something went wrong.