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

Combined PR-140 & PR-209 #211

Closed
wants to merge 6 commits into from
Closed
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
17 changes: 0 additions & 17 deletions src/components/Backups/StyledBackups.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,23 +72,6 @@ export const DataTable = styled.div`
padding-right: 15px;
}

.btn-download {
width: 173px;
padding-inline: 22px;
white-space: nowrap;

&-lg {
font-size: 80%;
}

@media (max-width: 1200px) {
width: unset;
&-lg {
font-size: initial;
}
}
}

& > div {
padding-left: 20px;
@media ${bp.wideDown} {
Expand Down
1 change: 0 additions & 1 deletion src/components/Backups/index.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const backupsData = [
restore: {
status: 'completed',
restoreLocation: 'https://example.com/backup',
restoreSize: 300
},
},
{
Expand Down
1 change: 0 additions & 1 deletion src/components/Backups/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export interface BackupsProps {
restore: {
status: 'completed' | 'pending' | 'failed';
restoreLocation?: string;
restoreSize?: number;
};
}[];
}
Expand Down
15 changes: 1 addition & 14 deletions src/components/RestoreButton/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,6 @@ import React from 'react';
import Button from 'components/Button';
import Prepare from 'components/RestoreButton/Prepare';

function humanFileSize(size) {
var i = size == 0 ? 0 : Math.floor(Math.log(size) / Math.log(1024));
const formatted = (size / Math.pow(1024, i)).toFixed(2) * 1 + ' ' + ['B', 'kB', 'MB', 'GB', 'TB'][i];

return [formatted.length > 5, formatted];
}

/**
* A button to restore a backup.
*/
Expand All @@ -20,13 +13,7 @@ const RestoreButton = ({ backup: { backupId, restore } }) => {

if (restore.status === 'failed') return <Button disabled>Retrieve failed</Button>;

const [isOverflowing, formattedSize] = humanFileSize(restore.restoreSize);

return (
<Button variant={`download ${isOverflowing ? 'btn-download-lg' : ''}`} href={restore.restoreLocation}>
Download ({formattedSize})
</Button>
);
return <Button href={restore.restoreLocation}>Download</Button>;
};

export default RestoreButton;
1 change: 1 addition & 0 deletions src/lib/ApiConnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const ApiConnection = ({ children }) => (
const wsLink = new WebSocketLink({
uri: publicRuntimeConfig.GRAPHQL_API.replace(/https/, 'wss').replace(/http/, 'ws'),
options: {
lazy: true,
reconnect: true,
connectionParams: {
authToken: auth.apiToken,
Expand Down
1 change: 0 additions & 1 deletion src/lib/query/EnvironmentWithBackups.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export default gql`
id
status
restoreLocation
restoreSize
}
}
}
Expand Down
17 changes: 0 additions & 17 deletions src/lib/subscription/Backups.js

This file was deleted.

15 changes: 0 additions & 15 deletions src/lib/subscription/Deployments.js

This file was deleted.

13 changes: 0 additions & 13 deletions src/lib/subscription/Tasks.js

This file was deleted.

49 changes: 1 addition & 48 deletions src/pages/backups.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ import NavTabsSkeleton from 'components/NavTabs/NavTabsSkeleton';
import ResultsLimited from 'components/ResultsLimited';
import MainLayout from 'layouts/MainLayout';
import EnvironmentWithBackupsQuery from 'lib/query/EnvironmentWithBackups';
import BackupsSubscription from 'lib/subscription/Backups';
import * as R from 'ramda';

import EnvironmentNotFound from '../components/errors/EnvironmentNotFound';
import QueryError from '../components/errors/QueryError';
import { CommonWrapperWNotification } from '../styles/commonPageStyles';
Expand All @@ -34,7 +32,7 @@ export const PageBackups = ({ router }) => {
const [resultLimit, setResultLimit] = useState(null);

const { continueTour } = useTourContext();
const { data, error, loading, subscribeToMore } = useQuery(EnvironmentWithBackupsQuery, {
const { data, error, loading } = useQuery(EnvironmentWithBackupsQuery, {
variables: {
openshiftProjectName: router.query.openshiftProjectName,
limit: resultLimit,
Expand Down Expand Up @@ -117,51 +115,6 @@ 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;
}

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
else {
newBackups = R.remove(existingIndex, 1, prevBackups);
}
}

const newStore = {
...prevStore,
environment: {
...prevStore.environment,
backups: newBackups,
},
};

return newStore;
},
});

return (
<>
<Head>
Expand Down
37 changes: 1 addition & 36 deletions src/pages/deployments.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ import NavTabsSkeleton from 'components/NavTabs/NavTabsSkeleton';
import ResultsLimited from 'components/ResultsLimited';
import MainLayout from 'layouts/MainLayout';
import EnvironmentWithDeploymentsQuery from 'lib/query/EnvironmentWithDeployments';
import DeploymentsSubscription from 'lib/subscription/Deployments';

import EnvironmentNotFound from '../components/errors/EnvironmentNotFound';
import QueryError from '../components/errors/QueryError';
import { DeploymentsWrapper } from '../styles/pageStyles';
Expand All @@ -36,7 +34,7 @@ export const PageDeployments = ({ router }) => {

const [resultLimit, setResultLimit] = useState(null);

const { data, error, loading, subscribeToMore, refetch } = useQuery(EnvironmentWithDeploymentsQuery, {
const { data, error, loading, refetch } = useQuery(EnvironmentWithDeploymentsQuery, {
variables: {
openshiftProjectName: router.query.openshiftProjectName,
limit: resultLimit,
Expand Down Expand Up @@ -119,39 +117,6 @@ export const PageDeployments = ({ router }) => {
);
}

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;
},
});

return (
<>
<Head>
Expand Down
37 changes: 1 addition & 36 deletions src/pages/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ import Tasks from 'components/Tasks';
import TasksSkeleton from 'components/Tasks/TasksSkeleton';
import MainLayout from 'layouts/MainLayout';
import EnvironmentWithTasksQuery from 'lib/query/EnvironmentWithTasks';
import TasksSubscription from 'lib/subscription/Tasks';

import EnvironmentNotFound from '../components/errors/EnvironmentNotFound';
import QueryError from '../components/errors/QueryError';
import { TasksWrapper } from '../styles/pageStyles';
Expand All @@ -35,7 +33,7 @@ export const PageTasks = ({ router, renderAddTasks }) => {
const [resultLimit, setResultLimit] = useState(null);

const { continueTour } = useTourContext();
const { data, error, loading, subscribeToMore, refetch } = useQuery(EnvironmentWithTasksQuery, {
const { data, error, loading, refetch } = useQuery(EnvironmentWithTasksQuery, {
variables: {
openshiftProjectName: router.query.openshiftProjectName,
limit: resultLimit,
Expand Down Expand Up @@ -120,39 +118,6 @@ 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,
},
};

return newStore;
},
});

return (
<>
<Head>
Expand Down
Loading