-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Exporter les membres d'un salon dans un fichier csv #625
Merged
estellecomment
merged 33 commits into
develop_tchap
from
add-tab-to-download-csv-file-of-the-list-of-users-in-a-room
Aug 29, 2023
Merged
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
3032915
Add tab to download csv file of the list of users in a room
aulamber f3ff280
Put download file in tchap utils, and change csv to txt donwload
aulamber 71b0cbf
Add tooltip
aulamber d52fa19
Fix conflict and change wording
aulamber 1e29119
Add tab to download csv file of the list of users in a room (#613)
aulamber 18cc90f
Add tests for button download txt file
aulamber 8cb2c16
Undo cypress modifs
aulamber 3c51d99
Fix eslint
aulamber a098545
Add cypress test
aulamber 140532f
Merge develop and fix conflict
aulamber eb2d9ed
Fix eslint
aulamber a7eab5a
Merge branch 'develop_tchap' into add-tab-to-download-csv-file-of-the…
estellecomment 471612d
Cleanup
estellecomment f77581b
Move button to Members menu
estellecomment 4c04bbb
Add back tooltip, using AccessibleTooltipButton
estellecomment 998b37c
Move button to the top, with other button
estellecomment 9dabf94
Use FileDownloader from react-sdk rather than implement our own
estellecomment d36f930
Remove previous implementation
estellecomment f4c8ad3
add room name in exported filename
estellecomment 6fcd45f
Rename patch, shorter name
estellecomment 078c839
Update translations
estellecomment 0c8b690
Add icon (better icon coming)
estellecomment 8538a09
Button styling
estellecomment 533880e
Final icon
estellecomment de3f331
Better names for things
estellecomment 455cb1b
Separate ids with commas in text file
estellecomment 44df2ae
Cypress test WIP
estellecomment 751134d
Cypress : use normal room name
estellecomment 7fc4249
Cypress tooltip test
estellecomment e2996db
Cypress : leave room when done
estellecomment ba4129f
Rename file
estellecomment 51db713
Fit linter
estellecomment 0cd42ff
Make separate component for minimal footprint in patch
estellecomment 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
46 changes: 46 additions & 0 deletions
46
cypress/e2e/export-room-members/export-room-members.spec.ts
This file contains 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,46 @@ | ||
/// <reference types="cypress" /> | ||
|
||
import RoomUtils from "../../utils/room-utils"; | ||
import RandomUtils from "../../utils/random-utils"; | ||
import { normalize } from "../../../yarn-linked-dependencies/matrix-js-sdk/src/utils"; | ||
|
||
describe("Export room members feature", () => { | ||
const homeserverUrl = Cypress.env("E2E_TEST_USER_HOMESERVER_URL"); | ||
const homeserverShort = Cypress.env("E2E_TEST_USER_HOMESERVER_SHORT"); | ||
const email = Cypress.env("E2E_TEST_USER_EMAIL"); | ||
const password = Cypress.env("E2E_TEST_USER_PASSWORD"); | ||
const today = new Date().toISOString().slice(0, 10).replace(/-/g, ""); | ||
// This will fail if email has special characters. | ||
const userId = "@" + email.replace("@", "-") + ":" + homeserverShort; | ||
|
||
beforeEach(() => { | ||
cy.loginUser(homeserverUrl, email, password); | ||
}); | ||
|
||
afterEach(() => {}); | ||
|
||
it("should display the tooltip on button hover", () => { | ||
const roomName = "test/" + today + "/export_room_members/" + RandomUtils.generateRandom(4); | ||
RoomUtils.createPublicRoom(roomName).then((roomId) => { | ||
RoomUtils.openPeopleMenu(roomName); | ||
cy.get('[data-testid="tc_exportRoomMembersButton"]') | ||
.trigger("mouseover") | ||
.get(".tc_exportRoomMembersTooltip"); // tooltip should show | ||
cy.leaveRoom(roomId); | ||
}); | ||
}); | ||
|
||
it("downloads the file when button is clicked", () => { | ||
const roomName = "test/" + today + "/export_room_members/" + RandomUtils.generateRandom(4); | ||
const normalizedRoomName = normalize(roomName); | ||
RoomUtils.createPublicRoom(roomName).then((roomId) => { | ||
RoomUtils.openPeopleMenu(roomName); | ||
cy.get('[data-testid="tc_exportRoomMembersButton"]') | ||
.click() | ||
.then(() => { | ||
cy.readFile("cypress/downloads/membres_de_" + normalizedRoomName + ".txt").should("eq", userId); | ||
}); | ||
cy.leaveRoom(roomId); | ||
}); | ||
}); | ||
}); |
This file contains 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 |
---|---|---|
@@ -1,21 +1,32 @@ | ||
import Chainable = Cypress.Chainable; | ||
import TchapCreateRoom from "../../src/tchap/lib/createTchapRoom"; | ||
import { TchapRoomType } from "../../src/tchap/@types/tchap"; | ||
|
||
export default class RoomUtils { | ||
public static createPublicRoom(roomName: string): Chainable<string> { | ||
return cy.createRoom(TchapCreateRoom.roomCreateOptions(roomName, TchapRoomType.Forum).createOpts); | ||
return cy.createRoom(TchapCreateRoom.roomCreateOptions(roomName, TchapRoomType.Forum, false).createOpts); | ||
} | ||
public static createPrivateRoom(roomName: string): Chainable<string> { | ||
return cy.createRoom(TchapCreateRoom.roomCreateOptions(roomName, TchapRoomType.Private).createOpts); | ||
return cy.createRoom(TchapCreateRoom.roomCreateOptions(roomName, TchapRoomType.Private, false).createOpts); | ||
} | ||
public static createPrivateWithExternalRoom(roomName: string): Chainable<string> { | ||
return cy.createRoom(TchapCreateRoom.roomCreateOptions(roomName, TchapRoomType.External).createOpts); | ||
return cy.createRoom(TchapCreateRoom.roomCreateOptions(roomName, TchapRoomType.External, false).createOpts); | ||
} | ||
public static openRoom(roomName: string): Chainable<JQuery<HTMLElement>> { | ||
return cy.get('[aria-label="' + roomName + '"]').click(); | ||
} | ||
public static openRoomAccessSettings(roomName: string): Chainable<JQuery<HTMLElement>> { | ||
//open room | ||
cy.get('[aria-label="' + roomName + '"]').click(); | ||
cy.get('[aria-label="' + roomName + '"]').click(); //open room | ||
cy.get(".mx_RoomHeader_chevron").click(); | ||
cy.get('[aria-label="Paramètres"] > .mx_IconizedContextMenu_label').click(); | ||
return cy.get('[data-testid="settings-tab-ROOM_SECURITY_TAB"] > .mx_TabbedView_tabLabel_text').click(); | ||
} | ||
public static openRoomInformation(roomName: string): Chainable<JQuery<HTMLElement>> { | ||
cy.get('[aria-label="' + roomName + '"]').click(); //open room | ||
return cy.get('[aria-label="Information du salon"]').click(); | ||
} | ||
public static openPeopleMenu(roomName: string): Chainable<JQuery<HTMLElement>> { | ||
this.openRoomInformation(roomName); | ||
return cy.get(".mx_RoomSummaryCard_icon_people").click(); | ||
} | ||
} |
This file contains 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,25 @@ | ||
diff --git a/node_modules/matrix-react-sdk/src/components/views/rooms/MemberList.tsx b/node_modules/matrix-react-sdk/src/components/views/rooms/MemberList.tsx | ||
index 44dba2e..69ffbed 100644 | ||
--- a/node_modules/matrix-react-sdk/src/components/views/rooms/MemberList.tsx | ||
+++ b/node_modules/matrix-react-sdk/src/components/views/rooms/MemberList.tsx | ||
@@ -46,6 +46,7 @@ import { shouldShowComponent } from "../../../customisations/helpers/UIComponent | ||
import { UIComponent } from "../../../settings/UIFeature"; | ||
import PosthogTrackers from "../../../PosthogTrackers"; | ||
import { SDKContext } from "../../../contexts/SDKContext"; | ||
+import TchapExportMembersButton from "../../../../../../src/tchap/components/views/rooms/TchapExportMembersButton"; // TCHAP | ||
|
||
const INITIAL_LOAD_NUM_MEMBERS = 30; | ||
const INITIAL_LOAD_NUM_INVITED = 5; | ||
@@ -409,6 +410,12 @@ export default class MemberList extends React.Component<IProps, IState> { | ||
<React.Fragment> | ||
{scopeHeader} | ||
{inviteButton} | ||
+ {/** TCHAP */} | ||
+ <TchapExportMembersButton | ||
+ room={room} | ||
+ roomMembersIds={this.state.filteredJoinedMembers.map(roomMember => roomMember.userId)}> | ||
+ </TchapExportMembersButton> | ||
+ {/** end TCHAP */} | ||
</React.Fragment> | ||
} | ||
footer={footer} |
This file contains 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 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,31 @@ | ||
/** | ||
* Copyright DINUM 2023 | ||
*/ | ||
|
||
.mx_AccessibleButton.mx_AccessibleButton_hasKind.tc_MemberList_export { | ||
/* Copy the style from mx_MemberList_invite button just above. For some reason it doesn't follow the standard style. */ | ||
display: flex; | ||
justify-content: center; | ||
margin: 5px 9px 9px; | ||
padding: 0px; | ||
border-radius: 4px; | ||
font-weight: 600; | ||
} | ||
|
||
.tc_MemberList_export span { | ||
padding: 8px 0; | ||
display: inline-flex; | ||
|
||
&::before { | ||
content: ""; | ||
display: inline-block; | ||
background-color: var(--accent); | ||
mask-image: url("../../../img/tchap/user-export.svg"); | ||
mask-position: center; | ||
mask-repeat: no-repeat; | ||
mask-size: 20px; | ||
width: 20px; | ||
height: 20px; | ||
margin-right: 5px; | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
62 changes: 62 additions & 0 deletions
62
src/tchap/components/views/rooms/TchapExportMembersButton.tsx
This file contains 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,62 @@ | ||
/** | ||
* Copyright DINUM 2023 | ||
*/ | ||
|
||
import React from "react"; | ||
|
||
import { FileDownloader } from "matrix-react-sdk/src/utils/FileDownloader"; | ||
import AccessibleTooltipButton from "matrix-react-sdk/src/components/views/elements/AccessibleTooltipButton"; | ||
import { ButtonEvent } from "matrix-react-sdk/src/components/views/elements/AccessibleButton"; | ||
import { Room } from "matrix-js-sdk/src/models/room"; | ||
import { _t } from "matrix-react-sdk/src/languageHandler"; | ||
|
||
import "../../../../../res/css/views/rooms/TchapExportMembersButton.pcss"; | ||
|
||
interface IProps { | ||
room: Room; | ||
roomMembersIds: Array<string>; | ||
} | ||
|
||
interface IState { | ||
} | ||
|
||
export default class MemberList extends React.Component<IProps, IState> { | ||
private downloader = new FileDownloader(); | ||
|
||
public constructor(props: IProps) { | ||
super(props); | ||
} | ||
|
||
private onExportButtonClick = (ev: ButtonEvent): void => { | ||
const blob = new Blob([this.props.roomMembersIds.join()], { type : 'plain/text' }) | ||
|
||
const filename = _t('members_of_%(roomName)s.txt', { | ||
roomName: this.props.room.normalizedName, | ||
}); | ||
|
||
this.downloader.download({ | ||
blob: blob, | ||
name: filename, | ||
}); | ||
|
||
return; | ||
}; | ||
|
||
public render(): React.ReactNode { | ||
if (this.props.room?.getMyMembership() === "join" && !this.props.room.isSpaceRoom() && this.props.roomMembersIds.length > 0) { | ||
return ( | ||
<AccessibleTooltipButton | ||
data-testid="tc_exportRoomMembersButton" | ||
className="tc_MemberList_export mx_AccessibleButton mx_AccessibleButton_hasKind mx_AccessibleButton_kind_primary_outline" | ||
onClick={this.onExportButtonClick} | ||
tooltip={_t("Download the list of all this room's members, in a text file. Useful for adding them all to another room.")} | ||
tooltipClassName="tc_exportRoomMembersTooltip" | ||
> | ||
<span>{_t("Export room members")}</span> | ||
</AccessibleTooltipButton> | ||
); | ||
} | ||
return null; | ||
} | ||
|
||
} |
This file contains 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
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.
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.
nice