Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix code formatting in Preview Web UI #24691

Merged
merged 1 commit into from
Jan 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"package": "npm install && npm run build",
"package:clean": "npm clean-install && npm run build",
"preview": "vite preview",
"prettier:format": "prettier --write \"./src/*.{ts,tsx}\"",
"prettier:check": "prettier --check \"./src/*.{ts,tsx}\"",
"prettier:format": "prettier --write \"./src/**/*.{ts,tsx}\"",
"prettier:check": "prettier --check \"./src/**/*.{ts,tsx}\"",
"check": "npm install && npm run lint && npm run prettier:check",
"check:clean": "npm clean-install && npm run lint && npm run prettier:check"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export interface ApiResponse<T> {
}

export class ClientApi {
axiosInstance: AxiosInstance = axios.create();
axiosInstance: AxiosInstance = axios.create()

paramsToQueryString = (params: Record<string, string>): string => {
let queryString = ''
Expand All @@ -32,13 +32,13 @@ export class ClientApi {

fetchData = async <T, P = undefined>(url: string, method: 'GET' | 'POST', params?: P): Promise<ApiResponse<T>> => {
try {
let response: AxiosResponse<T>;
let response: AxiosResponse<T>
if (method === 'GET') {
response = await this.axiosInstance.get(url)
} else if (method === 'POST') {
response = await this.axiosInstance.post(url, params)
} else {
throw new Error(`Unsupported HTTP method: ${method}`);
throw new Error(`Unsupported HTTP method: ${method}`)
}
return {
status: response.status,
Expand All @@ -53,17 +53,17 @@ export class ClientApi {
message: axiosError.message,
}
}
throw error;
throw error
}
}

get = async <T>(url: string, params: Record<string, string> = {}): Promise<ApiResponse<T>> => {
return this.fetchData(url + this.paramsToQueryString(params), 'GET');
return this.fetchData(url + this.paramsToQueryString(params), 'GET')
}

post = async<T>(url: string, body: Record<string, string> = {}): Promise<ApiResponse<T>> => {
return this.fetchData(url, 'POST', body);
post = async <T>(url: string, body: Record<string, string> = {}): Promise<ApiResponse<T>> => {
return this.fetchData(url, 'POST', body)
}
}

export const api = new ClientApi();
export const api = new ClientApi()
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@
import { api, ApiResponse } from '../base.ts'

export interface Stats {
runningQueries: number;
blockedQueries: number;
queuedQueries: number;
activeCoordinators: number;
activeWorkers: number;
runningDrivers: number;
totalAvailableProcessors: number;
reservedMemory: number;
totalInputRows: number;
totalInputBytes: number;
totalCpuTimeSecs: number;
runningQueries: number
blockedQueries: number
queuedQueries: number
activeCoordinators: number
activeWorkers: number
runningDrivers: number
totalAvailableProcessors: number
reservedMemory: number
totalInputRows: number
totalInputBytes: number
totalCpuTimeSecs: number
}

export async function statsApi(): Promise<ApiResponse<Stats>> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,25 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { api, ApiResponse } from "../base";
import { api, ApiResponse } from '../base'

export interface AuthInfo
{
authType: "insecure" | "form" | "fixed" | "oauth2" | null;
passwordAllowed: boolean;
authenticated: boolean;
username?: string;
export interface AuthInfo {
authType: 'insecure' | 'form' | 'fixed' | 'oauth2' | null
passwordAllowed: boolean
authenticated: boolean
username?: string
}

export type Empty = object;
export type Empty = object

export async function authInfoApi(): Promise<ApiResponse<AuthInfo>> {
return api.get('/ui/preview/auth/info')
return api.get('/ui/preview/auth/info')
}

export async function loginApi(body: Record<string, string>): Promise<ApiResponse<Empty>> {
return api.post('/ui/preview/auth/login', body)
return api.post('/ui/preview/auth/login', body)
}

export async function logoutApi(): Promise<ApiResponse<Empty>> {
return api.get('/ui/preview/auth/logout')
return api.get('/ui/preview/auth/logout')
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,32 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Box, CircularProgress, Alert, Typography } from "@mui/material";
import { Box, CircularProgress, Alert, Typography } from '@mui/material'
import { useAuth } from './AuthContext'
import { Texts } from "../constant";
import { Login } from './Login';
import { Texts } from '../constant'
import { Login } from './Login'

export const Auth = () => {
const { authInfo, error, loading } = useAuth();
const { authInfo, error, loading } = useAuth()

if (!authInfo) {
return (
<Box sx={{ p: 10 }} display="flex" flexDirection="column" alignItems="center" justifyContent="center">
{loading ?
<>
<CircularProgress/>
<Typography mt={2}>{Texts.Auth.Authenticating}</Typography>
</> : error &&
<Alert severity="error">
{error}
</Alert>
}
</Box>
)
}
if (!authInfo) {
return (
<Box sx={{ p: 10 }} display="flex" flexDirection="column" alignItems="center" justifyContent="center">
{loading ? (
<>
<CircularProgress />
<Typography mt={2}>{Texts.Auth.Authenticating}</Typography>
</>
) : (
error && <Alert severity="error">{error}</Alert>
)}
</Box>
)
}

if (authInfo.authType === 'form' && !authInfo?.authenticated) {
return <Login passwordAllowed={authInfo.passwordAllowed} />
}
if (authInfo.authType === 'form' && !authInfo?.authenticated) {
return <Login passwordAllowed={authInfo.passwordAllowed} />
}

return <div>{Texts.Auth.NotImplementedAuthType}</div>
return <div>{Texts.Auth.NotImplementedAuthType}</div>
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,27 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { createContext, useContext } from "react";
import { AuthInfo } from '../api/webapp/auth';
import { createContext, useContext } from 'react'
import { AuthInfo } from '../api/webapp/auth'

export interface LogoutParams {
redirect?: boolean;
redirect?: boolean
}

interface AuthContextType {
authInfo: AuthInfo | null;
login: (username: string, password: string) => Promise<void>;
logout: (params: LogoutParams) => void;
loading: boolean;
error: string | null;
authInfo: AuthInfo | null
login: (username: string, password: string) => Promise<void>
logout: (params: LogoutParams) => void
loading: boolean
error: string | null
}

export const AuthContext = createContext<AuthContextType | undefined>(undefined);
export const AuthContext = createContext<AuthContextType | undefined>(undefined)

export const useAuth = (): AuthContextType => {
const context = useContext(AuthContext);
if (context === undefined) {
throw new Error('AuthContext must be used within an AuthProvider');
}
return context;
};
const context = useContext(AuthContext)
if (context === undefined) {
throw new Error('AuthContext must be used within an AuthProvider')
}
return context
}
Loading
Loading