Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
8b39e171
Commit
8b39e171
authored
Apr 30, 2021
by
Angelo Gulina
Committed by
Frédéric Caplette
Apr 30, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Subscription Activation Modal: Better arrange GraphQL mutation and query
parent
65aa90c7
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
111 additions
and
92 deletions
+111
-92
ee/app/assets/javascripts/pages/admin/cloud_licenses/components/app.vue
...javascripts/pages/admin/cloud_licenses/components/app.vue
+21
-14
ee/app/assets/javascripts/pages/admin/cloud_licenses/components/subscription_activation_form.vue
...loud_licenses/components/subscription_activation_form.vue
+39
-23
ee/app/assets/javascripts/pages/admin/cloud_licenses/graphql/fragments/license.fragment.graphql
...cloud_licenses/graphql/fragments/license.fragment.graphql
+16
-0
ee/app/assets/javascripts/pages/admin/cloud_licenses/graphql/mutations/activate_subscription.mutation.graphql
.../graphql/mutations/activate_subscription.mutation.graphql
+3
-14
ee/app/assets/javascripts/pages/admin/cloud_licenses/graphql/queries/get_current_license.query.graphql
...icenses/graphql/queries/get_current_license.query.graphql
+3
-14
ee/app/assets/javascripts/pages/admin/cloud_licenses/show/mount_cloud_licenses.js
...s/pages/admin/cloud_licenses/show/mount_cloud_licenses.js
+6
-1
ee/spec/frontend/admin/cloud_licenses/components/app_spec.js
ee/spec/frontend/admin/cloud_licenses/components/app_spec.js
+18
-13
ee/spec/frontend/admin/cloud_licenses/components/subscription_activation_form_spec.js
..._licenses/components/subscription_activation_form_spec.js
+3
-11
ee/spec/frontend/admin/cloud_licenses/mock_data.js
ee/spec/frontend/admin/cloud_licenses/mock_data.js
+2
-2
No files found.
ee/app/assets/javascripts/pages/admin/cloud_licenses/components/app.vue
View file @
8b39e171
...
@@ -37,10 +37,10 @@ export default {
...
@@ -37,10 +37,10 @@ export default {
currentSubscription
:
{
currentSubscription
:
{
query
:
subscriptionQueries
.
query
,
query
:
subscriptionQueries
.
query
,
update
({
currentLicense
})
{
update
({
currentLicense
})
{
return
currentLicense
;
return
currentLicense
||
{}
;
},
},
skip
(
)
{
result
({
data
}
)
{
return
!
this
.
canShowSubscriptionDetails
;
this
.
hasNewLicense
=
data
?.
currentLicense
&&
!
this
.
hasActiveLicense
;
},
},
},
},
subscriptionHistory
:
{
subscriptionHistory
:
{
...
@@ -52,20 +52,27 @@ export default {
...
@@ -52,20 +52,27 @@ export default {
},
},
data
()
{
data
()
{
return
{
return
{
canShowSubscriptionDetails
:
this
.
hasActiveLicense
,
currentSubscription
:
{},
currentSubscription
:
{},
shouldShowSubscriptionActivationNotification
:
false
,
hasDismissedNotification
:
false
,
hasNewLicense
:
false
,
subscriptionHistory
:
[],
subscriptionHistory
:
[],
notification
:
null
,
notification
:
null
,
};
};
},
},
methods
:
{
computed
:
{
didDismissSuccessAlert
()
{
hasValidSubscriptionData
()
{
this
.
shouldShowSubscriptionActivationNotification
=
false
;
return
Boolean
(
Object
.
keys
(
this
.
currentSubscription
).
length
);
},
canShowSubscriptionDetails
()
{
return
this
.
hasActiveLicense
||
this
.
hasValidSubscriptionData
;
},
shouldShowActivationNotification
()
{
return
!
this
.
hasDismissedNotification
&&
this
.
hasNewLicense
&&
this
.
hasValidSubscriptionData
;
},
},
handleActivation
(
hasLicense
)
{
},
this
.
shouldShowSubscriptionActivationNotification
=
hasLicense
;
methods
:
{
this
.
canShowSubscriptionDetails
=
hasLicense
;
dismissSuccessAlert
()
{
this
.
hasDismissedNotification
=
true
;
},
},
},
},
};
};
...
@@ -76,12 +83,12 @@ export default {
...
@@ -76,12 +83,12 @@ export default {
<h4
data-testid=
"subscription-main-title"
>
{{
$options
.
i18n
.
subscriptionMainTitle
}}
</h4>
<h4
data-testid=
"subscription-main-title"
>
{{
$options
.
i18n
.
subscriptionMainTitle
}}
</h4>
<hr
/>
<hr
/>
<gl-alert
<gl-alert
v-if=
"shouldShow
Subscription
ActivationNotification"
v-if=
"shouldShowActivationNotification"
variant=
"success"
variant=
"success"
:title=
"$options.i18n.subscriptionActivationNotificationText"
:title=
"$options.i18n.subscriptionActivationNotificationText"
class=
"mb-4"
class=
"mb-4"
data-testid=
"subscription-activation-success-alert"
data-testid=
"subscription-activation-success-alert"
@
dismiss=
"di
dDi
smissSuccessAlert"
@
dismiss=
"dismissSuccessAlert"
/>
/>
<subscription-breakdown
<subscription-breakdown
v-if=
"canShowSubscriptionDetails"
v-if=
"canShowSubscriptionDetails"
...
@@ -93,7 +100,7 @@ export default {
...
@@ -93,7 +100,7 @@ export default {
<h3
class=
"gl-mb-7 gl-mt-6 gl-text-center"
data-testid=
"subscription-activation-title"
>
<h3
class=
"gl-mb-7 gl-mt-6 gl-text-center"
data-testid=
"subscription-activation-title"
>
{{
$options
.
i18n
.
subscriptionActivationTitle
}}
{{
$options
.
i18n
.
subscriptionActivationTitle
}}
</h3>
</h3>
<cloud-license-subscription-activation-form
@
subscription-activation=
"handleActivation"
/>
<cloud-license-subscription-activation-form
/>
<div
class=
"row gl-mt-7"
>
<div
class=
"row gl-mt-7"
>
<div
class=
"col-lg-6"
>
<div
class=
"col-lg-6"
>
<subscription-trial-card
/>
<subscription-trial-card
/>
...
...
ee/app/assets/javascripts/pages/admin/cloud_licenses/components/subscription_activation_form.vue
View file @
8b39e171
...
@@ -9,6 +9,7 @@ import {
...
@@ -9,6 +9,7 @@ import {
GlLink
,
GlLink
,
GlSprintf
,
GlSprintf
,
}
from
'
@gitlab/ui
'
;
}
from
'
@gitlab/ui
'
;
import
produce
from
'
immer
'
;
import
{
helpPagePath
}
from
'
~/helpers/help_page_helper
'
;
import
{
helpPagePath
}
from
'
~/helpers/help_page_helper
'
;
import
validation
from
'
~/vue_shared/directives/validation
'
;
import
validation
from
'
~/vue_shared/directives/validation
'
;
import
{
import
{
...
@@ -17,19 +18,22 @@ import {
...
@@ -17,19 +18,22 @@ import {
subscriptionQueries
,
subscriptionQueries
,
}
from
'
../constants
'
;
}
from
'
../constants
'
;
export
const
SUBSCRIPTION_ACTIVATION_EVENT
=
'
subscription-activation
'
;
const
getLicenseFromData
=
({
data
:
{
gitlabSubscriptionActivate
:
{
license
},
},
})
=>
license
;
const
getErrorsAsData
=
({
data
:
{
gitlabSubscriptionActivate
:
{
errors
},
},
})
=>
errors
;
export
const
SUBSCRIPTION_ACTIVATION_FAILURE_EVENT
=
'
subscription-activation-failure
'
;
export
const
adminLicenseUrl
=
helpPagePath
(
'
/user/admin_area/license
'
);
export
const
adminLicenseUrl
=
helpPagePath
(
'
/user/admin_area/license
'
);
export
default
{
export
default
{
i18n
:
{
title
:
subscriptionActivationForm
.
title
,
howToActivateSubscription
:
subscriptionActivationForm
.
howToActivateSubscription
,
activationCode
:
subscriptionActivationForm
.
activationCode
,
pasteActivationCode
:
subscriptionActivationForm
.
pasteActivationCode
,
acceptTerms
:
subscriptionActivationForm
.
acceptTerms
,
activateLabel
:
subscriptionActivationForm
.
activateLabel
,
fieldRequiredMessage
,
},
name
:
'
CloudLicenseSubscriptionActivationForm
'
,
name
:
'
CloudLicenseSubscriptionActivationForm
'
,
components
:
{
components
:
{
GlButton
,
GlButton
,
...
@@ -41,12 +45,22 @@ export default {
...
@@ -41,12 +45,22 @@ export default {
GlSprintf
,
GlSprintf
,
GlLink
,
GlLink
,
},
},
i18n
:
{
title
:
subscriptionActivationForm
.
title
,
howToActivateSubscription
:
subscriptionActivationForm
.
howToActivateSubscription
,
activationCode
:
subscriptionActivationForm
.
activationCode
,
pasteActivationCode
:
subscriptionActivationForm
.
pasteActivationCode
,
acceptTerms
:
subscriptionActivationForm
.
acceptTerms
,
activateLabel
:
subscriptionActivationForm
.
activateLabel
,
fieldRequiredMessage
,
},
links
:
{
links
:
{
adminLicenseUrl
,
adminLicenseUrl
,
},
},
directives
:
{
directives
:
{
validation
:
validation
(),
validation
:
validation
(),
},
},
emits
:
[
SUBSCRIPTION_ACTIVATION_FAILURE_EVENT
],
data
()
{
data
()
{
const
form
=
{
const
form
=
{
state
:
false
,
state
:
false
,
...
@@ -95,21 +109,23 @@ export default {
...
@@ -95,21 +109,23 @@ export default {
activationCode
:
this
.
form
.
fields
.
activationCode
.
value
,
activationCode
:
this
.
form
.
fields
.
activationCode
.
value
,
},
},
},
},
})
update
:
(
cache
,
mutation
)
=>
{
.
then
(
const
license
=
getLicenseFromData
(
mutation
);
({
const
{
query
}
=
subscriptionQueries
;
data
:
{
const
data
=
produce
(
license
,
(
draftData
)
=>
{
gitlabSubscriptionActivate
:
{
errors
},
draftData
.
currentLicense
=
license
;
},
});
})
=>
{
cache
.
writeQuery
({
query
,
data
});
if
(
errors
.
length
)
{
throw
new
Error
();
}
this
.
$emit
(
SUBSCRIPTION_ACTIVATION_EVENT
,
true
);
},
},
)
})
.
then
((
res
)
=>
{
const
errors
=
getErrorsAsData
(
res
);
if
(
errors
.
length
)
{
throw
new
Error
();
}
})
.
catch
(()
=>
{
.
catch
(()
=>
{
this
.
$emit
(
SUBSCRIPTION_ACTIVATION_EVENT
,
null
);
this
.
$emit
(
SUBSCRIPTION_ACTIVATION_
FAILURE_
EVENT
,
null
);
})
})
.
finally
(()
=>
{
.
finally
(()
=>
{
this
.
isLoading
=
false
;
this
.
isLoading
=
false
;
...
...
ee/app/assets/javascripts/pages/admin/cloud_licenses/graphql/fragments/license.fragment.graphql
0 → 100644
View file @
8b39e171
fragment
License
on
CurrentLicense
{
id
type
plan
name
email
company
startsAt
expiresAt
activatedAt
lastSync
usersInLicenseCount
billableUsersCount
maximumUserCount
usersOverLicenseCount
}
ee/app/assets/javascripts/pages/admin/cloud_licenses/graphql/mutations/activate_subscription.mutation.graphql
View file @
8b39e171
#import "../fragments/license.fragment.graphql"
mutation
(
$gitlabSubscriptionActivateInput
:
GitlabSubscriptionActivateInput
!)
{
mutation
(
$gitlabSubscriptionActivateInput
:
GitlabSubscriptionActivateInput
!)
{
gitlabSubscriptionActivate
(
input
:
$gitlabSubscriptionActivateInput
)
{
gitlabSubscriptionActivate
(
input
:
$gitlabSubscriptionActivateInput
)
{
errors
errors
license
{
license
{
id
...
License
type
plan
name
email
company
startsAt
expiresAt
activatedAt
lastSync
usersInLicenseCount
billableUsersCount
maximumUserCount
usersOverLicenseCount
}
}
}
}
}
}
ee/app/assets/javascripts/pages/admin/cloud_licenses/graphql/queries/get_current_license.query.graphql
View file @
8b39e171
#import "../fragments/license.fragment.graphql"
query
getCurrentLicense
{
query
getCurrentLicense
{
currentLicense
{
currentLicense
{
id
...
License
type
plan
name
email
company
startsAt
expiresAt
activatedAt
lastSync
usersInLicenseCount
billableUsersCount
maximumUserCount
usersOverLicenseCount
}
}
}
}
ee/app/assets/javascripts/pages/admin/cloud_licenses/show/mount_cloud_licenses.js
View file @
8b39e171
...
@@ -8,7 +8,12 @@ import CloudLicenseShowApp from '../components/app.vue';
...
@@ -8,7 +8,12 @@ import CloudLicenseShowApp from '../components/app.vue';
Vue
.
use
(
VueApollo
);
Vue
.
use
(
VueApollo
);
const
apolloProvider
=
new
VueApollo
({
const
apolloProvider
=
new
VueApollo
({
defaultClient
:
createDefaultClient
(),
defaultClient
:
createDefaultClient
(
{},
{
assumeImmutableResults
:
true
,
},
),
});
});
export
default
()
=>
{
export
default
()
=>
{
...
...
ee/spec/frontend/admin/cloud_licenses/components/app_spec.js
View file @
8b39e171
...
@@ -52,12 +52,10 @@ describe('CloudLicenseApp', () => {
...
@@ -52,12 +52,10 @@ describe('CloudLicenseApp', () => {
afterEach
(()
=>
{
afterEach
(()
=>
{
wrapper
.
destroy
();
wrapper
.
destroy
();
currentSubscriptionResolver
.
mockRestore
();
subscriptionHistoryResolver
.
mockRestore
();
});
});
describe
(
'
Subscription Activation Form
'
,
()
=>
{
describe
(
'
Subscription Activation Form
'
,
()
=>
{
beforeEach
(
()
=>
{
it
(
'
shows the main title
'
,
()
=>
{
currentSubscriptionResolver
=
jest
currentSubscriptionResolver
=
jest
.
fn
()
.
fn
()
.
mockResolvedValue
({
data
:
{
currentLicense
:
license
.
ULTIMATE
}
});
.
mockResolvedValue
({
data
:
{
currentLicense
:
license
.
ULTIMATE
}
});
...
@@ -65,21 +63,23 @@ describe('CloudLicenseApp', () => {
...
@@ -65,21 +63,23 @@ describe('CloudLicenseApp', () => {
.
fn
()
.
fn
()
.
mockResolvedValue
({
data
:
{
licenseHistoryEntries
:
{
nodes
:
subscriptionHistory
}
}
});
.
mockResolvedValue
({
data
:
{
licenseHistoryEntries
:
{
nodes
:
subscriptionHistory
}
}
});
createComponent
({},
[
currentSubscriptionResolver
,
subscriptionHistoryResolver
]);
createComponent
({},
[
currentSubscriptionResolver
,
subscriptionHistoryResolver
]);
});
it
(
'
shows the main title
'
,
()
=>
{
expect
(
findSubscriptionMainTitle
().
text
()).
toBe
(
subscriptionMainTitle
);
expect
(
findSubscriptionMainTitle
().
text
()).
toBe
(
subscriptionMainTitle
);
});
});
describe
(
'
without an active license
'
,
()
=>
{
describe
(
'
without an active license
'
,
()
=>
{
beforeEach
(()
=>
{
currentSubscriptionResolver
=
jest
.
fn
()
.
mockResolvedValue
({
data
:
{
currentLicense
:
null
}
});
subscriptionHistoryResolver
=
jest
.
fn
()
.
mockResolvedValue
({
data
:
{
licenseHistoryEntries
:
{
nodes
:
[]
}
}
});
createComponent
({},
[
currentSubscriptionResolver
,
subscriptionHistoryResolver
]);
});
it
(
'
shows a title saying there is no active subscription
'
,
()
=>
{
it
(
'
shows a title saying there is no active subscription
'
,
()
=>
{
expect
(
findSubscriptionActivationTitle
().
text
()).
toBe
(
subscriptionActivationTitle
);
expect
(
findSubscriptionActivationTitle
().
text
()).
toBe
(
subscriptionActivationTitle
);
});
});
it
(
'
does not query for the current license
'
,
()
=>
{
expect
(
currentSubscriptionResolver
).
toHaveBeenCalledTimes
(
0
);
});
it
(
'
queries for the current history
'
,
()
=>
{
it
(
'
queries for the current history
'
,
()
=>
{
expect
(
subscriptionHistoryResolver
).
toHaveBeenCalledTimes
(
1
);
expect
(
subscriptionHistoryResolver
).
toHaveBeenCalledTimes
(
1
);
});
});
...
@@ -88,18 +88,23 @@ describe('CloudLicenseApp', () => {
...
@@ -88,18 +88,23 @@ describe('CloudLicenseApp', () => {
expect
(
findActivateSubscriptionForm
().
exists
()).
toBe
(
true
);
expect
(
findActivateSubscriptionForm
().
exists
()).
toBe
(
true
);
});
});
it
(
'
does not the activation success notification
'
,
()
=>
{
it
(
'
does not
show
the activation success notification
'
,
()
=>
{
expect
(
findSubscriptionActivationSuccessAlert
().
exists
()).
toBe
(
false
);
expect
(
findSubscriptionActivationSuccessAlert
().
exists
()).
toBe
(
false
);
});
});
});
});
describe
(
'
activat
e
the license
'
,
()
=>
{
describe
(
'
activat
ing
the license
'
,
()
=>
{
beforeEach
(()
=>
{
beforeEach
(()
=>
{
currentSubscriptionResolver
=
jest
.
fn
()
.
mockResolvedValue
({
data
:
{
currentLicense
:
license
.
ULTIMATE
}
});
subscriptionHistoryResolver
=
jest
.
fn
()
.
mockResolvedValue
({
data
:
{
licenseHistoryEntries
:
{
nodes
:
subscriptionHistory
}
}
});
createComponent
({
hasActiveLicense
:
false
},
[
createComponent
({
hasActiveLicense
:
false
},
[
currentSubscriptionResolver
,
currentSubscriptionResolver
,
subscriptionHistoryResolver
,
subscriptionHistoryResolver
,
]);
]);
findActivateSubscriptionForm
().
vm
.
$emit
(
'
subscription-activation
'
,
true
);
});
});
it
(
'
passes the correct data to the subscription breakdown
'
,
()
=>
{
it
(
'
passes the correct data to the subscription breakdown
'
,
()
=>
{
...
...
ee/spec/frontend/admin/cloud_licenses/components/subscription_activation_form_spec.js
View file @
8b39e171
...
@@ -2,7 +2,7 @@ import { GlForm, GlFormCheckbox, GlFormInput } from '@gitlab/ui';
...
@@ -2,7 +2,7 @@ import { GlForm, GlFormCheckbox, GlFormInput } from '@gitlab/ui';
import
{
createLocalVue
,
shallowMount
}
from
'
@vue/test-utils
'
;
import
{
createLocalVue
,
shallowMount
}
from
'
@vue/test-utils
'
;
import
VueApollo
from
'
vue-apollo
'
;
import
VueApollo
from
'
vue-apollo
'
;
import
CloudLicenseSubscriptionActivationForm
,
{
import
CloudLicenseSubscriptionActivationForm
,
{
SUBSCRIPTION_ACTIVATION_EVENT
,
SUBSCRIPTION_ACTIVATION_
FAILURE_
EVENT
,
}
from
'
ee/pages/admin/cloud_licenses/components/subscription_activation_form.vue
'
;
}
from
'
ee/pages/admin/cloud_licenses/components/subscription_activation_form.vue
'
;
import
{
fieldRequiredMessage
,
subscriptionQueries
}
from
'
ee/pages/admin/cloud_licenses/constants
'
;
import
{
fieldRequiredMessage
,
subscriptionQueries
}
from
'
ee/pages/admin/cloud_licenses/constants
'
;
import
createMockApollo
from
'
helpers/mock_apollo_helper
'
;
import
createMockApollo
from
'
helpers/mock_apollo_helper
'
;
...
@@ -132,10 +132,6 @@ describe('CloudLicenseApp', () => {
...
@@ -132,10 +132,6 @@ describe('CloudLicenseApp', () => {
},
},
});
});
});
});
it
(
'
emits a successful event
'
,
()
=>
{
expect
(
wrapper
.
emitted
(
SUBSCRIPTION_ACTIVATION_EVENT
)).
toEqual
([[
true
]]);
});
});
});
describe
(
'
when the mutation is not successful but looks like it is
'
,
()
=>
{
describe
(
'
when the mutation is not successful but looks like it is
'
,
()
=>
{
...
@@ -147,10 +143,6 @@ describe('CloudLicenseApp', () => {
...
@@ -147,10 +143,6 @@ describe('CloudLicenseApp', () => {
findActivateSubscriptionForm
().
vm
.
$emit
(
'
submit
'
,
createFakeEvent
());
findActivateSubscriptionForm
().
vm
.
$emit
(
'
submit
'
,
createFakeEvent
());
});
});
it
(
'
emits a successful event
'
,
()
=>
{
expect
(
wrapper
.
emitted
(
SUBSCRIPTION_ACTIVATION_EVENT
)).
toBeUndefined
();
});
it
.
todo
(
'
deals with failures in a meaningful way
'
);
it
.
todo
(
'
deals with failures in a meaningful way
'
);
});
});
...
@@ -161,8 +153,8 @@ describe('CloudLicenseApp', () => {
...
@@ -161,8 +153,8 @@ describe('CloudLicenseApp', () => {
findActivateSubscriptionForm
().
vm
.
$emit
(
'
submit
'
,
createFakeEvent
());
findActivateSubscriptionForm
().
vm
.
$emit
(
'
submit
'
,
createFakeEvent
());
});
});
it
(
'
emits a successful event
'
,
()
=>
{
it
(
'
emits a
un
successful event
'
,
()
=>
{
expect
(
wrapper
.
emitted
(
SUBSCRIPTION_ACTIVATION_EVENT
)).
toBeUndefined
();
expect
(
wrapper
.
emitted
(
SUBSCRIPTION_ACTIVATION_
FAILURE_
EVENT
)).
toBeUndefined
();
});
});
it
.
todo
(
'
deals with failures in a meaningful way
'
);
it
.
todo
(
'
deals with failures in a meaningful way
'
);
...
...
ee/spec/frontend/admin/cloud_licenses/mock_data.js
View file @
8b39e171
...
@@ -86,9 +86,9 @@ export const activateLicenseMutationResponse = {
...
@@ -86,9 +86,9 @@ export const activateLicenseMutationResponse = {
gitlabSubscriptionActivate
:
{
gitlabSubscriptionActivate
:
{
license
:
{
license
:
{
id
:
'
gid://gitlab/License/3
'
,
id
:
'
gid://gitlab/License/3
'
,
type
:
'
legacy
'
,
type
:
'
cloud
'
,
plan
:
'
ultimate
'
,
plan
:
'
ultimate
'
,
name
:
'
Test l
icense
'
,
name
:
'
Cloud L
icense
'
,
email
:
'
user@example.com
'
,
email
:
'
user@example.com
'
,
company
:
'
Example Inc
'
,
company
:
'
Example Inc
'
,
startsAt
:
'
2020-01-01
'
,
startsAt
:
'
2020-01-01
'
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment