mirror of
https://github.com/portainer/portainer.git
synced 2025-07-25 00:09:40 +02:00
refactor(containers): migrate restart policy tab to react [EE-5213] (#10347)
This commit is contained in:
parent
3d19c46326
commit
2dfa4a7c45
9 changed files with 122 additions and 15 deletions
|
@ -0,0 +1,27 @@
|
|||
import { ButtonSelector } from '@@/form-components/ButtonSelector/ButtonSelector';
|
||||
import { FormControl } from '@@/form-components/FormControl';
|
||||
|
||||
import { RestartPolicy } from './types';
|
||||
|
||||
export function RestartPolicyTab({
|
||||
values,
|
||||
onChange,
|
||||
}: {
|
||||
values: RestartPolicy;
|
||||
onChange: (values: RestartPolicy) => void;
|
||||
}) {
|
||||
return (
|
||||
<FormControl label="Restart Policy">
|
||||
<ButtonSelector
|
||||
options={[
|
||||
{ label: 'Never', value: RestartPolicy.No },
|
||||
{ label: 'Always', value: RestartPolicy.Always },
|
||||
{ label: 'On failure', value: RestartPolicy.OnFailure },
|
||||
{ label: 'Unless stopped', value: RestartPolicy.UnlessStopped },
|
||||
]}
|
||||
value={values}
|
||||
onChange={onChange}
|
||||
/>
|
||||
</FormControl>
|
||||
);
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
import { validation } from './validation';
|
||||
import { toViewModel, getDefaultViewModel } from './toViewModel';
|
||||
import { toRequest } from './toRequest';
|
||||
|
||||
export { RestartPolicyTab } from './RestartPolicyTab';
|
||||
export { RestartPolicy } from './types';
|
||||
|
||||
export const restartPolicyTabUtils = {
|
||||
toViewModel,
|
||||
toRequest,
|
||||
validation,
|
||||
getDefaultViewModel,
|
||||
};
|
|
@ -0,0 +1,19 @@
|
|||
import { CreateContainerRequest } from '../types';
|
||||
|
||||
import { RestartPolicy } from './types';
|
||||
|
||||
export function toRequest(
|
||||
config: CreateContainerRequest,
|
||||
value: RestartPolicy
|
||||
): CreateContainerRequest {
|
||||
return {
|
||||
...config,
|
||||
HostConfig: {
|
||||
...config.HostConfig,
|
||||
RestartPolicy: {
|
||||
...config.HostConfig.RestartPolicy,
|
||||
Name: value,
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
import { ContainerJSON } from '../../queries/container';
|
||||
|
||||
import { RestartPolicy } from './types';
|
||||
|
||||
export function toViewModel(config: ContainerJSON): RestartPolicy {
|
||||
switch (config.HostConfig?.RestartPolicy?.Name) {
|
||||
case 'always':
|
||||
return RestartPolicy.Always;
|
||||
case 'on-failure':
|
||||
return RestartPolicy.OnFailure;
|
||||
case 'unless-stopped':
|
||||
return RestartPolicy.UnlessStopped;
|
||||
case 'no':
|
||||
default:
|
||||
return RestartPolicy.No;
|
||||
}
|
||||
}
|
||||
|
||||
export function getDefaultViewModel(): RestartPolicy {
|
||||
return RestartPolicy.No;
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
// Enum version of RestartPolicy
|
||||
export enum RestartPolicy {
|
||||
No = 'no',
|
||||
Always = 'always',
|
||||
OnFailure = 'on-failure',
|
||||
UnlessStopped = 'unless-stopped',
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
import { mixed, SchemaOf } from 'yup';
|
||||
|
||||
import { RestartPolicy } from './types';
|
||||
|
||||
export function validation(): SchemaOf<RestartPolicy> {
|
||||
return mixed<RestartPolicy>()
|
||||
.oneOf(Object.values(RestartPolicy))
|
||||
.default(RestartPolicy.No) as SchemaOf<RestartPolicy>;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue