From 7c21905b879012c19b0a3b6f80115a8bb24dfb2d Mon Sep 17 00:00:00 2001 From: Stephen Benjamin Date: Wed, 22 Oct 2025 07:23:22 -0400 Subject: [PATCH 1/3] Fix proxy for websocket --- chat/sippy_agent/web_server.py | 12 ------------ pkg/sippyserver/chatproxy.go | 9 +-------- sippy-ng/src/chat/chatUtils.js | 17 ++++------------- sippy-ng/src/chat/store/personaSlice.js | 6 +----- 4 files changed, 6 insertions(+), 38 deletions(-) diff --git a/chat/sippy_agent/web_server.py b/chat/sippy_agent/web_server.py index 99b0655000..12e3978c2c 100644 --- a/chat/sippy_agent/web_server.py +++ b/chat/sippy_agent/web_server.py @@ -11,7 +11,6 @@ from typing import List, Dict, Any, Optional import uvicorn from fastapi import FastAPI, WebSocket, WebSocketDisconnect, Response -from fastapi.middleware.cors import CORSMiddleware from prometheus_client import generate_latest, CONTENT_TYPE_LATEST from .agent import SippyAgent @@ -92,7 +91,6 @@ def __init__(self, config: Config, metrics_port: Optional[int] = None): version="1.0.0", ) self.websocket_manager = WebSocketManager() - self._setup_middleware() self._setup_routes() # Initialize agent info metrics @@ -103,16 +101,6 @@ def __init__(self, config: Config, metrics_port: Optional[int] = None): "persona": config.persona, }) - def _setup_middleware(self): - """Setup CORS and other middleware.""" - self.app.add_middleware( - CORSMiddleware, - allow_origins=["*"], # Configure this for production - allow_credentials=True, - allow_methods=["*"], - allow_headers=["*"], - ) - def _setup_routes(self): """Setup API routes.""" diff --git a/pkg/sippyserver/chatproxy.go b/pkg/sippyserver/chatproxy.go index 3108811812..1283c53790 100644 --- a/pkg/sippyserver/chatproxy.go +++ b/pkg/sippyserver/chatproxy.go @@ -12,14 +12,7 @@ import ( // rewriteChatPath rewrites /api/chat paths to /chat for the target service func rewriteChatPath(path string) string { - // Only replace /api/chat when it's followed by end of string or a slash - if path == "/api/chat" { - return "/chat" - } - if strings.HasPrefix(path, "/api/chat/") { - return "/chat" + strings.TrimPrefix(path, "/api/chat") - } - return path + return strings.Replace(path, "/api/chat", "/chat", 1) } // ChatProxy handles proxying HTTP and WebSocket requests to the sippy-chat service diff --git a/sippy-ng/src/chat/chatUtils.js b/sippy-ng/src/chat/chatUtils.js index 4dbdd00243..40a915e312 100644 --- a/sippy-ng/src/chat/chatUtils.js +++ b/sippy-ng/src/chat/chatUtils.js @@ -57,20 +57,11 @@ function getRelativeTime(date) { return `${diffDays} days ago` } -// Get WebSocket URL based on current environment +// Get WebSocket URL for the chat proxy export function getChatWebSocketUrl() { - const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:' - const baseUrl = process.env.REACT_APP_CHAT_API_URL || '/api/chat' - - let url - if (baseUrl.startsWith('/')) { - url = new URL(baseUrl, window.location.origin) - } else { - url = new URL(baseUrl) - url.protocol = protocol - } - - url.pathname = url.pathname.replace(/\/$/, '') + '/stream' + const apiUrl = process.env.REACT_APP_API_URL || window.location.origin + const url = new URL('/api/chat/stream', apiUrl) + url.protocol = url.protocol === 'https:' ? 'wss:' : 'ws:' return url.toString() } diff --git a/sippy-ng/src/chat/store/personaSlice.js b/sippy-ng/src/chat/store/personaSlice.js index 9579699a26..ed3ad4330a 100644 --- a/sippy-ng/src/chat/store/personaSlice.js +++ b/sippy-ng/src/chat/store/personaSlice.js @@ -7,13 +7,9 @@ export const createPersonaSlice = (set, get) => ({ personasError: null, loadPersonas: () => { - const apiUrl = - process.env.REACT_APP_CHAT_API_URL || window.location.origin + '/api/chat' - const baseUrl = apiUrl.replace(/\/$/, '').replace(/\/stream$/, '') - set({ personasLoading: true, personasError: null }) - fetch(`${baseUrl}/personas`) + fetch(process.env.REACT_APP_API_URL + '/api/chat/personas') .then((response) => { if (!response.ok) { throw new Error(`Failed to fetch personas: ${response.statusText}`) From 4d6ed333e61cd10372a6102b7540508d993978cf Mon Sep 17 00:00:00 2001 From: Stephen Benjamin Date: Wed, 22 Oct 2025 07:43:47 -0400 Subject: [PATCH 2/3] Write apiFetch wrapper to avoid contenatation every place we make an API call --- AGENTS.md | 19 +++++++++++++++++++ sippy-ng/src/App.js | 7 ++++--- sippy-ng/src/bugs/BugTable.js | 8 +++----- .../build_clusters/BuildClusterHealthChart.js | 7 ++----- .../src/build_clusters/BuildClusterTable.js | 6 ++---- sippy-ng/src/chat/store/personaSlice.js | 4 +++- sippy-ng/src/chat/store/shareSlice.js | 11 +++++------ sippy-ng/src/chat/useSessionRating.js | 18 ++++++++---------- .../src/component_readiness/CompReadyUtils.js | 2 +- .../ComponentReadinessIndicator.js | 12 ++++-------- .../src/datagrid/GridToolbarAutocomplete.js | 7 +++---- sippy-ng/src/helpers.js | 18 ++++++++++++++++++ sippy-ng/src/jobs/JobAnalysis.js | 11 +++-------- sippy-ng/src/jobs/JobRunsTable.js | 7 ++----- sippy-ng/src/jobs/JobStackedChart.js | 4 ++-- sippy-ng/src/jobs/JobTable.js | 6 +++--- sippy-ng/src/jobs/JobsDetail.js | 7 +++---- sippy-ng/src/prow_job_runs/IntervalsChart.js | 7 +++---- .../src/pull_requests/PullRequestsTable.js | 6 +++--- sippy-ng/src/releases/Install.js | 9 +++------ sippy-ng/src/releases/PayloadCalendar.js | 14 ++++---------- sippy-ng/src/releases/PayloadMiniCalendar.js | 7 +++---- .../src/releases/PayloadStreamOverview.js | 7 ++----- .../src/releases/PayloadStreamTestFailures.js | 6 +++--- sippy-ng/src/releases/PayloadStreamsTable.js | 8 ++------ sippy-ng/src/releases/PayloadTestFailures.js | 7 ++----- sippy-ng/src/releases/ReleaseOverview.js | 5 ++--- .../src/releases/ReleasePayloadAcceptance.js | 7 +++---- .../src/releases/ReleasePayloadDetails.js | 8 ++------ .../src/releases/ReleasePayloadJobRuns.js | 8 ++------ .../releases/ReleasePayloadPullRequests.js | 8 ++------ sippy-ng/src/releases/ReleasePayloadTable.js | 7 ++----- sippy-ng/src/releases/Upgrades.js | 5 ++--- .../src/repositories/RepositoriesTable.js | 6 +++--- sippy-ng/src/tests/FeatureGates.js | 6 +++--- sippy-ng/src/tests/TestAnalysis.js | 5 ++--- sippy-ng/src/tests/TestDurationChart.js | 7 +++---- sippy-ng/src/tests/TestOutputs.js | 7 +++---- sippy-ng/src/tests/TestPassRateCharts.js | 6 +++--- sippy-ng/src/tests/TestStackedChart.js | 6 ++---- sippy-ng/src/tests/TestTable.js | 3 ++- sippy-ng/src/tests/TestsDetail.js | 7 +++---- 42 files changed, 149 insertions(+), 177 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index a5e49e63c9..9af189adef 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -38,6 +38,25 @@ npx prettier --write . * Prefer functional components and React hooks over class components. * Keep UI elements consistent with Material-UI standards. +### Making API Calls + +* **Always use `apiFetch()` from `helpers.js` instead of direct `fetch()` calls** when making API requests to Sippy's backend. +* `apiFetch()` automatically prepends `REACT_APP_API_URL` to relative URLs, making the code cleaner and handling development/production environments correctly. + +```javascript +// ✅ Good - uses apiFetch +import { apiFetch } from '../helpers' + +apiFetch('/api/releases') + .then(response => response.json()) + .then(data => console.log(data)) + +// ❌ Bad - manual concatenation +fetch(process.env.REACT_APP_API_URL + '/api/releases') + .then(response => response.json()) + .then(data => console.log(data)) +``` + ## General Notes * Favor clarity and maintainability over cleverness. diff --git a/sippy-ng/src/App.js b/sippy-ng/src/App.js index b9a19babdd..1463639bd9 100644 --- a/sippy-ng/src/App.js +++ b/sippy-ng/src/App.js @@ -12,6 +12,7 @@ import { cyan, green, orange, red } from '@mui/material/colors' import { DarkMode, LightMode, ToggleOff, ToggleOn } from '@mui/icons-material' import { ErrorBoundary } from 'react-error-boundary' import { + apiFetch, findFirstNonGARelease, getReportStartDate, getUrlWithoutParams, @@ -433,9 +434,9 @@ function App(props) { const fetchData = () => { Promise.all([ - fetch(process.env.REACT_APP_API_URL + '/api/releases'), - fetch(process.env.REACT_APP_API_URL + '/api/capabilities'), - fetch(process.env.REACT_APP_API_URL + '/api/report_date'), + apiFetch('/api/releases'), + apiFetch('/api/capabilities'), + apiFetch('/api/report_date'), ]) .then(([releases, capabilities, reportDate]) => { if (releases.status !== 200) { diff --git a/sippy-ng/src/bugs/BugTable.js b/sippy-ng/src/bugs/BugTable.js index d59102db31..cd216bda36 100644 --- a/sippy-ng/src/bugs/BugTable.js +++ b/sippy-ng/src/bugs/BugTable.js @@ -12,7 +12,7 @@ import { Typography, } from '@mui/material' import { getTriagesAPIUrl } from '../component_readiness/CompReadyUtils' -import { relativeTime, safeEncodeURIComponent } from '../helpers' +import { apiFetch, relativeTime, safeEncodeURIComponent } from '../helpers' import Alert from '@mui/material/Alert' import PropTypes from 'prop-types' import React, { useEffect } from 'react' @@ -26,12 +26,10 @@ export default function BugTable(props) { const fetchData = () => { let bugsURL = props.bugsURL if (!bugsURL || bugsURL.length === 0) { - bugsURL = `${ - process.env.REACT_APP_API_URL - }/api/tests/bugs?test=${safeEncodeURIComponent(props.testName)}` + bugsURL = `/api/tests/bugs?test=${safeEncodeURIComponent(props.testName)}` } - Promise.all([fetch(bugsURL)]) + Promise.all([apiFetch(bugsURL)]) .then(([bugs]) => { if (bugs.status !== 200) { throw new Error('server returned when fetching bugs' + bugs.status) diff --git a/sippy-ng/src/build_clusters/BuildClusterHealthChart.js b/sippy-ng/src/build_clusters/BuildClusterHealthChart.js index 4aea03dd4e..9092bba593 100644 --- a/sippy-ng/src/build_clusters/BuildClusterHealthChart.js +++ b/sippy-ng/src/build_clusters/BuildClusterHealthChart.js @@ -1,3 +1,4 @@ +import { apiFetch } from '../helpers' import { Line } from 'react-chartjs-2' import Alert from '@mui/material/Alert' import chroma from 'chroma-js' @@ -10,11 +11,7 @@ export default function BuildClusterHealthChart(props) { const [data, setData] = React.useState([]) const fetchData = () => { - fetch( - process.env.REACT_APP_API_URL + - '/api/health/build_cluster/analysis?period=' + - props.period - ) + apiFetch('/api/health/build_cluster/analysis?period=' + props.period) .then((response) => { if (response.status !== 200) { throw new Error('server returned ' + response.status) diff --git a/sippy-ng/src/build_clusters/BuildClusterTable.js b/sippy-ng/src/build_clusters/BuildClusterTable.js index 3e00916153..1c816b6db1 100644 --- a/sippy-ng/src/build_clusters/BuildClusterTable.js +++ b/sippy-ng/src/build_clusters/BuildClusterTable.js @@ -5,7 +5,7 @@ import { generateClasses } from '../datagrid/utils' import { Link } from 'react-router-dom' import { makeStyles } from '@mui/styles' import { NumberParam, StringParam, useQueryParam } from 'use-query-params' -import { safeEncodeURIComponent, SafeJSONParam } from '../helpers' +import { apiFetch, safeEncodeURIComponent, SafeJSONParam } from '../helpers' import { withStyles } from '@mui/styles' import Alert from '@mui/material/Alert' import GridToolbar from '../datagrid/GridToolbar' @@ -134,9 +134,7 @@ function BuildClusterTable(props) { queryString += '?period=' + safeEncodeURIComponent(period) } - fetch( - process.env.REACT_APP_API_URL + '/api/health/build_cluster' + queryString - ) + apiFetch('/api/health/build_cluster' + queryString) .then((response) => { if (response.status !== 200) { throw new Error('server returned ' + response.status) diff --git a/sippy-ng/src/chat/store/personaSlice.js b/sippy-ng/src/chat/store/personaSlice.js index ed3ad4330a..5ffcfb3051 100644 --- a/sippy-ng/src/chat/store/personaSlice.js +++ b/sippy-ng/src/chat/store/personaSlice.js @@ -1,3 +1,5 @@ +import { apiFetch } from '../../helpers' + /** * Persona slice - manages available chat personas */ @@ -9,7 +11,7 @@ export const createPersonaSlice = (set, get) => ({ loadPersonas: () => { set({ personasLoading: true, personasError: null }) - fetch(process.env.REACT_APP_API_URL + '/api/chat/personas') + apiFetch('/api/chat/personas') .then((response) => { if (!response.ok) { throw new Error(`Failed to fetch personas: ${response.statusText}`) diff --git a/sippy-ng/src/chat/store/shareSlice.js b/sippy-ng/src/chat/store/shareSlice.js index a7b557d031..76d9225b8f 100644 --- a/sippy-ng/src/chat/store/shareSlice.js +++ b/sippy-ng/src/chat/store/shareSlice.js @@ -1,5 +1,5 @@ +import { apiFetch, relativeTime } from '../../helpers' import { createMessage, MESSAGE_TYPES } from '../chatUtils' -import { relativeTime } from '../../helpers' import { SESSION_TYPES } from './sessionSlice' /** @@ -32,10 +32,9 @@ export const createShareSlice = (set, get) => ({ set({ loadingShared: true }) - fetch( - `${process.env.REACT_APP_API_URL}/api/chat/conversations/${conversationId}`, - { signal: abortController.signal } - ) + apiFetch(`/api/chat/conversations/${conversationId}`, { + signal: abortController.signal, + }) .then((response) => { if (!response.ok) { return response.json().then( @@ -175,7 +174,7 @@ export const createShareSlice = (set, get) => ({ payload.parent_id = activeSession.sharedId || activeSession.parentId } - fetch(process.env.REACT_APP_API_URL + '/api/chat/conversations', { + apiFetch('/api/chat/conversations', { method: 'POST', headers: { 'Content-Type': 'application/json', diff --git a/sippy-ng/src/chat/useSessionRating.js b/sippy-ng/src/chat/useSessionRating.js index 0e421e0d1a..7134d40944 100644 --- a/sippy-ng/src/chat/useSessionRating.js +++ b/sippy-ng/src/chat/useSessionRating.js @@ -1,3 +1,4 @@ +import { apiFetch } from '../helpers' import { MESSAGE_TYPES } from './chatUtils' import { useCallback } from 'react' import { useSessionActions, useSettings } from './store/useChatStore' @@ -74,16 +75,13 @@ export function useSessionRating() { try { // Submit to API - const response = await fetch( - process.env.REACT_APP_API_URL + '/api/chat/ratings', - { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify(payload), - } - ) + const response = await apiFetch('/api/chat/ratings', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify(payload), + }) if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`) diff --git a/sippy-ng/src/component_readiness/CompReadyUtils.js b/sippy-ng/src/component_readiness/CompReadyUtils.js index 96da9eeafd..32185bd631 100644 --- a/sippy-ng/src/component_readiness/CompReadyUtils.js +++ b/sippy-ng/src/component_readiness/CompReadyUtils.js @@ -79,7 +79,7 @@ export const jiraUrlPrefix = 'https://issues.redhat.com/browse/' // Make one place to create the Component Readiness api call export function getAPIUrl(endpoint) { - return `${process.env.REACT_APP_API_URL}/api/${endpoint}` + return `/api/${endpoint}` } export function getCRMainAPIUrl() { diff --git a/sippy-ng/src/component_readiness/ComponentReadinessIndicator.js b/sippy-ng/src/component_readiness/ComponentReadinessIndicator.js index 86f4476ed1..c3ba18c42a 100644 --- a/sippy-ng/src/component_readiness/ComponentReadinessIndicator.js +++ b/sippy-ng/src/component_readiness/ComponentReadinessIndicator.js @@ -13,7 +13,7 @@ import { import { COMPONENT_READINESS_THRESHOLDS } from '../constants' import { Link } from 'react-router-dom' import { makeStyles } from '@mui/styles' -import { relativeTime } from '../helpers' +import { apiFetch, relativeTime } from '../helpers' import ArrowForwardIcon from '@mui/icons-material/ArrowForward' import Grid from '@mui/material/Grid' import HealingIcon from '@mui/icons-material/Healing' @@ -60,12 +60,10 @@ export default function ComponentReadinessIndicator({ release }) { useEffect(() => { const viewName = `${release}-main` const componentReportUrl = - process.env.REACT_APP_API_URL + - '/api/component_readiness?view=' + - encodeURIComponent(viewName) + '/api/component_readiness?view=' + encodeURIComponent(viewName) // Fetch both the component report and triages - const componentReportPromise = fetch(componentReportUrl) + const componentReportPromise = apiFetch(componentReportUrl) .then((response) => { if (response.status !== 200) { return null @@ -74,9 +72,7 @@ export default function ComponentReadinessIndicator({ release }) { }) .catch(() => null) - const triagesPromise = fetch( - process.env.REACT_APP_API_URL + '/api/component_readiness/triages' - ) + const triagesPromise = apiFetch('/api/component_readiness/triages') .then((response) => { if (response.status !== 200) { return [] diff --git a/sippy-ng/src/datagrid/GridToolbarAutocomplete.js b/sippy-ng/src/datagrid/GridToolbarAutocomplete.js index 04da195e58..d8ccecf763 100644 --- a/sippy-ng/src/datagrid/GridToolbarAutocomplete.js +++ b/sippy-ng/src/datagrid/GridToolbarAutocomplete.js @@ -1,4 +1,4 @@ -import { safeEncodeURIComponent } from '../helpers' +import { apiFetch, safeEncodeURIComponent } from '../helpers' import Autocomplete from '@mui/lab/Autocomplete' import CircularProgress from '@mui/material/CircularProgress' import PropTypes from 'prop-types' @@ -20,9 +20,8 @@ export default function GridToolbarAutocomplete(props) { queryParams.push('release=' + safeEncodeURIComponent(props.release)) } - const response = await fetch( - process.env.REACT_APP_API_URL + - `/api/autocomplete/${props.field}?${queryParams.join('&')}` + const response = await apiFetch( + `/api/autocomplete/${props.field}?${queryParams.join('&')}` ) const values = await response.json() diff --git a/sippy-ng/src/helpers.js b/sippy-ng/src/helpers.js index 29b7114a0f..2097e34c21 100644 --- a/sippy-ng/src/helpers.js +++ b/sippy-ng/src/helpers.js @@ -1,6 +1,24 @@ // Compute relative times -- Intl.RelativeTimeFormat is new-ish, // and not supported in all browsers, and it's not in node yet. +/** + * Fetch wrapper that automatically prepends REACT_APP_API_URL to relative URLs. + * Use this for all API calls instead of direct fetch. + * + * @param {string} url - URL to fetch (relative URLs starting with / will be prepended with REACT_APP_API_URL) + * @param {RequestInit} options - Standard fetch options + * @returns {Promise} + * + * @example apiFetch('/api/releases') + */ +export function apiFetch(url, options) { + const fullUrl = url.startsWith('/') + ? `${process.env.REACT_APP_API_URL}${url}` + : url + + return fetch(fullUrl, options) +} + export const SafeJSONParam = { encode: (j) => { return safeEncodeURIComponent(JSON.stringify(j)) diff --git a/sippy-ng/src/jobs/JobAnalysis.js b/sippy-ng/src/jobs/JobAnalysis.js index 4ba69a5691..c61dcc6dea 100644 --- a/sippy-ng/src/jobs/JobAnalysis.js +++ b/sippy-ng/src/jobs/JobAnalysis.js @@ -21,6 +21,7 @@ import { DataGrid } from '@mui/x-data-grid' import { filterList } from '../datagrid/utils' import { getColumns, getViews } from './JobTable' import { + apiFetch, getReportStartDate, pathForJobRunsWithFilter, pathForJobsWithFilter, @@ -89,11 +90,7 @@ export function JobAnalysis(props) { queryParams += `&period=${period}` } - Promise.all([ - fetch( - `${process.env.REACT_APP_API_URL}/api/jobs/analysis?${queryParams}` - ), - ]) + Promise.all([apiFetch(`/api/jobs/analysis?${queryParams}`)]) .then(([analysis]) => { if (analysis.status !== 200) { throw new Error('server returned ' + analysis.status) @@ -103,9 +100,7 @@ export function JobAnalysis(props) { }) .then(([analysis]) => { setAnalysis(analysis) - setBugsURL( - `${process.env.REACT_APP_API_URL}/api/jobs/bugs?${queryParams}` - ) + setBugsURL(`/api/jobs/bugs?${queryParams}`) // allTests maps each test name to a struct containing the test name again, and the total number of // failures in the past 7 days. This value is used to sort on and determine the most relevant tests diff --git a/sippy-ng/src/jobs/JobRunsTable.js b/sippy-ng/src/jobs/JobRunsTable.js index 6df3b1c29c..fb00f00810 100644 --- a/sippy-ng/src/jobs/JobRunsTable.js +++ b/sippy-ng/src/jobs/JobRunsTable.js @@ -9,6 +9,7 @@ import { import { DataGrid } from '@mui/x-data-grid' import { DirectionsBoat, GitHub } from '@mui/icons-material' import { + apiFetch, getReportStartDate, pathForExactJob, relativeTime, @@ -298,11 +299,7 @@ export default function JobRunsTable(props) { queryString += '&perPage=' + safeEncodeURIComponent(pageSize) queryString += '&page=' + safeEncodeURIComponent(page) - fetch( - process.env.REACT_APP_API_URL + - '/api/jobs/runs?' + - queryString.substring(1) - ) + apiFetch('/api/jobs/runs?' + queryString.substring(1)) .then((response) => { if (response.status !== 200) { throw new Error('server returned ' + response.status) diff --git a/sippy-ng/src/jobs/JobStackedChart.js b/sippy-ng/src/jobs/JobStackedChart.js index 4c92086f45..ec5aa6887d 100644 --- a/sippy-ng/src/jobs/JobStackedChart.js +++ b/sippy-ng/src/jobs/JobStackedChart.js @@ -4,7 +4,7 @@ import PropTypes from 'prop-types' import React, { useEffect } from 'react' import './JobAnalysis.css' -import { safeEncodeURIComponent } from '../helpers' +import { apiFetch, safeEncodeURIComponent } from '../helpers' import { useNavigate } from 'react-router-dom' export const dayFilter = (days, startDate) => { @@ -51,7 +51,7 @@ export function JobStackedChart(props) { queryParams += `&period=${props.period}` } - fetch(`${process.env.REACT_APP_API_URL}/api/jobs/analysis?${queryParams}`) + apiFetch(`/api/jobs/analysis?${queryParams}`) .then((analysis) => { if (analysis.status !== 200) { throw new Error('server returned ' + analysis.status) diff --git a/sippy-ng/src/jobs/JobTable.js b/sippy-ng/src/jobs/JobTable.js index ebcb137f89..8c7424491f 100644 --- a/sippy-ng/src/jobs/JobTable.js +++ b/sippy-ng/src/jobs/JobTable.js @@ -3,6 +3,7 @@ import { BOOKMARKS, JOB_THRESHOLDS } from '../constants' import { BugReport, DirectionsRun, GridOn } from '@mui/icons-material' import { Button, Container, Tooltip, Typography } from '@mui/material' import { + apiFetch, chooseVariantsToDisplay, escapeRegex, getVariantStyle, @@ -562,9 +563,8 @@ function JobTable(props) { queryString += '&sortField=' + safeEncodeURIComponent(sortField) queryString += '&sort=' + safeEncodeURIComponent(sort) - fetch( - process.env.REACT_APP_API_URL + - '/api/jobs?release=' + + apiFetch( + '/api/jobs?release=' + props.release + queryString ) diff --git a/sippy-ng/src/jobs/JobsDetail.js b/sippy-ng/src/jobs/JobsDetail.js index e8e5850ca0..297fb32300 100644 --- a/sippy-ng/src/jobs/JobsDetail.js +++ b/sippy-ng/src/jobs/JobsDetail.js @@ -1,7 +1,7 @@ import { Backdrop, CircularProgress } from '@mui/material' import { makeStyles } from '@mui/styles' import { PropTypes } from 'prop-types' -import { safeEncodeURIComponent } from '../helpers' +import { apiFetch, safeEncodeURIComponent } from '../helpers' import { StringParam, useQueryParam } from 'use-query-params' import Alert from '@mui/material/Alert' import GridToolbarSearchBox from '../datagrid/GridToolbarSearchBox' @@ -41,9 +41,8 @@ export default function JobsDetail(props) { urlQuery = '&job=' + safeEncodeURIComponent(filter) } - fetch( - process.env.REACT_APP_API_URL + - '/api/jobs/details?release=' + + apiFetch( + '/api/jobs/details?release=' + props.release + urlQuery ) diff --git a/sippy-ng/src/prow_job_runs/IntervalsChart.js b/sippy-ng/src/prow_job_runs/IntervalsChart.js index 89831a9bcd..2959714df6 100644 --- a/sippy-ng/src/prow_job_runs/IntervalsChart.js +++ b/sippy-ng/src/prow_job_runs/IntervalsChart.js @@ -16,7 +16,7 @@ import { TextField, Tooltip, } from '@mui/material' -import { escapeRegex } from '../helpers' +import { apiFetch, escapeRegex } from '../helpers' import { makeStyles } from '@mui/styles' import { stringify } from 'query-string' import { useNavigate } from 'react-router-dom' @@ -288,9 +288,8 @@ export default function IntervalsChart(props) { intervalFile ) - fetch( - process.env.REACT_APP_API_URL + - '/api/jobs/runs/intervals?prow_job_run_id=' + + apiFetch( + '/api/jobs/runs/intervals?prow_job_run_id=' + props.jobRunID + (props.jobName ? '&job_name=' + props.jobName : '') + (props.repoInfo ? '&repo_info=' + props.repoInfo : '') + diff --git a/sippy-ng/src/pull_requests/PullRequestsTable.js b/sippy-ng/src/pull_requests/PullRequestsTable.js index 54b39ff51d..9542c3e0b1 100644 --- a/sippy-ng/src/pull_requests/PullRequestsTable.js +++ b/sippy-ng/src/pull_requests/PullRequestsTable.js @@ -16,6 +16,7 @@ import { } from '@mui/icons-material' import { DataGrid } from '@mui/x-data-grid' import { + apiFetch, getReportStartDate, relativeTime, safeEncodeURIComponent, @@ -341,9 +342,8 @@ export default function PullRequestsTable(props) { queryString += '&sortField=' + safeEncodeURIComponent(sortField) queryString += '&sort=' + safeEncodeURIComponent(sort) - fetch( - process.env.REACT_APP_API_URL + - '/api/pull_requests?release=' + + apiFetch( + '/api/pull_requests?release=' + props.release + queryString ) diff --git a/sippy-ng/src/releases/Install.js b/sippy-ng/src/releases/Install.js index 2d66314b3e..20e2fdcac9 100644 --- a/sippy-ng/src/releases/Install.js +++ b/sippy-ng/src/releases/Install.js @@ -1,4 +1,5 @@ import './Install.css' +import { apiFetch } from '../helpers' import { Grid, Typography } from '@mui/material' import { Navigate, Route, Routes, useLocation } from 'react-router-dom' import Alert from '@mui/material/Alert' @@ -19,12 +20,8 @@ export default function Install(props) { const fetchData = () => { Promise.all([ - fetch( - process.env.REACT_APP_API_URL + '/api/install?release=' + props.release - ), - fetch( - process.env.REACT_APP_API_URL + '/api/health?release=' + props.release - ), + apiFetch('/api/install?release=' + props.release), + apiFetch('/api/health?release=' + props.release), ]) .then(([install, health]) => { if (install.status !== 200) { diff --git a/sippy-ng/src/releases/PayloadCalendar.js b/sippy-ng/src/releases/PayloadCalendar.js index cc3106a59d..fff393f0d0 100644 --- a/sippy-ng/src/releases/PayloadCalendar.js +++ b/sippy-ng/src/releases/PayloadCalendar.js @@ -1,7 +1,7 @@ import FullCalendar from '@fullcalendar/react' import { Alert, Grid } from '@mui/material' -import { filterFor } from '../helpers' +import { apiFetch, filterFor } from '../helpers' import { useNavigate } from 'react-router-dom' import { useTheme } from '@mui/material/styles' import dayGridPlugin from '@fullcalendar/daygrid' @@ -44,10 +44,7 @@ export default function PayloadCalendar(props) { const eventSources = [ { - url: - process.env.REACT_APP_API_URL + - '/api/releases/tags/events?release=' + - props.release, + url: '/api/releases/tags/events?release=' + props.release, method: 'GET', extraParams: { filter: JSON.stringify({ @@ -63,10 +60,7 @@ export default function PayloadCalendar(props) { success: acceptedSourceSuccess, }, { - url: - process.env.REACT_APP_API_URL + - '/api/releases/tags/events?release=' + - props.release, + url: '/api/releases/tags/events?release=' + props.release, method: 'GET', extraParams: { filter: JSON.stringify({ @@ -82,7 +76,7 @@ export default function PayloadCalendar(props) { success: rejectedSourceSuccess, }, { - url: process.env.REACT_APP_API_URL + '/api/incidents', + url: '/api/incidents', method: 'GET', color: theme.palette.common.black, textColor: theme.palette.error.contrastText, diff --git a/sippy-ng/src/releases/PayloadMiniCalendar.js b/sippy-ng/src/releases/PayloadMiniCalendar.js index 0e3e32f96d..96ec3fbd55 100644 --- a/sippy-ng/src/releases/PayloadMiniCalendar.js +++ b/sippy-ng/src/releases/PayloadMiniCalendar.js @@ -1,6 +1,6 @@ import FullCalendar from '@fullcalendar/react' -import { filterFor, safeEncodeURIComponent } from '../helpers' +import { apiFetch, filterFor, safeEncodeURIComponent } from '../helpers' import { Tooltip, Typography } from '@mui/material' import { useNavigate } from 'react-router-dom' import { useTheme } from '@mui/material/styles' @@ -57,9 +57,8 @@ export default function PayloadMiniCalendar(props) { }) ) - fetch( - process.env.REACT_APP_API_URL + - '/api/releases/tags/events?release=' + + apiFetch( + '/api/releases/tags/events?release=' + props.release + '&filter=' + filter diff --git a/sippy-ng/src/releases/PayloadStreamOverview.js b/sippy-ng/src/releases/PayloadStreamOverview.js index 0b49f4b485..321be72831 100644 --- a/sippy-ng/src/releases/PayloadStreamOverview.js +++ b/sippy-ng/src/releases/PayloadStreamOverview.js @@ -1,5 +1,6 @@ import { Card, Container, Tooltip } from '@mui/material' import { + apiFetch, getReportStartDate, relativeDuration, relativeTime, @@ -44,11 +45,7 @@ function PayloadStreamOverview(props) { queryString += '&release=' + safeEncodeURIComponent(props.release) } - fetch( - process.env.REACT_APP_API_URL + - '/api/releases/health?' + - queryString.substring(1) - ) + apiFetch('/api/releases/health?' + queryString.substring(1)) .then((response) => { if (response.status !== 200) { throw new Error('server returned ' + response.status) diff --git a/sippy-ng/src/releases/PayloadStreamTestFailures.js b/sippy-ng/src/releases/PayloadStreamTestFailures.js index ab36d185d5..634bd22d5a 100644 --- a/sippy-ng/src/releases/PayloadStreamTestFailures.js +++ b/sippy-ng/src/releases/PayloadStreamTestFailures.js @@ -4,7 +4,7 @@ import { DataGrid } from '@mui/x-data-grid' import { generateClasses } from '../datagrid/utils' import { Link } from 'react-router-dom' import { NumberParam, StringParam, useQueryParam } from 'use-query-params' -import { safeEncodeURIComponent, SafeJSONParam } from '../helpers' +import { apiFetch, safeEncodeURIComponent, SafeJSONParam } from '../helpers' import { withStyles } from '@mui/styles' import Alert from '@mui/material/Alert' import GridToolbar from '../datagrid/GridToolbar' @@ -165,8 +165,8 @@ function PayloadStreamTestFailures(props) { } Promise.all([ - fetch( - `${process.env.REACT_APP_API_URL}/api/releases/test_failures?release=${release}&arch=${arch}&stream=${stream}` + + apiFetch( + `/api/releases/test_failures?release=${release}&arch=${arch}&stream=${stream}` + queryString ), ]) diff --git a/sippy-ng/src/releases/PayloadStreamsTable.js b/sippy-ng/src/releases/PayloadStreamsTable.js index 216163018e..f7cded72d8 100644 --- a/sippy-ng/src/releases/PayloadStreamsTable.js +++ b/sippy-ng/src/releases/PayloadStreamsTable.js @@ -3,7 +3,7 @@ import { DataGrid } from '@mui/x-data-grid' import { Link } from 'react-router-dom' import { makeStyles, useTheme } from '@mui/styles' import { NumberParam, StringParam, useQueryParam } from 'use-query-params' -import { safeEncodeURIComponent, SafeJSONParam } from '../helpers' +import { apiFetch, safeEncodeURIComponent, SafeJSONParam } from '../helpers' import { Tooltip } from '@mui/material' import Alert from '@mui/material/Alert' import GridToolbar from '../datagrid/GridToolbar' @@ -182,11 +182,7 @@ function PayloadStreamsTable(props) { queryString += '&sortField=' + safeEncodeURIComponent(sortField) queryString += '&sort=' + safeEncodeURIComponent(sort) - fetch( - process.env.REACT_APP_API_URL + - '/api/releases/health?' + - queryString.substring(1) - ) + apiFetch('/api/releases/health?' + queryString.substring(1)) .then((response) => { if (response.status !== 200) { throw new Error('server returned ' + response.status) diff --git a/sippy-ng/src/releases/PayloadTestFailures.js b/sippy-ng/src/releases/PayloadTestFailures.js index 4a2d32f88b..54c4df648c 100644 --- a/sippy-ng/src/releases/PayloadTestFailures.js +++ b/sippy-ng/src/releases/PayloadTestFailures.js @@ -3,7 +3,7 @@ import { Box, Card, Grid, Tooltip, Typography } from '@mui/material' import { DataGrid } from '@mui/x-data-grid' import { generateClasses } from '../datagrid/utils' import { NumberParam, StringParam, useQueryParam } from 'use-query-params' -import { safeEncodeURIComponent, SafeJSONParam } from '../helpers' +import { apiFetch, safeEncodeURIComponent, SafeJSONParam } from '../helpers' import { withStyles } from '@mui/styles' import Alert from '@mui/material/Alert' import GridToolbar from '../datagrid/GridToolbar' @@ -144,10 +144,7 @@ function PayloadTestFailures(props) { } Promise.all([ - fetch( - `${process.env.REACT_APP_API_URL}/api/payloads/test_failures?payload=${payload}` + - queryString - ), + apiFetch(`/api/payloads/test_failures?payload=${payload}` + queryString), ]) .then(([analysis]) => { if (analysis.status !== 200) { diff --git a/sippy-ng/src/releases/ReleaseOverview.js b/sippy-ng/src/releases/ReleaseOverview.js index c6de2a6819..40631051f6 100644 --- a/sippy-ng/src/releases/ReleaseOverview.js +++ b/sippy-ng/src/releases/ReleaseOverview.js @@ -6,6 +6,7 @@ import { Tooltip, Typography, } from '@mui/material' +import { apiFetch } from '../helpers' import { Link } from 'react-router-dom' import { makeStyles } from '@mui/styles' import { ReleasesContext } from '../App' @@ -85,9 +86,7 @@ export default function ReleaseOverview(props) { const releases = React.useContext(ReleasesContext) const fetchData = () => { - fetch( - process.env.REACT_APP_API_URL + '/api/health?release=' + props.release - ) + apiFetch('/api/health?release=' + props.release) .then((response) => { if (response.status !== 200) { throw new Error('server returned ' + response.status) diff --git a/sippy-ng/src/releases/ReleasePayloadAcceptance.js b/sippy-ng/src/releases/ReleasePayloadAcceptance.js index a07e24ef08..6fe9dfbfdd 100644 --- a/sippy-ng/src/releases/ReleasePayloadAcceptance.js +++ b/sippy-ng/src/releases/ReleasePayloadAcceptance.js @@ -6,6 +6,7 @@ import { Warning, } from '@mui/icons-material' import { + apiFetch, getReportStartDate, relativeTime, safeEncodeURIComponent, @@ -42,10 +43,8 @@ function ReleasePayloadAcceptance(props) { const startDate = getReportStartDate(React.useContext(ReportEndContext)) const fetchData = () => { - fetch( - process.env.REACT_APP_API_URL + - '/api/releases/health?release=' + - safeEncodeURIComponent(props.release) + apiFetch( + '/api/releases/health?release=' + safeEncodeURIComponent(props.release) ) .then((response) => { if (response.status !== 200) { diff --git a/sippy-ng/src/releases/ReleasePayloadDetails.js b/sippy-ng/src/releases/ReleasePayloadDetails.js index a408a5cd85..7d3bb16e67 100644 --- a/sippy-ng/src/releases/ReleasePayloadDetails.js +++ b/sippy-ng/src/releases/ReleasePayloadDetails.js @@ -8,7 +8,7 @@ import { Tooltip, Typography, } from '@mui/material' -import { filterFor, safeEncodeURIComponent } from '../helpers' +import { apiFetch, filterFor, safeEncodeURIComponent } from '../helpers' import { Fragment } from 'react' import { Link, Route, Routes, useLocation } from 'react-router-dom' import { makeStyles } from '@mui/styles' @@ -54,11 +54,7 @@ export default function ReleasePayloadDetails(props) { }) ) - Promise.all([ - fetch( - `${process.env.REACT_APP_API_URL}/api/releases/tags?filter=${filter}` - ), - ]) + Promise.all([apiFetch(`/api/releases/tags?filter=${filter}`)]) .then(([tag]) => { if (tag.status !== 200) { throw new Error('server returned ' + tag.status) diff --git a/sippy-ng/src/releases/ReleasePayloadJobRuns.js b/sippy-ng/src/releases/ReleasePayloadJobRuns.js index 5f1320f47d..e72854f074 100644 --- a/sippy-ng/src/releases/ReleasePayloadJobRuns.js +++ b/sippy-ng/src/releases/ReleasePayloadJobRuns.js @@ -3,7 +3,7 @@ import { Check, DirectionsBoat } from '@mui/icons-material' import { DataGrid } from '@mui/x-data-grid' import { makeStyles, useTheme } from '@mui/styles' import { NumberParam, StringParam, useQueryParam } from 'use-query-params' -import { safeEncodeURIComponent, SafeJSONParam } from '../helpers' +import { apiFetch, safeEncodeURIComponent, SafeJSONParam } from '../helpers' import Alert from '@mui/material/Alert' import GridToolbar from '../datagrid/GridToolbar' import PropTypes from 'prop-types' @@ -159,11 +159,7 @@ function ReleasePayloadJobRuns(props) { queryString += '&sortField=' + safeEncodeURIComponent(sortField) queryString += '&sort=' + safeEncodeURIComponent(sort) - fetch( - process.env.REACT_APP_API_URL + - '/api/releases/job_runs?' + - queryString.substring(1) - ) + apiFetch('/api/releases/job_runs?' + queryString.substring(1)) .then((response) => { if (response.status !== 200) { throw new Error('server returned ' + response.status) diff --git a/sippy-ng/src/releases/ReleasePayloadPullRequests.js b/sippy-ng/src/releases/ReleasePayloadPullRequests.js index 09e677a671..007a7ed527 100644 --- a/sippy-ng/src/releases/ReleasePayloadPullRequests.js +++ b/sippy-ng/src/releases/ReleasePayloadPullRequests.js @@ -1,7 +1,7 @@ import { DataGrid } from '@mui/x-data-grid' import { makeStyles, useTheme } from '@mui/styles' import { NumberParam, StringParam, useQueryParam } from 'use-query-params' -import { safeEncodeURIComponent, SafeJSONParam } from '../helpers' +import { apiFetch, safeEncodeURIComponent, SafeJSONParam } from '../helpers' import Alert from '@mui/material/Alert' import GridToolbar from '../datagrid/GridToolbar' import PropTypes from 'prop-types' @@ -136,11 +136,7 @@ function ReleasePayloadPullRequests(props) { queryString += '&sortField=' + safeEncodeURIComponent(sortField) queryString += '&sort=' + safeEncodeURIComponent(sort) - fetch( - process.env.REACT_APP_API_URL + - '/api/releases/pull_requests?' + - queryString.substring(1) - ) + apiFetch('/api/releases/pull_requests?' + queryString.substring(1)) .then((response) => { if (response.status !== 200) { throw new Error('server returned ' + response.status) diff --git a/sippy-ng/src/releases/ReleasePayloadTable.js b/sippy-ng/src/releases/ReleasePayloadTable.js index 6f3b0d5d10..ca5fead2a2 100644 --- a/sippy-ng/src/releases/ReleasePayloadTable.js +++ b/sippy-ng/src/releases/ReleasePayloadTable.js @@ -9,6 +9,7 @@ import { } from '@mui/icons-material' import { DataGrid } from '@mui/x-data-grid' import { + apiFetch, getReportStartDate, relativeTime, safeEncodeURIComponent, @@ -379,11 +380,7 @@ function ReleasePayloadTable(props) { queryString += '&sortField=' + safeEncodeURIComponent(sortField) queryString += '&sort=' + safeEncodeURIComponent(sort) - fetch( - process.env.REACT_APP_API_URL + - '/api/releases/tags?' + - queryString.substring(1) - ) + apiFetch('/api/releases/tags?' + queryString.substring(1)) .then((response) => { if (response.status !== 200) { throw new Error('server returned ' + response.status) diff --git a/sippy-ng/src/releases/Upgrades.js b/sippy-ng/src/releases/Upgrades.js index ec8f8fcbbe..1e4a8e1954 100644 --- a/sippy-ng/src/releases/Upgrades.js +++ b/sippy-ng/src/releases/Upgrades.js @@ -1,4 +1,5 @@ import './Upgrades.css' +import { apiFetch } from '../helpers' import { Grid, Typography } from '@mui/material' import { Navigate, Route, Routes, useLocation } from 'react-router-dom' import Alert from '@mui/material/Alert' @@ -19,9 +20,7 @@ export default function Upgrades(props) { const [data, setData] = React.useState({}) const fetchData = () => { - fetch( - process.env.REACT_APP_API_URL + '/api/upgrade?release=' + props.release - ) + apiFetch('/api/upgrade?release=' + props.release) .then((response) => { if (response.status !== 200) { throw new Error('server returned ' + response.status) diff --git a/sippy-ng/src/repositories/RepositoriesTable.js b/sippy-ng/src/repositories/RepositoriesTable.js index bc6fafbb3f..1653d91f96 100644 --- a/sippy-ng/src/repositories/RepositoriesTable.js +++ b/sippy-ng/src/repositories/RepositoriesTable.js @@ -13,6 +13,7 @@ import { Launch } from '@mui/icons-material' import { makeStyles } from '@mui/styles' import { MERGE_FAILURE_THERSHOLDS } from '../constants' import { + apiFetch, pathForRepository, safeEncodeURIComponent, SafeJSONParam, @@ -202,9 +203,8 @@ function RepositoriesTable(props) { queryString += '&sortField=' + safeEncodeURIComponent(sortField) queryString += '&sort=' + safeEncodeURIComponent(sort) - fetch( - process.env.REACT_APP_API_URL + - '/api/repositories?release=' + + apiFetch( + '/api/repositories?release=' + props.release + queryString ) diff --git a/sippy-ng/src/tests/FeatureGates.js b/sippy-ng/src/tests/FeatureGates.js index 2d3c38c929..f2eb71e9d8 100644 --- a/sippy-ng/src/tests/FeatureGates.js +++ b/sippy-ng/src/tests/FeatureGates.js @@ -3,6 +3,7 @@ import { DataGrid } from '@mui/x-data-grid' import { Link, useNavigate } from 'react-router-dom' import { NumberParam, StringParam, useQueryParam } from 'use-query-params' import { + apiFetch, pathForTestSubstringByVariant, safeEncodeURIComponent, SafeJSONParam, @@ -283,9 +284,8 @@ export default function FeatureGates(props) { queryString += '&sortField=' + safeEncodeURIComponent(sortField) queryString += '&sort=' + safeEncodeURIComponent(sort) - fetch( - process.env.REACT_APP_API_URL + - '/api/feature_gates?release=' + + apiFetch( + '/api/feature_gates?release=' + props.release + queryString ) diff --git a/sippy-ng/src/tests/TestAnalysis.js b/sippy-ng/src/tests/TestAnalysis.js index 4c7f12495a..0d9886ed25 100644 --- a/sippy-ng/src/tests/TestAnalysis.js +++ b/sippy-ng/src/tests/TestAnalysis.js @@ -12,6 +12,7 @@ import { } from '@mui/material' import { DirectionsRun } from '@mui/icons-material' import { + apiFetch, filterFor, not, pathForJobRunsWithTestFailure, @@ -80,9 +81,7 @@ export function TestAnalysis(props) { const filter = safeEncodeURIComponent(JSON.stringify(filterModel)) Promise.all([ - fetch( - `${process.env.REACT_APP_API_URL}/api/tests?release=${props.release}&filter=${filter}` - ), + apiFetch(`/api/tests?release=${props.release}&filter=${filter}`), ]) .then(([test]) => { if (test.status !== 200) { diff --git a/sippy-ng/src/tests/TestDurationChart.js b/sippy-ng/src/tests/TestDurationChart.js index 473a15c9ce..875021b66a 100644 --- a/sippy-ng/src/tests/TestDurationChart.js +++ b/sippy-ng/src/tests/TestDurationChart.js @@ -1,6 +1,6 @@ import { CircularProgress } from '@mui/material' import { Line } from 'react-chartjs-2' -import { safeEncodeURIComponent } from '../helpers' +import { apiFetch, safeEncodeURIComponent } from '../helpers' import Alert from '@mui/material/Alert' import PropTypes from 'prop-types' import React, { useEffect } from 'react' @@ -21,9 +21,8 @@ export function TestDurationChart(props) { '&filter=' + safeEncodeURIComponent(JSON.stringify(props.filterModel)) } - fetch( - process.env.REACT_APP_API_URL + - `/api/tests/durations?release=${ + apiFetch( + `/api/tests/durations?release=${ props.release }&test=${safeEncodeURIComponent(props.test)}` + queryString diff --git a/sippy-ng/src/tests/TestOutputs.js b/sippy-ng/src/tests/TestOutputs.js index e493a24f16..96fe3070db 100644 --- a/sippy-ng/src/tests/TestOutputs.js +++ b/sippy-ng/src/tests/TestOutputs.js @@ -10,7 +10,7 @@ import { } from '@mui/material' import { DirectionsBoat } from '@mui/icons-material' import { makeStyles } from '@mui/styles' -import { safeEncodeURIComponent } from '../helpers' +import { apiFetch, safeEncodeURIComponent } from '../helpers' import Alert from '@mui/material/Alert' import PropTypes from 'prop-types' import React, { Fragment, useEffect } from 'react' @@ -42,9 +42,8 @@ export function TestOutputs(props) { '&filter=' + safeEncodeURIComponent(JSON.stringify(props.filterModel)) } - fetch( - process.env.REACT_APP_API_URL + - `/api/tests/outputs?release=${ + apiFetch( + `/api/tests/outputs?release=${ props.release }&test=${safeEncodeURIComponent(props.test)}` + queryString diff --git a/sippy-ng/src/tests/TestPassRateCharts.js b/sippy-ng/src/tests/TestPassRateCharts.js index fe5b484ae5..fa63f9cd2f 100644 --- a/sippy-ng/src/tests/TestPassRateCharts.js +++ b/sippy-ng/src/tests/TestPassRateCharts.js @@ -1,6 +1,6 @@ import { Card, CircularProgress, Grid, Typography } from '@mui/material' import { Line } from 'react-chartjs-2' -import { safeEncodeURIComponent } from '../helpers' +import { apiFetch, safeEncodeURIComponent } from '../helpers' import { scale } from 'chroma-js' import Alert from '@mui/material/Alert' import PropTypes from 'prop-types' @@ -14,8 +14,8 @@ export default function TestPassRateCharts(props) { const filter = safeEncodeURIComponent(JSON.stringify(props.filterModel)) Promise.all([ - fetch( - `${process.env.REACT_APP_API_URL}/api/tests/analysis/${props.grouping}?release=${props.release}&test=${props.test}&filter=${filter}` + apiFetch( + `/api/tests/analysis/${props.grouping}?release=${props.release}&test=${props.test}&filter=${filter}` ), ]) .then(([apiResponse]) => { diff --git a/sippy-ng/src/tests/TestStackedChart.js b/sippy-ng/src/tests/TestStackedChart.js index 2fd6d1a04b..c0cba5fe38 100644 --- a/sippy-ng/src/tests/TestStackedChart.js +++ b/sippy-ng/src/tests/TestStackedChart.js @@ -1,6 +1,6 @@ import { Card, CircularProgress, Grid, Typography } from '@mui/material' import { Line } from 'react-chartjs-2' -import { safeEncodeURIComponent } from '../helpers' +import { apiFetch, safeEncodeURIComponent } from '../helpers' import { useTheme } from '@mui/material/styles' import Alert from '@mui/material/Alert' import PropTypes from 'prop-types' @@ -24,9 +24,7 @@ export function TestStackedChart(props) { )}` } - fetch( - `${process.env.REACT_APP_API_URL}/api/tests/analysis/overall?${queryParams}` - ) + apiFetch(`/api/tests/analysis/overall?${queryParams}`) .then((analysis) => { if (analysis.status !== 200) { throw new Error('server returned ' + analysis.status) diff --git a/sippy-ng/src/tests/TestTable.js b/sippy-ng/src/tests/TestTable.js index 90891258cf..41d6ec4bb1 100644 --- a/sippy-ng/src/tests/TestTable.js +++ b/sippy-ng/src/tests/TestTable.js @@ -10,6 +10,7 @@ import { } from '@mui/material' import { BOOKMARKS, TEST_THRESHOLDS } from '../constants' import { + apiFetch, chooseVariantsToDisplay, escapeRegex, filterFor, @@ -846,7 +847,7 @@ function TestTable(props) { testAPI = '/api/tests/v2?release=' } - fetch(process.env.REACT_APP_API_URL + testAPI + props.release + queryString) + apiFetch(testAPI + props.release + queryString) .then((response) => { if (response.status !== 200) { throw new Error('server returned ' + response.status) diff --git a/sippy-ng/src/tests/TestsDetail.js b/sippy-ng/src/tests/TestsDetail.js index 9927b0336b..4999ebae43 100644 --- a/sippy-ng/src/tests/TestsDetail.js +++ b/sippy-ng/src/tests/TestsDetail.js @@ -1,7 +1,7 @@ import { ArrayParam, useQueryParam } from 'use-query-params' import { Backdrop, CircularProgress } from '@mui/material' import { makeStyles } from '@mui/styles' -import { safeEncodeURIComponent } from '../helpers' +import { apiFetch, safeEncodeURIComponent } from '../helpers' import Alert from '@mui/material/Alert' import GridToolbarSearchBox from '../datagrid/GridToolbarSearchBox' import PropTypes from 'prop-types' @@ -32,9 +32,8 @@ export default function TestsDetails(props) { } const fetchData = () => { - fetch( - process.env.REACT_APP_API_URL + - '/api/tests/details?release=' + + apiFetch( + '/api/tests/details?release=' + props.release + nameParams() ) From 3225c482170b73f4416c2469847a32448e7a870a Mon Sep 17 00:00:00 2001 From: Stephen Benjamin Date: Wed, 22 Oct 2025 07:56:04 -0400 Subject: [PATCH 3/3] Component Readiness to use apiFetch --- sippy-ng/src/bugs/BugTable.js | 5 ++--- sippy-ng/src/bugs/FileBug.js | 9 +++------ sippy-ng/src/component_readiness/AddRegressionPanel.js | 4 ++-- .../component_readiness/CompReadyEnvCapabilities.js | 4 ++-- .../src/component_readiness/CompReadyEnvCapability.js | 4 ++-- .../component_readiness/CompReadyEnvCapabilityTest.js | 4 ++-- sippy-ng/src/component_readiness/CompReadyVars.js | 9 ++++----- sippy-ng/src/component_readiness/ComponentReadiness.js | 4 ++-- .../component_readiness/ComponentReadinessToolBar.js | 4 ++-- sippy-ng/src/component_readiness/JobArtifactQuery.js | 4 ++-- .../RegressionPotentialMatchesTab.js | 10 ++++------ sippy-ng/src/component_readiness/TestDetailsReport.js | 4 ++-- sippy-ng/src/component_readiness/Triage.js | 9 +++++---- .../src/component_readiness/TriageAuditLogsModal.js | 4 ++-- sippy-ng/src/component_readiness/TriageFields.js | 9 ++++++--- sippy-ng/src/component_readiness/TriageList.js | 4 ++-- .../src/component_readiness/TriagePotentialMatches.js | 6 +++--- sippy-ng/src/component_readiness/UpdateTriagePanel.js | 6 +++--- sippy-ng/src/component_readiness/UpsertTriageModal.js | 4 ++-- 19 files changed, 52 insertions(+), 55 deletions(-) diff --git a/sippy-ng/src/bugs/BugTable.js b/sippy-ng/src/bugs/BugTable.js index cd216bda36..4b018fe54d 100644 --- a/sippy-ng/src/bugs/BugTable.js +++ b/sippy-ng/src/bugs/BugTable.js @@ -11,7 +11,6 @@ import { Tooltip, Typography, } from '@mui/material' -import { getTriagesAPIUrl } from '../component_readiness/CompReadyUtils' import { apiFetch, relativeTime, safeEncodeURIComponent } from '../helpers' import Alert from '@mui/material/Alert' import PropTypes from 'prop-types' @@ -45,7 +44,7 @@ export default function BugTable(props) { props.regressionId && bugs.length > 0 ) { - return fetch(getTriagesAPIUrl()) + return apiFetch('/api/component_readiness/triages') .then((res) => { if (res.status !== 200) { throw new Error( @@ -94,7 +93,7 @@ export default function BugTable(props) { const addToTriage = (triage) => { triage.regressions.push({ id: props.regressionId }) - fetch(getTriagesAPIUrl(triage.id), { + apiFetch(`/api/component_readiness/triages/${triage.id}`, { method: 'PUT', body: JSON.stringify(triage), }).then((res) => { diff --git a/sippy-ng/src/bugs/FileBug.js b/sippy-ng/src/bugs/FileBug.js index 15db5752cf..b8a9b20690 100644 --- a/sippy-ng/src/bugs/FileBug.js +++ b/sippy-ng/src/bugs/FileBug.js @@ -21,10 +21,7 @@ import { } from '@mui/material' import { AutoAwesome as AutoAwesomeIcon, Close } from '@mui/icons-material' import { CapabilitiesContext } from '../App' -import { - getBugsAPIUrl, - getTriagesAPIUrl, -} from '../component_readiness/CompReadyUtils' +import { apiFetch } from '../helpers' import { makeStyles } from '@mui/styles' import BugButton from './BugButton' import OneShotChatModal from '../chat/OneShotChatModal' @@ -197,7 +194,7 @@ See the [sippy test details|${document.location.href}] for additional context. affects_versions: formData.affectsVersions, } - fetch(getBugsAPIUrl(), { + apiFetch('/api/component_readiness/bugs', { method: 'POST', body: JSON.stringify(bugData), }) @@ -215,7 +212,7 @@ See the [sippy test details|${document.location.href}] for additional context. type: formData.triageType, } - return fetch(getTriagesAPIUrl(), { + return apiFetch('/api/component_readiness/triages', { method: 'POST', body: JSON.stringify(triageData), }).then((triageResponse) => { diff --git a/sippy-ng/src/component_readiness/AddRegressionPanel.js b/sippy-ng/src/component_readiness/AddRegressionPanel.js index 3bf9e9d87b..60e08410c2 100644 --- a/sippy-ng/src/component_readiness/AddRegressionPanel.js +++ b/sippy-ng/src/component_readiness/AddRegressionPanel.js @@ -1,4 +1,4 @@ -import { getTriagesAPIUrl } from './CompReadyUtils' +import { apiFetch } from '../helpers' import { makeStyles } from '@mui/styles' import { Tab, Tabs } from '@mui/material' import DialogContent from '@mui/material/DialogContent' @@ -76,7 +76,7 @@ export default function AddRegressionPanel({ ], } - fetch(getTriagesAPIUrl(existingTriageId), { + apiFetch(`/api/component_readiness/triages/${existingTriageId}`, { method: 'PUT', body: JSON.stringify(updatedTriage), }).then((response) => { diff --git a/sippy-ng/src/component_readiness/CompReadyEnvCapabilities.js b/sippy-ng/src/component_readiness/CompReadyEnvCapabilities.js index 77fd1bf39e..beeb2d00fc 100644 --- a/sippy-ng/src/component_readiness/CompReadyEnvCapabilities.js +++ b/sippy-ng/src/component_readiness/CompReadyEnvCapabilities.js @@ -12,7 +12,7 @@ import { } from './CompReadyUtils' import { ComponentReadinessStyleContext } from './ComponentReadiness' import { CompReadyVarsContext } from './CompReadyVars' -import { escapeRegex, safeEncodeURIComponent } from '../helpers' +import { apiFetch, escapeRegex, safeEncodeURIComponent } from '../helpers' import { Link } from 'react-router-dom' import { TableContainer, Tooltip, Typography } from '@mui/material' import CompCapRow from './CompCapRow' @@ -81,7 +81,7 @@ export default function CompReadyEnvCapabilities(props) { apiCallStr += '&forceRefresh=true' } - fetch(apiCallStr, { signal: abortController.signal }) + apiFetch(apiCallStr, { signal: abortController.signal }) .then((response) => response.json()) .then((data) => { if (data.code < 200 || data.code >= 300) { diff --git a/sippy-ng/src/component_readiness/CompReadyEnvCapability.js b/sippy-ng/src/component_readiness/CompReadyEnvCapability.js index 1d9ed11c93..8defa2ff0a 100644 --- a/sippy-ng/src/component_readiness/CompReadyEnvCapability.js +++ b/sippy-ng/src/component_readiness/CompReadyEnvCapability.js @@ -12,7 +12,7 @@ import { } from './CompReadyUtils' import { ComponentReadinessStyleContext } from './ComponentReadiness' import { CompReadyVarsContext } from './CompReadyVars' -import { escapeRegex, safeEncodeURIComponent } from '../helpers' +import { apiFetch, escapeRegex, safeEncodeURIComponent } from '../helpers' import { Link } from 'react-router-dom' import { TableContainer, Tooltip, Typography } from '@mui/material' import ComponentReadinessToolBar from './ComponentReadinessToolBar' @@ -80,7 +80,7 @@ export default function CompReadyEnvCapability(props) { apiCallStr += '&forceRefresh=true' } - fetch(apiCallStr, { signal: abortController.signal }) + apiFetch(apiCallStr, { signal: abortController.signal }) .then((response) => response.json()) .then((data) => { if (data.code < 200 || data.code >= 300) { diff --git a/sippy-ng/src/component_readiness/CompReadyEnvCapabilityTest.js b/sippy-ng/src/component_readiness/CompReadyEnvCapabilityTest.js index fe02a40d06..7db09436da 100644 --- a/sippy-ng/src/component_readiness/CompReadyEnvCapabilityTest.js +++ b/sippy-ng/src/component_readiness/CompReadyEnvCapabilityTest.js @@ -12,7 +12,7 @@ import { import { ComponentReadinessStyleContext } from './ComponentReadiness' import { CompReadyVarsContext } from './CompReadyVars' import { Link } from 'react-router-dom' -import { safeEncodeURIComponent } from '../helpers' +import { apiFetch, safeEncodeURIComponent } from '../helpers' import { TableContainer, Tooltip, Typography } from '@mui/material' import CompCapTestRow from './CompCapTestRow' import ComponentReadinessToolBar from './ComponentReadinessToolBar' @@ -133,7 +133,7 @@ export default function CompReadyEnvCapabilityTest(props) { apiCallStr += '&forceRefresh=true' } - fetch(apiCallStr, { signal: abortController.signal }) + apiFetch(apiCallStr, { signal: abortController.signal }) .then((response) => response.json()) .then((data) => { if (data.code < 200 || data.code >= 300) { diff --git a/sippy-ng/src/component_readiness/CompReadyVars.js b/sippy-ng/src/component_readiness/CompReadyVars.js index a6f1470447..0c9d5c0e39 100644 --- a/sippy-ng/src/component_readiness/CompReadyVars.js +++ b/sippy-ng/src/component_readiness/CompReadyVars.js @@ -10,10 +10,9 @@ import { dateEndFormat, dateFormat, formatLongDate, - getComponentReadinessViewsAPIUrl, - getJobVariantsAPIUrl, gotFetchError, } from './CompReadyUtils' +import { apiFetch } from '../helpers' import { ReleasesContext } from '../App' import { safeEncodeURIComponent, SafeStringParam } from '../helpers' import CompReadyProgress from './CompReadyProgress' @@ -432,9 +431,9 @@ export const CompReadyVarsProvider = ({ children }) => { } useEffect(() => { - const jobVariantsAPIURL = getJobVariantsAPIUrl() - const viewsAPIURL = getComponentReadinessViewsAPIUrl() - Promise.all([fetch(jobVariantsAPIURL), fetch(viewsAPIURL)]) + const jobVariantsAPIURL = '/api/job_variants' + const viewsAPIURL = '/api/component_readiness/views' + Promise.all([apiFetch(jobVariantsAPIURL), apiFetch(viewsAPIURL)]) .then(([variantsResp, viewsResp]) => { if (variantsResp.code < 200 || variantsResp.code >= 300) { const errorMessage = variantsResp.message diff --git a/sippy-ng/src/component_readiness/ComponentReadiness.js b/sippy-ng/src/component_readiness/ComponentReadiness.js index 433ec199e9..652b5e5491 100644 --- a/sippy-ng/src/component_readiness/ComponentReadiness.js +++ b/sippy-ng/src/component_readiness/ComponentReadiness.js @@ -14,7 +14,7 @@ import { noDataTable, } from './CompReadyUtils' import { CompReadyVarsContext } from './CompReadyVars' -import { escapeRegex } from '../helpers' +import { apiFetch, escapeRegex } from '../helpers' import { grey } from '@mui/material/colors' import { Grid, TableContainer, Tooltip, Typography } from '@mui/material' import { makeStyles, useTheme } from '@mui/styles' @@ -344,7 +344,7 @@ export default function ComponentReadiness(props) { if (fresh) { formattedApiCallStr += '&forceRefresh=true' } - fetch(formattedApiCallStr, { signal: abortController.signal }) + apiFetch(formattedApiCallStr, { signal: abortController.signal }) .then((response) => { if (response.status !== 200) { throw new Error('API server returned ' + response.status) diff --git a/sippy-ng/src/component_readiness/ComponentReadinessToolBar.js b/sippy-ng/src/component_readiness/ComponentReadinessToolBar.js index 2cb1e5166c..cf54948b82 100644 --- a/sippy-ng/src/component_readiness/ComponentReadinessToolBar.js +++ b/sippy-ng/src/component_readiness/ComponentReadinessToolBar.js @@ -30,12 +30,12 @@ import { CompReadyVarsContext } from './CompReadyVars' import { formColumnName, generateTestDetailsReportLink, - getTriagesAPIUrl, mergeRegressionData, Search, SearchIconWrapper, StyledInputBase, } from './CompReadyUtils' +import { apiFetch } from '../helpers' import { Link } from 'react-router-dom' import { usePageContextForChat } from '../chat/store/useChatStore' import IconButton from '@mui/material/IconButton' @@ -74,7 +74,7 @@ export default function ComponentReadinessToolBar(props) { // triage entries will only be available when there is a postgres connection let triageFetch if (localDBEnabled) { - triageFetch = fetch(getTriagesAPIUrl(), { + triageFetch = apiFetch('/api/component_readiness/triages', { method: 'GET', }).then((response) => { if (response.status !== 200) { diff --git a/sippy-ng/src/component_readiness/JobArtifactQuery.js b/sippy-ng/src/component_readiness/JobArtifactQuery.js index ceec6ed489..0a6cf9f6e9 100644 --- a/sippy-ng/src/component_readiness/JobArtifactQuery.js +++ b/sippy-ng/src/component_readiness/JobArtifactQuery.js @@ -29,7 +29,7 @@ import { OpenInNew, } from '@mui/icons-material' import { getArtifactQueryAPIUrl } from './CompReadyUtils' -import { relativeTime, safeEncodeURIComponent } from '../helpers' +import { apiFetch, relativeTime, safeEncodeURIComponent } from '../helpers' import LaunderedLink from '../components/Laundry' import PropTypes from 'prop-types' import React, { Fragment } from 'react' @@ -175,7 +175,7 @@ export default function JobArtifactQuery(props) { } setLoading(true) - fetch(url, { signal: abortController.signal }) + apiFetch(url, { signal: abortController.signal }) .then((response) => { setLoading(false) if (response.status < 200 || response.status >= 300) { diff --git a/sippy-ng/src/component_readiness/RegressionPotentialMatchesTab.js b/sippy-ng/src/component_readiness/RegressionPotentialMatchesTab.js index c5f2ac8e1b..4410ceac29 100644 --- a/sippy-ng/src/component_readiness/RegressionPotentialMatchesTab.js +++ b/sippy-ng/src/component_readiness/RegressionPotentialMatchesTab.js @@ -5,10 +5,8 @@ import { Info as InfoIcon, } from '@mui/icons-material' import { DataGrid } from '@mui/x-data-grid' -import { formatDateToSeconds, relativeTime } from '../helpers' +import { apiFetch, formatDateToSeconds, relativeTime } from '../helpers' import { - getRegressionAPIUrl, - getTriagesAPIUrl, jiraUrlPrefix, } from './CompReadyUtils' import { makeStyles } from '@mui/styles' @@ -60,8 +58,8 @@ export default function RegressionPotentialMatchesTab({ setLoadingMatches(true) setMatchesError('') - const matchesApiCall = getRegressionAPIUrl(regressionId) + '/matches' - fetch(matchesApiCall) + const matchesApiCall = `/api/component_readiness/regressions/${regressionId}/matches` + apiFetch(matchesApiCall) .then((response) => response.json()) .then((data) => { if (data && data.code && (data.code < 200 || data.code >= 300)) { @@ -123,7 +121,7 @@ export default function RegressionPotentialMatchesTab({ regressions: [...triage.regressions, { id: Number(regressionId) }], } - fetch(getTriagesAPIUrl(triage.id), { + apiFetch(`/api/component_readiness/triages/${triage.id}`, { method: 'PUT', body: JSON.stringify(updatedTriage), }) diff --git a/sippy-ng/src/component_readiness/TestDetailsReport.js b/sippy-ng/src/component_readiness/TestDetailsReport.js index f4e2eccd4b..07b55b2616 100644 --- a/sippy-ng/src/component_readiness/TestDetailsReport.js +++ b/sippy-ng/src/component_readiness/TestDetailsReport.js @@ -23,7 +23,7 @@ import { CapabilitiesContext, ReleasesContext } from '../App' import { CompReadyVarsContext } from './CompReadyVars' import { FileCopy, Help } from '@mui/icons-material' import { Link } from 'react-router-dom' -import { pathForExactTestAnalysisWithFilter } from '../helpers' +import { apiFetch, pathForExactTestAnalysisWithFilter } from '../helpers' import { Tooltip } from '@mui/material' import { usePageContextForChat } from '../chat/store/useChatStore' import AskSippyButton from '../chat/AskSippyButton' @@ -173,7 +173,7 @@ export default function TestDetailsReport(props) { if (!testId) return // wait until the vars are initialized from params // fetch the test_details data followed by any triage records that match the regressionId (if found) - fetch(testDetailsApiCall, { signal: abortController.signal }) + apiFetch(testDetailsApiCall, { signal: abortController.signal }) .then((response) => response.json()) .then((data) => { if (data.code < 200 || data.code >= 300) { diff --git a/sippy-ng/src/component_readiness/Triage.js b/sippy-ng/src/component_readiness/Triage.js index 919d93e760..bd52c879e0 100644 --- a/sippy-ng/src/component_readiness/Triage.js +++ b/sippy-ng/src/component_readiness/Triage.js @@ -2,9 +2,8 @@ import { Box, Button, Tooltip } from '@mui/material' import { CapabilitiesContext } from '../App' import { CheckCircle, Error as ErrorIcon } from '@mui/icons-material' import { CompReadyVarsContext } from './CompReadyVars' -import { formatDateToSeconds, relativeTime } from '../helpers' +import { apiFetch, formatDateToSeconds, relativeTime } from '../helpers' import { - getTriagesAPIUrl, hasFailedFixRegression, jiraUrlPrefix, } from './CompReadyUtils' @@ -49,7 +48,9 @@ export default function Triage({ id }) { let triageFetch // triage entries will only be available when there is a postgres connection if (localDBEnabled) { - triageFetch = fetch(`${getTriagesAPIUrl(id)}?expand=regressions`).then( + triageFetch = apiFetch( + `/api/component_readiness/triages/${id}?expand=regressions` + ).then( (response) => { if (response.status !== 200) { throw new Error('API server returned ' + response.status) @@ -180,7 +181,7 @@ export default function Triage({ id }) { 'Are you sure you want to delete this triage record?' ) if (confirmed) { - fetch(triage.links.self, { + apiFetch(triage.links.self, { method: 'DELETE', }) .then((response) => { diff --git a/sippy-ng/src/component_readiness/TriageAuditLogsModal.js b/sippy-ng/src/component_readiness/TriageAuditLogsModal.js index 134f89fdc6..4b419b5b71 100644 --- a/sippy-ng/src/component_readiness/TriageAuditLogsModal.js +++ b/sippy-ng/src/component_readiness/TriageAuditLogsModal.js @@ -16,7 +16,7 @@ import { Tooltip, Typography, } from '@mui/material' -import { formatDateToSeconds, relativeTime } from '../helpers' +import { apiFetch, formatDateToSeconds, relativeTime } from '../helpers' import { History } from '@mui/icons-material' import { makeStyles } from '@mui/styles' import PropTypes from 'prop-types' @@ -66,7 +66,7 @@ export default function TriageAuditLogsModal({ triage }) { setError('') try { - const response = await fetch(triage.links.audit_logs) + const response = await apiFetch(triage.links.audit_logs) if (response.status !== 200) { throw new Error(`API server returned ${response.status}`) } diff --git a/sippy-ng/src/component_readiness/TriageFields.js b/sippy-ng/src/component_readiness/TriageFields.js index 6738a1decd..b67749a703 100644 --- a/sippy-ng/src/component_readiness/TriageFields.js +++ b/sippy-ng/src/component_readiness/TriageFields.js @@ -13,7 +13,8 @@ import { TextField, Tooltip, } from '@mui/material' -import { getTriagesAPIUrl, jiraUrlPrefix } from './CompReadyUtils' +import { jiraUrlPrefix } from './CompReadyUtils' +import { apiFetch } from '../helpers' import { makeStyles } from '@mui/styles' import Button from '@mui/material/Button' import ExistingTriageSelector from './ExistingTriageSelector' @@ -159,7 +160,7 @@ export default function TriageFields({ } } - fetch(triagesAPIUrl, { + apiFetch(triagesAPIUrl, { method: method, body: JSON.stringify(data), }).then((response) => { @@ -188,7 +189,9 @@ export default function TriageFields({ handleFormCompletion() } else { response.json().then((createdTriage) => { - fetch(`${getTriagesAPIUrl(createdTriage.id)}/matches?view=${view}`) + apiFetch( + `/api/component_readiness/triages/${createdTriage.id}/matches?view=${view}` + ) .then((matchesResponse) => { if (matchesResponse.status === 200) { return matchesResponse.json() diff --git a/sippy-ng/src/component_readiness/TriageList.js b/sippy-ng/src/component_readiness/TriageList.js index e66674a065..4b3f5558c0 100644 --- a/sippy-ng/src/component_readiness/TriageList.js +++ b/sippy-ng/src/component_readiness/TriageList.js @@ -1,5 +1,5 @@ import { CapabilitiesContext } from '../App' -import { getTriagesAPIUrl } from './CompReadyUtils' +import { apiFetch } from '../helpers' import React, { Fragment } from 'react' import TriagedTestsPanel from './TriagedTestsPanel' @@ -16,7 +16,7 @@ export default function TriageList() { let triageFetch // triage entries will only be available when there is a postgres connection if (localDBEnabled) { - triageFetch = fetch(getTriagesAPIUrl()).then((response) => { + triageFetch = apiFetch('/api/component_readiness/triages').then((response) => { if (response.status !== 200) { throw new Error('API server returned ' + response.status) } diff --git a/sippy-ng/src/component_readiness/TriagePotentialMatches.js b/sippy-ng/src/component_readiness/TriagePotentialMatches.js index dcd17df5c9..f585ced145 100644 --- a/sippy-ng/src/component_readiness/TriagePotentialMatches.js +++ b/sippy-ng/src/component_readiness/TriagePotentialMatches.js @@ -22,7 +22,7 @@ import { CompReadyVarsContext } from './CompReadyVars' import { DataGrid, GridToolbar } from '@mui/x-data-grid' import { generateTestDetailsReportLink } from './CompReadyUtils' import { makeStyles } from '@mui/styles' -import { relativeTime } from '../helpers' +import { apiFetch, relativeTime } from '../helpers' import CompSeverityIcon from './CompSeverityIcon' import PropTypes from 'prop-types' import React, { Fragment, useContext } from 'react' @@ -143,7 +143,7 @@ export default function TriagePotentialMatches({ const findPotentialMatches = () => { setIsLoading(true) setIsModalOpen(true) - fetch(`${triage.links.potential_matches}?view=${selectedView}`) + apiFetch(`${triage.links.potential_matches}?view=${selectedView}`) .then((response) => { if (response.status !== 200) { throw new Error('API server returned ' + response.status) @@ -189,7 +189,7 @@ export default function TriagePotentialMatches({ ], } - fetch(triage.links.self, { + apiFetch(triage.links.self, { method: 'PUT', body: JSON.stringify(updatedTriage), }) diff --git a/sippy-ng/src/component_readiness/UpdateTriagePanel.js b/sippy-ng/src/component_readiness/UpdateTriagePanel.js index f038462b47..31460ec240 100644 --- a/sippy-ng/src/component_readiness/UpdateTriagePanel.js +++ b/sippy-ng/src/component_readiness/UpdateTriagePanel.js @@ -1,8 +1,8 @@ import { Button, FormHelperText, Tab, Tabs } from '@mui/material' import { DataGrid } from '@mui/x-data-grid' -import { formColumnName, getTriagesAPIUrl } from './CompReadyUtils' +import { formColumnName } from './CompReadyUtils' import { makeStyles } from '@mui/styles' -import { relativeTime } from '../helpers' +import { apiFetch, relativeTime } from '../helpers' import DialogContent from '@mui/material/DialogContent' import DialogTitle from '@mui/material/DialogTitle' import PropTypes from 'prop-types' @@ -71,7 +71,7 @@ export default function UpdateTriagePanel({ (regression) => !removedRegressions.includes(String(regression.id)) ) - fetch(getTriagesAPIUrl(triage.id), { + apiFetch(`/api/component_readiness/triages/${triage.id}`, { method: 'PUT', body: JSON.stringify({ ...triage, regressions: updatedRegressions }), }).then((response) => { diff --git a/sippy-ng/src/component_readiness/UpsertTriageModal.js b/sippy-ng/src/component_readiness/UpsertTriageModal.js index 3fe7ab4fb8..56d88cadc4 100644 --- a/sippy-ng/src/component_readiness/UpsertTriageModal.js +++ b/sippy-ng/src/component_readiness/UpsertTriageModal.js @@ -1,5 +1,5 @@ import { Button, DialogActions, Snackbar, Tooltip } from '@mui/material' -import { getTriagesAPIUrl } from './CompReadyUtils' +import { apiFetch } from '../helpers' import { makeStyles } from '@mui/styles' import AddRegressionPanel from './AddRegressionPanel' import Alert from '@mui/material/Alert' @@ -51,7 +51,7 @@ export default function UpsertTriageModal({ const [triageModalOpen, setTriageModalOpen] = React.useState(false) const handleTriageModalOpen = () => { // Only get all existing entries when actually adding/editing a triage - fetch(getTriagesAPIUrl()) + apiFetch('/api/component_readiness/triages') .then((response) => { if (response.status !== 200) { throw new Error(