This repository was archived by the owner on Sep 11, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 813
add-privileged-users-in-room #9596
Merged
weeman1337
merged 15 commits into
matrix-org:develop
from
bwi-de:add-privileged-users-in-room
Dec 8, 2022
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
9e200f4
adds a new section under 'Room Settings' > 'Roles & Permissions' whic…
GoodGuyMarco d8aa22a
fixes rethemendex, style lint and i18n ci checks
GoodGuyMarco 3e7e362
uses spacing, size and color variables instead of hardcoded values, a…
GoodGuyMarco 102f6bd
uses ellipsis character, introduces form element, removes unwanted bo…
GoodGuyMarco 1f9a045
changes selection to be completely controlled by parent component
GoodGuyMarco 84bc8d4
reuses SettingsFieldSet component with some inline-style hacks
GoodGuyMarco 4c00725
utilizes existing useFocus hook, fixes TypeScript issues in strict mo…
GoodGuyMarco cf7b652
resolves TODO, resolves remaining typescript strict type checks
GoodGuyMarco 8956d9f
adds magnifier icon, aligned look and feel to regular input component…
GoodGuyMarco 9b3c90b
removes check icon as suggested by design review
GoodGuyMarco 027a044
filters out undefined values
GoodGuyMarco bd9e453
adds happy path test for <AddPriviligedUsers /> component
GoodGuyMarco 360a7bd
restructures code to improve testability
GoodGuyMarco 8de4f27
handles not existing RoomPowerLevels event gracefully
GoodGuyMarco 990ea94
removes async from tests where not required
GoodGuyMarco 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 hidden or 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 hidden or 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,129 @@ | ||
| /* | ||
| Copyright 2022 The Matrix.org Foundation C.I.C. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| .mx_AutocompleteInput { | ||
| position: relative; | ||
| } | ||
|
|
||
| .mx_AutocompleteInput_search_icon { | ||
| margin-left: $spacing-8; | ||
| fill: $secondary-content; | ||
| } | ||
|
|
||
| .mx_AutocompleteInput_editor { | ||
| flex: 1; | ||
| display: flex; | ||
| flex-wrap: wrap; | ||
| align-items: center; | ||
| overflow-x: hidden; | ||
| overflow-y: auto; | ||
| border: 1px solid $input-border-color; | ||
| border-radius: 4px; | ||
| transition: border-color 0.25s; | ||
|
|
||
| > input { | ||
| flex: 1; | ||
| min-width: 40%; | ||
| resize: none; | ||
| // `!important` is required to bypass global input styles. | ||
| margin: 0 !important; | ||
| padding: $spacing-8 9px; | ||
| border: none !important; | ||
| color: $primary-content !important; | ||
| font-weight: normal !important; | ||
|
|
||
| &::placeholder { | ||
| color: $primary-content !important; | ||
| font-weight: normal !important; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| .mx_AutocompleteInput_editor--focused { | ||
| border-color: $links; | ||
| } | ||
|
|
||
| .mx_AutocompleteInput_editor--has-suggestions { | ||
| border-bottom-left-radius: 0; | ||
| border-bottom-right-radius: 0; | ||
| } | ||
|
|
||
| .mx_AutocompleteInput_editor_selection { | ||
| display: flex; | ||
| margin-left: $spacing-8; | ||
| } | ||
|
|
||
| .mx_AutocompleteInput_editor_selection_pill { | ||
| display: flex; | ||
| align-items: center; | ||
| border-radius: 12px; | ||
| padding-left: $spacing-8; | ||
| padding-right: $spacing-8; | ||
| background-color: $username-variant1-color; | ||
| color: #ffffff; | ||
|
Contributor
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. needs to be updated, waiting on @matrix-org/design input |
||
| font-size: $font-12px; | ||
| } | ||
|
|
||
| .mx_AutocompleteInput_editor_selection_remove_button { | ||
| padding: 0 $spacing-4; | ||
| } | ||
|
|
||
| .mx_AutocompleteInput_matches { | ||
| position: absolute; | ||
| left: 0; | ||
| right: 0; | ||
| background-color: $background; | ||
| border: 1px solid $links; | ||
| border-top-color: $input-border-color; | ||
| border-bottom-left-radius: 4px; | ||
| border-bottom-right-radius: 4px; | ||
| z-index: 1000; | ||
| } | ||
|
|
||
| .mx_AutocompleteInput_suggestion { | ||
| display: flex; | ||
| align-items: center; | ||
| padding: $spacing-8; | ||
| cursor: pointer; | ||
|
|
||
| > * { | ||
| user-select: none; | ||
| } | ||
|
|
||
| &:hover { | ||
| background-color: $quinary-content; | ||
| border-bottom-left-radius: 4px; | ||
| border-bottom-right-radius: 4px; | ||
| } | ||
| } | ||
|
|
||
| .mx_AutocompleteInput_suggestion--selected { | ||
| background-color: $quinary-content; | ||
|
|
||
| &:last-child { | ||
| border-bottom-left-radius: 4px; | ||
| border-bottom-right-radius: 4px; | ||
| } | ||
| } | ||
|
|
||
| .mx_AutocompleteInput_suggestion_title { | ||
| margin-right: $spacing-8; | ||
| } | ||
|
|
||
| .mx_AutocompleteInput_suggestion_description { | ||
| color: $secondary-content; | ||
| font-size: $font-12px; | ||
| } | ||
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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,248 @@ | ||
| /* | ||
| Copyright 2022 The Matrix.org Foundation C.I.C. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| import React, { useState, ReactNode, ChangeEvent, KeyboardEvent, useRef, ReactElement } from 'react'; | ||
| import classNames from 'classnames'; | ||
|
|
||
| import Autocompleter from "../../autocomplete/AutocompleteProvider"; | ||
| import { Key } from '../../Keyboard'; | ||
| import { ICompletion } from '../../autocomplete/Autocompleter'; | ||
| import AccessibleButton from '../../components/views/elements/AccessibleButton'; | ||
| import { Icon as PillRemoveIcon } from '../../../res/img/icon-pill-remove.svg'; | ||
| import { Icon as SearchIcon } from '../../../res/img/element-icons/roomlist/search.svg'; | ||
| import useFocus from "../../hooks/useFocus"; | ||
|
|
||
| interface AutocompleteInputProps { | ||
| provider: Autocompleter; | ||
| placeholder: string; | ||
| selection: ICompletion[]; | ||
| onSelectionChange: (selection: ICompletion[]) => void; | ||
| maxSuggestions?: number; | ||
| renderSuggestion?: (s: ICompletion) => ReactElement; | ||
| renderSelection?: (m: ICompletion) => ReactElement; | ||
| additionalFilter?: (suggestion: ICompletion) => boolean; | ||
| } | ||
|
|
||
| export const AutocompleteInput: React.FC<AutocompleteInputProps> = ({ | ||
| provider, | ||
| renderSuggestion, | ||
| renderSelection, | ||
| maxSuggestions = 5, | ||
| placeholder, | ||
| onSelectionChange, | ||
| selection, | ||
| additionalFilter, | ||
| }) => { | ||
| const [query, setQuery] = useState<string>(''); | ||
| const [suggestions, setSuggestions] = useState<ICompletion[]>([]); | ||
| const [isFocused, onFocusChangeHandlerFunctions] = useFocus(); | ||
| const editorContainerRef = useRef<HTMLDivElement>(null); | ||
| const editorRef = useRef<HTMLInputElement>(null); | ||
|
|
||
| const focusEditor = () => { | ||
| editorRef?.current?.focus(); | ||
| }; | ||
|
|
||
| const onQueryChange = async (e: ChangeEvent<HTMLInputElement>) => { | ||
| const value = e.target.value.trim(); | ||
| setQuery(value); | ||
|
|
||
| let matches = await provider.getCompletions( | ||
| query, | ||
| { start: query.length, end: query.length }, | ||
| true, | ||
| maxSuggestions, | ||
| ); | ||
|
|
||
| if (additionalFilter) { | ||
| matches = matches.filter(additionalFilter); | ||
| } | ||
|
|
||
| setSuggestions(matches); | ||
| }; | ||
|
|
||
| const onClickInputArea = () => { | ||
| focusEditor(); | ||
| }; | ||
|
|
||
| const onKeyDown = (e: KeyboardEvent) => { | ||
| const hasModifiers = e.ctrlKey || e.shiftKey || e.metaKey; | ||
|
|
||
| // when the field is empty and the user hits backspace remove the right-most target | ||
| if (!query && selection.length > 0 && e.key === Key.BACKSPACE && !hasModifiers) { | ||
| removeSelection(selection[selection.length - 1]); | ||
| } | ||
| }; | ||
|
|
||
| const toggleSelection = (completion: ICompletion) => { | ||
| const newSelection = [...selection]; | ||
| const index = selection.findIndex(selection => selection.completionId === completion.completionId); | ||
|
|
||
| if (index >= 0) { | ||
| newSelection.splice(index, 1); | ||
| } else { | ||
| newSelection.push(completion); | ||
| } | ||
|
|
||
| onSelectionChange(newSelection); | ||
| focusEditor(); | ||
| }; | ||
|
|
||
| const removeSelection = (completion: ICompletion) => { | ||
| const newSelection = [...selection]; | ||
| const index = selection.findIndex(selection => selection.completionId === completion.completionId); | ||
|
|
||
| if (index >= 0) { | ||
| newSelection.splice(index, 1); | ||
| onSelectionChange(newSelection); | ||
| } | ||
| }; | ||
|
|
||
| const hasPlaceholder = (): boolean => selection.length === 0 && query.length === 0; | ||
|
|
||
| return ( | ||
| <div className="mx_AutocompleteInput"> | ||
| <div | ||
| ref={editorContainerRef} | ||
| className={classNames({ | ||
| 'mx_AutocompleteInput_editor': true, | ||
| 'mx_AutocompleteInput_editor--focused': isFocused, | ||
| 'mx_AutocompleteInput_editor--has-suggestions': suggestions.length > 0, | ||
| })} | ||
| onClick={onClickInputArea} | ||
| data-testid="autocomplete-editor" | ||
| > | ||
| <SearchIcon className="mx_AutocompleteInput_search_icon" width={16} height={16} /> | ||
| { | ||
| selection.map(item => ( | ||
| <SelectionItem | ||
| key={item.completionId} | ||
| item={item} | ||
| onClick={removeSelection} | ||
| render={renderSelection} | ||
| /> | ||
| )) | ||
| } | ||
| <input | ||
| ref={editorRef} | ||
| type="text" | ||
| onKeyDown={onKeyDown} | ||
| onChange={onQueryChange} | ||
| value={query} | ||
| autoComplete="off" | ||
| placeholder={hasPlaceholder() ? placeholder : undefined} | ||
| data-testid="autocomplete-input" | ||
weeman1337 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| {...onFocusChangeHandlerFunctions} | ||
| /> | ||
| </div> | ||
| { | ||
| (isFocused && suggestions.length) ? ( | ||
| <div | ||
| className="mx_AutocompleteInput_matches" | ||
| style={{ top: editorContainerRef.current?.clientHeight }} | ||
| data-testid="autocomplete-matches" | ||
| > | ||
| { | ||
| suggestions.map((item) => ( | ||
| <SuggestionItem | ||
| key={item.completionId} | ||
| item={item} | ||
| selection={selection} | ||
| onClick={toggleSelection} | ||
| render={renderSuggestion} | ||
| /> | ||
| )) | ||
| } | ||
| </div> | ||
| ) : null | ||
| } | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| type SelectionItemProps = { | ||
| item: ICompletion; | ||
| onClick: (completion: ICompletion) => void; | ||
| render?: (completion: ICompletion) => ReactElement; | ||
| }; | ||
|
|
||
| const SelectionItem: React.FC<SelectionItemProps> = ({ item, onClick, render }) => { | ||
| const withContainer = (children: ReactNode): ReactElement => ( | ||
| <span | ||
| className='mx_AutocompleteInput_editor_selection' | ||
| data-testid={`autocomplete-selection-item-${item.completionId}`} | ||
| > | ||
| <span className='mx_AutocompleteInput_editor_selection_pill'> | ||
| { children } | ||
| </span> | ||
| <AccessibleButton | ||
| className='mx_AutocompleteInput_editor_selection_remove_button' | ||
| onClick={() => onClick(item)} | ||
| data-testid={`autocomplete-selection-remove-button-${item.completionId}`} | ||
| > | ||
| <PillRemoveIcon width={8} height={8} /> | ||
| </AccessibleButton> | ||
| </span> | ||
| ); | ||
|
|
||
| if (render) { | ||
| return withContainer(render(item)); | ||
| } | ||
|
|
||
| return withContainer( | ||
| <span className='mx_AutocompleteInput_editor_selection_text'>{ item.completion }</span>, | ||
| ); | ||
| }; | ||
|
|
||
| type SuggestionItemProps = { | ||
| item: ICompletion; | ||
| selection: ICompletion[]; | ||
| onClick: (completion: ICompletion) => void; | ||
| render?: (completion: ICompletion) => ReactElement; | ||
| }; | ||
|
|
||
| const SuggestionItem: React.FC<SuggestionItemProps> = ({ item, selection, onClick, render }) => { | ||
| const isSelected = selection.some(selection => selection.completionId === item.completionId); | ||
| const classes = classNames({ | ||
| 'mx_AutocompleteInput_suggestion': true, | ||
| 'mx_AutocompleteInput_suggestion--selected': isSelected, | ||
| }); | ||
|
|
||
| const withContainer = (children: ReactNode): ReactElement => ( | ||
| <div | ||
| className={classes} | ||
| // `onClick` cannot be used here as it would lead to focus loss and closing the suggestion list. | ||
| onMouseDown={(event) => { | ||
| event.preventDefault(); | ||
| onClick(item); | ||
| }} | ||
| data-testid={`autocomplete-suggestion-item-${item.completionId}`} | ||
| > | ||
| { children } | ||
| </div> | ||
| ); | ||
|
|
||
| if (render) { | ||
| return withContainer(render(item)); | ||
| } | ||
|
|
||
| return withContainer( | ||
| <> | ||
| <span className='mx_AutocompleteInput_suggestion_title'>{ item.completion }</span> | ||
| <span className='mx_AutocompleteInput_suggestion_description'>{ item.completionId }</span> | ||
| </>, | ||
| ); | ||
| }; | ||
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.
Uh oh!
There was an error while loading. Please reload this page.