Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Poll history: detail screen #10172

Merged
merged 18 commits into from
Feb 27, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/components/views/dialogs/polls/PollDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { Action } from "../../../../dispatcher/actions";
import { ViewRoomPayload } from "../../../../dispatcher/payloads/ViewRoomPayload";
import { RoomPermalinkCreator } from "../../../../utils/permalinks/Permalinks";
import { MediaEventHelper } from "../../../../utils/MediaEventHelper";
import AccessibleButton from "../../elements/AccessibleButton";
import AccessibleButton, { ButtonEvent } from "../../elements/AccessibleButton";
import MPollBody from "../../messages/MPollBody";

interface Props {
Expand All @@ -34,13 +34,16 @@ interface Props {

const NOOP = (): void => {};

/**
* Content of the PollHistoryDialog when a specific poll is selected
*/
export const PollDetail: React.FC<Props> = ({ poll, permalinkCreator, requestModalClose }) => {
richvdh marked this conversation as resolved.
Show resolved Hide resolved
// link to end event for ended polls
const eventIdToLinkTo = poll.isEnded ? poll.endEventId! : poll.pollId;
const linkToTimeline = permalinkCreator.forEvent(eventIdToLinkTo);

const onLinkClick = (e: React.MouseEvent): void => {
if (e.ctrlKey || e.metaKey) {
const onLinkClick = (e: ButtonEvent): void => {
if ((e as React.MouseEvent).ctrlKey || (e as React.MouseEvent).metaKey) {
// native behavior for link on ctrl/cmd + click
return;
}
Expand Down
9 changes: 4 additions & 5 deletions src/components/views/dialogs/polls/PollHistoryDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ limitations under the License.

import React, { useState } from "react";
import { MatrixClient } from "matrix-js-sdk/src/client";
import { MatrixEvent, Poll } from "matrix-js-sdk/src/matrix";
import { MatrixEvent, Poll, Room } from "matrix-js-sdk/src/matrix";

import { _t } from "../../../../languageHandler";
import BaseDialog from "../BaseDialog";
Expand All @@ -30,7 +30,7 @@ import { usePollsWithRelations } from "./usePollHistory";
import { useFetchPastPolls } from "./fetchPastPolls";

type PollHistoryDialogProps = Pick<IDialogProps, "onFinished"> & {
roomId: string;
room: Room;
matrixClient: MatrixClient;
permalinkCreator: RoomPermalinkCreator;
};
Expand All @@ -51,15 +51,14 @@ const filterAndSortPolls = (polls: Map<string, Poll>, filter: PollHistoryFilter)
};

export const PollHistoryDialog: React.FC<PollHistoryDialogProps> = ({
roomId,
room,
matrixClient,
permalinkCreator,
onFinished,
}) => {
const { polls } = usePollsWithRelations(roomId, matrixClient);
const { polls } = usePollsWithRelations(room.roomId, matrixClient);
const [filter, setFilter] = useState<PollHistoryFilter>("ACTIVE");
const [focusedPollId, setFocusedPollId] = useState<string | null>(null);
const room = matrixClient.getRoom(roomId)!;
const { isLoading } = useFetchPastPolls(room, matrixClient);

const pollStartEvents = filterAndSortPolls(polls, filter);
Expand Down
4 changes: 2 additions & 2 deletions src/components/views/right_panel/RoomSummaryCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ import { PollHistoryDialog } from "../dialogs/polls/PollHistoryDialog";

interface IProps {
room: Room;
permalinkCreator: RoomPermalinkCreator;
permalinkCreator?: RoomPermalinkCreator;
onClose(): void;
}

Expand Down Expand Up @@ -287,7 +287,7 @@ const RoomSummaryCard: React.FC<IProps> = ({ room, permalinkCreator, onClose })

const onRoomPollHistoryClick = (): void => {
Modal.createDialog(PollHistoryDialog, {
roomId: room.roomId,
room,
matrixClient: cli,
permalinkCreator,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks to me like it ought to introduce a type-checking error, and I'm slightly mystified as to why it doesn't. Am I missing some reason why we can rely on permalinkCreator to be defined despite the ? in IProps ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(it feels like the right solution here is to make permalinkCreator a required prop for RoomSummaryCard and add a ! in RightPanel. YMMV though)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

createDialog has very soft types

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

createDialog has very soft types

Ah that explains why typescript isn't catching it. Still feel like it's a thing that we should address though.

To expand on my thinking here: AIUI currently we're assuming that whenever RightPanel is given a Room, it is also given a permalink creator. That's okayyyy though I wish that assumption was made explicit either via comments or, better, via the typing system. Still it's not a new situation so doesn't particularly need fixing in this PR. What we can do in this PR is limit the impact of that assumption by sticking a ! in RightPanel rather than softening the types for RoomSummaryCard.

});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe("<PollHistoryDialog />", () => {
});

const defaultProps = {
roomId,
room,
matrixClient: mockClient,
permalinkCreator: new RoomPermalinkCreator(room),
onFinished: jest.fn(),
Expand All @@ -74,6 +74,7 @@ describe("<PollHistoryDialog />", () => {
beforeEach(() => {
room = new Room(roomId, mockClient, userId);
mockClient.getRoom.mockReturnValue(room);
defaultProps.room = room;
mockClient.relations.mockResolvedValue({ events: [] });
const timeline = room.getLiveTimeline();
jest.spyOn(timeline, "getEvents").mockReturnValue([]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ describe("<RoomSummaryCard />", () => {
fireEvent.click(getByText("Polls history"));

expect(modalSpy).toHaveBeenCalledWith(PollHistoryDialog, {
roomId,
room,
matrixClient: mockClient,
permalinkCreator: defaultProps.permalinkCreator,
});
Expand Down