From 2df2c6e6a744cda38be08dd692ed2ebf225c72cc Mon Sep 17 00:00:00 2001 From: Craig Conover Date: Sun, 14 Nov 2021 08:22:41 -0700 Subject: [PATCH 1/7] forgot I was on master; need to move this to another branch and clean master --- .../ObjectAdmin/pages/dialogs/AddMembers | 61 +++++++++++++++++++ src/tools/PushDebug/pages/ManageDevice.js | 18 ------ 2 files changed, 61 insertions(+), 18 deletions(-) create mode 100644 src/tools/ObjectAdmin/pages/dialogs/AddMembers diff --git a/src/tools/ObjectAdmin/pages/dialogs/AddMembers b/src/tools/ObjectAdmin/pages/dialogs/AddMembers new file mode 100644 index 0000000..8bdd7b0 --- /dev/null +++ b/src/tools/ObjectAdmin/pages/dialogs/AddMembers @@ -0,0 +1,61 @@ +// import { useState, useRef } from "react"; + +// reactstrap components +import { + Button, + Input, + Modal, + ModalHeader, + ModalBody, + ModalFooter, +} from "reactstrap"; + +// core components + + +const AddMembers = (props) => { + + const handleClick = (e, isConfirmed) => { + e.preventDefault(); + props.addChannels(isConfirmed); + } + + return ( +
+ + +

Add New Channels

+
+ + {/* TODO: allow comma separated values */} +
+ +
+ props.newChannels.current = e.target.value} + rows="10" + /> +
+ + {' '} + + +
+
+ ); +} + +export default AddMembers; \ No newline at end of file diff --git a/src/tools/PushDebug/pages/ManageDevice.js b/src/tools/PushDebug/pages/ManageDevice.js index 22e548f..0ef3f91 100755 --- a/src/tools/PushDebug/pages/ManageDevice.js +++ b/src/tools/PushDebug/pages/ManageDevice.js @@ -500,24 +500,6 @@ function ChannelRows(props) { const rows = channels.map((ch, index) => {ch} - {/* - - Future Feature
(will nav to Inspect Channel) -
- - */} - + + + diff --git a/src/tools/ObjectAdmin/pages/ChannelsSearch.js b/src/tools/ObjectAdmin/pages/ChannelsSearch.js index 4dc338f..8e6f6a3 100755 --- a/src/tools/ObjectAdmin/pages/ChannelsSearch.js +++ b/src/tools/ObjectAdmin/pages/ChannelsSearch.js @@ -484,7 +484,7 @@ const MetadataRow = ({index, row, isTruncate, handleRemove, handleEdit}) => { )} {row.updated} - + handleEdit(e, row, index)}> diff --git a/src/tools/ObjectAdmin/pages/MembersList.js b/src/tools/ObjectAdmin/pages/MembersSearch.js similarity index 96% rename from src/tools/ObjectAdmin/pages/MembersList.js rename to src/tools/ObjectAdmin/pages/MembersSearch.js index 689dc11..18a3b1a 100755 --- a/src/tools/ObjectAdmin/pages/MembersList.js +++ b/src/tools/ObjectAdmin/pages/MembersSearch.js @@ -58,7 +58,7 @@ import EditIcon from '@mui/icons-material/Edit'; import GroupIcon from '@mui/icons-material/Group'; import ReactBSAlert from "react-bootstrap-sweetalert"; -const MembersList = () => { +const MembersSearch = () => { const keySetContext = useKeySetData(); const objectAdminContext = useObjectAdminData(); @@ -85,7 +85,7 @@ const MembersList = () => { // page state const [channelId, setChannelId] = useState(objectAdminContext.channelId); const [channelFilter, setChannelFilter] = useState(objectAdminContext.channelFilter); - + const [isTruncate, setIsTruncate] = useState(true); const [sweetAlert, setSweetAlert] = useState(null); const history = useHistory(); @@ -96,6 +96,9 @@ const MembersList = () => { let more = true; let results = []; let next = null; + let totalRecords = 0; + + confirmAlert("Searching Channel Members", "Searching for Channel Members, please wait..."); const limit = objectAdminContext.maxRows < 100 ? objectAdminContext.maxRows : 100; do { @@ -105,23 +108,24 @@ const MembersList = () => { filter : channelFilter, // || 'id = channel"*"', include: { totalCount: true, - customFields: true, - UUIDFields: true + customFields: true, + UUIDFields: true, + customUUIDFields: true }, page: {next: next} }); + totalRecords = result.totalCount; + if (result != null && result.data.length > 0) { results = results.concat(result.data); more = result.data.length >= limit; next = result.next; } - else { - more = false; - timerAlert("No Records Found!", "Your filter found 0 records.", 3); - } + else more = false; } catch (status) { + hideAlert(); // hide the please wait dialog confirmAlert(status.status.errorData.error.message, status.status.errorData.error.details[0].message, "Dismiss", ()=>hideAlert() @@ -132,7 +136,13 @@ const MembersList = () => { } } while (more); - objectAdminContext.setChannelMetadataResults(results); + hideAlert(); // hide the "searching please wait" dialog + + totalRecords === 0 + ? timerAlert("No Members Found!", "Your filter found none Channel Members.", 3) + : timerAlert("Channel Members Found!", `${totalRecords} Channel Members Found.`, 2); + + objectAdminContext.setChannelMembersResults(results); } const handleEdit = (e, record, index) => { @@ -355,7 +365,7 @@ const MembersList = () => { ); }; -export default MembersList; +export default MembersSearch; const MetadataTable = ({metadata, rowsPerPage, page, emptyRows, handleChangePage, handleChangeRowsPerPage, isTruncate, setIsTruncate, handleRemove, handleEdit}) => { diff --git a/src/tools/ObjectAdmin/pages/dialogs/AddMembers b/src/tools/ObjectAdmin/pages/dialogs/AddMembersDialog.js similarity index 65% rename from src/tools/ObjectAdmin/pages/dialogs/AddMembers rename to src/tools/ObjectAdmin/pages/dialogs/AddMembersDialog.js index 8bdd7b0..29bb936 100644 --- a/src/tools/ObjectAdmin/pages/dialogs/AddMembers +++ b/src/tools/ObjectAdmin/pages/dialogs/AddMembersDialog.js @@ -12,12 +12,14 @@ import { // core components +const AddMembersDialog = (props) => { -const AddMembers = (props) => { - + let newItems = null; const handleClick = (e, isConfirmed) => { +debugger; e.preventDefault(); - props.addChannels(isConfirmed); + props.newItems.current = (newItems == null || newItems === "") ? null : newItems.split("\n"); + props.addMembers(isConfirmed); } return ( @@ -27,25 +29,25 @@ const AddMembers = (props) => { className="modal-dialog-centered" > -

Add New Channels

+

Add New Members

{/* TODO: allow comma separated values */}
props.newChannels.current = e.target.value} + // defaultValue={props.newMembers.current} + onChange={(e) => newItems = e.target.value} rows="10" />
@@ -58,4 +60,4 @@ const AddMembers = (props) => { ); } -export default AddMembers; \ No newline at end of file +export default AddMembersDialog; \ No newline at end of file diff --git a/src/tools/ObjectAdmin/routesObjectAdmin.js b/src/tools/ObjectAdmin/routesObjectAdmin.js index 079e6d3..8192ecd 100644 --- a/src/tools/ObjectAdmin/routesObjectAdmin.js +++ b/src/tools/ObjectAdmin/routesObjectAdmin.js @@ -10,7 +10,7 @@ import ChannelsSearch from './pages/ChannelsSearch'; import UserForm from './pages/UserForm'; import UsersSearch from './pages/UsersSearch'; -// import MembersList from './pages/MembersList'; +import MembersSearch from './pages/MembersSearch'; import ImportChannels from './pages/ImportChannels'; import ImportUsers from './pages/ImportUsers'; @@ -53,14 +53,14 @@ var routesObjectAdmin = { layout: "/admin", }, {divider: true,}, - // { - // path: "/objects/members-list", - // name: "Get Members", - // component: MembersList, - // parent: ObjectAdminProvider, - // layout: "/admin", - // }, - // {divider: true,}, + { + path: "/objects/members-search", + name: "Members Search", + component: MembersSearch, + parent: ObjectAdminProvider, + layout: "/admin", + }, + {divider: true,}, { path: "/objects/import-channels", name: "Import Channels", From 84bcc72e9522e80025a11855498a65f379ea08a6 Mon Sep 17 00:00:00 2001 From: Craig Conover Date: Mon, 15 Nov 2021 20:03:16 -0700 Subject: [PATCH 3/7] add channel members and members search done but needs refactoring --- src/tools/ObjectAdmin/ObjectAdminProvider.js | 2 + src/tools/ObjectAdmin/pages/ChannelForm.js | 5 +- src/tools/ObjectAdmin/pages/MembersSearch.js | 208 +++++++++--------- src/tools/ObjectAdmin/pages/UsersSearch.js | 6 +- .../pages/dialogs/AddMembersDialog.js | 7 +- 5 files changed, 115 insertions(+), 113 deletions(-) diff --git a/src/tools/ObjectAdmin/ObjectAdminProvider.js b/src/tools/ObjectAdmin/ObjectAdminProvider.js index 5fc5d32..fe91d59 100644 --- a/src/tools/ObjectAdmin/ObjectAdminProvider.js +++ b/src/tools/ObjectAdmin/ObjectAdminProvider.js @@ -36,6 +36,7 @@ export const ObjectAdminProvider = ({ children }) => { // share UsersSearch state: const [userFilter, setUserFilter] = useState('name LIKE "*"'); // share ChannelsSearch state: const [maxRows, setMaxRows] = useState(500); const [channelMembersResults, setChannelMembersResults] = useState([]); + const [memberFilter, setMemberFilter] = useState(); // expose data/functions to context users @@ -72,6 +73,7 @@ export const ObjectAdminProvider = ({ children }) => { // ChannelMembersSearch State channelMembersResults, setChannelMembersResults, + memberFilter, setMemberFilter, } diff --git a/src/tools/ObjectAdmin/pages/ChannelForm.js b/src/tools/ObjectAdmin/pages/ChannelForm.js index ac37abb..cc3908c 100755 --- a/src/tools/ObjectAdmin/pages/ChannelForm.js +++ b/src/tools/ObjectAdmin/pages/ChannelForm.js @@ -75,7 +75,7 @@ const ChannelForm = () => { try { const result = await keySetContext.pubnub.objects.setChannelMembers({ channel: channelId, - uuids: newMembers, + uuids: newMembers.current, }); console.log(" setChannelMembers result", result) @@ -228,7 +228,8 @@ const ChannelForm = () => { // toggle={toggle} modal={modal} newItems={newMembers} - addMembers={addMembers} + addItems={addMembers} + newMembers={newMembers} /> { @@ -84,28 +84,29 @@ const MembersSearch = () => { // page state const [channelId, setChannelId] = useState(objectAdminContext.channelId); - const [channelFilter, setChannelFilter] = useState(objectAdminContext.channelFilter); + const [memberFilter, setMemberFilter] = useState(objectAdminContext.memberFilter); const [isTruncate, setIsTruncate] = useState(true); const [sweetAlert, setSweetAlert] = useState(null); const history = useHistory(); async function retrieveMetadata() { - console.log("retrieveMetadata", channelId, channelFilter); + console.log("retrieveMetadata", channelId, memberFilter); let more = true; let results = []; let next = null; let totalRecords = 0; - confirmAlert("Searching Channel Members", "Searching for Channel Members, please wait..."); const limit = objectAdminContext.maxRows < 100 ? objectAdminContext.maxRows : 100; + confirmAlert("Searching Channel Members", "Searching for Channel Members, please wait..."); + do { try { const result = await keySetContext.pubnub.objects.getChannelMembers({ channel: channelId, - filter : channelFilter, // || 'id = channel"*"', + filter : memberFilter, include: { totalCount: true, customFields: true, @@ -142,42 +143,48 @@ const MembersSearch = () => { ? timerAlert("No Members Found!", "Your filter found none Channel Members.", 3) : timerAlert("Channel Members Found!", `${totalRecords} Channel Members Found.`, 2); + console.log(" members found", results); objectAdminContext.setChannelMembersResults(results); } const handleEdit = (e, record, index) => { - objectAdminContext.setChannelId(record.id); - objectAdminContext.setChannelName(record.name); - objectAdminContext.setChannelDesc(record.description); - objectAdminContext.setChannelCustom(JSON.stringify(record.custom, null, 2)); - objectAdminContext.setChannelUpdated(record.updated); - objectAdminContext.setChannelEtag(record.eTag); - - history.push("/admin/channel-metadata"); + // objectAdminContext.setUserId(record.id); + // objectAdminContext.setUserName(record.name); + // objectAdminContext.setUserExternalId(record.externalId); + // objectAdminContext.setUserProfileUrl(record.profileUrl); + // objectAdminContext.setUserEmail(record.email); + // objectAdminContext.setUserCustom(JSON.stringify(record.custom, null, 2)); + // objectAdminContext.setUserUpdated(record.updated); + // objectAdminContext.setUserEtag(record.eTag); + + // history.push("/admin/objects/user-form"); } - const handleRemove = (e, channel, index) => { + const handleRemove = (e, userId, index) => { e.preventDefault(); - confirmAlert("Confirm Remove Metadata?", - `${index} - ${channel}`, - "Confirm", ()=>removeMetadata(channel, index), "Cancel", ()=>hideAlert() + confirmAlert("Confirm Remove Member?", + `${index} - ${userId}`, + "Confirm", ()=>removeUser(userId, index), "Cancel", ()=>hideAlert() ); } - async function removeMetadata(channel, index) { - // console.log("removeChannelMetadata", channel); - hideAlert(); + async function removeUser(userId, index) { + console.log("removeUser", userId); + hideAlert(); try { - const result = await keySetContext.pubnub.objects.removeChannelMetadata({channel : channel}); - timerAlert("Remove Success!", "ChannelMetadata removed.", 2); + const result = await keySetContext.pubnub.objects.removeUUIDMetadata({ + channel: channelId, + uuid : userId + }); + timerAlert("Remove Success!", "User removed.", 2); - let temp = Array.from(objectAdminContext.channelMetadataResults); + let temp = Array.from(objectAdminContext.channelMembersResults); temp.splice(index, 1); - objectAdminContext.setChannelMetadataResults(temp); + objectAdminContext.setChannelMembersResults(temp); } catch (status) { confirmAlert(status.status.errorData.error.message, @@ -213,6 +220,7 @@ const MembersSearch = () => { style={{ display: "block", marginTop: "100px" }} title={title} onConfirm={confirmFn} + showConfirm={confirmButton != null} confirmBtnBsStyle="danger" confirmBtnText={confirmButton} onCancel={cancelFn} @@ -270,18 +278,18 @@ const MembersSearch = () => { setChannelFilter(e.target.value)} + value={memberFilter} + onChange={(e) => setMemberFilter(e.target.value)} /> @@ -314,7 +322,7 @@ const MembersSearch = () => { onClick={retrieveMetadata} disabled = {keySetContext.pubnub == null || channelId == null} > - Get Metadata + Search Members @@ -339,7 +347,7 @@ const MembersSearch = () => { # - Channel ID - Channel Name - Description - Custom Field Data + User ID + User Name + {/* Email */} + Custom Membership Data Last Updated Actions @@ -421,12 +429,10 @@ const MetadataTable = ({metadata, rowsPerPage, page, emptyRows, handleChangePage ? metadata.slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage) : metadata ).map((row, index) => ( - - ))} {emptyRows > 0 && ( @@ -471,9 +477,7 @@ const truncate = (data, size, noDots) => { } const MetadataRow = ({index, row, isTruncate, handleRemove, handleEdit}) => { - console.log("MetadataRow", row); - - // const {row} = props; + // console.log("MetadataRow", row); const [open, setOpen] = React.useState(false); return ( @@ -492,17 +496,17 @@ const MetadataRow = ({index, row, isTruncate, handleRemove, handleEdit}) => { {index} {isTruncate && ( <> - {truncate(row.id, 40)} - {truncate(row.name, 40)} - {truncate(row.description, 40)} + {truncate(row.uuid.id, 40)} + {truncate(row.uuid.name, 40)} + {/* {truncate(row.email, 40)} */} {truncate(JSON.stringify(row.custom), 40)} )} {!isTruncate && ( <> - {row.id} - {row.name} - {row.description} + {row.uuid.id} + {row.uuid.name} + {/* {row.email} */} {JSON.stringify(row.custom, null, 2)} )} @@ -513,11 +517,11 @@ const MetadataRow = ({index, row, isTruncate, handleRemove, handleEdit}) => { handleEdit(e, row, index)}> - handleMembership(e, row.id, index)} > - +
*/} handleRemove(e, row.id, index)}> @@ -533,30 +537,74 @@ const MetadataRow = ({index, row, isTruncate, handleRemove, handleEdit}) => { - Channel ID - {row.id} + + + User ID + {row.uuid.id} + + + + + + User Name + {row.uuid.name} - Channel Name - {row.name} + + + Email + {row.uuid.email} - Description - {row.description} + + + External ID + {row.uuid.externalId} - Custom Fields + + + Profile URL + {row.uuid.profileUrl} - {Object.keys(row.custom).map((key) => ( + + + + + Custom User Fields + + + {Object.keys(row.uuid.custom).map((key) => ( + + + + {key} + {row.uuid.custom[key]} + + ))} + + + + + + Custom Membership Fields + + + {row.custom && + Object.keys(row.custom).map((key) => ( + + + {key} {row.custom[key]} ))} + @@ -627,51 +675,3 @@ TablePaginationActions.propTypes = { page: PropTypes.number.isRequired, rowsPerPage: PropTypes.number.isRequired, }; - - -// const TruncateSwitch = ({isTruncate, setIsTruncate}) => { - // return( - // <> - // - //
- // - // - // - // - // - // ); - // } \ No newline at end of file diff --git a/src/tools/ObjectAdmin/pages/UsersSearch.js b/src/tools/ObjectAdmin/pages/UsersSearch.js index 54b4a49..3a66ec4 100755 --- a/src/tools/ObjectAdmin/pages/UsersSearch.js +++ b/src/tools/ObjectAdmin/pages/UsersSearch.js @@ -159,7 +159,7 @@ const UsersSearch = () => { const handleRemove = (e, userId, index) => { e.preventDefault(); - confirmAlert("Confirm Remove Metadata?", + confirmAlert("Confirm Remove User?", `${index} - ${userId}`, "Confirm", ()=>removeUser(userId, index), "Cancel", ()=>hideAlert() ); @@ -400,7 +400,7 @@ const MetadataTable = ({metadata, rowsPerPage, page, emptyRows, handleChangePage ? metadata.slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage) : metadata ).map((row, index) => ( - @@ -520,7 +520,7 @@ const MetadataRow = ({index, row, isTruncate, handleRemove, handleEdit}) => { Email - {row.description} + {row.email} diff --git a/src/tools/ObjectAdmin/pages/dialogs/AddMembersDialog.js b/src/tools/ObjectAdmin/pages/dialogs/AddMembersDialog.js index 29bb936..8802327 100644 --- a/src/tools/ObjectAdmin/pages/dialogs/AddMembersDialog.js +++ b/src/tools/ObjectAdmin/pages/dialogs/AddMembersDialog.js @@ -13,13 +13,12 @@ import { // core components const AddMembersDialog = (props) => { - let newItems = null; + const handleClick = (e, isConfirmed) => { -debugger; e.preventDefault(); props.newItems.current = (newItems == null || newItems === "") ? null : newItems.split("\n"); - props.addMembers(isConfirmed); + props.addItems(isConfirmed); } return ( @@ -46,7 +45,7 @@ debugger; id="input-new-members" placeholder="Add one member UUID per line" type="textarea" - // defaultValue={props.newMembers.current} + defaultValue={props.newMembers.current} onChange={(e) => newItems = e.target.value} rows="10" /> From f5b300a13479b9ccd2343f6fb5c0d91a34f4658e Mon Sep 17 00:00:00 2001 From: Craig Conover Date: Mon, 15 Nov 2021 21:40:27 -0700 Subject: [PATCH 4/7] moved add member dialog to MemberSearch page and is working --- src/tools/ObjectAdmin/pages/ChannelForm.js | 101 +------------------ src/tools/ObjectAdmin/pages/MembersSearch.js | 99 ++++++++++++++++-- src/tools/ObjectAdmin/pages/UsersSearch.js | 5 +- 3 files changed, 94 insertions(+), 111 deletions(-) diff --git a/src/tools/ObjectAdmin/pages/ChannelForm.js b/src/tools/ObjectAdmin/pages/ChannelForm.js index cc3908c..5aebf82 100755 --- a/src/tools/ObjectAdmin/pages/ChannelForm.js +++ b/src/tools/ObjectAdmin/pages/ChannelForm.js @@ -16,11 +16,8 @@ */ -import { useState, useRef } from "react"; +import { useState } from "react"; // import classnames from "classnames"; -import { ToastContainer, toast } from 'react-toastify'; -import 'react-toastify/dist/ReactToastify.css'; - // reactstrap components import { @@ -43,8 +40,6 @@ import ReactBSAlert from "react-bootstrap-sweetalert"; import { useKeySetData } from "../../KeySetProvider"; import { useObjectAdminData } from "../ObjectAdminProvider"; -import AddMembersDialog from "./dialogs/AddMembersDialog.js"; - const ChannelForm = () => { const keySetContext = useKeySetData(); @@ -55,69 +50,8 @@ const ChannelForm = () => { const [channelId, setChannelId] = useState(objectAdminContext.channelId); const [sweetAlert, setSweetAlert] = useState(null); - const [modal, setModal] = useState(false); - const toggle = () => setModal(!modal); - const newMembers = useRef([]); - - async function addMembers(isConfirmed) { - console.log("addMembers: isConfirmed = ", isConfirmed); - - toggle(); // dismiss the modal - if (!isConfirmed) return; - - if (newMembers.current == null || newMembers.current.length === 0) { - toastNotify("info", "No New Channel Members provided.") - return; - } - - console.log(" new members", newMembers); - - try { - const result = await keySetContext.pubnub.objects.setChannelMembers({ - channel: channelId, - uuids: newMembers.current, - }); - - console.log(" setChannelMembers result", result) - } - catch (status) { - console.log("operation failed w/ error:", status); - } - - - // const result = await keySetContext.pubnub.objects.setMemberships({ - // "channels": channels}), - // (status) => { - // console.log("status", status); - // if (!status.error) { - // toastNotify("success", "Channels added."); - // listChannels(); - // } - // else { - // toastNotify("error", status.errorData.error); - // } - // }); - } - - const toastNotify = (type, title) => { - const params = { - position: "top-center", - autoClose: 5000, - hideProgressBar: false, - closeOnClick: true, - pauseOnHover: true, - draggable: true, - progress: undefined, - }; - - if (type === "success") toast.success(title, params); - else if (type === "error") toast.error(title, params); - else toast.info(title, params); - } - - - async function getChannelObject() { + const getChannelObject = async () => { // console.log("channelId", channelId); try { const result = await keySetContext.pubnub.objects.getChannelMetadata({ @@ -132,7 +66,6 @@ const ChannelForm = () => { : timerAlert("No Records Found!", "Your filter found 0 records.", 3); } catch (status) { - confirmAlert("Get Channel Failed", // for some reason, the status.errorData.error is null // even though the console shows it has a value???? @@ -143,7 +76,7 @@ const ChannelForm = () => { } } - async function saveChannelObject() { + const saveChannelObject = async () => { // console.log("channelId", channelId); try { const result = await keySetContext.pubnub.objects.setChannelMetadata({ @@ -224,25 +157,6 @@ const ChannelForm = () => { return ( <> {sweetAlert} - - - @@ -469,15 +383,6 @@ const ChannelForm = () => { Save Metadata - - - diff --git a/src/tools/ObjectAdmin/pages/MembersSearch.js b/src/tools/ObjectAdmin/pages/MembersSearch.js index 4e0f93d..cfd2a40 100755 --- a/src/tools/ObjectAdmin/pages/MembersSearch.js +++ b/src/tools/ObjectAdmin/pages/MembersSearch.js @@ -16,8 +16,10 @@ */ -import React, { useState } from "react"; +import React, { useState, useRef } from "react"; import { useHistory } from "react-router-dom"; +import { ToastContainer, toast } from 'react-toastify'; +import 'react-toastify/dist/ReactToastify.css'; // reactstrap components import { @@ -57,6 +59,7 @@ import { Switch, FormControlLabel } from "@mui/material"; import EditIcon from '@mui/icons-material/Edit'; // import GroupIcon from '@mui/icons-material/Group'; import ReactBSAlert from "react-bootstrap-sweetalert"; +import AddMembersDialog from "./dialogs/AddMembersDialog"; const MembersSearch = () => { const keySetContext = useKeySetData(); @@ -90,7 +93,58 @@ const MembersSearch = () => { const [sweetAlert, setSweetAlert] = useState(null); const history = useHistory(); - async function retrieveMetadata() { + const [modal, setModal] = useState(false); + const toggle = () => setModal(!modal); + const newMembers = useRef([]); + + const addMembers = async (isConfirmed) => { + console.log("addMembers: isConfirmed = ", isConfirmed); + + toggle(); // dismiss the modal + if (!isConfirmed) return; + + if (newMembers.current == null || newMembers.current.length === 0) { + toastNotify("info", "No New Channel Members provided.") + return; + } + + console.log(" new members", newMembers); + + try { + const result = await keySetContext.pubnub.objects.setChannelMembers({ + channel: channelId, + uuids: newMembers.current + }); + + retrieveMetadata(); + + // let temp = Array.from(objectAdminContext.channelMembersResults); + // objectAdminContext.setChannelMembersResults(temp.concat(result)); + + console.log(" setChannelMembers result", result) + } + catch (status) { + console.log("operation failed w/ error:", status); + } + } + + const toastNotify = (type, title) => { + const params = { + position: "top-center", + autoClose: 5000, + hideProgressBar: false, + closeOnClick: true, + pauseOnHover: true, + draggable: true, + progress: undefined, + }; + + if (type === "success") toast.success(title, params); + else if (type === "error") toast.error(title, params); + else toast.info(title, params); + } + + const retrieveMetadata = async () => { console.log("retrieveMetadata", channelId, memberFilter); let more = true; @@ -170,7 +224,7 @@ const MembersSearch = () => { ); } - async function removeUser(userId, index) { + const removeUser = async (userId, index) => { console.log("removeUser", userId); hideAlert(); @@ -238,6 +292,24 @@ const MembersSearch = () => { return ( <> {sweetAlert} + + @@ -315,7 +387,6 @@ const MembersSearch = () => { -          + + @@ -379,7 +458,7 @@ export default MembersSearch; const MetadataTable = ({metadata, rowsPerPage, page, emptyRows, handleChangePage, handleChangeRowsPerPage, isTruncate, setIsTruncate, handleRemove, handleEdit}) => { console.log("MetadataTable", metadata); - if (metadata == null || metadata.length ===0) return <>

No Results

; + if (metadata == null || metadata.length ===0) return <>No Results; return ( diff --git a/src/tools/ObjectAdmin/pages/UsersSearch.js b/src/tools/ObjectAdmin/pages/UsersSearch.js index 3a66ec4..58b517a 100755 --- a/src/tools/ObjectAdmin/pages/UsersSearch.js +++ b/src/tools/ObjectAdmin/pages/UsersSearch.js @@ -88,7 +88,7 @@ const UsersSearch = () => { const [sweetAlert, setSweetAlert] = useState(null); const history = useHistory(); - async function retrieveUser() { + const retrieveUser = async () => { console.log("userFilter", userFilter); let more = true; @@ -356,7 +356,6 @@ const MetadataTable = ({metadata, rowsPerPage, page, emptyRows, handleChangePage - @@ -400,7 +399,7 @@ const MetadataTable = ({metadata, rowsPerPage, page, emptyRows, handleChangePage ? metadata.slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage) : metadata ).map((row, index) => ( - From 46d86485f0f60fddd709da0d5c0126e8a8d8127e Mon Sep 17 00:00:00 2001 From: Craig Conover Date: Mon, 15 Nov 2021 21:49:48 -0700 Subject: [PATCH 5/7] nothing really --- src/tools/ObjectAdmin/pages/MembersSearch.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/tools/ObjectAdmin/pages/MembersSearch.js b/src/tools/ObjectAdmin/pages/MembersSearch.js index cfd2a40..31a8cdc 100755 --- a/src/tools/ObjectAdmin/pages/MembersSearch.js +++ b/src/tools/ObjectAdmin/pages/MembersSearch.js @@ -116,12 +116,9 @@ const MembersSearch = () => { uuids: newMembers.current }); + // console.log(" result", result); retrieveMetadata(); - - // let temp = Array.from(objectAdminContext.channelMembersResults); - // objectAdminContext.setChannelMembersResults(temp.concat(result)); - - console.log(" setChannelMembers result", result) + // objectAdminContext.setChannelMembersResults(result.data); } catch (status) { console.log("operation failed w/ error:", status); From f6c16df1cade5d73c384866916a5672b04f8b18d Mon Sep 17 00:00:00 2001 From: Craig Conover Date: Tue, 16 Nov 2021 06:05:51 -0700 Subject: [PATCH 6/7] changed object icon; added auth token to key set init and moved initialize button to top of form --- src/tools/KeySet.js | 36 ++++++++++++++++++-- src/tools/KeySetProvider.js | 8 +++-- src/tools/ObjectAdmin/pages/MembersSearch.js | 6 ++-- src/tools/ObjectAdmin/routesObjectAdmin.js | 4 +-- 4 files changed, 44 insertions(+), 10 deletions(-) diff --git a/src/tools/KeySet.js b/src/tools/KeySet.js index 24ad1fe..7c5d432 100755 --- a/src/tools/KeySet.js +++ b/src/tools/KeySet.js @@ -57,6 +57,7 @@ const KeySet = () => { const [pubKey, setPubKey] = useState(keySetContext.pubKey); const [secKey, setSecKey] = useState(keySetContext.secKey); const [uuid, setUuid] = useState(keySetContext.uuid); + const [authToken, setAuthToken] = useState(keySetContext.authToken); // const [authKey, setAuthKey] = useState(); const [tab, setTab] = useState(2); @@ -83,7 +84,7 @@ const KeySet = () => { subKey: subKey, secKey: secKey, uuid: uuid, - // authKey: authKey, + authKey: authToken, }); } @@ -305,6 +306,15 @@ const KeySet = () => { keySetName={keySetContext.keySetName} /> +
+ +
@@ -389,10 +399,30 @@ const KeySet = () => { + + + + + setAuthToken(e.target.value)} + /> + + + -
+ {/*
-
+
*/}
diff --git a/src/tools/KeySetProvider.js b/src/tools/KeySetProvider.js index 7fc4ec2..755cf05 100644 --- a/src/tools/KeySetProvider.js +++ b/src/tools/KeySetProvider.js @@ -11,14 +11,16 @@ export const KeySetProvider = ({ children }) => { const [subKey, setSubKey] = useState(""); const [secKey, setSecKey] = useState(""); const [uuid, setUuid] = useState(""); + const [authToken, setAuthToken] = useState(""); const [keySetProps, setKeySetProps] = useState(); const initKeySet = (keySetConfig) => { const pn = new PubNub({ subscribeKey: keySetConfig.subKey, - publishKey: keySetConfig.pubKey, - secretKey: keySetConfig.secKey, + publishKey: keySetConfig.pubKey, // conditional null check? + secretKey: keySetConfig.secKey, // conditional null check? uuid: (keySetConfig.uuid !== null ? keySetConfig.uuid : null), + authKey: (keySetConfig.authToken !== null ? keySetConfig.authToken : null), }); setKeySetName(keySetConfig.keySetName); @@ -32,6 +34,7 @@ export const KeySetProvider = ({ children }) => { setSubKey(pn._config.subscribeKey); setSecKey(pn._config.secretKey); setUuid(pn.getUUID()); + // setAuthToken(pn.getToken) no api??? setPubNub(pn); }).catch((error) => { console.log("key set init failed:", error); @@ -57,6 +60,7 @@ export const KeySetProvider = ({ children }) => { pubKey, setSubKey, secKey, setSecKey, uuid, setUuid, + authToken, setAuthToken, keySetProps, setKeySetProps, status, pubnub, diff --git a/src/tools/ObjectAdmin/pages/MembersSearch.js b/src/tools/ObjectAdmin/pages/MembersSearch.js index 31a8cdc..d705d56 100755 --- a/src/tools/ObjectAdmin/pages/MembersSearch.js +++ b/src/tools/ObjectAdmin/pages/MembersSearch.js @@ -117,7 +117,7 @@ const MembersSearch = () => { }); // console.log(" result", result); - retrieveMetadata(); + retrieveMembers(); // objectAdminContext.setChannelMembersResults(result.data); } catch (status) { @@ -141,7 +141,7 @@ const MembersSearch = () => { else toast.info(title, params); } - const retrieveMetadata = async () => { + const retrieveMembers = async () => { console.log("retrieveMetadata", channelId, memberFilter); let more = true; @@ -387,7 +387,7 @@ const MembersSearch = () => { @@ -421,17 +438,7 @@ const KeySet = () => { - - {/*
- -
*/} -
+ @@ -473,26 +480,27 @@ const KeySetSelector = (props) => { } const options = props.keySets.pn_keys.map((item, index) => - props.keySetSelected(index)}> - {item.name + ": " + item.sub_key.substring(0,14)} - - /* */ + props.keySetSelected(index)}> + {item.name + ": " + item.sub_key.substring(0,14)} + ); return ( - //
<> - - - {props.keySetName} - - - {options} - - + Key Sets +

- //

- ); } \ No newline at end of file