From 75f40fe485cc2a59f1411b8564e085347f9f47d5 Mon Sep 17 00:00:00 2001 From: Chaim Lev-Ari Date: Mon, 21 Nov 2022 09:50:47 +0200 Subject: [PATCH] refactor(portainer): remove offline mode [EE-4348] (#7761) Co-authored-by: deviantony --- .../images-datatable/imagesDatatable.html | 11 ++---- .../images-datatable/imagesDatatable.js | 1 - .../networkRowContent.html | 5 +-- .../networks-datatable/networksDatatable.html | 4 +- .../networks-datatable/networksDatatable.js | 1 - .../volumes-datatable/volumesDatatable.html | 13 +++---- .../volumes-datatable/volumesDatatable.js | 1 - .../host-overview/host-overview.html | 8 ++-- .../components/host-overview/host-overview.js | 1 - .../interceptors/containersInterceptor.js | 24 ------------ app/docker/interceptors/imagesInterceptor.js | 24 ------------ app/docker/interceptors/infoInterceptor.js | 24 ------------ .../interceptors/networksInterceptor.js | 24 ------------ app/docker/interceptors/versionInterceptor.js | 24 ------------ app/docker/interceptors/volumesInterceptor.js | 24 ------------ app/docker/views/dashboard/dashboard.html | 1 - .../views/dashboard/dashboardController.js | 3 -- app/docker/views/host/host-view-controller.js | 4 -- app/docker/views/host/host-view.html | 1 - app/docker/views/images/images.html | 4 +- app/docker/views/images/imagesController.js | 4 -- app/docker/views/networks/networks.html | 2 - .../views/networks/networksController.js | 8 +--- app/docker/views/volumes/volumes.html | 2 - app/docker/views/volumes/volumesController.js | 5 --- .../applicationsDatatable.html | 2 +- .../stacks-datatable/stacksDatatable.html | 9 ++--- .../stacks-datatable/stacksDatatable.js | 1 - .../informationPanelOffline.html | 15 -------- .../informationPanelOffline.js | 4 -- .../informationPanelOfflineController.js | 38 ------------------- app/portainer/helpers/endpointHelper.js | 4 -- app/portainer/services/stateManager.js | 6 +-- app/portainer/views/stacks/stacks.html | 2 - .../views/stacks/stacksController.js | 4 -- .../ContainersDatatable/columns/image.tsx | 9 ----- .../ContainersDatatable/columns/name.tsx | 8 ---- .../columns/quick-actions.tsx | 9 +---- app/react/sidebar/DockerSidebar.tsx | 5 +-- 39 files changed, 28 insertions(+), 311 deletions(-) delete mode 100644 app/docker/interceptors/containersInterceptor.js delete mode 100644 app/docker/interceptors/imagesInterceptor.js delete mode 100644 app/docker/interceptors/infoInterceptor.js delete mode 100644 app/docker/interceptors/networksInterceptor.js delete mode 100644 app/docker/interceptors/versionInterceptor.js delete mode 100644 app/docker/interceptors/volumesInterceptor.js delete mode 100644 app/portainer/components/information-panel-offline/informationPanelOffline.html delete mode 100644 app/portainer/components/information-panel-offline/informationPanelOffline.js delete mode 100644 app/portainer/components/information-panel-offline/informationPanelOfflineController.js diff --git a/app/docker/components/datatables/images-datatable/imagesDatatable.html b/app/docker/components/datatables/images-datatable/imagesDatatable.html index 58db4f7c5..63b3c9a11 100644 --- a/app/docker/components/datatables/images-datatable/imagesDatatable.html +++ b/app/docker/components/datatables/images-datatable/imagesDatatable.html @@ -21,7 +21,7 @@ data-cy="image-searchInput" /> -
+
-
+
- diff --git a/app/docker/views/images/images.html b/app/docker/views/images/images.html index c2bd3b0ea..91dcb51d7 100644 --- a/app/docker/views/images/images.html +++ b/app/docker/views/images/images.html @@ -1,6 +1,6 @@ -
+
@@ -44,7 +44,6 @@
-
diff --git a/app/docker/views/images/imagesController.js b/app/docker/views/images/imagesController.js index 4b5115e46..e5fc58b67 100644 --- a/app/docker/views/images/imagesController.js +++ b/app/docker/views/images/imagesController.js @@ -1,6 +1,5 @@ import _ from 'lodash-es'; import { PorImageRegistryModel } from 'Docker/models/porImageRegistry'; -import { isOfflineEndpoint } from '@/portainer/helpers/endpointHelper'; angular.module('portainer.docker').controller('ImagesController', [ '$scope', @@ -135,14 +134,11 @@ angular.module('portainer.docker').controller('ImagesController', [ }); }; - $scope.offlineMode = false; - $scope.getImages = getImages; function getImages() { ImageService.images(true) .then(function success(data) { $scope.images = data; - $scope.offlineMode = isOfflineEndpoint(endpoint); }) .catch(function error(err) { Notifications.error('Failure', err, 'Unable to retrieve images'); diff --git a/app/docker/views/networks/networks.html b/app/docker/views/networks/networks.html index e0c2f9c3f..7b38e2e8b 100644 --- a/app/docker/views/networks/networks.html +++ b/app/docker/views/networks/networks.html @@ -1,6 +1,5 @@ -
diff --git a/app/docker/views/networks/networksController.js b/app/docker/views/networks/networksController.js index 5ae8aa3b2..4830b9950 100644 --- a/app/docker/views/networks/networksController.js +++ b/app/docker/views/networks/networksController.js @@ -1,7 +1,6 @@ import _ from 'lodash-es'; -import DockerNetworkHelper from 'Docker/helpers/networkHelper'; -import { isOfflineEndpoint } from '@/portainer/helpers/endpointHelper'; -import { confirmDeletionAsync } from 'Portainer/services/modal.service/confirm'; +import DockerNetworkHelper from '@/docker/helpers/networkHelper'; +import { confirmDeletionAsync } from '@/portainer/services/modal.service/confirm'; angular.module('portainer.docker').controller('NetworksController', [ '$q', @@ -39,8 +38,6 @@ angular.module('portainer.docker').controller('NetworksController', [ }); }; - $scope.offlineMode = false; - $scope.getNetworks = getNetworks; function groupSwarmNetworksManagerNodesFirst(networks, agents) { @@ -71,7 +68,6 @@ angular.module('portainer.docker').controller('NetworksController', [ $q.all(req) .then((data) => { - $scope.offlineMode = isOfflineEndpoint(endpoint); const networks = _.forEach(data.networks, (item) => (item.Subs = [])); if ($scope.applicationState.endpoint.mode.agentProxy && $scope.applicationState.endpoint.mode.provider === 'DOCKER_SWARM_MODE') { $scope.networks = groupSwarmNetworksManagerNodesFirst(data.networks, data.agents); diff --git a/app/docker/views/volumes/volumes.html b/app/docker/views/volumes/volumes.html index fc6bf41d1..93c4be0ff 100644 --- a/app/docker/views/volumes/volumes.html +++ b/app/docker/views/volumes/volumes.html @@ -1,6 +1,5 @@ -
diff --git a/app/docker/views/volumes/volumesController.js b/app/docker/views/volumes/volumesController.js index ccd36db7d..404aa47e4 100644 --- a/app/docker/views/volumes/volumesController.js +++ b/app/docker/views/volumes/volumesController.js @@ -1,5 +1,3 @@ -import { isOfflineEndpoint } from '@/portainer/helpers/endpointHelper'; - angular.module('portainer.docker').controller('VolumesController', [ '$q', '$scope', @@ -39,8 +37,6 @@ angular.module('portainer.docker').controller('VolumesController', [ }); }; - $scope.offlineMode = false; - $scope.getVolumes = getVolumes; function getVolumes() { var endpointProvider = $scope.applicationState.endpoint.mode.provider; @@ -53,7 +49,6 @@ angular.module('portainer.docker').controller('VolumesController', [ }) .then(function success(data) { var services = data.services; - $scope.offlineMode = isOfflineEndpoint(endpoint); $scope.volumes = data.attached .map(function (volume) { volume.dangling = false; diff --git a/app/kubernetes/components/datatables/applications-datatable/applicationsDatatable.html b/app/kubernetes/components/datatables/applications-datatable/applicationsDatatable.html index 642cded3a..51d6aae14 100644 --- a/app/kubernetes/components/datatables/applications-datatable/applicationsDatatable.html +++ b/app/kubernetes/components/datatables/applications-datatable/applicationsDatatable.html @@ -21,7 +21,7 @@ data-cy="k8sApp-searchApplicationsInput" />
-
+
-
+
- - diff --git a/app/portainer/components/information-panel-offline/informationPanelOffline.js b/app/portainer/components/information-panel-offline/informationPanelOffline.js deleted file mode 100644 index 83b76325f..000000000 --- a/app/portainer/components/information-panel-offline/informationPanelOffline.js +++ /dev/null @@ -1,4 +0,0 @@ -angular.module('portainer.app').component('informationPanelOffline', { - templateUrl: './informationPanelOffline.html', - controller: 'InformationPanelOfflineController', -}); diff --git a/app/portainer/components/information-panel-offline/informationPanelOfflineController.js b/app/portainer/components/information-panel-offline/informationPanelOfflineController.js deleted file mode 100644 index 7fe42ce17..000000000 --- a/app/portainer/components/information-panel-offline/informationPanelOfflineController.js +++ /dev/null @@ -1,38 +0,0 @@ -angular.module('portainer.app').controller('InformationPanelOfflineController', [ - '$state', - 'EndpointProvider', - 'EndpointService', - 'Authentication', - 'Notifications', - function StackDuplicationFormController($state, EndpointProvider, EndpointService, Authentication, Notifications) { - var ctrl = this; - - this.$onInit = onInit; - this.triggerSnapshot = triggerSnapshot; - - function triggerSnapshot() { - var endpointId = EndpointProvider.endpointID(); - - EndpointService.snapshotEndpoint(endpointId) - .then(function onSuccess() { - $state.reload(); - }) - .catch(function onError(err) { - Notifications.error('Failure', err, 'An error occurred during environment snapshot'); - }); - } - - function onInit() { - var endpointId = EndpointProvider.endpointID(); - ctrl.showRefreshButton = Authentication.isAdmin(); - - EndpointService.endpoint(endpointId) - .then(function onSuccess(data) { - ctrl.snapshotTime = data.Snapshots[0].Time; - }) - .catch(function onError(err) { - Notifications.error('Failure', err, 'Unable to retrieve environment information'); - }); - } - }, -]); diff --git a/app/portainer/helpers/endpointHelper.js b/app/portainer/helpers/endpointHelper.js index e0a706168..42c9dbff8 100644 --- a/app/portainer/helpers/endpointHelper.js +++ b/app/portainer/helpers/endpointHelper.js @@ -39,7 +39,3 @@ export default class EndpointHelper { } } } - -export function isOfflineEndpoint(endpoint) { - return endpoint.Status !== 1; -} diff --git a/app/portainer/services/stateManager.js b/app/portainer/services/stateManager.js index a470e9958..b3210182d 100644 --- a/app/portainer/services/stateManager.js +++ b/app/portainer/services/stateManager.js @@ -194,11 +194,9 @@ function StateManagerFactory( return deferred.promise; } - const reload = endpoint.Status === 1 || !endpoint.Snaphosts || !endpoint.Snaphosts.length || !endpoint.Snapshots[0].SnapshotRaw; - $q.all({ - version: reload ? SystemService.version() : $q.when(endpoint.Snapshots[0].SnapshotRaw.Version), - info: reload ? SystemService.info() : $q.when(endpoint.Snapshots[0].SnapshotRaw.Info), + version: SystemService.version(), + info: SystemService.info(), }) .then(function success(data) { var endpointMode = InfoHelper.determineEndpointMode(data.info, endpoint.Type); diff --git a/app/portainer/views/stacks/stacks.html b/app/portainer/views/stacks/stacks.html index b67479622..b1c6d0829 100644 --- a/app/portainer/views/stacks/stacks.html +++ b/app/portainer/views/stacks/stacks.html @@ -1,6 +1,5 @@ -
diff --git a/app/portainer/views/stacks/stacksController.js b/app/portainer/views/stacks/stacksController.js index 28334e494..a75485e84 100644 --- a/app/portainer/views/stacks/stacksController.js +++ b/app/portainer/views/stacks/stacksController.js @@ -1,5 +1,3 @@ -import { isOfflineEndpoint } from '@/portainer/helpers/endpointHelper'; - angular.module('portainer.app').controller('StacksController', StacksController); /* @ngInject */ @@ -35,7 +33,6 @@ function StacksController($scope, $state, Notifications, StackService, ModalServ }); } - $scope.offlineMode = false; $scope.createEnabled = false; $scope.getStacks = getStacks; @@ -48,7 +45,6 @@ function StacksController($scope, $state, Notifications, StackService, ModalServ StackService.stacks(true, endpointMode.provider === 'DOCKER_SWARM_MODE' && endpointMode.role === 'MANAGER', endpointId, includeOrphanedStacks) .then(function success(stacks) { $scope.stacks = stacks; - $scope.offlineMode = isOfflineEndpoint(endpoint); }) .catch(function error(err) { $scope.stacks = []; diff --git a/app/react/docker/containers/ListView/ContainersDatatable/columns/image.tsx b/app/react/docker/containers/ListView/ContainersDatatable/columns/image.tsx index 8d872e364..95aa0db33 100644 --- a/app/react/docker/containers/ListView/ContainersDatatable/columns/image.tsx +++ b/app/react/docker/containers/ListView/ContainersDatatable/columns/image.tsx @@ -2,9 +2,6 @@ import { Column } from 'react-table'; import { useSref } from '@uirouter/react'; import type { DockerContainer } from '@/react/docker/containers/types'; -import { isOfflineEndpoint } from '@/portainer/helpers/endpointHelper'; - -import { useRowContext } from '../RowContext'; export const image: Column = { Header: 'Image', @@ -25,12 +22,6 @@ function ImageCell({ value: imageName }: Props) { const linkProps = useSref('docker.images.image', { id: imageName }); const shortImageName = trimSHASum(imageName); - const { environment } = useRowContext(); - - if (isOfflineEndpoint(environment)) { - return {shortImageName}; - } - return ( {shortImageName} diff --git a/app/react/docker/containers/ListView/ContainersDatatable/columns/name.tsx b/app/react/docker/containers/ListView/ContainersDatatable/columns/name.tsx index 6024c154b..3172aa80e 100644 --- a/app/react/docker/containers/ListView/ContainersDatatable/columns/name.tsx +++ b/app/react/docker/containers/ListView/ContainersDatatable/columns/name.tsx @@ -3,12 +3,10 @@ import _ from 'lodash'; import { useSref } from '@uirouter/react'; import type { DockerContainer } from '@/react/docker/containers/types'; -import { isOfflineEndpoint } from '@/portainer/helpers/endpointHelper'; import { useTableSettings } from '@@/datatables/useZustandTableSettings'; import { TableSettings } from '../types'; -import { useRowContext } from '../RowContext'; export const name: Column = { Header: 'Name', @@ -36,17 +34,11 @@ export function NameCell({ const { settings } = useTableSettings(); const truncate = settings.truncateContainerName; - const { environment } = useRowContext(); - let shortName = name; if (truncate > 0) { shortName = _.truncate(name, { length: truncate }); } - if (isOfflineEndpoint(environment)) { - return {shortName}; - } - return ( {shortName} diff --git a/app/react/docker/containers/ListView/ContainersDatatable/columns/quick-actions.tsx b/app/react/docker/containers/ListView/ContainersDatatable/columns/quick-actions.tsx index bb72af80e..5db53704a 100644 --- a/app/react/docker/containers/ListView/ContainersDatatable/columns/quick-actions.tsx +++ b/app/react/docker/containers/ListView/ContainersDatatable/columns/quick-actions.tsx @@ -1,8 +1,6 @@ import { CellProps, Column } from 'react-table'; import { useAuthorizations } from '@/react/hooks/useUser'; -import { isOfflineEndpoint } from '@/portainer/helpers/endpointHelper'; -import { useCurrentEnvironment } from '@/react/hooks/useCurrentEnvironment'; import { ContainerQuickActions } from '@/react/docker/containers/components/ContainerQuickActions'; import { DockerContainer } from '@/react/docker/containers/types'; @@ -24,11 +22,6 @@ export const quickActions: Column = { function QuickActionsCell({ row: { original: container }, }: CellProps) { - const environmentQuery = useCurrentEnvironment(); - - const environment = environmentQuery.data; - const offlineMode = !environment || isOfflineEndpoint(environment); - const { settings } = useTableSettings(); const { hiddenQuickActions = [] } = settings; @@ -57,7 +50,7 @@ function QuickActionsCell({ 'DockerTaskLogs', ]); - if (offlineMode || !someOn || !isAuthorized) { + if (!someOn || !isAuthorized) { return null; } diff --git a/app/react/sidebar/DockerSidebar.tsx b/app/react/sidebar/DockerSidebar.tsx index 7975fa1ab..4a7e51853 100644 --- a/app/react/sidebar/DockerSidebar.tsx +++ b/app/react/sidebar/DockerSidebar.tsx @@ -14,7 +14,6 @@ import { import { type Environment, type EnvironmentId, - EnvironmentStatus, } from '@/react/portainer/environments/types'; import { Authorized, useUser, isEnvironmentAdmin } from '@/react/hooks/useUser'; import { useInfo, useVersion } from '@/docker/services/system.service'; @@ -47,8 +46,6 @@ export function DockerSidebar({ environmentId, environment }: Props) { const isSwarmManager = envInfoQuery.data; const apiVersion = envVersionQuery.data || 0; - const offlineMode = environment.Status === EnvironmentStatus.Down; - const setupSubMenuProps = isSwarmManager ? { label: 'Swarm', @@ -163,7 +160,7 @@ export function DockerSidebar({ environmentId, environment }: Props) { /> )} - {!isSwarmManager && isAdmin && !offlineMode && ( + {!isSwarmManager && isAdmin && (