Skip to content

Commit 7d6a223

Browse files
committed
Correctly use new widgetcontextmenu component
1 parent afa24bf commit 7d6a223

File tree

6 files changed

+59
-66
lines changed

6 files changed

+59
-66
lines changed

packages/shared-components/jest-sonar.xml

Lines changed: 0 additions & 7 deletions
This file was deleted.

packages/shared-components/src/right-panel/WidgetContextMenu/WidgetContextMenuView.test.tsx

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
/*
2-
Copyright 2024 New Vector Ltd.
3-
Copyright 2023 Mikhail Aheichyk
4-
Copyright 2023 Nordeck IT + Consulting GmbH.
5-
6-
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
7-
Please see LICENSE files in the repository root for full details.
8-
*/
2+
* Copyright 2025 New Vector Ltd.
3+
*
4+
* SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
5+
* Please see LICENSE files in the repository root for full details.
6+
*/
97

108
import React from "react";
119
import { screen, render } from "jest-matrix-react";
@@ -20,12 +18,10 @@ import TriggerIcon from "@vector-im/compound-design-tokens/assets/web/icons/over
2018
const { Default, OnlyBasicModification } = composeStories(stories);
2119

2220
describe("<WidgetContextMenuView />", () => {
23-
2421
afterEach(() => {
25-
jest.resetAllMocks();
22+
jest.clearAllMocks();
2623
});
2724

28-
2925
it("renders widget contextmenu with all options", () => {
3026
const { container } = render(<Default />);
3127
expect(container).toMatchSnapshot();
@@ -62,7 +58,7 @@ describe("<WidgetContextMenuView />", () => {
6258
public onRevokeClick = onRevokeClick;
6359
public onFinished = onFinished;
6460
public onMoveButton = onMoveButton;
65-
};
61+
}
6662

6763
const defaultValue: WidgetContextMenuSnapshot = {
6864
showStreamAudioStreamButton: true,
@@ -97,10 +93,10 @@ describe("<WidgetContextMenuView />", () => {
9793

9894
await userEvent.click(screen.getByRole("menuitem", { name: "Revoke permissions" }));
9995
expect(onRevokeClick).toHaveBeenCalled();
100-
96+
10197
await userEvent.click(screen.getByRole("menuitem", { name: "Remove for everyone" }));
10298
expect(onDeleteClick).toHaveBeenCalled();
103-
99+
104100
await userEvent.click(screen.getByRole("menuitem", { name: "Move left" }));
105101
expect(onMoveButton).toHaveBeenCalledWith(-1);
106102

src/components/views/elements/AppTile.tsx

Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import Spinner from "./Spinner";
3838
import dis from "../../../dispatcher/dispatcher";
3939
import ActiveWidgetStore from "../../../stores/ActiveWidgetStore";
4040
import SettingsStore from "../../../settings/SettingsStore";
41-
import { aboveLeftOf, ContextMenuButton } from "../../structures/ContextMenu";
41+
import { ContextMenuButton } from "../../structures/ContextMenu";
4242
import PersistedElement, { getPersistKey } from "./PersistedElement";
4343
import { WidgetType } from "../../../widgets/WidgetType";
4444
import { ElementWidget, StopGapWidget } from "../../../stores/widgets/StopGapWidget";
@@ -132,7 +132,6 @@ interface IState {
132132
error: Error | null;
133133
menuDisplayed: boolean;
134134
requiresClient: boolean;
135-
hasContextMenuOptions: boolean;
136135
}
137136

138137
export default class AppTile extends React.Component<IProps, IState> {
@@ -269,15 +268,7 @@ export default class AppTile extends React.Component<IProps, IState> {
269268
isUserProfileReady: OwnProfileStore.instance.isProfileInfoFetched,
270269
error: null,
271270
menuDisplayed: false,
272-
requiresClient: this.determineInitialRequiresClientState(),
273-
hasContextMenuOptions: showContextMenu(
274-
this.context,
275-
this.props.room,
276-
newProps.app,
277-
newProps.userWidget,
278-
!newProps.userWidget,
279-
newProps.onDeleteClick,
280-
),
271+
requiresClient: this.determineInitialRequiresClientState()
281272
};
282273
}
283274

@@ -801,28 +792,26 @@ export default class AppTile extends React.Component<IProps, IState> {
801792
<PopoutIcon className="mx_Icon mx_Icon_12 mx_Icon--stroke" />
802793
</AccessibleButton>
803794
)}
804-
{this.state.hasContextMenuOptions && (
805-
<WidgetContextMenu
806-
trigger={
807-
<ContextMenuButton
808-
className="mx_AppTileMenuBar_widgets_button"
809-
label={_t("common|options")}
810-
isExpanded={this.state.menuDisplayed}
811-
ref={this.contextMenuButton}
812-
onClick={() => {}}
813-
>
814-
<OverflowHorizontalIcon className="mx_Icon mx_Icon_12" />
815-
</ContextMenuButton>
816-
}
817-
app={this.props.app}
818-
onFinished={() => this.state.menuDisplayed ? this.closeContextMenu() : this.onContextMenuClick()}
819-
showUnpin={!this.props.userWidget}
820-
userWidget={this.props.userWidget}
821-
onEditClick={this.props.onEditClick}
822-
onDeleteClick={this.props.onDeleteClick}
823-
menuDisplayed={this.state.menuDisplayed}
824-
/>
825-
)}
795+
<WidgetContextMenu
796+
trigger={
797+
<ContextMenuButton
798+
className="mx_AppTileMenuBar_widgets_button"
799+
label={_t("common|options")}
800+
isExpanded={this.state.menuDisplayed}
801+
ref={this.contextMenuButton}
802+
onClick={this.onContextMenuClick}
803+
>
804+
<OverflowHorizontalIcon className="mx_Icon mx_Icon_12" />
805+
</ContextMenuButton>
806+
}
807+
app={this.props.app}
808+
onFinished={this.closeContextMenu}
809+
showUnpin={!this.props.userWidget}
810+
userWidget={this.props.userWidget}
811+
onEditClick={this.props.onEditClick}
812+
onDeleteClick={this.props.onDeleteClick}
813+
menuDisplayed={this.state.menuDisplayed}
814+
/>
826815
</span>
827816
</div>
828817
)}

src/components/views/right_panel/ExtensionsCard.tsx

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Com
66
Please see LICENSE files in the repository root for full details.
77
*/
88

9-
import React, { type JSX, useEffect, useMemo, useRef, useState } from "react";
9+
import React, { type JSX, useEffect, useMemo, useState } from "react";
1010
import { type Room } from "matrix-js-sdk/src/matrix";
1111
import classNames from "classnames";
1212
import { Button, Link, Separator, Text } from "@vector-im/compound-web";
@@ -16,8 +16,7 @@ import ExtensionsIcon from "@vector-im/compound-design-tokens/assets/web/icons/e
1616
import BaseCard from "./BaseCard";
1717
import WidgetUtils, { useWidgets } from "../../../utils/WidgetUtils";
1818
import { _t } from "../../../languageHandler";
19-
import { ChevronFace, ContextMenuTooltipButton, useContextMenu } from "../../structures/ContextMenu";
20-
import UIStore from "../../../stores/UIStore";
19+
import { useContextMenu } from "../../structures/ContextMenu";
2120
import RightPanelStore from "../../../stores/right-panel/RightPanelStore";
2221
import { type IApp } from "../../../stores/WidgetStore";
2322
import { RightPanelPhases } from "../../../stores/right-panel/RightPanelStorePhases";
@@ -107,15 +106,15 @@ const AppRow: React.FC<IAppRowProps> = ({ app, room }) => {
107106
{canModifyWidget && (
108107
<WidgetContextMenu
109108
app={app}
110-
onFinished={() => menuDisplayed ? closeMenu() : openMenu()}
109+
onFinished={closeMenu}
111110
menuDisplayed={menuDisplayed}
112111
trigger={
113112
<AccessibleButton
114113
ref={handle}
115114
className="mx_ExtensionsCard_app_options"
116-
onClick={() => {}}
115+
onClick={openMenu}
117116
title={_t("common|options")}
118-
/>
117+
/>
119118
}
120119
/>
121120
)}
@@ -126,8 +125,6 @@ const AppRow: React.FC<IAppRowProps> = ({ app, room }) => {
126125
title={pinTitle}
127126
disabled={cannotPin}
128127
/>
129-
130-
{/* {contextMenu} */}
131128
</div>
132129
);
133130
};

src/components/views/right_panel/WidgetCard.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,20 @@ const WidgetCard: React.FC<IProps> = ({ room, widgetId, onClose }) => {
4545
// Don't render anything as we are about to transition
4646
if (!app || !isRight) return null;
4747

48-
const contextMenu : JSX.Element = (
48+
const contextMenu: JSX.Element = (
4949
<WidgetContextMenu
5050
trigger={
5151
<ContextMenuButton
5252
className="mx_BaseCard_header_title_button--option"
5353
ref={handle}
54-
onClick={() => {}}
54+
onClick={openMenu}
5555
isExpanded={menuDisplayed}
5656
label={_t("common|options")}
5757
/>
5858
}
59-
onFinished={() => (menuDisplayed ? closeMenu : openMenu)}
59+
onFinished={closeMenu}
6060
app={app}
61-
menuDisplayed={true}
61+
menuDisplayed={menuDisplayed}
6262
/>
6363
);
6464

src/viewmodels/right-panel/WidgetContextMenuViewModel.tsx

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ export class WidgetContextMenuViewModel
218218
} else if (this._room) {
219219
WidgetUtils.editWidget(this._room, this._app);
220220
}
221+
console.log("finished edit", this.props.onFinished);
221222
this.props.onFinished!();
222223
};
223224
}
@@ -279,5 +280,22 @@ export function WidgetContextMenu(props: WidgetContextMenuProps): ReactElement {
279280
};
280281
}, [vm]);
281282

282-
return <WidgetContextMenuView vm={vm} />;
283+
const {
284+
showStreamAudioStreamButton,
285+
showEditButton,
286+
showRevokeButton,
287+
showDeleteButton,
288+
showSnapshotButton,
289+
showMoveButtons,
290+
} = vm.getSnapshot();
291+
292+
const hasContextMenuOptions =
293+
showStreamAudioStreamButton ||
294+
showEditButton ||
295+
showRevokeButton ||
296+
showDeleteButton ||
297+
showSnapshotButton ||
298+
showMoveButtons.some(Boolean);
299+
300+
return hasContextMenuOptions ? <WidgetContextMenuView vm={vm} /> : <></>;
283301
}

0 commit comments

Comments
 (0)