Skip to content

Commit

Permalink
Merge pull request #25 from PubNubDevelopers/addmembers
Browse files Browse the repository at this point in the history
Addmembers
  • Loading branch information
pubnubcraig authored Nov 16, 2021
2 parents ad065e7 + ee0cba7 commit 39d02aa
Show file tree
Hide file tree
Showing 10 changed files with 403 additions and 221 deletions.
140 changes: 89 additions & 51 deletions src/tools/KeySet.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
*/
import { useState } from "react";
import classnames from "classnames";
// import { ToastContainer, toast } from 'react-toastify';
// import 'react-toastify/dist/ReactToastify.css';
import { ToastContainer, toast } from 'react-toastify';
import 'react-toastify/dist/ReactToastify.css';

// reactstrap components
import {
Expand All @@ -33,10 +33,10 @@ import {
Row,
Col,
CardFooter,
DropdownToggle,
DropdownMenu,
DropdownItem,
UncontrolledDropdown,
// DropdownToggle,
// DropdownMenu,
// DropdownItem,
// UncontrolledDropdown,
Table,
Nav,
NavLink,
Expand All @@ -47,6 +47,8 @@ import {

// core components
import { useKeySetData } from "./KeySetProvider";
import { MenuItem } from "@material-ui/core";
import { InputLabel, Select } from "@mui/material";

const KeySet = () => {
const keySetContext = useKeySetData();
Expand All @@ -57,6 +59,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);
Expand All @@ -77,42 +80,57 @@ const KeySet = () => {
}

const submitForm = () => {

keySetContext.initKeySet({
keySetName: keySetName,
pubKey: pubKey,
subKey: subKey,
secKey: secKey,
uuid: uuid,
// authKey: authKey,
authKey: authToken,
});

notify("Key Set Initialized");
}

const keySetSelected = (index) => {
console.log("keySetSelected: index: ", index);
console.log(" keSetProps: ", keySetContext.keySetProps);

const keySet = keySetContext.keySetProps.pn_keys[index];
setKeySetName(keySet.name);
setPubKey(keySet.pub_key);
setSubKey(keySet.sub_key);
setSecKey(keySet.secret_key);
if (index === -1) {
setKeySetName("Key Set Not Selected");
setPubKey("");
setSubKey("");
setSecKey("");
setUuid("");
setAuthToken("");
}
else {
const keySet = keySetContext.keySetProps.pn_keys[index];
setKeySetName(keySet.name);
setPubKey(keySet.pub_key);
setSubKey(keySet.sub_key);
setSecKey(keySet.secret_key);
setUuid(keySet.uuid);
setAuthToken(keySet.authToken);
}
}

// const notify = (title) => {
// toast.success(title, {
// position: "top-center",
// autoClose: 3000,
// hideProgressBar: false,
// closeOnClick: true,
// pauseOnHover: true,
// draggable: true,
// progress: undefined,
// });
// }
const notify = (title) => {
toast.success(title, {
position: "top-center",
autoClose: 3000,
hideProgressBar: false,
closeOnClick: true,
pauseOnHover: true,
draggable: true,
progress: undefined,
});
}

return (
<>
{/* <ToastContainer
<ToastContainer
position="top-center"
autoClose={3000}
hideProgressBar={false}
Expand All @@ -122,7 +140,7 @@ const KeySet = () => {
pauseOnFocusLoss
draggable
pauseOnHover
/> */}
/>
<Container className="mt--7" fluid>
<Row className="mt-0">
<Col className="order-xl-2">
Expand Down Expand Up @@ -305,6 +323,15 @@ const KeySet = () => {
keySetName={keySetContext.keySetName}
/>
</Col>
<div className="col text-right">
<Button
color="danger"
disabled={subKey === ""}
onClick={submitForm}
>
Initialize
</Button>
</div>
</Row>
<Row>
<Col>
Expand Down Expand Up @@ -389,19 +416,29 @@ const KeySet = () => {
</FormGroup>
</Col>
</Row>
<Row>
<Col>
<FormGroup>
<label
className="form-control-label"
htmlFor="input-auth-token"
>
Auth Token (Auth Key)
</label>
<Input
className="form-control-alternative"
id="input-auth-token"
placeholder="Enter auth token/key if required"
type="text"
name="auth-token"
onChange={(e) => setAuthToken(e.target.value)}
/>
</FormGroup>
</Col>
</Row>
</div>
</CardBody>
<CardFooter>
<div className="col text-right">
<Button
color="danger"
disabled={subKey === ""}
onClick={submitForm}
>
Initialize
</Button>
</div>
</CardFooter>

</Form>
</Card>
</Col>
Expand Down Expand Up @@ -443,26 +480,27 @@ const KeySetSelector = (props) => {
}

const options = props.keySets.pn_keys.map((item, index) =>
<DropdownItem key={index} onClick={() => props.keySetSelected(index)}>
{item.name + ": " + item.sub_key.substring(0,14)}
</DropdownItem>
/* <DropdownItem divider /> */
<MenuItem key={index} value={index} onClick={() => props.keySetSelected(index)}>
{item.name + ": " + item.sub_key.substring(0,14)}
</MenuItem>
);

return (
// <div className="col text-left">
<>
<UncontrolledDropdown group>
<DropdownToggle width="100px" caret color="danger">
{props.keySetName}
</DropdownToggle>
<DropdownMenu>
{options}
</DropdownMenu>
</UncontrolledDropdown>
<InputLabel htmlFor="select-key-set">Key Sets</InputLabel>
<Select
variant="standard"
defaultValue={-1}
id="select-key-set"
label="Key Sets"
autoWidth={true}
>
<MenuItem value={-1} onClick={() => props.keySetSelected(-1)}>
Select a Key Set
</MenuItem>
{options}
</Select>
<p />
</>
// </div>

);
}
8 changes: 6 additions & 2 deletions src/tools/KeySetProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -57,6 +60,7 @@ export const KeySetProvider = ({ children }) => {
pubKey, setSubKey,
secKey, setSecKey,
uuid, setUuid,
authToken, setAuthToken,
keySetProps, setKeySetProps,
status,
pubnub,
Expand Down
22 changes: 17 additions & 5 deletions src/tools/ObjectAdmin/ObjectAdminProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const ObjectAdminProvider = ({ children }) => {
const [channelUpdated, setChannelUpdated] = useState([]);
const [channelEtag, setChannelEtag] = useState([]);

// UserMetadata State
// UserForm State
const [userId, setUserId] = useState();
const [userName, setUserName] = useState([]);
const [userExternalId, setUserExternalId] = useState([]);
Expand All @@ -22,16 +22,23 @@ export const ObjectAdminProvider = ({ children }) => {
const [userUpdated, setUserUpdated] = useState([]);
const [userEtag, setUserEtag] = useState([]);

// ChannelsList State
// ChannelsSearch State
const [channelFilter, setChannelFilter] = useState('name LIKE "*"');
const [maxRows, setMaxRows] = useState(500);
const [channelMetadataResults, setChannelMetadataResults] = useState([]);

// UsersList State
// UsersSearch State
const [userFilter, setUserFilter] = useState('name LIKE "*"');
// share ChannelsList state: const [maxRows, setMaxRows] = useState(500);
const [userMetadataResults, setUserMetadataResults] = useState([]);

// ChannelMembersSearch State
// 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
/////////////////////////////////////////

Expand All @@ -54,17 +61,22 @@ export const ObjectAdminProvider = ({ children }) => {
userUpdated, setUserUpdated,
userEtag, setUserEtag,

// ChannelsList State
// ChannelsSearch State
channelFilter, setChannelFilter,
maxRows, setMaxRows,
channelMetadataResults, setChannelMetadataResults,

// UsersList State
// UsersSearch State
userFilter, setUserFilter,
// share ChannelsList state: maxRows, setMaxRows,
userMetadataResults, setUserMetadataResults,

// ChannelMembersSearch State
channelMembersResults, setChannelMembersResults,
memberFilter, setMemberFilter,
}


return <Context.Provider value={useObjectAdminData}> {children} </Context.Provider>
}

Expand Down
11 changes: 5 additions & 6 deletions src/tools/ObjectAdmin/pages/ChannelForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,15 @@ import {
Input,
Row,
Col,
// ButtonGroup,
CardFooter,
} from "reactstrap";

import ReactBSAlert from "react-bootstrap-sweetalert";

// // core components
import { useKeySetData } from "../../KeySetProvider";
import { useObjectAdminData } from "../ObjectAdminProvider";
import ReactBSAlert from "react-bootstrap-sweetalert";


const ChannelForm = () => {
const keySetContext = useKeySetData();
Expand All @@ -50,7 +51,7 @@ const ChannelForm = () => {
const [channelId, setChannelId] = useState(objectAdminContext.channelId);
const [sweetAlert, setSweetAlert] = useState(null);

async function getChannelObject() {
const getChannelObject = async () => {
// console.log("channelId", channelId);
try {
const result = await keySetContext.pubnub.objects.getChannelMetadata({
Expand All @@ -65,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????
Expand All @@ -76,7 +76,7 @@ const ChannelForm = () => {
}
}

async function saveChannelObject() {
const saveChannelObject = async () => {
// console.log("channelId", channelId);
try {
const result = await keySetContext.pubnub.objects.setChannelMetadata({
Expand Down Expand Up @@ -383,7 +383,6 @@ const ChannelForm = () => {
Save Metadata
</Button>
</Col>
<Col lg="3" className="text-center"></Col>
</Row>
</CardFooter>
</Card>
Expand Down
2 changes: 1 addition & 1 deletion src/tools/ObjectAdmin/pages/ChannelsSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ const MetadataRow = ({index, row, isTruncate, handleRemove, handleEdit}) => {
)}

<TableCell>{row.updated}</TableCell>

<TableCell align="center">
<IconButton aria-label="edit" size="small" onClick={(e) => handleEdit(e, row, index)}>
<EditIcon/>
Expand Down
Loading

0 comments on commit 39d02aa

Please sign in to comment.