Skip to content

Commit 0eff1ca

Browse files
authored
Add options to hide right panel in room view (#31252)
* feat: add options to hide right panel in room view This option is added for the module API. * test: add test for hideRightPanel=true of room view * test: update snapshot ids
1 parent b7acbe6 commit 0eff1ca

File tree

3 files changed

+424
-31
lines changed

3 files changed

+424
-31
lines changed

src/components/structures/RoomView.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,11 @@ interface IRoomProps extends RoomViewProps {
175175
* If true, hide the composer
176176
*/
177177
hideComposer?: boolean;
178+
179+
/*
180+
* If true, hide the right panel
181+
*/
182+
hideRightPanel?: boolean;
178183
}
179184

180185
export { MainSplitContentType };
@@ -2557,7 +2562,8 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
25572562
);
25582563
}
25592564

2560-
const showRightPanel = !isRoomEncryptionLoading && this.state.room && this.state.showRightPanel;
2565+
const showRightPanel =
2566+
!this.props.hideRightPanel && !isRoomEncryptionLoading && this.state.room && this.state.showRightPanel;
25612567

25622568
const rightPanel = showRightPanel ? (
25632569
<RightPanel

test/unit-tests/components/structures/RoomView-test.tsx

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -154,18 +154,21 @@ describe("RoomView", () => {
154154
}
155155

156156
const roomView = render(
157-
<MatrixClientContext.Provider value={cli}>
158-
<SDKContext.Provider value={stores}>
159-
<RoomView
160-
// threepidInvite should be optional on RoomView props
161-
// it is treated as optional in RoomView
162-
threepidInvite={undefined as any}
163-
forceTimeline={false}
164-
ref={ref}
165-
{...props}
166-
/>
167-
</SDKContext.Provider>
168-
</MatrixClientContext.Provider>,
157+
<RoomView
158+
// threepidInvite should be optional on RoomView props
159+
// it is treated as optional in RoomView
160+
threepidInvite={undefined as any}
161+
forceTimeline={false}
162+
ref={ref}
163+
{...props}
164+
/>,
165+
{
166+
wrapper: ({ children }) => (
167+
<MatrixClientContext.Provider value={cli}>
168+
<SDKContext.Provider value={stores}>{children}</SDKContext.Provider>
169+
</MatrixClientContext.Provider>
170+
),
171+
},
169172
);
170173
await flushPromises();
171174
return roomView;
@@ -273,6 +276,28 @@ describe("RoomView", () => {
273276
expect(asFragment()).toMatchSnapshot();
274277
});
275278

279+
it("should hide the right panel when hideRightPanel=true", async () => {
280+
// Join the room
281+
jest.spyOn(room, "getMyMembership").mockReturnValue(KnownMembership.Join);
282+
const { asFragment, rerender } = await mountRoomView(undefined);
283+
284+
defaultDispatcher.dispatch<ViewUserPayload>(
285+
{
286+
action: Action.ViewUser,
287+
member: undefined,
288+
},
289+
true,
290+
);
291+
292+
// Check that the right panel is rendered
293+
await expect(screen.findByTestId("right-panel")).resolves.toBeTruthy();
294+
// Now rerender with hideRightPanel=true
295+
rerender(<RoomView threepidInvite={undefined} forceTimeline={false} hideRightPanel={true} />);
296+
// Check that the right panel is not rendered
297+
await expect(screen.findByTestId("right-panel")).rejects.toThrow();
298+
expect(asFragment()).toMatchSnapshot();
299+
});
300+
276301
describe("invites", () => {
277302
beforeEach(() => {
278303
const member = new RoomMember(room.roomId, cli.getSafeUserId());

0 commit comments

Comments
 (0)