mirror of
https://github.com/portainer/portainer.git
synced 2025-07-22 06:49:40 +02:00
refactor(containers): migrate resources tab to react [EE-5214] (#10355)
This commit is contained in:
parent
ec091efe3b
commit
ffac83864d
28 changed files with 1114 additions and 537 deletions
|
@ -0,0 +1,49 @@
|
|||
import { ContainerJSON } from '../../queries/container';
|
||||
|
||||
import { toDevicesViewModel } from './DevicesField';
|
||||
import { gpuFieldsetUtils } from './GpuFieldset';
|
||||
import { toViewModelCpu, toViewModelMemory } from './memory-utils';
|
||||
import { Values } from './ResourcesTab';
|
||||
|
||||
export function toViewModel(config: ContainerJSON): Values {
|
||||
return {
|
||||
runtime: {
|
||||
privileged: config.HostConfig?.Privileged || false,
|
||||
init: config.HostConfig?.Init || false,
|
||||
type: config.HostConfig?.Runtime || '',
|
||||
},
|
||||
devices: toDevicesViewModel(config.HostConfig?.Devices || []),
|
||||
sysctls: Object.entries(config.HostConfig?.Sysctls || {}).map(
|
||||
([name, value]) => ({
|
||||
name,
|
||||
value,
|
||||
})
|
||||
),
|
||||
gpu: gpuFieldsetUtils.toViewModel(config.HostConfig?.DeviceRequests || []),
|
||||
sharedMemorySize: toViewModelMemory(config.HostConfig?.ShmSize),
|
||||
resources: {
|
||||
cpu: toViewModelCpu(config.HostConfig?.NanoCpus),
|
||||
reservation: toViewModelMemory(config.HostConfig?.MemoryReservation),
|
||||
limit: toViewModelMemory(config.HostConfig?.Memory),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export function getDefaultViewModel(): Values {
|
||||
return {
|
||||
runtime: {
|
||||
privileged: false,
|
||||
init: false,
|
||||
type: '',
|
||||
},
|
||||
devices: [],
|
||||
sysctls: [],
|
||||
sharedMemorySize: 64,
|
||||
gpu: gpuFieldsetUtils.getDefaultViewModel(),
|
||||
resources: {
|
||||
reservation: 0,
|
||||
limit: 0,
|
||||
cpu: 0,
|
||||
},
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue