Compare commits
No commits in common. '38a3d4b564f4e6708db75ba11f61aa952c66d691' and 'de7a4b6d52dc8398832165d44d37f91c876b807f' have entirely different histories.
38a3d4b564
...
de7a4b6d52
@ -1,17 +0,0 @@ |
||||
export interface AuthenticationInterface { |
||||
key: string |
||||
token(): string |
||||
} |
||||
|
||||
export class BearerAuthentication implements AuthenticationInterface { |
||||
key = 'Authorization' |
||||
_token: string |
||||
|
||||
constructor(token: string) { |
||||
this._token = token |
||||
} |
||||
|
||||
token(): string { |
||||
return `Bearer ${this._token}`; |
||||
} |
||||
} |
@ -1,3 +0,0 @@ |
||||
export interface ApproveProcessRequest { |
||||
id: string |
||||
} |
@ -1,3 +0,0 @@ |
||||
export interface UnlockProcessRequest { |
||||
id: string |
||||
} |
@ -1,10 +0,0 @@ |
||||
import {Method, SchemaInterface} from "../../schema-client"; |
||||
|
||||
class ApproveProcessSchema implements SchemaInterface { |
||||
method = Method.POST |
||||
url = '/system-monitoring/processes/{id}/approve' |
||||
contentType = null |
||||
} |
||||
|
||||
export let approveProcessSchema = new ApproveProcessSchema() |
||||
export default approveProcessSchema |
@ -1,10 +0,0 @@ |
||||
import {Method, SchemaInterface} from "../../schema-client"; |
||||
|
||||
class UnlockProcessSchema implements SchemaInterface { |
||||
method = Method.POST |
||||
url = '/system-monitoring/processes/{id}/unlock' |
||||
contentType = null |
||||
} |
||||
|
||||
export let unlockProcessSchema = new UnlockProcessSchema() |
||||
export default unlockProcessSchema |
@ -1,116 +0,0 @@ |
||||
import styles from './styles.module.css' |
||||
import {Autocomplete, IconButton, TextareaAutosize, TextField} from "@mui/material"; |
||||
import {useContext, useEffect, useState} from "react"; |
||||
import Context from "../../../context/token"; |
||||
import AddCircleOutlineOutlinedIcon from '@mui/icons-material/AddCircleOutlineOutlined'; |
||||
import DeleteForeverOutlined from '@mui/icons-material/DeleteForeverOutlined'; |
||||
import Modal from '@mui/material/Modal'; |
||||
import Fade from '@mui/material/Fade'; |
||||
import Backdrop from '@mui/material/Backdrop'; |
||||
import Box from '@mui/material/Box'; |
||||
import Grid from "@mui/material/Grid"; |
||||
import ConfirmDialog from "../confirm-dialog"; |
||||
|
||||
const style = { |
||||
position: 'absolute' as 'absolute', |
||||
top: '50%', |
||||
left: '50%', |
||||
transform: 'translate(-50%, -50%)', |
||||
width: '100%', |
||||
bgcolor: 'background.paper', |
||||
border: '2px solid #000', |
||||
boxShadow: 24, |
||||
p: 4, |
||||
}; |
||||
|
||||
export default function Tokens() { |
||||
const {token, tokens, addToken, deleteToken, switchToken} = useContext(Context) |
||||
const [showAddForm, setShowAddForm] = useState(false) |
||||
const [showConfirm, setShowConfirm] = useState(false) |
||||
|
||||
let variants = tokens.map((token, index) => ({ |
||||
...token, |
||||
label: `${token.host} [${token.id}]` |
||||
})); |
||||
|
||||
useEffect(() => { |
||||
setShowAddForm(!token) |
||||
}, [token]) |
||||
|
||||
return ( |
||||
<> |
||||
<Grid container> |
||||
<Grid item xs={2}> |
||||
<Autocomplete |
||||
freeSolo |
||||
value={{ |
||||
...token, |
||||
label: token?.host ? `${token.host} [${token.id}]` : '' |
||||
}} |
||||
onChange={(event: any, newValue: any) => { |
||||
console.log('newValue', newValue); |
||||
if (newValue?.id) { |
||||
switchToken(newValue?.id) |
||||
} |
||||
}} |
||||
disablePortal |
||||
options={variants} |
||||
renderInput={(params) => <TextField {...params} label="Tokens"/>} |
||||
/> |
||||
</Grid> |
||||
<Grid item xs={1}> |
||||
<IconButton onClick={() => setShowAddForm(true)} title={`Add new token`} |
||||
aria-label="Add new token"> |
||||
<AddCircleOutlineOutlinedIcon/> |
||||
</IconButton> |
||||
<IconButton onClick={() => setShowConfirm(true)} title={`Delete current token`} |
||||
aria-label="Add new token"> |
||||
<DeleteForeverOutlined/> |
||||
</IconButton> |
||||
</Grid> |
||||
</Grid> |
||||
<Modal |
||||
aria-labelledby="transition-modal-title" |
||||
aria-describedby="transition-modal-description" |
||||
open={showAddForm} |
||||
onClose={() => setShowAddForm(false)} |
||||
closeAfterTransition |
||||
slots={{backdrop: Backdrop}} |
||||
slotProps={{ |
||||
backdrop: { |
||||
timeout: 500, |
||||
}, |
||||
}} |
||||
> |
||||
<Fade in={showAddForm}> |
||||
<Box sx={style}> |
||||
<TextareaAutosize |
||||
placeholder={`Pass JWT token`} |
||||
minRows={25} |
||||
style={{width: '100%'}} |
||||
onInput={(event: any) => { |
||||
if (addToken(event.target.value)) { |
||||
setShowAddForm(false) |
||||
} |
||||
}} |
||||
/> |
||||
</Box> |
||||
</Fade> |
||||
</Modal> |
||||
<ConfirmDialog |
||||
title={`Delete curent token`} |
||||
open={showConfirm} |
||||
agreeCallback={async () => { |
||||
let tokenId = token?.id || null |
||||
if (tokenId) { |
||||
deleteToken(tokenId) |
||||
} |
||||
setShowConfirm(false) |
||||
}} |
||||
|
||||
closeCallback={() => {setShowConfirm(false)}}> |
||||
Confirm? |
||||
</ConfirmDialog> |
||||
</> |
||||
) |
||||
} |
@ -1,6 +0,0 @@ |
||||
import React from 'react' |
||||
import {UseTokenInterface} from "../hooks/use-token" |
||||
|
||||
const Context = React.createContext({} as UseTokenInterface) |
||||
export const Provider = Context.Provider |
||||
export default Context |
@ -1,130 +0,0 @@ |
||||
|
||||
|
||||
export interface TokenData<T=any> { |
||||
payload: T |
||||
headers: Record<string, any> |
||||
} |
||||
|
||||
const isClient = () => { |
||||
return typeof window !== 'undefined' |
||||
} |
||||
|
||||
export const storeToken = (token: string) => { |
||||
if (!isClient()) { |
||||
return; |
||||
} |
||||
let tokenData = grabTokenData(token) |
||||
let tokenId = tokenData?.payload?.id; |
||||
if (!tokenId) { |
||||
return; |
||||
} |
||||
|
||||
let tokens: string | null = window.localStorage.getItem('tokens') |
||||
let tokensData: string[] = JSON.parse(tokens || '[]'); |
||||
if (!tokensData) { |
||||
return |
||||
} |
||||
window.localStorage.setItem('token', tokenId) |
||||
window.localStorage.setItem(tokenId, token) |
||||
tokensData.push(tokenId) |
||||
window.localStorage.setItem('tokens', JSON.stringify(tokensData)) |
||||
} |
||||
|
||||
export const cleanToken = (id: string) => { |
||||
if (!isClient()) { |
||||
return; |
||||
} |
||||
let tokens: string | null = window.localStorage.getItem('tokens') |
||||
let tokensData: string[] = JSON.parse(tokens || '[]'); |
||||
if (!tokensData) { |
||||
return |
||||
} |
||||
|
||||
tokensData = tokensData.filter((storedTokenId: string) => storedTokenId !== id) |
||||
window.localStorage.setItem('tokens', JSON.stringify(tokensData)) |
||||
window.localStorage.removeItem(id) |
||||
|
||||
// Чистим текущий токен
|
||||
let activeTokenId: string | null = window.localStorage.getItem('token') |
||||
if (id === activeTokenId) { |
||||
window.localStorage.removeItem('token') |
||||
} |
||||
} |
||||
|
||||
export const selectToken = (id: string) => { |
||||
if (!isClient()) { |
||||
return; |
||||
} |
||||
window.localStorage.setItem('token', id) |
||||
} |
||||
|
||||
export const grabTokenData = (token: string): TokenData|null => { |
||||
if (!isClient()) { |
||||
return null |
||||
} |
||||
|
||||
const parts = token.split('.') |
||||
if (parts.length !== 3) { |
||||
return null |
||||
} |
||||
|
||||
let payload = JSON.parse(window.atob(parts[1])) |
||||
if (!payload){ |
||||
return null |
||||
} |
||||
|
||||
let headers = JSON.parse(window.atob(parts[0])) |
||||
if (!headers){ |
||||
return null |
||||
} |
||||
|
||||
return { |
||||
payload, |
||||
headers, |
||||
}; |
||||
} |
||||
|
||||
export const grabRawToken = (): string | null => { |
||||
if (!isClient()) { |
||||
return null |
||||
} |
||||
const tokenId = window.localStorage.getItem('token') |
||||
if (!tokenId) { |
||||
return null |
||||
} |
||||
return window.localStorage.getItem(tokenId) |
||||
} |
||||
|
||||
export const grabToken = (): TokenData | null => { |
||||
const token = grabRawToken() |
||||
if (!token) { |
||||
return null |
||||
} |
||||
return grabTokenData(token); |
||||
} |
||||
|
||||
export const grabTokens = (): TokenData[] => { |
||||
if (!isClient()) { |
||||
return [] |
||||
} |
||||
const storedTokens = window.localStorage.getItem('tokens') |
||||
let tokens: string[] = JSON.parse(storedTokens || '[]'); |
||||
if (!tokens) { |
||||
return [] |
||||
} |
||||
|
||||
let result: TokenData[] = [] |
||||
|
||||
tokens.forEach((tokenId) => { |
||||
let token = window.localStorage.getItem(tokenId) |
||||
if (!token) { |
||||
return true |
||||
} |
||||
let tokenData = grabTokenData(token) |
||||
if (tokenData) { |
||||
result.push(tokenData) |
||||
} |
||||
}) |
||||
|
||||
return result |
||||
} |
@ -1,30 +0,0 @@ |
||||
import {useContext, useEffect, useState} from 'react' |
||||
import {SMClient} from "../api/sm/sm-client"; |
||||
import Context from "../context/token"; |
||||
import {Token} from "./use-token"; |
||||
import {BearerAuthentication} from "../api/authentication"; |
||||
import {grabRawToken} from "../functions/token"; |
||||
|
||||
const grabClient = (token: Token | null, rawToken: string | null): SMClient => { |
||||
let authentication = {} |
||||
if (rawToken) { |
||||
authentication = { |
||||
authentication: new BearerAuthentication(rawToken) |
||||
} |
||||
} |
||||
return new SMClient({ |
||||
baseUrl: token?.host || 'localhost', |
||||
...authentication |
||||
}) |
||||
} |
||||
|
||||
export function useApi(): SMClient { |
||||
let {token} = useContext(Context) |
||||
let [client, setClient] = useState<SMClient>(grabClient(token, grabRawToken())) |
||||
|
||||
useEffect(() => { |
||||
setClient(grabClient(token, grabRawToken())) |
||||
}, [token]) |
||||
|
||||
return client |
||||
} |
@ -1,57 +0,0 @@ |
||||
import {useState, useEffect} from 'react' |
||||
import {cleanToken, grabToken, grabTokenData, grabTokens, selectToken, storeToken} from "../functions/token"; |
||||
|
||||
export class Token { |
||||
id!: string |
||||
host!: string |
||||
permissions!: string[] |
||||
} |
||||
|
||||
export interface UseTokenInterface { |
||||
token: Token|null |
||||
tokens: Token[] |
||||
switchToken(tokenId: string): void |
||||
deleteToken(tokenId: string): void |
||||
addToken(tokenId: string): boolean |
||||
} |
||||
|
||||
export function useToken(): UseTokenInterface { |
||||
const [token, setToken] = useState<Token|null>(null); |
||||
const [tokens, setTokens] = useState<Token[]>([]); |
||||
useEffect(() => { |
||||
setToken(grabToken()?.payload) |
||||
|
||||
let tokens = grabTokens().map((tokenData) => tokenData.payload as Token) |
||||
setTokens(tokens) |
||||
|
||||
return () => { |
||||
|
||||
} |
||||
}, []) |
||||
|
||||
const switchToken = (tokenId: string) => { |
||||
selectToken(tokenId) |
||||
setToken(grabToken()?.payload) |
||||
} |
||||
|
||||
const deleteToken = (tokenId: string) => { |
||||
cleanToken(tokenId) |
||||
setToken(grabToken()?.payload) |
||||
} |
||||
|
||||
const addToken = (token: string): boolean => { |
||||
if (!grabTokenData(token)) { |
||||
return false; |
||||
} |
||||
|
||||
storeToken(token) |
||||
setToken(grabToken()?.payload) |
||||
setTokens([ |
||||
...tokens, |
||||
grabToken()?.payload |
||||
]) |
||||
return true |
||||
} |
||||
|
||||
return {token, tokens, switchToken, deleteToken, addToken} |
||||
} |
@ -1,13 +1,6 @@ |
||||
import '../styles/globals.css' |
||||
import type { AppProps } from 'next/app' |
||||
import {Provider} from "../context/token"; |
||||
import {useToken} from "../hooks/use-token"; |
||||
|
||||
export default function App({ Component, pageProps }: AppProps) { |
||||
let {token, tokens, switchToken, deleteToken, addToken} = useToken() |
||||
return ( |
||||
<Provider value={{token, tokens, switchToken, deleteToken, addToken}}> |
||||
<Component {...pageProps} /> |
||||
</Provider> |
||||
) |
||||
return <Component {...pageProps} /> |
||||
} |
||||
|
@ -1 +0,0 @@ |
||||
self.__BUILD_MANIFEST={__rewrites:{beforeFiles:[],afterFiles:[],fallback:[]},"/":["static/chunks/317-7a9f5b1fcf3cfbe5.js","static/css/758d1a1ad3b56ec4.css","static/chunks/pages/index-e05dda18f04fa62a.js"],"/_error":["static/chunks/pages/_error-8353112a01355ec2.js"],sortedPages:["/","/_app","/_error"]},self.__BUILD_MANIFEST_CB&&self.__BUILD_MANIFEST_CB(); |
@ -0,0 +1 @@ |
||||
self.__BUILD_MANIFEST={__rewrites:{beforeFiles:[],afterFiles:[],fallback:[]},"/":["static/chunks/556-56e85e4880bbe04b.js","static/css/758d1a1ad3b56ec4.css","static/chunks/pages/index-84dfafb8f3c7c7ce.js"],"/_error":["static/chunks/pages/_error-8353112a01355ec2.js"],sortedPages:["/","/_app","/_error"]},self.__BUILD_MANIFEST_CB&&self.__BUILD_MANIFEST_CB(); |
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -1 +0,0 @@ |
||||
(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[888],{6840:function(t,e,n){(window.__NEXT_P=window.__NEXT_P||[]).push(["/_app",function(){return n(2595)}])},7889:function(t,e,n){"use strict";n.d(e,{z:function(){return l}});var r=n(7294);let o=r.createContext({}),l=o.Provider;e.Z=o},4085:function(t,e,n){"use strict";n.d(e,{DR:function(){return c},F8:function(){return d},Y0:function(){return l},gn:function(){return a},mB:function(){return o},rK:function(){return u},se:function(){return i}});let r=()=>!0,o=t=>{var e;if(!r())return;let n=i(t),o=null==n?void 0:null===(e=n.payload)||void 0===e?void 0:e.id;if(!o)return;let l=JSON.parse(window.localStorage.getItem("tokens")||"[]");l&&(window.localStorage.setItem("token",o),window.localStorage.setItem(o,t),l.push(o),window.localStorage.setItem("tokens",JSON.stringify(l)))},l=t=>{if(!r())return;let e=JSON.parse(window.localStorage.getItem("tokens")||"[]");e&&(e=e.filter(e=>e!==t),window.localStorage.setItem("tokens",JSON.stringify(e)),window.localStorage.removeItem(t),t===window.localStorage.getItem("token")&&window.localStorage.removeItem("token"))},u=t=>{r()&&window.localStorage.setItem("token",t)},i=t=>{if(!r())return null;let e=t.split(".");if(3!==e.length)return null;let n=JSON.parse(window.atob(e[1]));if(!n)return null;let o=JSON.parse(window.atob(e[0]));return o?{payload:n,headers:o}:null},a=()=>{if(!r())return null;let t=window.localStorage.getItem("token");return t?window.localStorage.getItem(t):null},d=()=>{let t=a();return t?i(t):null},c=()=>{if(!r())return[];let t=window.localStorage.getItem("tokens"),e=JSON.parse(t||"[]");if(!e)return[];let n=[];return e.forEach(t=>{let e=window.localStorage.getItem(t);if(!e)return!0;let r=i(e);r&&n.push(r)}),n}},2595:function(t,e,n){"use strict";n.r(e),n.d(e,{default:function(){return i}});var r=n(5893);n(4744);var o=n(7889),l=n(7294),u=n(4085);function i(t){let{Component:e,pageProps:n}=t,{token:i,tokens:a,switchToken:d,deleteToken:c,addToken:f}=function(){let[t,e]=(0,l.useState)(null),[n,r]=(0,l.useState)([]);(0,l.useEffect)(()=>{var t;return e(null===(t=(0,u.F8)())||void 0===t?void 0:t.payload),r((0,u.DR)().map(t=>t.payload)),()=>{}},[]);let o=t=>{var n;(0,u.rK)(t),e(null===(n=(0,u.F8)())||void 0===n?void 0:n.payload)},i=t=>{var n;(0,u.Y0)(t),e(null===(n=(0,u.F8)())||void 0===n?void 0:n.payload)},a=t=>{var o,l;return!!(0,u.se)(t)&&((0,u.mB)(t),e(null===(o=(0,u.F8)())||void 0===o?void 0:o.payload),r([...n,null===(l=(0,u.F8)())||void 0===l?void 0:l.payload]),!0)};return{token:t,tokens:n,switchToken:o,deleteToken:i,addToken:a}}();return(0,r.jsx)(o.z,{value:{token:i,tokens:a,switchToken:d,deleteToken:c,addToken:f},children:(0,r.jsx)(e,{...n})})}},4744:function(){}},function(t){var e=function(e){return t(t.s=e)};t.O(0,[774,179],function(){return e(6840),e(880)}),_N_E=t.O()}]); |
@ -0,0 +1 @@ |
||||
(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[888],{6840:function(n,u,t){(window.__NEXT_P=window.__NEXT_P||[]).push(["/_app",function(){return t(3847)}])},3847:function(n,u,t){"use strict";t.r(u),t.d(u,{default:function(){return _}});var r=t(5893);function _(n){let{Component:u,pageProps:t}=n;return(0,r.jsx)(u,{...t})}t(4744)},4744:function(){}},function(n){var u=function(u){return n(n.s=u)};n.O(0,[774,179],function(){return u(6840),u(880)}),_N_E=n.O()}]); |
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Reference in new issue