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

feat: disable subscriptions #280

Merged
merged 2 commits into from
Jul 4, 2024
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
4 changes: 3 additions & 1 deletion src/lib/ApiConnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import ErrorPage from 'pages/_error.js';

const { serverRuntimeConfig, publicRuntimeConfig } = getConfig();

const disableSubscriptions = publicRuntimeConfig.DISABLE_SUBSCRIPTIONS?.toLowerCase() === 'true';

const ApiConnection = ({ children }) => (
<AuthContext.Consumer>
{auth => {
Expand All @@ -34,13 +36,13 @@ 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,
},
},
});

return ApolloLink.split(
({ query }) => {
const { kind, operation } = getMainDefinition(query);
Expand Down
1 change: 1 addition & 0 deletions src/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ module.exports = {
LAGOON_UI_VIEW_ENV_VARIABLES: process.env.LAGOON_UI_VIEW_ENV_VARIABLES,
PLUGIN_SCRIPTS: pluginRegistry,
WEBHOOK_URL: process.env.WEBHOOK_URL,
DISABLE_SUBSCRIPTIONS: process.env.DISABLE_SUBSCRIPTIONS,
},
distDir: '../build',
webpack(config, options) {
Expand Down
84 changes: 44 additions & 40 deletions src/pages/backups.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ const { publicRuntimeConfig } = getConfig();
const envLimit = parseInt(publicRuntimeConfig.LAGOON_UI_BACKUPS_LIMIT, 10);
const customMessage = publicRuntimeConfig.LAGOON_UI_BACKUPS_LIMIT_MESSAGE;

const disableSubscriptions = publicRuntimeConfig.DISABLE_SUBSCRIPTIONS?.toLowerCase() === 'true';

/**
* Displays the backups page, given the name of an openshift project.
*/
Expand Down Expand Up @@ -117,50 +119,52 @@ 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;
},
});
}

return (
<>
Expand Down
72 changes: 39 additions & 33 deletions src/pages/deployments.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ const { publicRuntimeConfig } = getConfig();
const envLimit = parseInt(publicRuntimeConfig.LAGOON_UI_DEPLOYMENTS_LIMIT, 10);
const customMessage = publicRuntimeConfig.LAGOON_UI_DEPLOYMENTS_LIMIT_MESSAGE;

const disableSubscriptions = publicRuntimeConfig.DISABLE_SUBSCRIPTIONS?.toLowerCase() === 'true';

/**
* Displays the deployments page, given the openshift project name.
*/
Expand All @@ -44,7 +46,10 @@ export const PageDeployments = ({ router }) => {
});

const handleRefetch = async () =>
await refetch({ openshiftProjectName: router.query.openshiftProjectName, limit: resultLimit });
await refetch({
openshiftProjectName: router.query.openshiftProjectName,
limit: resultLimit,
});

useEffect(() => {
let urlResultLimit = envLimit;
Expand Down Expand Up @@ -118,39 +123,40 @@ 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;
},
});
}

return (
<>
Expand Down
71 changes: 39 additions & 32 deletions src/pages/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ const { publicRuntimeConfig } = getConfig();
const envLimit = parseInt(publicRuntimeConfig.LAGOON_UI_TASKS_LIMIT, 10);
const customMessage = publicRuntimeConfig.AGOON_UI_TASKS_LIMIT_MESSAGE;

const disableSubscriptions = publicRuntimeConfig.DISABLE_SUBSCRIPTIONS?.toLowerCase() === 'true';

/**
* Displays the tasks page, given the openshift project name.
*/
Expand All @@ -43,7 +45,10 @@ export const PageTasks = ({ router, renderAddTasks }) => {
});

const handleRefetch = async () =>
await refetch({ openshiftProjectName: router.query.openshiftProjectName, limit: resultLimit });
await refetch({
openshiftProjectName: router.query.openshiftProjectName,
limit: resultLimit,
});

useEffect(() => {
let urlResultLimit = envLimit;
Expand Down Expand Up @@ -120,38 +125,40 @@ 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;
},
});
}

return (
<>
Expand Down