mirror of https://github.com/portainer/portainer
refactor(containers): migrate restart policy tab to react [EE-5213] (#10347)
parent
3d19c46326
commit
2dfa4a7c45
|
@ -34,6 +34,10 @@ import {
|
||||||
CapabilitiesTab,
|
CapabilitiesTab,
|
||||||
capabilitiesTabUtils,
|
capabilitiesTabUtils,
|
||||||
} from '@/react/docker/containers/CreateView/CapabilitiesTab';
|
} from '@/react/docker/containers/CreateView/CapabilitiesTab';
|
||||||
|
import {
|
||||||
|
RestartPolicyTab,
|
||||||
|
restartPolicyTabUtils,
|
||||||
|
} from '@/react/docker/containers/CreateView/RestartPolicyTab';
|
||||||
|
|
||||||
const ngModule = angular
|
const ngModule = angular
|
||||||
.module('portainer.docker.react.components.containers', [])
|
.module('portainer.docker.react.components.containers', [])
|
||||||
|
@ -103,3 +107,10 @@ withFormValidation(
|
||||||
[],
|
[],
|
||||||
capabilitiesTabUtils.validation
|
capabilitiesTabUtils.validation
|
||||||
);
|
);
|
||||||
|
withFormValidation(
|
||||||
|
ngModule,
|
||||||
|
RestartPolicyTab,
|
||||||
|
'dockerCreateContainerRestartPolicyTab',
|
||||||
|
[],
|
||||||
|
restartPolicyTabUtils.validation
|
||||||
|
);
|
||||||
|
|
|
@ -17,6 +17,7 @@ import './createcontainer.css';
|
||||||
import { envVarsTabUtils } from '@/react/docker/containers/CreateView/EnvVarsTab';
|
import { envVarsTabUtils } from '@/react/docker/containers/CreateView/EnvVarsTab';
|
||||||
import { getContainers } from '@/react/docker/containers/queries/containers';
|
import { getContainers } from '@/react/docker/containers/queries/containers';
|
||||||
import { resourcesTabUtils } from '@/react/docker/containers/CreateView/ResourcesTab';
|
import { resourcesTabUtils } from '@/react/docker/containers/CreateView/ResourcesTab';
|
||||||
|
import { restartPolicyTabUtils } from '@/react/docker/containers/CreateView/RestartPolicyTab';
|
||||||
|
|
||||||
angular.module('portainer.docker').controller('CreateContainerController', [
|
angular.module('portainer.docker').controller('CreateContainerController', [
|
||||||
'$q',
|
'$q',
|
||||||
|
@ -86,12 +87,14 @@ angular.module('portainer.docker').controller('CreateContainerController', [
|
||||||
AccessControlData: new AccessControlFormData(),
|
AccessControlData: new AccessControlFormData(),
|
||||||
NodeName: null,
|
NodeName: null,
|
||||||
RegistryModel: new PorImageRegistryModel(),
|
RegistryModel: new PorImageRegistryModel(),
|
||||||
|
|
||||||
commands: commandsTabUtils.getDefaultViewModel(),
|
commands: commandsTabUtils.getDefaultViewModel(),
|
||||||
envVars: envVarsTabUtils.getDefaultViewModel(),
|
envVars: envVarsTabUtils.getDefaultViewModel(),
|
||||||
volumes: volumesTabUtils.getDefaultViewModel(),
|
volumes: volumesTabUtils.getDefaultViewModel(),
|
||||||
network: networkTabUtils.getDefaultViewModel(),
|
network: networkTabUtils.getDefaultViewModel(),
|
||||||
resources: resourcesTabUtils.getDefaultViewModel(),
|
resources: resourcesTabUtils.getDefaultViewModel(),
|
||||||
capabilities: capabilitiesTabUtils.getDefaultViewModel(),
|
capabilities: capabilitiesTabUtils.getDefaultViewModel(),
|
||||||
|
restartPolicy: restartPolicyTabUtils.getDefaultViewModel(),
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.state = {
|
$scope.state = {
|
||||||
|
@ -146,6 +149,12 @@ angular.module('portainer.docker').controller('CreateContainerController', [
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
$scope.onRestartPolicyChange = function (restartPolicy) {
|
||||||
|
return $scope.$evalAsync(() => {
|
||||||
|
$scope.formValues.restartPolicy = restartPolicy;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
function onAlwaysPullChange(checked) {
|
function onAlwaysPullChange(checked) {
|
||||||
return $scope.$evalAsync(() => {
|
return $scope.$evalAsync(() => {
|
||||||
$scope.formValues.alwaysPull = checked;
|
$scope.formValues.alwaysPull = checked;
|
||||||
|
@ -315,6 +324,7 @@ angular.module('portainer.docker').controller('CreateContainerController', [
|
||||||
config = networkTabUtils.toRequest(config, $scope.formValues.network, $scope.fromContainer.Id);
|
config = networkTabUtils.toRequest(config, $scope.formValues.network, $scope.fromContainer.Id);
|
||||||
config = resourcesTabUtils.toRequest(config, $scope.formValues.resources);
|
config = resourcesTabUtils.toRequest(config, $scope.formValues.resources);
|
||||||
config = capabilitiesTabUtils.toRequest(config, $scope.formValues.capabilities);
|
config = capabilitiesTabUtils.toRequest(config, $scope.formValues.capabilities);
|
||||||
|
config = restartPolicyTabUtils.toRequest(config, $scope.formValues.restartPolicy);
|
||||||
|
|
||||||
prepareImageConfig(config);
|
prepareImageConfig(config);
|
||||||
preparePortBindings(config);
|
preparePortBindings(config);
|
||||||
|
@ -372,6 +382,8 @@ angular.module('portainer.docker').controller('CreateContainerController', [
|
||||||
$scope.formValues.resources = resourcesTabUtils.toViewModel(d);
|
$scope.formValues.resources = resourcesTabUtils.toViewModel(d);
|
||||||
$scope.formValues.capabilities = capabilitiesTabUtils.toViewModel(d);
|
$scope.formValues.capabilities = capabilitiesTabUtils.toViewModel(d);
|
||||||
|
|
||||||
|
$scope.formValues.restartPolicy = restartPolicyTabUtils.toViewModel(d);
|
||||||
|
|
||||||
loadFromContainerPortBindings(d);
|
loadFromContainerPortBindings(d);
|
||||||
loadFromContainerLabels(d);
|
loadFromContainerLabels(d);
|
||||||
loadFromContainerImageConfig(d);
|
loadFromContainerImageConfig(d);
|
||||||
|
|
|
@ -264,23 +264,11 @@
|
||||||
></docker-create-container-env-vars-tab>
|
></docker-create-container-env-vars-tab>
|
||||||
</div>
|
</div>
|
||||||
<!-- !tab-env -->
|
<!-- !tab-env -->
|
||||||
<!-- tab-restart-policy -->
|
|
||||||
<div class="tab-pane" id="restart-policy">
|
<div class="tab-pane" id="restart-policy">
|
||||||
<form class="form-horizontal" style="margin-top: 15px">
|
<docker-create-container-restart-policy-tab values="formValues.restartPolicy" on-change="(onRestartPolicyChange)"></docker-create-container-restart-policy-tab>
|
||||||
<div class="form-group">
|
|
||||||
<div class="col-sm-12">
|
|
||||||
<label class="control-label text-left"> Restart policy </label>
|
|
||||||
<div class="btn-group btn-group-sm" style="margin-left: 20px">
|
|
||||||
<label class="btn btn-light" ng-model="config.HostConfig.RestartPolicy.Name" uib-btn-radio="'no'"> Never </label>
|
|
||||||
<label class="btn btn-light" ng-model="config.HostConfig.RestartPolicy.Name" uib-btn-radio="'always'"> Always </label>
|
|
||||||
<label class="btn btn-light" ng-model="config.HostConfig.RestartPolicy.Name" uib-btn-radio="'on-failure'"> On failure </label>
|
|
||||||
<label class="btn btn-light" ng-model="config.HostConfig.RestartPolicy.Name" uib-btn-radio="'unless-stopped'"> Unless stopped </label>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</div>
|
</div>
|
||||||
<!-- !tab-restart-policy -->
|
|
||||||
<!-- tab-runtime-resources -->
|
<!-- tab-runtime-resources -->
|
||||||
<div class="tab-pane" id="runtime-resources">
|
<div class="tab-pane" id="runtime-resources">
|
||||||
<docker-create-container-resources-tab
|
<docker-create-container-resources-tab
|
||||||
|
|
|
@ -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…
Reference in New Issue