mirror of
https://github.com/portainer/portainer.git
synced 2025-07-22 06:49:40 +02:00
refactor(docker/containers): migrate commands tab to react [EE-5208] (#10085)
This commit is contained in:
parent
46e73ee524
commit
f7366d9788
42 changed files with 1783 additions and 951 deletions
|
@ -0,0 +1,70 @@
|
|||
import { HostConfig } from 'docker-types/generated/1.41';
|
||||
|
||||
import { commandArrayToString } from '@/docker/helpers/containers';
|
||||
|
||||
import { ContainerJSON } from '../../queries/container';
|
||||
|
||||
import { ConsoleConfig, ConsoleSetting } from './ConsoleSettings';
|
||||
import { LogConfig } from './LoggerConfig';
|
||||
import { Values } from './types';
|
||||
|
||||
export function getDefaultViewModel(): Values {
|
||||
return {
|
||||
cmd: null,
|
||||
entrypoint: null,
|
||||
user: '',
|
||||
workingDir: '',
|
||||
console: 'none',
|
||||
logConfig: getLogConfig(),
|
||||
};
|
||||
}
|
||||
|
||||
export function toViewModel(config: ContainerJSON): Values {
|
||||
if (!config.Config) {
|
||||
return getDefaultViewModel();
|
||||
}
|
||||
|
||||
return {
|
||||
cmd: config.Config.Cmd ? commandArrayToString(config.Config.Cmd) : null,
|
||||
entrypoint: config.Config.Entrypoint
|
||||
? commandArrayToString(config.Config.Entrypoint)
|
||||
: null,
|
||||
user: config.Config.User || '',
|
||||
workingDir: config.Config.WorkingDir || '',
|
||||
console: config ? getConsoleSetting(config.Config) : 'none',
|
||||
logConfig: getLogConfig(config.HostConfig?.LogConfig),
|
||||
};
|
||||
}
|
||||
|
||||
function getLogConfig(value?: HostConfig['LogConfig']): LogConfig {
|
||||
if (!value || !value.Type) {
|
||||
return {
|
||||
type: 'none',
|
||||
options: [],
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
type: value.Type,
|
||||
options: Object.entries(value.Config || {}).map(([option, value]) => ({
|
||||
option,
|
||||
value,
|
||||
})),
|
||||
};
|
||||
}
|
||||
|
||||
function getConsoleSetting(value: ConsoleConfig): ConsoleSetting {
|
||||
if (value.OpenStdin && value.Tty) {
|
||||
return 'both';
|
||||
}
|
||||
|
||||
if (!value.OpenStdin && value.Tty) {
|
||||
return 'tty';
|
||||
}
|
||||
|
||||
if (value.OpenStdin && !value.Tty) {
|
||||
return 'interactive';
|
||||
}
|
||||
|
||||
return 'none';
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue