-
-
Notifications
You must be signed in to change notification settings - Fork 814
Reuse empty string & space string logic for event types in devtools #9218
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,52 +41,61 @@ export const StateEventEditor = ({ mxEvent, onBack }: IEditorProps) => { | |
| return <EventEditor fieldDefs={fields} defaultContent={defaultContent} onSend={onSend} onBack={onBack} />; | ||
| }; | ||
|
|
||
| interface StateEventButtonProps { | ||
| label: string; | ||
| onClick(): void; | ||
| } | ||
|
|
||
| const StateEventButton = ({ label, onClick }: StateEventButtonProps) => { | ||
| const trimmed = label.trim(); | ||
|
|
||
| return <button | ||
| className={classNames("mx_DevTools_button", { | ||
| mx_DevTools_RoomStateExplorer_button_hasSpaces: trimmed.length !== label.length, | ||
| mx_DevTools_RoomStateExplorer_button_emptyString: !trimmed, | ||
| })} | ||
| onClick={onClick} | ||
| > | ||
| { trimmed ? label : _t("<%(count)s spaces>", { count: label.length }) } | ||
|
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. As indicated above, this may also be tabs or other white spaces.
Member
Author
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. Sure, feel free to open a new issue for that, it isn't a new issue
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. When I first saw the screenshot I thought of Matrix Spaces.
Member
Author
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. This isn't a new issue though |
||
| </button>; | ||
| }; | ||
|
|
||
| interface IEventTypeProps extends Pick<IDevtoolsProps, "onBack"> { | ||
| eventType: string; | ||
| } | ||
|
|
||
| const RoomStateExplorerEventType = ({ eventType, onBack }: IEventTypeProps) => { | ||
| const context = useContext(DevtoolsContext); | ||
| const [query, setQuery] = useState(""); | ||
| const [event, setEvent] = useState<MatrixEvent>(null); | ||
| const [event, setEvent] = useState<MatrixEvent | null>(null); | ||
|
|
||
| const events = context.room.currentState.events.get(eventType); | ||
| const events = context.room.currentState.events.get(eventType)!; | ||
|
|
||
| useEffect(() => { | ||
| if (events.size === 1 && events.has("")) { | ||
| setEvent(events.get("")); | ||
| setEvent(events.get("")!); | ||
| } else { | ||
| setEvent(null); | ||
| } | ||
| }, [events]); | ||
|
|
||
| if (event) { | ||
| const onBack = () => { | ||
| setEvent(null); | ||
| const _onBack = () => { | ||
|
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. I know this inside an still I'd like to point out that ideally this would be wrapped in an
Member
Author
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. You can't use |
||
| if (events?.size === 1 && events.has("")) { | ||
| onBack(); | ||
| } else { | ||
| setEvent(null); | ||
| } | ||
| }; | ||
| return <EventViewer mxEvent={event} onBack={onBack} Editor={StateEventEditor} />; | ||
| return <EventViewer mxEvent={event} onBack={_onBack} Editor={StateEventEditor} />; | ||
| } | ||
|
|
||
| return <BaseTool onBack={onBack}> | ||
| <FilteredList query={query} onChange={setQuery}> | ||
| { | ||
| Array.from(events.entries()).map(([stateKey, ev]) => { | ||
| const trimmed = stateKey.trim(); | ||
| const onClick = () => { | ||
| setEvent(ev); | ||
| }; | ||
|
|
||
| return <button | ||
| className={classNames("mx_DevTools_button", { | ||
| mx_DevTools_RoomStateExplorer_button_hasSpaces: trimmed.length !== stateKey.length, | ||
| mx_DevTools_RoomStateExplorer_button_emptyString: !trimmed, | ||
| })} | ||
| key={stateKey} | ||
| onClick={onClick} | ||
| > | ||
| { trimmed ? stateKey : _t("<%(count)s spaces>", { count: stateKey.length }) } | ||
| </button>; | ||
| }) | ||
| Array.from(events.entries()).map(([stateKey, ev]) => ( | ||
| <StateEventButton key={stateKey} label={stateKey} onClick={() => setEvent(ev)} /> | ||
|
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. If this list of events is long, performance could be improved by using
Member
Author
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. You can't use
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. You can define a new functional component outside this functional component. :) |
||
| )) | ||
| } | ||
| </FilteredList> | ||
| </BaseTool>; | ||
|
|
@@ -95,11 +104,11 @@ const RoomStateExplorerEventType = ({ eventType, onBack }: IEventTypeProps) => { | |
| export const RoomStateExplorer = ({ onBack, setTool }: IDevtoolsProps) => { | ||
| const context = useContext(DevtoolsContext); | ||
| const [query, setQuery] = useState(""); | ||
| const [eventType, setEventType] = useState<string>(null); | ||
| const [eventType, setEventType] = useState<string | null>(null); | ||
|
|
||
| const events = context.room.currentState.events; | ||
|
|
||
| if (eventType) { | ||
| if (eventType !== null) { | ||
| const onBack = () => { | ||
| setEventType(null); | ||
| }; | ||
|
|
@@ -113,19 +122,9 @@ export const RoomStateExplorer = ({ onBack, setTool }: IDevtoolsProps) => { | |
| return <BaseTool onBack={onBack} actionLabel={_t("Send custom state event")} onAction={onAction}> | ||
| <FilteredList query={query} onChange={setQuery}> | ||
| { | ||
| Array.from(events.keys()).map((eventType) => { | ||
| const onClick = () => { | ||
| setEventType(eventType); | ||
| }; | ||
|
|
||
| return <button | ||
| className="mx_DevTools_button" | ||
| key={eventType} | ||
| onClick={onClick} | ||
| > | ||
| { eventType } | ||
| </button>; | ||
| }) | ||
| Array.from(events.keys()).map((eventType) => ( | ||
| <StateEventButton key={eventType} label={eventType} onClick={() => setEventType(eventType)} /> | ||
|
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. If this list of events is long, performance could be improved by using
Member
Author
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. You can't use |
||
| )) | ||
| } | ||
| </FilteredList> | ||
| </BaseTool>; | ||
|
|
||
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.
.trim()is for all whitespaces.I think we're opening up a box that the spec should have sealed.
Source: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/Trim