From 35d4ec6e803978d8861b4f5205f90b264f56af3c Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 29 Nov 2021 09:23:25 +0000 Subject: [PATCH] Fix Manage Restricted Join Rule Dialog for Spaces (#7208) --- .../ManageRestrictedJoinRuleDialog.tsx | 32 ++++++++++++++----- src/i18n/strings/en_EN.json | 1 + 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/components/views/dialogs/ManageRestrictedJoinRuleDialog.tsx b/src/components/views/dialogs/ManageRestrictedJoinRuleDialog.tsx index e4b01526fcf..b80f7741235 100644 --- a/src/components/views/dialogs/ManageRestrictedJoinRuleDialog.tsx +++ b/src/components/views/dialogs/ManageRestrictedJoinRuleDialog.tsx @@ -66,6 +66,17 @@ const Entry = ({ room, checked, onChange }) => { ; }; +const addAllParents = (set: Set, room: Room): void => { + const cli = room.client; + const parents = Array.from(SpaceStore.instance.getKnownParents(room.roomId)).map(parentId => cli.getRoom(parentId)); + + parents.forEach(parent => { + if (set.has(parent)) return; + set.add(parent); + addAllParents(set, parent); + }); +}; + const ManageRestrictedJoinRuleDialog: React.FC = ({ room, selected = [], onFinished }) => { const cli = room.client; const [newSelected, setNewSelected] = useState(new Set(selected)); @@ -73,9 +84,10 @@ const ManageRestrictedJoinRuleDialog: React.FC = ({ room, selected = [], const lcQuery = query.toLowerCase().trim(); const [spacesContainingRoom, otherEntries] = useMemo(() => { - const spaces = cli.getVisibleRooms().filter(r => r.getMyMembership() === "join" && r.isSpaceRoom()); + const parents = new Set(); + addAllParents(parents, room); return [ - spaces.filter(r => SpaceStore.instance.getSpaceFilteredRoomIds(r.roomId).has(room.roomId)), + Array.from(parents), selected.map(roomId => { const room = cli.getRoom(roomId); if (!room) { @@ -86,9 +98,9 @@ const ManageRestrictedJoinRuleDialog: React.FC = ({ room, selected = [], } }).filter(Boolean), ]; - }, [cli, selected, room.roomId]); + }, [cli, selected, room]); - const [filteredSpacesContainingRooms, filteredOtherEntries] = useMemo(() => [ + const [filteredSpacesContainingRoom, filteredOtherEntries] = useMemo(() => [ spacesContainingRoom.filter(r => r.name.toLowerCase().includes(lcQuery)), otherEntries.filter(r => r.name.toLowerCase().includes(lcQuery)), ], [spacesContainingRoom, otherEntries, lcQuery]); @@ -129,10 +141,14 @@ const ManageRestrictedJoinRuleDialog: React.FC = ({ room, selected = [], autoFocus={true} /> - { filteredSpacesContainingRooms.length > 0 ? ( + { filteredSpacesContainingRoom.length > 0 ? (
-

{ _t("Spaces you know that contain this room") }

- { filteredSpacesContainingRooms.map(space => { +

+ { room.isSpaceRoom() + ? _t("Spaces you know that contain this space") + : _t("Spaces you know that contain this room") } +

+ { filteredSpacesContainingRoom.map(space => { return = ({ room, selected = [],
) : null } - { filteredSpacesContainingRooms.length + filteredOtherEntries.length < 1 + { filteredSpacesContainingRoom.length + filteredOtherEntries.length < 1 ? { _t("No results") } diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index a6738d889fe..c12cd4161a8 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -2570,6 +2570,7 @@ "Select spaces": "Select spaces", "Decide which spaces can access this room. If a space is selected, its members can find and join .": "Decide which spaces can access this room. If a space is selected, its members can find and join .", "Search spaces": "Search spaces", + "Spaces you know that contain this space": "Spaces you know that contain this space", "Spaces you know that contain this room": "Spaces you know that contain this room", "Other spaces or rooms you might not know": "Other spaces or rooms you might not know", "These are likely ones other room admins are a part of.": "These are likely ones other room admins are a part of.",