Skip to content

Commit

Permalink
made the default namespace as username (#223)
Browse files Browse the repository at this point in the history
* made the default namespace as username

* replace all special characters to "-", @ to "--"
  • Loading branch information
ATomkivEX committed Dec 21, 2022
1 parent 7a89678 commit 193d97e
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 16 deletions.
8 changes: 8 additions & 0 deletions frontend/src/app/hooks/useGetMe.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { useSelector } from 'react-redux';

import { selectUser } from 'app/store/userSlice';

export const useGetMe = () => {
const user = useSelector(selectUser);
return user;
};
19 changes: 11 additions & 8 deletions frontend/src/app/main/applications/NamespacesSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,28 @@ import Autocomplete, { createFilterOptions } from '@mui/material/Autocomplete';
import { useState, useEffect } from 'react';

import { getNamespacesList as getNamespacesListAPI } from '../../api';
import { useGetMe } from '../../hooks/useGetMe';
import { formattedNamespace } from '../../uitls/formattedNamespace';

const filter = createFilterOptions();

const NamespacesSelect = ({ clusterContextName, handleGetNamespace }) => {
const [namespace, setNamespace] = useState(null);
const [open, toggleOpen] = useState(false);
const [list, setList] = useState([]);
const user = useGetMe();

useEffect(() => {
handleGetNamespace(namespace?.name);
}, [namespace]);

useEffect(() => {
const defaultNamespace = {
name: formattedNamespace(user.email),
states: 'active',
};
setNamespace(defaultNamespace);
}, [user]);

useEffect(() => {
let canceled = false;
if (clusterContextName) {
Expand All @@ -38,13 +48,6 @@ const NamespacesSelect = ({ clusterContextName, handleGetNamespace }) => {
};
}, [clusterContextName]);

useEffect(() => {
if (list.length) {
const namespaceItem = list.find((item) => item.name === 'default');
setNamespace(namespaceItem);
}
}, [list]);

return (
<Autocomplete
margin='normal'
Expand Down
21 changes: 13 additions & 8 deletions frontend/src/app/main/charts/NamespacesSelect.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,32 @@
import { Button, Dialog, DialogActions, DialogContent, DialogContentText, DialogTitle, TextField } from '@mui/material';
import { Button, Dialog, DialogActions, DialogContent, DialogTitle, TextField } from '@mui/material';
import Autocomplete, { createFilterOptions } from '@mui/material/Autocomplete';
import { useState, useEffect } from 'react';

import { getNamespacesList as getNamespacesListAPI } from '../../api';
import { useGetMe } from '../../hooks/useGetMe';
import { formattedNamespace } from '../../uitls/formattedNamespace';

const filter = createFilterOptions();

const NamespacesSelect = ({ clusterContextName, handleGetNamespace }) => {
const [namespace, setNamespace] = useState(null);
const [open, toggleOpen] = useState(false);
const [list, setList] = useState([]);
const user = useGetMe();

useEffect(() => {
handleGetNamespace(namespace?.name);
}, [namespace]);

useEffect(() => {
const defaultNamespace = {
name: formattedNamespace(user.email),
states: 'active',
};

setNamespace(defaultNamespace);
}, [user]);

useEffect(() => {
let canceled = false;
if (clusterContextName) {
Expand All @@ -38,13 +50,6 @@ const NamespacesSelect = ({ clusterContextName, handleGetNamespace }) => {
};
}, [clusterContextName]);

useEffect(() => {
if (list.length) {
const namespaceItem = list.find((item) => item.name === 'default');
setNamespace(namespaceItem);
}
}, [list]);

const handleClose = () => {
setDialogValue({
name: '',
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/app/uitls/formattedNamespace.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const formattedNamespace = (namespace) => {
return namespace.replaceAll(/[^@a-z0-9]/gi, '-').replaceAll(/[@]/g, '--');
};

0 comments on commit 193d97e

Please sign in to comment.