From a165fa9b4eb83545102c5c78b2f9174f3e98acdf Mon Sep 17 00:00:00 2001 From: Laurent Senta Date: Tue, 4 Jan 2022 14:13:29 +0100 Subject: [PATCH] feat: allows duplicate names in tags folder & smart tags (#792) * feat: tag rendering & validation uses hierarchy * feat: add prefix to autocomplete --- .../components/AutocompleteTagResult.tsx | 8 ++- app/assets/javascripts/components/NoteTag.tsx | 12 +++- .../ui_models/app_state/note_tags_state.ts | 39 ++++++++++- .../ui_models/app_state/tags_state.ts | 64 ++++++++++++++++++- 4 files changed, 117 insertions(+), 6 deletions(-) diff --git a/app/assets/javascripts/components/AutocompleteTagResult.tsx b/app/assets/javascripts/components/AutocompleteTagResult.tsx index 84bb150ac..d732541af 100644 --- a/app/assets/javascripts/components/AutocompleteTagResult.tsx +++ b/app/assets/javascripts/components/AutocompleteTagResult.tsx @@ -21,6 +21,9 @@ export const AutocompleteTagResult = observer( const tagResultRef = useRef(null); + const title = tagResult.title; + const prefixTitle = appState.noteTags.getPrefixTitle(tagResult); + const onTagOptionClick = async (tag: SNTag) => { await appState.noteTags.addTagToActiveNote(tag); appState.noteTags.clearAutocompleteSearch(); @@ -86,9 +89,10 @@ export const AutocompleteTagResult = observer( > + {prefixTitle && {prefixTitle}} {autocompleteSearchQuery === '' - ? tagResult.title - : tagResult.title + ? title + : title .split(new RegExp(`(${autocompleteSearchQuery})`, 'gi')) .map((substring, index) => ( { - const { autocompleteInputFocused, focusedTagUuid, tags } = appState.noteTags; + const noteTags = appState.noteTags; + + const { autocompleteInputFocused, focusedTagUuid, tags } = noteTags; const [showDeleteButton, setShowDeleteButton] = useState(false); const [tagClicked, setTagClicked] = useState(false); @@ -18,6 +20,10 @@ export const NoteTag = observer(({ appState, tag }: Props) => { const tagRef = useRef(null); + const title = tag.title; + const prefixTitle = noteTags.getPrefixTitle(tag); + const longTitle = noteTags.getLongTitle(tag); + const deleteTag = () => { appState.noteTags.focusPreviousTag(tag); appState.noteTags.removeTagFromActiveNote(tag); @@ -97,10 +103,12 @@ export const NoteTag = observer(({ appState, tag }: Props) => { onFocus={onFocus} onBlur={onBlur} tabIndex={getTabIndex()} + title={longTitle} > - {tag.title} + {prefixTitle && {prefixTitle}} + {title} {showDeleteButton && (