Skip to content

Commit

Permalink
fix(dedicated-cloud): replace description by name in breadcrumb (#13249)
Browse files Browse the repository at this point in the history
ref: MANAGER-15258

Signed-off-by: Thibaud Crespin <[email protected]>
  • Loading branch information
ThibaudCrespin authored and chipp972 committed Oct 29, 2024
1 parent 39930cc commit b1d1b3a
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,6 @@ export default class {
datacenterId: this.datacenter.model.id,
destinationId,
value,
}).result.then((newValue) => {
if (contextTitle === 'dedicatedCloud_datacenter_name') {
this.datacenter.model.name = newValue;
} else {
this.datacenter.model.description = newValue;
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ export default class {
'dedicatedCloud_dashboard_nameModifying_success',
),
value,
}).result.then((newDescription) => {
this.dedicatedCloud.description = newDescription;
});
}).result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import isUndefined from 'lodash/isUndefined';
import set from 'lodash/set';
import snakeCase from 'lodash/snakeCase';
import some from 'lodash/some';
import toNumber from 'lodash/toNumber';

import {
DEDICATED_CLOUD_CONSTANTS,
Expand Down Expand Up @@ -344,59 +343,18 @@ class DedicatedCloudService {
);
}

getDatacenterInformations(serviceName, datacenterId, forceRefresh) {
return this.OvhHttp.get(
'/sws/dedicatedCloud/{serviceName}/datacenters/{datacenterId}',
{
rootPath: '2api',
urlParams: {
serviceName,
datacenterId,
},
cache: 'SUB_DATACENTERS',
clearCache: forceRefresh,
},
);
}

updateDatacenterName(serviceName, datacenterId, name) {
return this.OvhHttp.put(
'/dedicatedCloud/{serviceName}/datacenter/{datacenterId}',
{
rootPath: 'apiv6',
urlParams: {
serviceName,
datacenterId,
},
data: {
name,
},
},
);
getDatacenterInformations(serviceName, datacenterId) {
return this.$http
.get(`/sws/dedicatedCloud/${serviceName}/datacenters/${datacenterId}`, {
serviceType: 'aapi',
})
.then(({ data }) => data);
}

updateDatacenterDescription(serviceName, datacenterId, description) {
return this.OvhHttp.put(
'/dedicatedCloud/{serviceName}/datacenter/{datacenterId}',
{
rootPath: 'apiv6',
urlParams: {
serviceName,
datacenterId,
},
data: {
description,
},
broadcast: 'global_display_name_change',
broadcastParam: {
stateParams: {
productId: serviceName,
datacenterId: toNumber(datacenterId),
},
displayName: description,
},
},
);
updateDatacenterData(serviceName, datacenterId, data) {
return this.$http
.put(`/dedicatedCloud/${serviceName}/datacenter/${datacenterId}`, data)
.then(({ data: result }) => result);
}

/* ------- SUB DATACENTER HOSTS -------*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,52 @@ angular.module('App').controller(
'NameEditionCtrl',
class NameEditionCtrl {
/* @ngInject */
constructor($translate, $uibModalInstance, Alerter, DedicatedCloud, data) {
constructor(
$translate,
$interval,
$state,
$uibModalInstance,
Alerter,
DedicatedCloud,
data,
) {
this.$translate = $translate;
this.$interval = $interval;
this.$state = $state;
this.$uibModalInstance = $uibModalInstance;
this.Alerter = Alerter;
this.DedicatedCloud = DedicatedCloud;
this.data = data;
this.$poll = null;
}

pollTask(taskId) {
this.$poll = this.$interval(() => {
this.DedicatedCloud.getOperation(this.data.productId, {
taskId,
})
.then(({ state }) => {
if (state === 'done') {
this.stopPollTask();
this.$state.reload();
}
})
.catch(this.stopPollTask);
}, 3000);
}

stopPollTask() {
if (this.$poll) {
this.$interval.cancel(this.$poll);
this.$poll = null;
}
}

updateDescription() {
this.updating = true;

return this.updateName()
.then(() => {
.then((data) => {
if (this.data.successText) {
this.Alerter.success(
this.data.successText,
Expand All @@ -25,6 +58,9 @@ angular.module('App').controller(
}

this.$uibModalInstance.close(this.newValue);
if (data?.taskId) {
this.pollTask(data.taskId);
}
})
.catch((err) => {
const message = this.$translate.instant(
Expand Down Expand Up @@ -59,21 +95,15 @@ angular.module('App').controller(
);
break;
case 'dedicatedCloud_datacenter_name':
this.modalContextTitle = 'dedicatedCloud_datacenter_name';
this.updateName = () =>
this.DedicatedCloud.updateDatacenterName(
this.data.productId,
this.data.datacenterId,
this.newValue,
);
break;
case 'dedicatedCloud_datacenter_description':
this.modalContextTitle = 'dedicatedCloud_datacenter_description';
this.modalContextTitle = this.data.contextTitle;
this.updateName = () =>
this.DedicatedCloud.updateDatacenterDescription(
this.DedicatedCloud.updateDatacenterData(
this.data.productId,
this.data.datacenterId,
this.newValue,
this.modalContextTitle.endsWith('name')
? { name: this.newValue }
: { description: this.newValue },
);
break;
default:
Expand All @@ -82,5 +112,9 @@ angular.module('App').controller(
break;
}
}

$onDestroy() {
this.stopPollTask();
}
},
);
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<form name="updateNameForm" novalidate>
<oui-modal
data-primary-label="{{ :: 'common_change' | translate }}"
data-primary-disabled="updateNameForm.$invalid"
data-primary-disabled="updateNameForm.$invalid || $ctrl.newValue === $ctrl.data.value"
data-primary-action="$ctrl.updateDescription()"
data-secondary-label="{{ :: 'common_cancel' | translate }}"
data-secondary-action="$ctrl.$uibModalInstance.dismiss()"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,7 @@ export default /* @ngInject */ ($stateProvider) => {
...backup,
datacenterId: datacenter.id,
datacenterName:
datacenter.description ||
datacenter.displayName ||
datacenter.id.toString(),
datacenter.displayName || datacenter.id.toString(),
}),
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export default /* @ngInject */ ($stateProvider) => {
DedicatedCloud.getDatacenterInformations(
serviceName,
datacenterId,
true,
).then((datacenter) => ({
model: {
...datacenter,
Expand Down Expand Up @@ -58,7 +57,7 @@ export default /* @ngInject */ ($stateProvider) => {
'dedicatedCloudDatacenterAlert',
);
},
breadcrumb: /* @ngInject */ (datacenterId) => datacenterId,
breadcrumb: /* @ngInject */ (datacenter) => datacenter.model.name,
},
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export default /* @ngInject */ ($stateProvider) => {
DedicatedCloud.getDatacenterInformations(
serviceName,
datacenterId,
true,
).then((datacenter) => ({
model: {
...datacenter,
Expand Down Expand Up @@ -65,7 +64,7 @@ export default /* @ngInject */ ($stateProvider) => {
'dedicatedCloudDatacenterAlert',
);
},
breadcrumb: /* @ngInject */ (datacenterId) => datacenterId,
breadcrumb: /* @ngInject */ (datacenter) => datacenter.model.name,
trackClick: /* @ngInject */ (atInternet, trackingPrefix) => (click) => {
atInternet.trackClick({
name: `${trackingPrefix}::details::${click}`,
Expand Down

0 comments on commit b1d1b3a

Please sign in to comment.