diff --git a/src/lib/ApiConnection.js b/src/lib/ApiConnection.js index 34d50b56..95460110 100644 --- a/src/lib/ApiConnection.js +++ b/src/lib/ApiConnection.js @@ -16,6 +16,9 @@ import ErrorPage from 'pages/_error.js'; const { serverRuntimeConfig, publicRuntimeConfig } = getConfig(); +const ds = publicRuntimeConfig.DISABLE_SUBSCRIPTIONS +const disableSubscriptions = (!(ds == null) && ds.toLowerCase() || false) === 'true' + const ApiConnection = ({ children }) => ( {auth => { @@ -34,6 +37,7 @@ const ApiConnection = ({ children }) => ( const wsLink = new WebSocketLink({ uri: publicRuntimeConfig.GRAPHQL_API.replace(/https/, 'wss').replace(/http/, 'ws'), options: { + lazy: disableSubscriptions, reconnect: true, connectionParams: { authToken: auth.apiToken, diff --git a/src/pages/backups.js b/src/pages/backups.js index e1932671..366003c6 100644 --- a/src/pages/backups.js +++ b/src/pages/backups.js @@ -27,6 +27,9 @@ const { publicRuntimeConfig } = getConfig(); const envLimit = parseInt(publicRuntimeConfig.LAGOON_UI_BACKUPS_LIMIT, 10); const customMessage = publicRuntimeConfig.LAGOON_UI_BACKUPS_LIMIT_MESSAGE; +const ds = publicRuntimeConfig.DISABLE_SUBSCRIPTIONS +const disableSubscriptions = (!(ds == null) && ds.toLowerCase() || false) === 'true' + /** * Displays the backups page, given the name of an openshift project. */ @@ -117,50 +120,54 @@ export const PageBackups = ({ router }) => { ); } - subscribeToMore({ - document: BackupsSubscription, - variables: { environment: environment.id }, - updateQuery: (prevStore, { subscriptionData }) => { - if (!subscriptionData.data) return prevStore; - const prevBackups = prevStore.environment.backups; - const incomingBackup = subscriptionData.data.backupChanged; - const existingIndex = prevBackups.findIndex(prevBackup => prevBackup.id === incomingBackup.id); - let newBackups; - - // New backup. - if (existingIndex === -1) { - // Don't add new deleted backups. - if (incomingBackup.deleted !== '0000-00-00 00:00:00') { - return prevStore; + if (!disableSubscriptions) { + subscribeToMore({ + document: BackupsSubscription, + variables: { environment: environment.id }, + updateQuery: (prevStore, { subscriptionData }) => { + if (!subscriptionData.data) return prevStore; + const prevBackups = prevStore.environment.backups; + const incomingBackup = subscriptionData.data.backupChanged; + const existingIndex = prevBackups.findIndex(prevBackup => prevBackup.id === incomingBackup.id); + let newBackups; + + // New backup. + if (existingIndex === -1) { + // Don't add new deleted backups. + if (incomingBackup.deleted !== '0000-00-00 00:00:00') { + return prevStore; + } + + newBackups = [incomingBackup, ...prevBackups]; } - - newBackups = [incomingBackup, ...prevBackups]; - } - // Existing backup. - else { - // Updated backup - if (incomingBackup.deleted === '0000-00-00 00:00:00') { - newBackups = Object.assign([...prevBackups], { - [existingIndex]: incomingBackup, - }); - } - // Deleted backup + // Existing backup. else { - newBackups = R.remove(existingIndex, 1, prevBackups); + // Updated backup + if (incomingBackup.deleted === '0000-00-00 00:00:00') { + newBackups = Object.assign([...prevBackups], { + [existingIndex]: incomingBackup, + }); + } + // Deleted backup + else { + newBackups = R.remove(existingIndex, 1, prevBackups); + } } - } - const newStore = { - ...prevStore, - environment: { - ...prevStore.environment, - backups: newBackups, - }, - }; - - return newStore; - }, - }); + const newStore = { + ...prevStore, + environment: { + ...prevStore.environment, + backups: newBackups, + }, + }; + + return newStore; + }, + }); + } else { + subscribeToMore() + } return ( <> diff --git a/src/pages/deployments.js b/src/pages/deployments.js index 4b780716..7b70f928 100644 --- a/src/pages/deployments.js +++ b/src/pages/deployments.js @@ -28,6 +28,9 @@ const { publicRuntimeConfig } = getConfig(); const envLimit = parseInt(publicRuntimeConfig.LAGOON_UI_DEPLOYMENTS_LIMIT, 10); const customMessage = publicRuntimeConfig.LAGOON_UI_DEPLOYMENTS_LIMIT_MESSAGE; +const ds = publicRuntimeConfig.DISABLE_SUBSCRIPTIONS +const disableSubscriptions = (!(ds == null) && ds.toLowerCase() || false) === 'true' + /** * Displays the deployments page, given the openshift project name. */ @@ -118,39 +121,42 @@ export const PageDeployments = ({ router }) => { /> ); } + if (!disableSubscriptions) { + subscribeToMore({ + document: DeploymentsSubscription, + variables: { environment: environment.id }, + updateQuery: (prevStore, { subscriptionData }) => { + if (!subscriptionData.data) return prevStore; + const prevDeployments = prevStore.environment.deployments; + const incomingDeployment = subscriptionData.data.deploymentChanged; + const existingIndex = prevDeployments.findIndex(prevDeployment => prevDeployment.id === incomingDeployment.id); + let newDeployments; + + // New deployment. + if (existingIndex === -1) { + newDeployments = [incomingDeployment, ...prevDeployments]; + } + // Updated deployment + else { + newDeployments = Object.assign([...prevDeployments], { + [existingIndex]: incomingDeployment, + }); + } - subscribeToMore({ - document: DeploymentsSubscription, - variables: { environment: environment.id }, - updateQuery: (prevStore, { subscriptionData }) => { - if (!subscriptionData.data) return prevStore; - const prevDeployments = prevStore.environment.deployments; - const incomingDeployment = subscriptionData.data.deploymentChanged; - const existingIndex = prevDeployments.findIndex(prevDeployment => prevDeployment.id === incomingDeployment.id); - let newDeployments; - - // New deployment. - if (existingIndex === -1) { - newDeployments = [incomingDeployment, ...prevDeployments]; - } - // Updated deployment - else { - newDeployments = Object.assign([...prevDeployments], { - [existingIndex]: incomingDeployment, - }); - } - - const newStore = { - ...prevStore, - environment: { - ...prevStore.environment, - deployments: newDeployments, - }, - }; - - return newStore; - }, - }); + const newStore = { + ...prevStore, + environment: { + ...prevStore.environment, + deployments: newDeployments, + }, + }; + + return newStore; + }, + }); + } else { + subscribeToMore() + } return ( <> diff --git a/src/pages/tasks.js b/src/pages/tasks.js index 32699d63..dfe8a0b8 100644 --- a/src/pages/tasks.js +++ b/src/pages/tasks.js @@ -28,6 +28,9 @@ const { publicRuntimeConfig } = getConfig(); const envLimit = parseInt(publicRuntimeConfig.LAGOON_UI_TASKS_LIMIT, 10); const customMessage = publicRuntimeConfig.AGOON_UI_TASKS_LIMIT_MESSAGE; +const ds = publicRuntimeConfig.DISABLE_SUBSCRIPTIONS +const disableSubscriptions = (!(ds == null) && ds.toLowerCase() || false) === 'true' + /** * Displays the tasks page, given the openshift project name. */ @@ -120,38 +123,42 @@ export const PageTasks = ({ router, renderAddTasks }) => { ); } - subscribeToMore({ - document: TasksSubscription, - variables: { environment: environment.id }, - updateQuery: (prevStore, { subscriptionData }) => { - if (!subscriptionData.data) return prevStore; - const prevTasks = prevStore.environment.tasks; - const incomingTask = subscriptionData.data.taskChanged; - const existingIndex = prevTasks.findIndex(prevTask => prevTask.id === incomingTask.id); - let newTasks; - - // New task. - if (existingIndex === -1) { - newTasks = [incomingTask, ...prevTasks]; - } - // Updated task - else { - newTasks = Object.assign([...prevTasks], { - [existingIndex]: incomingTask, - }); - } - - const newStore = { - ...prevStore, - environment: { - ...prevStore.environment, - tasks: newTasks, - }, - }; + if (!disableSubscriptions) { + subscribeToMore({ + document: TasksSubscription, + variables: { environment: environment.id }, + updateQuery: (prevStore, { subscriptionData }) => { + if (!subscriptionData.data) return prevStore; + const prevTasks = prevStore.environment.tasks; + const incomingTask = subscriptionData.data.taskChanged; + const existingIndex = prevTasks.findIndex(prevTask => prevTask.id === incomingTask.id); + let newTasks; + + // New task. + if (existingIndex === -1) { + newTasks = [incomingTask, ...prevTasks]; + } + // Updated task + else { + newTasks = Object.assign([...prevTasks], { + [existingIndex]: incomingTask, + }); + } - return newStore; - }, - }); + const newStore = { + ...prevStore, + environment: { + ...prevStore.environment, + tasks: newTasks, + }, + }; + + return newStore; + }, + }); + } else { + subscribeToMore() + } return ( <>