Skip to content

Commit

Permalink
fix service conversion to route
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieuancelin committed Aug 1, 2023
1 parent f607707 commit 58c35aa
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,53 @@ import { NgSelectRenderer } from '../../components/nginputs';
import { FeedbackButton } from './FeedbackButton';
import { convertAsRoute } from '../../services/BackOfficeServices';
import { useHistory } from 'react-router-dom';
import * as BackOfficeServices from "../../services/BackOfficeServices";
import moment from 'moment';

export function ImportServiceDescriptor({ hide }) {
const [service, setService] = useState();
const history = useHistory();

function conversion() {
return convertAsRoute(service).then((res) => {
return BackOfficeServices
.fetchService("prod", service)
.then(fullService => {
const newService = {
...fullService,
name: '[MIGRATED TO ROUTE, PENDING DELETION] ' + fullService.name,
enabled: false,
metadata: {
...fullService.metadata,
converted_to_route_by: window.__user.email + ' - ' + window.__user.name,
converted_to_route_at: moment().format('YYYY-MM-DD hh:mm:ss')
}
};
return BackOfficeServices.updateService(newService.id, newService).then(() => {
return BackOfficeServices.nextClient
.forEntity('routes')
.create({
...res,
metadata: {
...res.metadata,
converted_from_service_by: window.__user.email + ' - ' + window.__user.name,
converted_from_service_at: moment().format('YYYY-MM-DD hh:mm:ss')
}
})
.then(() => {
history.push(`/routes/${res.id}?tab=informations`);
});
});
})
});
/*
convertAsRoute(service).then((res) => {
history.push(`/routes/${res.id}?tab=informations`, {
routeFromService: res,
});
})*/
}

return (
<div className="wizard">
<div className="wizard-container">
Expand Down Expand Up @@ -38,13 +80,7 @@ export function ImportServiceDescriptor({ hide }) {
disabled={!service}
text="Migrate and start editing"
className="mt-3"
onPress={() =>
convertAsRoute(service).then((res) => {
history.push(`/routes/${res.id}?tab=informations`, {
routeFromService: res,
});
})
}
onPress={() => conversion()}
icon={() => <i className="fas fa-paper-plane" />}
/>
</div>
Expand Down
24 changes: 19 additions & 5 deletions otoroshi/javascript/src/pages/ServicePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { Component, Suspense } from 'react';
import ReactDOM from 'react-dom';
import PropTypes from 'prop-types';
import YAML from 'yaml';
import moment from 'moment';

import cloneDeep from 'lodash/cloneDeep';
import merge from 'lodash/merge';
Expand Down Expand Up @@ -1159,21 +1160,34 @@ export class ServicePage extends Component {

convertToRoute = () => {
window.newConfirm(
"Are you sure you want to do that ? your current service will be disabled, but you'll have to delete it yourself.",
(ok) => {
"Are you sure you want to do that ? your current service will be disabled, but you'll have to delete it yourself."
).then((ok) => {
if (ok) {
BackOfficeServices.convertAsRoute(this.state.service.id).then((res) => {
BackOfficeServices.nextClient
BackOfficeServices
.nextClient
.forEntity('routes')
.create(res)
.create({
...res,
metadata: {
...res.metadata,
converted_from_service_by: window.__user.email + ' - ' + window.__user.name,
converted_from_service_at: moment().format('YYYY-MM-DD hh:mm:ss')
}
})
.then(() => {
const newService = {
...this.state.service,
name: '[MIGRATED TO ROUTE, PENDING DELETION] ' + this.state.service.name,
enabled: false,
metadata: {
...this.state.service.metadata,
converted_to_route_by: window.__user.email + ' - ' + window.__user.name,
converted_to_route_at: moment().format('YYYY-MM-DD hh:mm:ss')
}
};
this.setState({ service: newService }, () => {
BackOfficeServices.saveService(newService).then(() => {
BackOfficeServices.updateService(newService.id, newService).then(() => {
this.props.history.push(`/routes/${res.id}?tab=informations`);
});
});
Expand Down

0 comments on commit 58c35aa

Please sign in to comment.