New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add an option to mark that the Service acts as product (THREESCALE-3294) #1119
Conversation
9c51cbf
to
8f7b5db
Compare
private | ||
|
||
def find_backend_api | ||
current_account.backend_apis.find(params[:service][:backend_api]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
current_account.backend_apis.find(params.require(:service).require(:backend_api])
because otherwise if service
is not in the params, it will raise NoMethodError
|
||
def service_params | ||
params.require(:service).permit(:system_name, :name, :description, :act_as_product).tap do |p| | ||
p[:backend_api_configs] = [ BackendApiConfig.new(backend_api: find_backend_api) ] if params[:service][:backend_api].present? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
only do this is the account is authorized to do it 😄 or if we are not doing the authorizations in depth yet, then at leaaast make sure the rolling update is enabled
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and add a test to make sure this backend api part works and only if the rolling update is enabled
8f7b5db
to
6d07d6e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SelectBackendApi
should be rendered in NewServiceForm
instead of inside both Service*Form
.
app/javascript/src/NewService/components/FormElements/SelectBackendApi.jsx
Outdated
Show resolved
Hide resolved
import {Label} from 'NewService/components/FormElements' | ||
|
||
const SelectBackendApi = ({backendApis}: {backendApis: Array<{id: number, name: string}>}) => { | ||
const [actAsProduct, setActAsProduct] = useState(false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Flow complaints about this state not being covered, you can give it a type like this: useState<boolean>(false)
Note: in the past this would cause an error in Jest, let's keep an eye on that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see any error in Flow.
Where do you see it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't see error on this too.
app/javascript/src/NewService/components/FormElements/SelectBackendApi.jsx
Outdated
Show resolved
Hide resolved
app/javascript/src/NewService/components/FormElements/SelectBackendApi.jsx
Outdated
Show resolved
Hide resolved
app/javascript/src/NewService/components/FormElements/SelectBackendApi.jsx
Outdated
Show resolved
Hide resolved
app/javascript/src/NewService/components/FormElements/SelectBackendApi.jsx
Outdated
Show resolved
Hide resolved
import {Label} from 'NewService/components/FormElements' | ||
|
||
const SelectBackendApi = ({backendApis}: {backendApis: Array<{id: number, name: string}>}) => { | ||
const [actAsProduct, setActAsProduct] = useState(false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see any error in Flow.
Where do you see it?
htmlFor='service_backend_api' | ||
label='Backend API' | ||
/> | ||
<select name="service[backend_api]" id="service_backend_api"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also have a select
component you can reuse in
app/javascript/src/NewService/components/FormElements/Select.jsx
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't use it because that Select relies to set the value of option the same as the text. I want the id as the value and the name as the text
app/javascript/src/NewService/components/FormElements/ServiceDiscoveryListItems.jsx
Outdated
Show resolved
Hide resolved
app/javascript/src/NewService/components/FormElements/ServiceManualListItems.jsx
Outdated
Show resolved
Hide resolved
app/javascript/src/NewService/components/ServiceDiscoveryForm.jsx
Outdated
Show resolved
Hide resolved
spec/javascripts/NewService/formElements/ServiceDiscoveryListItems.spec.jsx
Outdated
Show resolved
Hide resolved
When an existing Backend API is selected to start the service with (as opposed to using the option "New Backend API"), we need to make sure the existing metrics of that backend API are synced with apisonator together with the new service. Right now I know we sync new metrics just added to a backend through all services using the backend, but not existing metrics of a backend when the backend is added to a service. The same needs to be done when we add a backend API to a existing service. (Another pending issue of APIAP, BTW.) |
990f349
to
14e87f0
Compare
app/javascript/src/NewService/components/FormElements/ServiceManualListItems.jsx
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should remove ServiceManualForm
and ServiceDiscoveryForm
from the map and simply use ServiceManualListItems
and ServiceDiscoveryListItems
respectively.
14e87f0
to
fc39be7
Compare
fc39be7
to
1d21f49
Compare
So, i guess i was out of the loop on this one. In my head services and api as product were never intended to exist side by side and thus this feature of marking a service as a product wouldn't exist. |
@@ -11,6 +11,10 @@ class BackendApiConfig < ApplicationRecord | |||
has_one :proxy, through: :service | |||
has_many :proxy_rules, through: :proxy | |||
|
|||
after_create do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this part of this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes it is. @guicassolato commented that we need to sync the metrics with the backend.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is because you can choose an existing backend API instead of creating a new one.
@thomasmaas @guicassolato @hallelujah so this is not valid ? or we should have this until we do not accept services without api as product? |
48427ed
to
0dd700b
Compare
spec/javascripts/NewService/formElements/BackendApiSelect.spec.jsx
Outdated
Show resolved
Hide resolved
spec/javascripts/NewService/formElements/BackendApiSelect.spec.jsx
Outdated
Show resolved
Hide resolved
spec/javascripts/NewService/formElements/BackendApiSelect.spec.jsx
Outdated
Show resolved
Hide resolved
spec/javascripts/NewService/formElements/BackendApiSelect.spec.jsx
Outdated
Show resolved
Hide resolved
41883ef
to
92924b2
Compare
THREESCALE-3294 This commit adds a new option in the screen to create a service to inform that it will act as product. If this options is checked, it will present a select to choose which backend api will be attached or if it will create a new one.
92924b2
to
5ed20fd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@duduribeiro It's OK for me, but let's wait for an approval of a rubyist
@@ -34,8 +36,8 @@ def settings | |||
|
|||
def create | |||
@service = collection.new # this is done in 2 steps so that the account_id is in place as preffix_key relies on it | |||
@service.attributes = params[:service] | |||
@service.system_name = params[:service][:system_name] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did system_name
need to be set separately and now we don't?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really don't know. I thought this was strange and removed, and it worked .
def service_params | ||
allowed_params = %i[system_name name description] | ||
allowed_params << :act_as_product if provider_can_use?(:api_as_product) | ||
params.require(:service).permit(allowed_params) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
params.require(:service).permit(allowed_params) | |
params.require(:service).permit(*allowed_params) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really needed as Rails flattens the array.
What this PR does / why we need it:
This commit adds a new option in the screen to create a service
to inform if it will act as product. If this options is checked, it will
present a select to choose which backend api it will be attached
or if it will create a new one.
This is when you create a Service without checking act as product:
This is when you create a Service checking act as product and let it create a new Backend API:
This is when you create a Service checking act as product and select an already existent Backend API:
Which issue(s) this PR fixes
THREESCALE-3294
Verification steps
act as product
checkbox.act as product
checkbox and selectingNew Backend API
in the Backend API combo box.act as product
checkbox and selecting some already created backend api in the Backend API combo box.