-
Notifications
You must be signed in to change notification settings - Fork 0
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
Tag Use Case #8
Merged
Tag Use Case #8
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
6b93e6e
add useDebounce
krfong916 845e5a0
update tag editor to use useCombobox hook edit type support for combobox
krfong916 0c9d2c0
fix onStateChange capitalization bug, add editor use case UI
krfong916 8d1b902
add spacing and screen-size standards for scss
krfong916 53bb3e0
implement loader, redo editor css, fix a11y bugs
krfong916 152a810
xed isopen state when user input changes, prevent default when user n…
krfong916 4d572e8
* fixed input isopen state when user input changes - our tests didn't…
krfong916 2d30eee
init useMultipleSelection, create generic types file
krfong916 41dc125
add keyboard tests for usemultiselect
krfong916 7166dd6
change keyboard navigation API for usemultiselect
krfong916 d4a79ee
implement all tests for usemultiselection
krfong916 0b1b344
fix combobox tests and cleanup type namespace
krfong916 a74ce35
move combobox folder
krfong916 5ffc4e7
implement tag use case, fix arrow navigation remove selectedItemListP…
krfong916 e033268
fix merge refs to include functions, this allows for composeable refs…
krfong916 96783d4
fix initial state, highlighted index
krfong916 67276b6
implement current item selection index and accessible navigation
krfong916 3b450a2
add cancel debounce callback and tests for tag editor
krfong916 655f397
add msw for mocking fetch and init tag tests, add event listeners for…
krfong916 aaded5a
add mock server setup for jest tests
krfong916 5e7e8b9
implement final tag editor tests
krfong916 d13e762
WIP: cursor position and highlighting selected items, implement creat…
krfong916 bad0890
fix keydown navigation for usemultislection, when we can focus a mult…
krfong916 9c6a1e9
WIP: question styling, implemented error-handling
krfong916 5434c43
implement focus for editor, button spacing and color, remove extran c…
krfong916 ff867ef
add link and editor bindings, refactor focus management for q compone…
krfong916 4e55f63
WIP: layout and styling, todo: spacing on large screens
krfong916 7d0d0b3
WIP: error handling, implement review and spacing
krfong916 f72f4ca
implement error handling, validate on change
krfong916 b9f7697
implement a11y for form and base tests, TODO: network error message
krfong916 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,17 +8,17 @@ import { | |
cleanText, | ||
isDuplicate, | ||
isEmpty, | ||
noop | ||
noop, | ||
fetchTags | ||
} from './utils'; | ||
import { useCombobox } from '../../combobox/hooks/useCombobox'; | ||
import useDebouncedCallback from '../../useDebounce/src/hooks/useDebouncedCallback'; | ||
import useAsync from '../../useDebounce/src/hooks/useAsync'; | ||
import { UseAsyncStatus } from '../../useDebounce/src/types'; | ||
import { BL } from '../../combobox/hooks/types'; | ||
import { BottomlineTag, BottomlineTags } from './types'; | ||
import { GoQuestion } from 'react-icons/go'; | ||
import { AiFillQuestionCircle } from 'react-icons/ai'; | ||
import classNames from 'classnames'; | ||
import './TagUseCase.scss'; | ||
import './TagEditor.scss'; | ||
|
||
/** | ||
|
@@ -43,14 +43,6 @@ export const TagEditor = () => { | |
const [selectedTags, setSelectedTags] = React.useState<BottomlineTags>({}); | ||
const [tagSuggestions, setTagSuggestions] = React.useState({ data: null }); | ||
const [duplicateTagAlert, setDuplicateTagAlert] = React.useState(''); | ||
const debounce = useDebouncedCallback( | ||
(dispatch) => { | ||
console.log('dispatch:', dispatch); | ||
dispatch(); | ||
}, | ||
2000, | ||
{ trailing: true } | ||
); | ||
|
||
function stateReducer( | ||
state: BL.ComboboxState<BottomlineTag>, | ||
|
@@ -95,35 +87,142 @@ export const TagEditor = () => { | |
stateReducer | ||
}); | ||
|
||
React.useEffect(() => { | ||
console.log('our input:', input); | ||
}, [input]); | ||
const debounce = useDebouncedCallback( | ||
(dispatch) => { | ||
console.log('dispatch:', dispatch); | ||
dispatch(); | ||
}, | ||
2000, | ||
{ trailing: true } | ||
); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we define a function callback for useDebounce. |
||
|
||
// const { data: tags, status, error } = useAsync( | ||
// () => { | ||
// if (input && input !== '') { | ||
// return fetchTags(input); | ||
// } | ||
// }, | ||
// { status: UseAsyncStatus.IDLE }, | ||
// [input] | ||
// ); | ||
const fetchTagResults = useAsync( | ||
() => { | ||
if (input && input !== '') { | ||
return fetchTags(input); | ||
} | ||
}, | ||
{ status: UseAsyncStatus.IDLE }, | ||
[input] | ||
); | ||
|
||
const { data: tags, error, status } = fetchTagResults; | ||
if (status === UseAsyncStatus.IDLE) { | ||
console.log('we are idle'); | ||
} else if (status === UseAsyncStatus.PENDING) { | ||
console.log('we are pending'); | ||
// set the loader | ||
} else if (status === UseAsyncStatus.RESOLVED) { | ||
console.log('we are resolved'); | ||
console.log(tags); | ||
// unset the loader | ||
// no results found | ||
} else { | ||
console.log('we are rejected'); | ||
console.log(error); | ||
// keep the loader don't do anything with the error | ||
} | ||
|
||
return ( | ||
<section className="tag-editor-section"> | ||
<span {...getLabelProps({ id: 'tagInputDescription' })}> | ||
Add up to 5 (five) tags to describe what your question is about | ||
</span> | ||
<div> | ||
<input | ||
{...getInputProps({ controlDispatch: debounce })} | ||
type="text" | ||
autoComplete="off" | ||
className="tag-editor-input" | ||
aria-describedby="tagInputDescription" | ||
ref={null} | ||
/> | ||
<div className="tag-editor"> | ||
<div className="tag-header-container"> | ||
<span | ||
className="tag-header-title" | ||
{...getLabelProps({ id: 'tagInputDescription' })} | ||
> | ||
Add up to 5 (five) tags to describe what your question is about | ||
</span> | ||
<AiFillQuestionCircle size="1.25em" className="tag-header-description" /> | ||
</div> | ||
<div className="selected-tags-container"> | ||
{selectedTags ? ( | ||
<ul className="selected-tags"> | ||
{Object.keys(selectedTags).map((tagName) => { | ||
const tag = selectedTags[tagName]; | ||
return ( | ||
<li className="selected-tag"> | ||
<Tag size="small" type="outlined" text={tag.name}> | ||
<TagCloseButton /> | ||
</Tag> | ||
</li> | ||
); | ||
})} | ||
</ul> | ||
) : null} | ||
</div> | ||
{duplicateTagAlert ? <p role="alert">{duplicateTagAlert}</p> : null} | ||
<div className="tag-search-container"> | ||
<input | ||
{...getInputProps({ controlDispatch: debounce })} | ||
type="text" | ||
autoComplete="off" | ||
className="tag-search-input" | ||
aria-describedby="tagInputDescription" | ||
ref={null} | ||
/> | ||
<span className="tag-search-loader">loader</span> | ||
</div> | ||
<div className="tag-results-container"> | ||
<ul className="tag-results"> | ||
<li className="tag-result"> | ||
<div className="tag-result-info"> | ||
<span className="tag-result-header"> | ||
<Tag className="tag-name" size="small" text="material-analysis" /> | ||
<span className="tag-result-count">{5}</span> | ||
<AiFillQuestionCircle size="1rem" className="tag-result-details" /> | ||
</span> | ||
</div> | ||
<p className="tag-result-excerpt"> | ||
Lorem ipsum dolor sit, amet consectetur, adipisicing elit. Qui | ||
</p> | ||
</li> | ||
<li className="tag-result"> | ||
<div className="tag-result-info"> | ||
<span className="tag-result-header"> | ||
<Tag className="tag-result" size="small" text="material-max" /> | ||
<span className="tag-result-count">{5}</span> | ||
<AiFillQuestionCircle size="1rem" className="tag-result-details" /> | ||
</span> | ||
</div> | ||
<p className="tag-result-excerpt"> | ||
Lorem ipsum dolor sit, amet consectetur, adipisicing elit. Qui | ||
expedita ratione, | ||
</p> | ||
</li> | ||
<li className="tag-result"> | ||
<span className="tag-result-header"> | ||
<Tag className="tag-result" size="small" text="analysis" /> | ||
<span className="tag-result-count">{5}</span> | ||
<AiFillQuestionCircle size="1rem" className="tag-result-details" /> | ||
</span> | ||
|
||
<p className="tag-result-excerpt"> | ||
Lorem ipsum dolor sit, amet consectetur, adipisicing elit. Qui | ||
expedita ratione, consectetur sint quibusdam placeat, beatae iusto | ||
ipsum perspiciatis consequuntur cupiditate omnis voluptatibus | ||
mollitia, fuga odio porro id praesentium. Dolore! Esse sunt, | ||
recusandae architecto praesentium consequuntur. Iusto quas odit | ||
pariatur fugiat ducimus itaque ad, natus dolore necessitatibus placeat | ||
corporis, sint voluptas ea impedit. Sit quasi, voluptas, blanditiis | ||
ullam fuga expedita? Accusamus distinctio praesentium deleniti saepe | ||
eum magnam et aperiam, dolorum voluptatem voluptates. Voluptate | ||
excepturi ipsa laudantium fugiat ex repellat magnam dolorum in. | ||
Dolores veritatis molestias saepe, nemo non molestiae repudiandae. | ||
</p> | ||
</li> | ||
<li className="tag-result"> | ||
<div className="tag-result-info"> | ||
<span className="tag-result-header"> | ||
<Tag className="tag-result" size="small" text="material" /> | ||
<span className="tag-result-count">{5}</span> | ||
<AiFillQuestionCircle size="1rem" className="tag-result-details" /> | ||
</span> | ||
</div> | ||
<p className="tag-result-excerpt">Lorem</p> | ||
</li> | ||
</ul> | ||
</div> | ||
</div> | ||
</section> | ||
); | ||
|
@@ -136,136 +235,3 @@ export const TagEditor = () => { | |
* | ||
* ******************* | ||
*/ | ||
|
||
// /** | ||
// * ******************* | ||
// * | ||
// * Focusing | ||
// * | ||
// * ******************* | ||
// * | ||
// * If leaving focus from text, convert the current text into a tag, apply TagCreation | ||
// * | ||
// */ | ||
|
||
// /** | ||
// * ******************* | ||
// * | ||
// * Update | ||
// * | ||
// * ******************* | ||
// * | ||
// * Update an existing tag for a click event | ||
// * If a user click's on a tag, convert the tag into input an input | ||
// * | ||
// */ | ||
// const editTag = (e: React.MouseEvent<React.ReactNode>) => { | ||
// console.log('[EDIT_TAG]'); | ||
// const { name, index, tagContainer } = getTagAttributes(); | ||
// }; | ||
|
||
// /** | ||
// * ******************* | ||
// * | ||
// * Deletion | ||
// * | ||
// * ******************* | ||
// * There are two ways to delete a tag | ||
// * - remove the tag via its close button | ||
// * - edit and delete existing tags text | ||
// * | ||
// */ | ||
// const removeTag = (e: React.MouseEvent<HTMLButtonElement>) => { | ||
// // prevents other click handlers on the Tag component from firing | ||
// e.stopPropagation(); | ||
// }; | ||
|
||
// /** | ||
// * ******************* | ||
// * | ||
// * Create | ||
// * | ||
// * ******************* | ||
// */ | ||
// const createTag = (userInput: string) => { | ||
// // strip text from characters not allowed | ||
// let text = cleanText(userInput); | ||
|
||
// // if the text contained bad characters, then return | ||
// if (text === '') return; | ||
|
||
// // check if we have a duplicate tag entry | ||
// if (isDuplicate(text, state)) { | ||
// setDuplicateTagAlert(getDuplicateTagAlert(text)); | ||
|
||
// // create the tag | ||
// } else { | ||
// // create a fresh piece of state to modify | ||
// let newState = { ...state }; | ||
|
||
// let newTag = { | ||
// name: text | ||
// } as EditorTag; | ||
|
||
// // insert the tag into our dictionary of tags | ||
// newState.tags.set(text, newTag); | ||
|
||
// // refresh the value of the input | ||
// newState.inputValue = ''; | ||
|
||
// // update state | ||
// setState(newState); | ||
// } | ||
// }; | ||
|
||
// const handleKeyPress = (e: React.KeyboardEvent<HTMLInputElement>) => { | ||
// if (e.charCode === SPACEBAR && isEmpty(state.inputValue) == false) { | ||
// } | ||
// }; | ||
|
||
// const handleOnChange = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
// console.log('[HANDLE_ONCHANGE]: ', e.target.value); | ||
// // console.log('[HANDLE_ONCHANGE]: ', e.charCode); | ||
|
||
// const text = e.target.value; | ||
|
||
// if (isWhitespace(text) === false) { | ||
// // update the text value | ||
// console.log({ ...state, ...{ inputValue: text } }); | ||
// setState({ ...state, ...{ inputValue: text } }); | ||
|
||
// // if the editor has a duplicate tag, we remove the duplicate flag in the onChange handler | ||
// // because the user is signaling that they've decided to correct the duplicate | ||
// if (duplicateTagAlert) { | ||
// setDuplicateTagAlert(''); | ||
// } | ||
// } | ||
// }; | ||
|
||
// const handleOnPaste = (e: React.ClipboardEvent<HTMLInputElement>) => { | ||
// console.log('[ON_PASTE]'); | ||
// const text = event.clipboardData.getData('text'); | ||
|
||
// if (text.length > 1) { | ||
// // create tags from the user's pasted text | ||
// text.split(' ').forEach((pieceOfText) => createTag(pieceOfText)); | ||
// } | ||
// }; | ||
// {tagSuggestions.data ? ( | ||
// <div className="tag-suggestions"> | ||
// <ul className="tag-suggestions__list"> | ||
// {tagSuggestions.suggestions.map((suggestion) => { | ||
// const url = `thebottomlineapp.com/tags/${suggestion.name}/info`; | ||
// return ( | ||
// <li className="tag-suggestions__list-item" tabIndex={0}> | ||
// <div className="tag-suggestions__header"> | ||
// <Tag size="small" type="no-outline" text={suggestion.name} /> | ||
// <span className="tag-suggestions__count">{suggestion.count}</span> | ||
// <a href={url}> | ||
// <GoQuestion className="tag-suggestions__info" /> | ||
// </a> | ||
// </div> | ||
// <span className="tag-suggestions__body">{suggestion.excerpt}</span> | ||
// </li> | ||
// ); | ||
// })} |
12 changes: 0 additions & 12 deletions
12
proof-of-concepts/features/stories/tags/TagEditor/TagUseCase.scss
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we are calling the piece of state that changed based on the recommendations from the reducer