1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-08-02 20:35:25 +02:00

feat(docker/networks): migrate networks datatable to React [EE-4670] (#10351)

Co-authored-by: LP B <xAt0mZ@users.noreply.github.com>
This commit is contained in:
Chaim Lev-Ari 2023-10-22 11:35:22 +02:00 committed by GitHub
parent 0dc1805881
commit b933bee95e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 333 additions and 440 deletions

View file

@ -1,33 +0,0 @@
import { ResourceControlViewModel } from '@/react/portainer/access-control/models/ResourceControlViewModel';
export function NetworkViewModel(data) {
this.Id = data.Id;
this.Name = data.Name;
this.Scope = data.Scope;
this.Driver = data.Driver;
this.Attachable = data.Attachable;
this.Internal = data.Internal;
this.IPAM = data.IPAM;
this.Containers = data.Containers;
this.Options = data.Options;
this.Ingress = data.Ingress;
this.Labels = data.Labels;
if (this.Labels && this.Labels['com.docker.compose.project']) {
this.StackName = this.Labels['com.docker.compose.project'];
} else if (this.Labels && this.Labels['com.docker.stack.namespace']) {
this.StackName = this.Labels['com.docker.stack.namespace'];
}
if (data.Portainer) {
if (data.Portainer.ResourceControl) {
this.ResourceControl = new ResourceControlViewModel(data.Portainer.ResourceControl);
}
if (data.Portainer.Agent && data.Portainer.Agent.NodeName) {
this.NodeName = data.Portainer.Agent.NodeName;
}
}
this.ConfigFrom = data.ConfigFrom;
this.ConfigOnly = data.ConfigOnly;
}

View file

@ -0,0 +1,79 @@
import { IPAM, Network, NetworkContainer } from 'docker-types/generated/1.41';
import { ResourceControlViewModel } from '@/react/portainer/access-control/models/ResourceControlViewModel';
import { IResource } from '@/react/docker/components/datatable/createOwnershipColumn';
import { PortainerMetadata } from '@/react/docker/types';
export class NetworkViewModel implements IResource {
Id: string;
Name: string;
Scope: string;
Driver: string;
Attachable: boolean;
Internal: boolean;
IPAM?: IPAM;
Containers?: Record<string, NetworkContainer>;
Options?: Record<string, string>;
Ingress: boolean;
Labels: Record<string, string>;
StackName?: string;
NodeName?: string;
ConfigFrom?: { Network: string };
ConfigOnly?: boolean;
ResourceControl?: ResourceControlViewModel;
constructor(
data: Network & {
Portainer?: PortainerMetadata;
ConfigFrom?: { Network: string };
ConfigOnly?: boolean;
}
) {
this.Id = data.Id || '';
this.Name = data.Name || '';
this.Scope = data.Scope || '';
this.Driver = data.Driver || '';
this.Attachable = data.Attachable || false;
this.Internal = data.Internal || false;
this.IPAM = data.IPAM;
this.Containers = data.Containers;
this.Options = data.Options;
this.Ingress = data.Ingress || false;
this.Labels = data.Labels || {};
if (this.Labels && this.Labels['com.docker.compose.project']) {
this.StackName = this.Labels['com.docker.compose.project'];
} else if (this.Labels && this.Labels['com.docker.stack.namespace']) {
this.StackName = this.Labels['com.docker.stack.namespace'];
}
if (data.Portainer) {
if (data.Portainer.ResourceControl) {
this.ResourceControl = new ResourceControlViewModel(
data.Portainer.ResourceControl
);
}
if (data.Portainer.Agent && data.Portainer.Agent.NodeName) {
this.NodeName = data.Portainer.Agent.NodeName;
}
}
this.ConfigFrom = data.ConfigFrom;
this.ConfigOnly = data.ConfigOnly;
}
}

View file

@ -10,9 +10,7 @@ import {
ResourceObject,
} from 'docker-types/generated/1.41';
type WithRequiredProperty<Type, Key extends keyof Type> = Type & {
[Property in Key]-?: Type[Property];
};
import { WithRequiredProperty } from '@/types';
export class NodeViewModel {
Model: Node;