fix(edge/stacks): show correct status for env [EE-3374] (#7466)

pull/7467/head
Chaim Lev-Ari 2022-08-12 04:20:36 +03:00 committed by GitHub
parent a247db7e93
commit 29f0daa7ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 39 additions and 21 deletions

View File

@ -56,8 +56,8 @@
ng-class="{ active: item.Checked }" ng-class="{ active: item.Checked }"
> >
<td>{{ item.Name }}</td> <td>{{ item.Name }}</td>
<td>{{ $ctrl.statusMap[item.Status.Type] || 'Pending' }}</td> <td>{{ $ctrl.endpointStatusLabel(item.Id) }}</td>
<td>{{ item.Status.Error ? item.Status.Error : '-' }}</td> <td>{{ $ctrl.endpointStatusError(item.Id) }}</td>
</tr> </tr>
<tr ng-if="$ctrl.state.loading"> <tr ng-if="$ctrl.state.loading">
<td colspan="5" class="text-center text-muted">Loading...</td> <td colspan="5" class="text-center text-muted">Loading...</td>

View File

@ -39,6 +39,22 @@ export class EdgeStackEndpointsDatatableController {
this.onTextFilterChange = onTextFilterChange; this.onTextFilterChange = onTextFilterChange;
} }
getEndpointStatus(endpointId) {
return this.endpointsStatus[endpointId];
}
endpointStatusLabel(endpointId) {
const status = this.getEndpointStatus(endpointId);
return status ? this.statusMap[status.Type] : 'Pending';
}
endpointStatusError(endpointId) {
const status = this.getEndpointStatus(endpointId);
return status && status.Error ? status.Error : '-';
}
$onInit() { $onInit() {
this.setDefaults(); this.setDefaults();
this.prepareTableFromDataset(); this.prepareTableFromDataset();

View File

@ -12,5 +12,7 @@ angular.module('portainer.edge').component('edgeStackEndpointsDatatable', {
orderBy: '@', orderBy: '@',
reverseOrder: '<', reverseOrder: '<',
retrievePage: '<', retrievePage: '<',
edgeStackId: '<',
endpointsStatus: '<',
}, },
}); });

View File

@ -33,6 +33,8 @@
table-key="edgeStackEndpoints" table-key="edgeStackEndpoints"
order-by="Name" order-by="Name"
retrieve-page="$ctrl.getPaginatedEndpoints" retrieve-page="$ctrl.getPaginatedEndpoints"
edge-stack-id="$ctrl.stack.Id"
endpoints-status="$ctrl.stack.Status"
> >
</edge-stack-endpoints-datatable> </edge-stack-endpoints-datatable>
</div> </div>

View File

@ -99,14 +99,14 @@ export class EditEdgeStackViewController {
async getPaginatedEndpointsAsync(lastId, limit, search) { async getPaginatedEndpointsAsync(lastId, limit, search) {
try { try {
if (this.stackEndpointIds.length === 0) {
return { endpoints: [], totalCount: 0 };
}
const query = { search, endpointIds: this.stackEndpointIds }; const query = { search, endpointIds: this.stackEndpointIds };
const { value, totalCount } = await getEnvironments({ start: lastId, limit, query }); const { value, totalCount } = await getEnvironments({ start: lastId, limit, query });
const endpoints = _.map(value, (endpoint) => {
const status = this.stack.Status[endpoint.Id]; return { endpoints: value, totalCount };
endpoint.Status = status;
return endpoint;
});
return { endpoints, totalCount };
} catch (err) { } catch (err) {
this.Notifications.error('Failure', err, 'Unable to retrieve environment information'); this.Notifications.error('Failure', err, 'Unable to retrieve environment information');
} }

View File

@ -3,7 +3,8 @@ import { useSref } from '@uirouter/react';
import type { DockerContainer } from '@/react/docker/containers/types'; import type { DockerContainer } from '@/react/docker/containers/types';
import { isOfflineEndpoint } from '@/portainer/helpers/endpointHelper'; import { isOfflineEndpoint } from '@/portainer/helpers/endpointHelper';
import { useCurrentEnvironment } from '@/portainer/hooks/useCurrentEnvironment';
import { useRowContext } from '../RowContext';
export const image: Column<DockerContainer> = { export const image: Column<DockerContainer> = {
Header: 'Image', Header: 'Image',
@ -24,11 +25,9 @@ function ImageCell({ value: imageName }: Props) {
const linkProps = useSref('docker.images.image', { id: imageName }); const linkProps = useSref('docker.images.image', { id: imageName });
const shortImageName = trimSHASum(imageName); const shortImageName = trimSHASum(imageName);
const environmentQuery = useCurrentEnvironment(); const { environment } = useRowContext();
const environment = environmentQuery.data; if (isOfflineEndpoint(environment)) {
if (!environment || isOfflineEndpoint(environment)) {
return <span>{shortImageName}</span>; return <span>{shortImageName}</span>;
} }

View File

@ -4,11 +4,11 @@ import { useSref } from '@uirouter/react';
import type { DockerContainer } from '@/react/docker/containers/types'; import type { DockerContainer } from '@/react/docker/containers/types';
import { isOfflineEndpoint } from '@/portainer/helpers/endpointHelper'; import { isOfflineEndpoint } from '@/portainer/helpers/endpointHelper';
import { useCurrentEnvironment } from '@/portainer/hooks/useCurrentEnvironment';
import { useTableSettings } from '@@/datatables/useZustandTableSettings'; import { useTableSettings } from '@@/datatables/useZustandTableSettings';
import { TableSettings } from '../types'; import { TableSettings } from '../types';
import { useRowContext } from '../RowContext';
export const name: Column<DockerContainer> = { export const name: Column<DockerContainer> = {
Header: 'Name', Header: 'Name',
@ -35,16 +35,15 @@ export function NameCell({
const { settings } = useTableSettings<TableSettings>(); const { settings } = useTableSettings<TableSettings>();
const truncate = settings.truncateContainerName; const truncate = settings.truncateContainerName;
const environmentQuery = useCurrentEnvironment();
const environment = environmentQuery.data; const { environment } = useRowContext();
let shortName = name; let shortName = name;
if (truncate > 0) { if (truncate > 0) {
shortName = _.truncate(name, { length: truncate }); shortName = _.truncate(name, { length: truncate });
} }
if (!environment || isOfflineEndpoint(environment)) { if (isOfflineEndpoint(environment)) {
return <span>{shortName}</span>; return <span>{shortName}</span>;
} }

View File

@ -2,7 +2,8 @@ import { Column } from 'react-table';
import _ from 'lodash'; import _ from 'lodash';
import type { DockerContainer, Port } from '@/react/docker/containers/types'; import type { DockerContainer, Port } from '@/react/docker/containers/types';
import { useCurrentEnvironment } from '@/portainer/hooks/useCurrentEnvironment';
import { useRowContext } from '../RowContext';
export const ports: Column<DockerContainer> = { export const ports: Column<DockerContainer> = {
Header: 'Published Ports', Header: 'Published Ports',
@ -20,10 +21,9 @@ interface Props {
} }
function PortsCell({ value: ports }: Props) { function PortsCell({ value: ports }: Props) {
const environmentQuery = useCurrentEnvironment(); const { environment } = useRowContext();
const environment = environmentQuery.data; if (ports.length === 0) {
if (!environment || ports.length === 0) {
return '-'; return '-';
} }