mirror of
https://github.com/kubeshark/kubeshark.git
synced 2025-09-28 22:08:34 +00:00
commit to enable merge
This commit is contained in:
@@ -207,7 +207,7 @@ export const AddUserModal: FC<AddUserModalProps> = ({isOpen, onCloseModal, userD
|
|||||||
onChange={(event) => setSearchValue(event.target.value)}/>
|
onChange={(event) => setSearchValue(event.target.value)}/>
|
||||||
</div>
|
</div>
|
||||||
<SelectList valuesListInput={workspaces} tableName={''} multiSelect={false} searchValue={searchValue}
|
<SelectList valuesListInput={workspaces} tableName={''} multiSelect={false} searchValue={searchValue}
|
||||||
setValues= {workspaceChange} tabelClassName={''} >
|
setValues={workspaceChange} tabelClassName={''} checkedValues={[]} >
|
||||||
</SelectList>
|
</SelectList>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
import { FC, useEffect, useState } from 'react';
|
import { FC, useEffect, useMemo, useState } from 'react';
|
||||||
import Api from '../../../helpers/api';
|
import Api from '../../../helpers/api';
|
||||||
import { useCommonStyles } from '../../../helpers/commonStyle';
|
import { useCommonStyles } from '../../../helpers/commonStyle';
|
||||||
import ConfirmationModal from '../../UI/Modals/ConfirmationModal';
|
import ConfirmationModal from '../../UI/Modals/ConfirmationModal';
|
||||||
@@ -13,34 +13,43 @@ export type WorkspaceData = {
|
|||||||
interface AddWorkspaceModalProp {
|
interface AddWorkspaceModalProp {
|
||||||
isOpen : boolean,
|
isOpen : boolean,
|
||||||
onCloseModal: () => void,
|
onCloseModal: () => void,
|
||||||
workspaceData: WorkspaceData,
|
workspaceDataInput: WorkspaceData,
|
||||||
onEdit: boolean
|
onEdit: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
const api = Api.getInstance();
|
const api = Api.getInstance();
|
||||||
|
|
||||||
const AddWorkspaceModal: FC<AddWorkspaceModalProp> = ({isOpen,onCloseModal, workspaceData ={}, onEdit}) => {
|
const AddWorkspaceModal: FC<AddWorkspaceModalProp> = ({isOpen,onCloseModal, workspaceDataInput ={}, onEdit}) => {
|
||||||
|
|
||||||
const [workspaceDataModel, setUserData] = useState(workspaceData as WorkspaceData);
|
const [workspaceDataModal, setWorkspaceData] = useState({} as WorkspaceData);
|
||||||
const [searchValue, setSearchValue] = useState("");
|
const [searchValue, setSearchValue] = useState("");
|
||||||
const classes = useCommonStyles()
|
const [namespaces, setNamespaces] = useState([]);
|
||||||
const [namespaces, setNamespaces] = useState({});
|
const [namespacesNames, setNamespaceNames] = useState([]);
|
||||||
|
const [workspaceName, setWorkspaceName] = useState("");
|
||||||
|
const [disable, setDisable] = useState(true);
|
||||||
|
|
||||||
|
console.log(workspaceDataInput);
|
||||||
|
console.log(workspaceDataModal);
|
||||||
|
|
||||||
|
const classes = useCommonStyles();
|
||||||
|
|
||||||
const title = onEdit ? "Edit Workspace" : "Add Workspace";
|
const title = onEdit ? "Edit Workspace" : "Add Workspace";
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setWorkspaceData(workspaceDataInput as WorkspaceData);
|
||||||
|
},[workspaceDataInput])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if(!isOpen) return;
|
if(!isOpen) return;
|
||||||
(async () => {
|
(async () => {
|
||||||
try {
|
try {
|
||||||
setSearchValue("");
|
setSearchValue("");
|
||||||
const tapConfig = await api.getTapConfig();
|
const namespaces = [{key:"1", value:"namespace1",isChecked:false},{key:"2", value:"namespace2",isChecked:false}];
|
||||||
const namespacesObj = {...tapConfig?.tappedNamespaces}
|
const list = namespaces.map(obj => {
|
||||||
Object.keys(tapConfig?.tappedNamespaces ?? {}).forEach(namespace => {
|
const isValueChecked = workspaceDataModal.namespaces.some(checkedValueKey => obj.key === checkedValueKey)
|
||||||
namespacesObj[namespace] = true;
|
return {...obj, isChecked: isValueChecked}
|
||||||
})
|
})
|
||||||
setNamespaces(namespacesObj);
|
setNamespaces(namespaces);
|
||||||
setNamespaces(tapConfig?.tappedNamespaces);
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
} finally {
|
} finally {
|
||||||
@@ -48,14 +57,51 @@ const AddWorkspaceModal: FC<AddWorkspaceModalProp> = ({isOpen,onCloseModal, work
|
|||||||
})()
|
})()
|
||||||
}, [isOpen])
|
}, [isOpen])
|
||||||
|
|
||||||
const onConfirm = () => {}
|
const onWorkspaceNameChange = (event) => {
|
||||||
|
// const data = {...workspaceData, name: event.target.value};
|
||||||
|
//setWorkspaceData(data);
|
||||||
|
setWorkspaceName(event.target.value);
|
||||||
|
setGenarateDisabledState();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const onNamespaceChange = (newVal) => {
|
||||||
|
var filteredValues = newVal.filter(obj => obj.isChecked);
|
||||||
|
var namespaceNames = filteredValues.map(obj => obj.value);
|
||||||
|
setNamespaceNames(namespaceNames);
|
||||||
|
|
||||||
|
// var filteredValues = newVal.filter(obj => obj.isChecked);
|
||||||
|
// var namespaceNames = filteredValues.map(obj => obj.value);
|
||||||
|
// const data = {...workspaceData, namespaces: namespaceNames};
|
||||||
|
// setWorkspaceData(data);
|
||||||
|
setGenarateDisabledState();
|
||||||
|
}
|
||||||
|
|
||||||
|
const isFormValid = () : boolean => {
|
||||||
|
return (Object.values(workspaceDataModal).length === 2) && Object.values(workspaceDataModal).every(val => val !== null)
|
||||||
|
}
|
||||||
|
|
||||||
|
const setGenarateDisabledState = () => {
|
||||||
|
const isValid = isFormValid()
|
||||||
|
setDisable(!isValid)
|
||||||
|
}
|
||||||
|
|
||||||
|
const onConfirm = () => {
|
||||||
|
const data = {name: workspaceName, namespaces: namespacesNames};
|
||||||
|
setWorkspaceData(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
const onClose = () => {
|
||||||
|
onCloseModal();
|
||||||
|
setWorkspaceData({} as WorkspaceData);
|
||||||
|
}
|
||||||
|
|
||||||
return (<>
|
return (<>
|
||||||
<ConfirmationModal isOpen={isOpen} onClose={onCloseModal} onConfirm={onConfirm} title={title}>
|
<ConfirmationModal isOpen={isOpen} onClose={onClose} onConfirm={onConfirm} title={title}>
|
||||||
<h3 className='headline'>DETAILS</h3>
|
<h3 className='headline'>DETAILS</h3>
|
||||||
<div>
|
<div>
|
||||||
<input type="text" value={workspaceData?.name ?? ""} className={classes.textField + " workspace__name"} placeholder={"Workspace Name"}
|
<input type="text" value={workspaceDataModal?.name ?? ""} className={classes.textField + " workspace__name"} placeholder={"Workspace Name"}
|
||||||
onChange={(e) => {}}></input>
|
onChange={onWorkspaceNameChange}></input>
|
||||||
</div>
|
</div>
|
||||||
<h3 className='headline'>TAP SETTINGS</h3>
|
<h3 className='headline'>TAP SETTINGS</h3>
|
||||||
<div className="namespacesSettingsContainer">
|
<div className="namespacesSettingsContainer">
|
||||||
@@ -63,7 +109,14 @@ const AddWorkspaceModal: FC<AddWorkspaceModalProp> = ({isOpen,onCloseModal, work
|
|||||||
<input className={classes.textField + " searchNamespace"} placeholder="Search" value={searchValue}
|
<input className={classes.textField + " searchNamespace"} placeholder="Search" value={searchValue}
|
||||||
onChange={(event) => setSearchValue(event.target.value)}/>
|
onChange={(event) => setSearchValue(event.target.value)}/>
|
||||||
</div>
|
</div>
|
||||||
<SelectList valuesListInput={namespaces} tableName={"Namespaces"} multiSelect={true} searchValue={searchValue} setValues={setUserData} tabelClassName={undefined}></SelectList>
|
<SelectList valuesListInput={namespaces}
|
||||||
|
tableName={"Namespaces"}
|
||||||
|
multiSelect={true}
|
||||||
|
checkedValues={workspaceDataModal.namespaces}
|
||||||
|
searchValue={searchValue}
|
||||||
|
setValues={onNamespaceChange}
|
||||||
|
tabelClassName={undefined}>
|
||||||
|
</SelectList>
|
||||||
</div>
|
</div>
|
||||||
</ConfirmationModal>
|
</ConfirmationModal>
|
||||||
</>);
|
</>);
|
||||||
|
@@ -38,7 +38,7 @@ export const InstallPage: React.FC<InstallPageProps> = ({onFirstLogin}) => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
await api.register(adminUsername, password);
|
await api.setupAdminUser(adminUsername, password);
|
||||||
if (!await api.isAuthenticationNeeded()) {
|
if (!await api.isAuthenticationNeeded()) {
|
||||||
setEntPage(Page.Traffic);
|
setEntPage(Page.Traffic);
|
||||||
onFirstLogin();
|
onFirstLogin();
|
||||||
|
@@ -87,7 +87,7 @@ export const SettingsModal: React.FC<SettingsModalProps> = ({isOpen, onClose, is
|
|||||||
<div style={{margin: "10px 0"}}>
|
<div style={{margin: "10px 0"}}>
|
||||||
<input className={classes.textField + " searchNamespace"} placeholder="Search" value={searchValue}
|
<input className={classes.textField + " searchNamespace"} placeholder="Search" value={searchValue}
|
||||||
onChange={(event) => setSearchValue(event.target.value)}/></div>
|
onChange={(event) => setSearchValue(event.target.value)}/></div>
|
||||||
<SelectList valuesListInput={namespaces} tableName={'Namespace'} multiSelect={true} searchValue={searchValue} setValues={setNamespaces} tabelClassName={'namespacesTable'}/>
|
<SelectList valuesListInput={namespaces} tableName={'Namespace'} multiSelect={true} searchValue={searchValue} setValues={setNamespaces} tabelClassName={'namespacesTable'} checkedValues={[]}/>
|
||||||
</div>
|
</div>
|
||||||
</>}
|
</>}
|
||||||
</div>
|
</div>
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
import { useMemo, useState } from "react";
|
import { useEffect, useMemo, useState } from "react";
|
||||||
import Checkbox from "./Checkbox"
|
import Checkbox from "./Checkbox"
|
||||||
import Radio from "./Radio";
|
import Radio from "./Radio";
|
||||||
import './style/SelectList.sass';
|
import './style/SelectList.sass';
|
||||||
@@ -6,6 +6,7 @@ import './style/SelectList.sass';
|
|||||||
export interface Props {
|
export interface Props {
|
||||||
valuesListInput;
|
valuesListInput;
|
||||||
tableName:string;
|
tableName:string;
|
||||||
|
checkedValues?:string[];
|
||||||
multiSelect:boolean;
|
multiSelect:boolean;
|
||||||
searchValue?:string;
|
searchValue?:string;
|
||||||
setValues: (newValues)=> void;
|
setValues: (newValues)=> void;
|
||||||
@@ -18,9 +19,17 @@ export type ValuesListInput = {
|
|||||||
isChecked: boolean;
|
isChecked: boolean;
|
||||||
}[]
|
}[]
|
||||||
|
|
||||||
const SelectList: React.FC<Props> = ({valuesListInput ,tableName,multiSelect=true,searchValue="",setValues,tabelClassName}) => {
|
const SelectList: React.FC<Props> = ({valuesListInput ,tableName,checkedValues=[],multiSelect=true,searchValue="",setValues,tabelClassName}) => {
|
||||||
const [valuesList, setValuesList] = useState(valuesListInput as ValuesListInput);
|
const [valuesList, setValuesList] = useState(valuesListInput as ValuesListInput);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const list = valuesList.map(obj => {
|
||||||
|
const isValueChecked = checkedValues.some(checkedValueKey => obj.key === checkedValueKey)
|
||||||
|
return {...obj, isChecked: isValueChecked}
|
||||||
|
})
|
||||||
|
setValuesList(list);
|
||||||
|
},[valuesListInput,checkedValues]);
|
||||||
|
|
||||||
const toggleValues = (checkedKey) => {
|
const toggleValues = (checkedKey) => {
|
||||||
if (!multiSelect){
|
if (!multiSelect){
|
||||||
unToggleAll(checkedKey);
|
unToggleAll(checkedKey);
|
||||||
@@ -43,8 +52,9 @@ const SelectList: React.FC<Props> = ({valuesListInput ,tableName,multiSelect=tru
|
|||||||
|
|
||||||
|
|
||||||
const toggleAll = () => {
|
const toggleAll = () => {
|
||||||
|
const isChecked = valuesList.every(valueTap => valueTap.isChecked === true);
|
||||||
const list = valuesList.map((obj) => {
|
const list = valuesList.map((obj) => {
|
||||||
return {...obj, isChecked: true}
|
return {...obj, isChecked: !isChecked}
|
||||||
})
|
})
|
||||||
setValuesList(list);
|
setValuesList(list);
|
||||||
setValues(list);
|
setValues(list);
|
||||||
@@ -52,7 +62,7 @@ const SelectList: React.FC<Props> = ({valuesListInput ,tableName,multiSelect=tru
|
|||||||
|
|
||||||
|
|
||||||
const tableHead = multiSelect ? <tr style={{borderBottomWidth: "2px"}}>
|
const tableHead = multiSelect ? <tr style={{borderBottomWidth: "2px"}}>
|
||||||
<th style={{width: 50}}><Checkbox checked={valuesList.every(valueTap => valueTap.isChecked === false)}
|
<th style={{width: 50}}><Checkbox checked={valuesList.every(valueTap => valueTap.isChecked === true)}
|
||||||
onToggle={toggleAll}/></th>
|
onToggle={toggleAll}/></th>
|
||||||
<th>{tableName}</th>
|
<th>{tableName}</th>
|
||||||
</tr> :
|
</tr> :
|
||||||
|
@@ -3,6 +3,8 @@ import {ColsType, FilterableTableAction} from "../UI/FilterableTableAction"
|
|||||||
// import Api from "../../helpers/api"
|
// import Api from "../../helpers/api"
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import AddWorkspaceModal, { WorkspaceData } from "../Modals/AddWorkspaceModal/AddWorkspaceModal";
|
import AddWorkspaceModal, { WorkspaceData } from "../Modals/AddWorkspaceModal/AddWorkspaceModal";
|
||||||
|
import { toast } from "react-toastify";
|
||||||
|
import ConfirmationModal from "../UI/Modals/ConfirmationModal";
|
||||||
|
|
||||||
interface Props {}
|
interface Props {}
|
||||||
|
|
||||||
@@ -14,6 +16,7 @@ export const WorkspaceSettings : React.FC<Props> = ({}) => {
|
|||||||
const [workspaceData,SetWorkspaceData] = useState({} as WorkspaceData);
|
const [workspaceData,SetWorkspaceData] = useState({} as WorkspaceData);
|
||||||
const [isOpenModal,setIsOpen] = useState(false);
|
const [isOpenModal,setIsOpen] = useState(false);
|
||||||
const [isEditMode,setIsEditMode] = useState(false);
|
const [isEditMode,setIsEditMode] = useState(false);
|
||||||
|
const [isOpenDeleteModal, setIsOpenDeleteModal] = useState(false);
|
||||||
|
|
||||||
const cols : ColsType[] = [{field : "id",header:"Id"},{field : "name",header:"Name"}];
|
const cols : ColsType[] = [{field : "id",header:"Id"},{field : "name",header:"Name"}];
|
||||||
|
|
||||||
@@ -37,9 +40,20 @@ export const WorkspaceSettings : React.FC<Props> = ({}) => {
|
|||||||
const searchConfig = { searchPlaceholder: "Search Workspace",filterRows: filterFuncFactory}
|
const searchConfig = { searchPlaceholder: "Search Workspace",filterRows: filterFuncFactory}
|
||||||
|
|
||||||
const onRowDelete = (row) => {
|
const onRowDelete = (row) => {
|
||||||
const filterFunc = filterFuncFactory(row.name)
|
setIsOpenDeleteModal(true);
|
||||||
const newWorkspaceList = workspacesRows.filter(filterFunc)
|
const findFunc = filterFuncFactory(row.id)
|
||||||
setWorkspacesRows(newWorkspaceList)
|
const newWorkspaceList = workspacesRows.find(findFunc)
|
||||||
|
setWorkspacesRows(newWorkspaceList);
|
||||||
|
(async() => {
|
||||||
|
try {
|
||||||
|
//await api.deleteUser(user)
|
||||||
|
const usersLeft = workspacesRows.filter(e => !findFunc(e))
|
||||||
|
setWorkspacesRows(usersLeft)
|
||||||
|
toast.success("Workspace Succesesfully Deleted")
|
||||||
|
} catch (error) {
|
||||||
|
toast.error("Unable To Delete")
|
||||||
|
}
|
||||||
|
})()
|
||||||
}
|
}
|
||||||
|
|
||||||
const onRowEdit = (row) => {
|
const onRowEdit = (row) => {
|
||||||
@@ -53,10 +67,13 @@ export const WorkspaceSettings : React.FC<Props> = ({}) => {
|
|||||||
<FilterableTableAction onRowEdit={onRowEdit} onRowDelete={onRowDelete} searchConfig={searchConfig}
|
<FilterableTableAction onRowEdit={onRowEdit} onRowDelete={onRowDelete} searchConfig={searchConfig}
|
||||||
buttonConfig={buttonConfig} rows={workspacesRows} cols={cols}>
|
buttonConfig={buttonConfig} rows={workspacesRows} cols={cols}>
|
||||||
</FilterableTableAction>
|
</FilterableTableAction>
|
||||||
<AddWorkspaceModal isOpen={isOpenModal} workspaceData={workspaceData} onEdit={isEditMode} onCloseModal={() => { setIsOpen(false);} } >
|
<AddWorkspaceModal isOpen={isOpenModal} workspaceDataInput={workspaceData} onEdit={isEditMode} onCloseModal={() => { setIsOpen(false);} } >
|
||||||
|
|
||||||
|
|
||||||
</AddWorkspaceModal>
|
</AddWorkspaceModal>
|
||||||
|
<ConfirmationModal isOpen={isOpenDeleteModal} onClose={function (): void {
|
||||||
|
throw new Error("Function not implemented.");
|
||||||
|
} } onConfirm={function (): void {
|
||||||
|
throw new Error("Function not implemented.");
|
||||||
|
} }></ConfirmationModal>
|
||||||
</>);
|
</>);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -166,13 +166,34 @@ export default class Api {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
register = async (username, password) => {
|
// register = async (username, password) => {
|
||||||
|
// const form = new FormData();
|
||||||
|
// form.append('username', username);
|
||||||
|
// form.append('password', password);
|
||||||
|
|
||||||
|
// try {
|
||||||
|
// const response = await this.client.post(`/user/register`, form);
|
||||||
|
// this.persistToken(response.data.token);
|
||||||
|
// return response;
|
||||||
|
// } catch (e) {
|
||||||
|
// if (e.response.status === 400) {
|
||||||
|
// const error = {
|
||||||
|
// 'type': FormValidationErrorType,
|
||||||
|
// 'messages': e.response.data
|
||||||
|
// };
|
||||||
|
// throw error;
|
||||||
|
// } else {
|
||||||
|
// throw e;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
setupAdminUser = async (password) => {
|
||||||
const form = new FormData();
|
const form = new FormData();
|
||||||
form.append('username', username);
|
|
||||||
form.append('password', password);
|
form.append('password', password);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await this.client.post(`/user/register`, form);
|
const response = await this.client.post(`/install/admin`, form);
|
||||||
this.persistToken(response.data.token);
|
this.persistToken(response.data.token);
|
||||||
return response;
|
return response;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
Reference in New Issue
Block a user