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
0
Merge Requests
0
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
Boxiang Sun
gitlab-ce
Commits
57f6be00
Commit
57f6be00
authored
Jun 04, 2019
by
Adriel Santiago
Committed by
Fatih Acet
Jun 04, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Handle external dashboard form submission
Connect frontend UI with backend api for external dashboard link
parent
52b2b325
Changes
12
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
222 additions
and
70 deletions
+222
-70
app/assets/javascripts/monitoring/components/dashboard.vue
app/assets/javascripts/monitoring/components/dashboard.vue
+4
-3
app/assets/javascripts/operation_settings/components/external_dashboard.vue
...ipts/operation_settings/components/external_dashboard.vue
+20
-11
app/assets/javascripts/operation_settings/index.js
app/assets/javascripts/operation_settings/index.js
+3
-6
app/assets/javascripts/operation_settings/store/actions.js
app/assets/javascripts/operation_settings/store/actions.js
+38
-0
app/assets/javascripts/operation_settings/store/index.js
app/assets/javascripts/operation_settings/store/index.js
+16
-0
app/assets/javascripts/operation_settings/store/mutation_types.js
...ts/javascripts/operation_settings/store/mutation_types.js
+3
-0
app/assets/javascripts/operation_settings/store/mutations.js
app/assets/javascripts/operation_settings/store/mutations.js
+7
-0
app/assets/javascripts/operation_settings/store/state.js
app/assets/javascripts/operation_settings/store/state.js
+5
-0
app/views/projects/settings/operations/_external_dashboard.html.haml
...rojects/settings/operations/_external_dashboard.html.haml
+2
-1
spec/frontend/operation_settings/components/external_dashboard_spec.js
.../operation_settings/components/external_dashboard_spec.js
+103
-47
spec/frontend/operation_settings/store/mutations_spec.js
spec/frontend/operation_settings/store/mutations_spec.js
+19
-0
spec/javascripts/monitoring/dashboard_spec.js
spec/javascripts/monitoring/dashboard_spec.js
+2
-2
No files found.
app/assets/javascripts/monitoring/components/dashboard.vue
View file @
57f6be00
...
@@ -38,7 +38,7 @@ export default {
...
@@ -38,7 +38,7 @@ export default {
GlModalDirective
,
GlModalDirective
,
},
},
props
:
{
props
:
{
externalDashboard
Path
:
{
externalDashboard
Url
:
{
type
:
String
,
type
:
String
,
required
:
false
,
required
:
false
,
default
:
''
,
default
:
''
,
...
@@ -299,10 +299,11 @@ export default {
...
@@ -299,10 +299,11 @@ export default {
</gl-modal>
</gl-modal>
</div>
</div>
<gl-button
<gl-button
v-if=
"externalDashboard
Path
.length"
v-if=
"externalDashboard
Url
.length"
class=
"js-external-dashboard-link prepend-left-8"
class=
"js-external-dashboard-link prepend-left-8"
variant=
"primary"
variant=
"primary"
:href=
"externalDashboardPath"
:href=
"externalDashboardUrl"
target=
"_blank"
>
>
{{
__
(
'
View full dashboard
'
)
}}
{{
__
(
'
View full dashboard
'
)
}}
<icon
name=
"external-link"
/>
<icon
name=
"external-link"
/>
...
...
app/assets/javascripts/operation_settings/components/external_dashboard.vue
View file @
57f6be00
<
script
>
<
script
>
import
{
mapState
,
mapActions
}
from
'
vuex
'
;
import
{
GlButton
,
GlFormGroup
,
GlFormInput
,
GlLink
}
from
'
@gitlab/ui
'
;
import
{
GlButton
,
GlFormGroup
,
GlFormInput
,
GlLink
}
from
'
@gitlab/ui
'
;
export
default
{
export
default
{
...
@@ -8,17 +9,24 @@ export default {
...
@@ -8,17 +9,24 @@ export default {
GlFormInput
,
GlFormInput
,
GlLink
,
GlLink
,
},
},
props
:
{
computed
:
{
externalDashboardPath
:
{
...
mapState
([
type
:
String
,
'
externalDashboardHelpPagePath
'
,
required
:
false
,
'
externalDashboardUrl
'
,
default
:
''
,
'
operationsSettingsEndpoint
'
,
]),
userDashboardUrl
:
{
get
()
{
return
this
.
externalDashboardUrl
;
},
},
externalDashboardHelpPagePath
:
{
set
(
url
)
{
type
:
String
,
this
.
setExternalDashboardUrl
(
url
);
required
:
true
,
},
},
},
},
},
methods
:
{
...
mapActions
([
'
setExternalDashboardUrl
'
,
'
updateExternalDashboardUrl
'
]),
},
};
};
</
script
>
</
script
>
...
@@ -45,11 +53,12 @@ export default {
...
@@ -45,11 +53,12 @@ export default {
:description=
"s__('ExternalMetrics|Enter the URL of the dashboard you want to link to')"
:description=
"s__('ExternalMetrics|Enter the URL of the dashboard you want to link to')"
>
>
<gl-form-input
<gl-form-input
:value=
"externalDashboardPath
"
v-model=
"userDashboardUrl
"
placeholder=
"https://my-org.gitlab.io/my-dashboards"
placeholder=
"https://my-org.gitlab.io/my-dashboards"
@
keydown.enter.native.prevent=
"updateExternalDashboardUrl"
/>
/>
</gl-form-group>
</gl-form-group>
<gl-button
variant=
"success"
>
<gl-button
variant=
"success"
@
click=
"updateExternalDashboardUrl"
>
{{
__
(
'
Save Changes
'
)
}}
{{
__
(
'
Save Changes
'
)
}}
</gl-button>
</gl-button>
</form>
</form>
...
...
app/assets/javascripts/operation_settings/index.js
View file @
57f6be00
import
Vue
from
'
vue
'
;
import
Vue
from
'
vue
'
;
import
store
from
'
./store
'
;
import
ExternalDashboardForm
from
'
./components/external_dashboard.vue
'
;
import
ExternalDashboardForm
from
'
./components/external_dashboard.vue
'
;
export
default
()
=>
{
export
default
()
=>
{
...
@@ -14,13 +15,9 @@ export default () => {
...
@@ -14,13 +15,9 @@ export default () => {
return
new
Vue
({
return
new
Vue
({
el
,
el
,
store
:
store
(
el
.
dataset
),
render
(
createElement
)
{
render
(
createElement
)
{
return
createElement
(
ExternalDashboardForm
,
{
return
createElement
(
ExternalDashboardForm
);
props
:
{
...
el
.
dataset
,
expanded
:
false
,
},
});
},
},
});
});
};
};
app/assets/javascripts/operation_settings/store/actions.js
0 → 100644
View file @
57f6be00
import
axios
from
'
~/lib/utils/axios_utils
'
;
import
{
__
}
from
'
~/locale
'
;
import
createFlash
from
'
~/flash
'
;
import
{
refreshCurrentPage
}
from
'
~/lib/utils/url_utility
'
;
import
*
as
mutationTypes
from
'
./mutation_types
'
;
export
const
setExternalDashboardUrl
=
({
commit
},
url
)
=>
commit
(
mutationTypes
.
SET_EXTERNAL_DASHBOARD_URL
,
url
);
export
const
updateExternalDashboardUrl
=
({
state
,
dispatch
})
=>
axios
.
patch
(
state
.
operationsSettingsEndpoint
,
{
project
:
{
metrics_setting_attributes
:
{
external_dashboard_url
:
state
.
externalDashboardUrl
,
},
},
})
.
then
(()
=>
dispatch
(
'
receiveExternalDashboardUpdateSuccess
'
))
.
catch
(
error
=>
dispatch
(
'
receiveExternalDashboardUpdateError
'
,
error
));
export
const
receiveExternalDashboardUpdateSuccess
=
()
=>
{
/**
* The operations_controller currently handles successful requests
* by creating a flash banner messsage to notify the user.
*/
refreshCurrentPage
();
};
export
const
receiveExternalDashboardUpdateError
=
(
_
,
error
)
=>
{
const
{
response
}
=
error
;
const
message
=
response
.
data
&&
response
.
data
.
message
?
response
.
data
.
message
:
''
;
createFlash
(
`
${
__
(
'
There was an error saving your changes.
'
)}
${
message
}
`
,
'
alert
'
);
};
// prevent babel-plugin-rewire from generating an invalid default during karma tests
export
default
()
=>
{};
app/assets/javascripts/operation_settings/store/index.js
0 → 100644
View file @
57f6be00
import
Vue
from
'
vue
'
;
import
Vuex
from
'
vuex
'
;
import
createState
from
'
./state
'
;
import
*
as
actions
from
'
./actions
'
;
import
mutations
from
'
./mutations
'
;
Vue
.
use
(
Vuex
);
export
const
createStore
=
initialState
=>
new
Vuex
.
Store
({
state
:
createState
(
initialState
),
actions
,
mutations
,
});
export
default
createStore
;
app/assets/javascripts/operation_settings/store/mutation_types.js
0 → 100644
View file @
57f6be00
/* eslint-disable import/prefer-default-export */
export
const
SET_EXTERNAL_DASHBOARD_URL
=
'
SET_EXTERNAL_DASHBOARD_URL
'
;
app/assets/javascripts/operation_settings/store/mutations.js
0 → 100644
View file @
57f6be00
import
*
as
types
from
'
./mutation_types
'
;
export
default
{
[
types
.
SET_EXTERNAL_DASHBOARD_URL
](
state
,
url
)
{
state
.
externalDashboardUrl
=
url
;
},
};
app/assets/javascripts/operation_settings/store/state.js
0 → 100644
View file @
57f6be00
export
default
(
initialState
=
{})
=>
({
externalDashboardUrl
:
initialState
.
externalDashboardUrl
||
''
,
operationsSettingsEndpoint
:
initialState
.
operationsSettingsEndpoint
,
externalDashboardHelpPagePath
:
initialState
.
externalDashboardHelpPagePath
,
});
app/views/projects/settings/operations/_external_dashboard.html.haml
View file @
57f6be00
.js-operation-settings
{
data:
{
external_dashboard:
{
path:
metrics_external_dashboard_url
,
.js-operation-settings
{
data:
{
operations_settings_endpoint:
project_settings_operations_path
(
@project
),
external_dashboard:
{
url:
metrics_external_dashboard_url
,
help_page_path:
help_page_path
(
'user/project/operations/link_to_external_dashboard'
)
}
}
}
help_page_path:
help_page_path
(
'user/project/operations/link_to_external_dashboard'
)
}
}
}
spec/frontend/operation_settings/components/external_dashboard_spec.js
View file @
57f6be00
import
{
shallowMount
}
from
'
@vue/test-utils
'
;
import
{
mount
,
shallowMount
,
createLocalVue
}
from
'
@vue/test-utils
'
;
import
{
GlButton
,
GlLink
,
GlFormGroup
,
GlFormInput
}
from
'
@gitlab/ui
'
;
import
{
GlButton
,
GlLink
,
GlFormGroup
,
GlFormInput
}
from
'
@gitlab/ui
'
;
import
ExternalDashboard
from
'
~/operation_settings/components/external_dashboard.vue
'
;
import
ExternalDashboard
from
'
~/operation_settings/components/external_dashboard.vue
'
;
import
store
from
'
~/operation_settings/store
'
;
import
axios
from
'
~/lib/utils/axios_utils
'
;
import
{
refreshCurrentPage
}
from
'
~/lib/utils/url_utility
'
;
import
createFlash
from
'
~/flash
'
;
import
{
TEST_HOST
}
from
'
helpers/test_constants
'
;
import
{
TEST_HOST
}
from
'
helpers/test_constants
'
;
jest
.
mock
(
'
~/lib/utils/axios_utils
'
);
jest
.
mock
(
'
~/lib/utils/url_utility
'
);
jest
.
mock
(
'
~/flash
'
);
describe
(
'
operation settings external dashboard component
'
,
()
=>
{
describe
(
'
operation settings external dashboard component
'
,
()
=>
{
let
wrapper
;
let
wrapper
;
const
externalDashboardPath
=
`http://mock-external-domain.com/external/dashboard/path`
;
const
operationsSettingsEndpoint
=
`
${
TEST_HOST
}
/mock/ops/settings/endpoint`
;
const
externalDashboardUrl
=
`http://mock-external-domain.com/external/dashboard/url`
;
const
externalDashboardHelpPagePath
=
`
${
TEST_HOST
}
/help/page/path`
;
const
externalDashboardHelpPagePath
=
`
${
TEST_HOST
}
/help/page/path`
;
const
localVue
=
createLocalVue
();
beforeEach
(()
=>
{
const
mountComponent
=
(
shallow
=
true
)
=>
{
wrapper
=
shallowMount
(
ExternalDashboard
,
{
const
config
=
[
propsData
:
{
ExternalDashboard
,
externalDashboardPath
,
{
localVue
,
store
:
store
({
operationsSettingsEndpoint
,
externalDashboardUrl
,
externalDashboardHelpPagePath
,
externalDashboardHelpPagePath
,
}),
},
},
});
];
wrapper
=
shallow
?
shallowMount
(...
config
)
:
mount
(...
config
);
};
afterEach
(()
=>
{
if
(
wrapper
.
destroy
)
{
wrapper
.
destroy
();
}
axios
.
patch
.
mockReset
();
refreshCurrentPage
.
mockReset
();
createFlash
.
mockReset
();
});
});
it
(
'
renders header text
'
,
()
=>
{
it
(
'
renders header text
'
,
()
=>
{
mountComponent
();
expect
(
wrapper
.
find
(
'
.js-section-header
'
).
text
()).
toBe
(
'
External Dashboard
'
);
expect
(
wrapper
.
find
(
'
.js-section-header
'
).
text
()).
toBe
(
'
External Dashboard
'
);
});
});
...
@@ -33,6 +58,7 @@ describe('operation settings external dashboard component', () => {
...
@@ -33,6 +58,7 @@ describe('operation settings external dashboard component', () => {
let
subHeader
;
let
subHeader
;
beforeEach
(()
=>
{
beforeEach
(()
=>
{
mountComponent
();
subHeader
=
wrapper
.
find
(
'
.js-section-sub-header
'
);
subHeader
=
wrapper
.
find
(
'
.js-section-sub-header
'
);
});
});
...
@@ -51,18 +77,12 @@ describe('operation settings external dashboard component', () => {
...
@@ -51,18 +77,12 @@ describe('operation settings external dashboard component', () => {
});
});
describe
(
'
form
'
,
()
=>
{
describe
(
'
form
'
,
()
=>
{
let
form
;
beforeEach
(()
=>
{
form
=
wrapper
.
find
(
'
form
'
);
});
describe
(
'
external dashboard url
'
,
()
=>
{
describe
(
'
input label
'
,
()
=>
{
describe
(
'
input label
'
,
()
=>
{
let
formGroup
;
let
formGroup
;
beforeEach
(()
=>
{
beforeEach
(()
=>
{
formGroup
=
form
.
find
(
GlFormGroup
);
mountComponent
();
formGroup
=
wrapper
.
find
(
GlFormGroup
);
});
});
it
(
'
uses label text
'
,
()
=>
{
it
(
'
uses label text
'
,
()
=>
{
...
@@ -80,11 +100,12 @@ describe('operation settings external dashboard component', () => {
...
@@ -80,11 +100,12 @@ describe('operation settings external dashboard component', () => {
let
input
;
let
input
;
beforeEach
(()
=>
{
beforeEach
(()
=>
{
input
=
form
.
find
(
GlFormInput
);
mountComponent
();
input
=
wrapper
.
find
(
GlFormInput
);
});
});
it
(
'
defaults to externalDashboardPath prop
'
,
()
=>
{
it
(
'
defaults to externalDashboardUrl
'
,
()
=>
{
expect
(
input
.
attributes
().
value
).
toBe
(
externalDashboardPath
);
expect
(
input
.
attributes
().
value
).
toBe
(
externalDashboardUrl
);
});
});
it
(
'
uses a placeholder
'
,
()
=>
{
it
(
'
uses a placeholder
'
,
()
=>
{
...
@@ -93,15 +114,50 @@ describe('operation settings external dashboard component', () => {
...
@@ -93,15 +114,50 @@ describe('operation settings external dashboard component', () => {
});
});
describe
(
'
submit button
'
,
()
=>
{
describe
(
'
submit button
'
,
()
=>
{
let
submit
;
const
endpointRequest
=
[
operationsSettingsEndpoint
,
beforeEach
(()
=>
{
{
submit
=
form
.
find
(
GlButton
);
project
:
{
});
metrics_setting_attributes
:
{
external_dashboard_url
:
externalDashboardUrl
,
},
},
},
];
it
(
'
renders button label
'
,
()
=>
{
it
(
'
renders button label
'
,
()
=>
{
mountComponent
();
const
submit
=
wrapper
.
find
(
GlButton
);
expect
(
submit
.
text
()).
toBe
(
'
Save Changes
'
);
expect
(
submit
.
text
()).
toBe
(
'
Save Changes
'
);
});
});
it
(
'
submits form on click
'
,
()
=>
{
mountComponent
(
false
);
axios
.
patch
.
mockResolvedValue
();
wrapper
.
find
(
GlButton
).
trigger
(
'
click
'
);
expect
(
axios
.
patch
).
toHaveBeenCalledWith
(...
endpointRequest
);
return
wrapper
.
vm
.
$nextTick
().
then
(()
=>
expect
(
refreshCurrentPage
).
toHaveBeenCalled
());
});
it
(
'
creates flash banner on error
'
,
()
=>
{
mountComponent
(
false
);
const
message
=
'
mockErrorMessage
'
;
axios
.
patch
.
mockRejectedValue
({
response
:
{
data
:
{
message
}
}
});
wrapper
.
find
(
GlButton
).
trigger
(
'
click
'
);
expect
(
axios
.
patch
).
toHaveBeenCalledWith
(...
endpointRequest
);
return
wrapper
.
vm
.
$nextTick
()
.
then
(
jest
.
runAllTicks
)
.
then
(()
=>
expect
(
createFlash
).
toHaveBeenCalledWith
(
`There was an error saving your changes.
${
message
}
`
,
'
alert
'
,
),
);
});
});
});
});
});
});
...
...
spec/frontend/operation_settings/store/mutations_spec.js
0 → 100644
View file @
57f6be00
import
mutations
from
'
~/operation_settings/store/mutations
'
;
import
createState
from
'
~/operation_settings/store/state
'
;
describe
(
'
operation settings mutations
'
,
()
=>
{
let
localState
;
beforeEach
(()
=>
{
localState
=
createState
();
});
describe
(
'
SET_EXTERNAL_DASHBOARD_URL
'
,
()
=>
{
it
(
'
sets externalDashboardUrl
'
,
()
=>
{
const
mockUrl
=
'
mockUrl
'
;
mutations
.
SET_EXTERNAL_DASHBOARD_URL
(
localState
,
mockUrl
);
expect
(
localState
.
externalDashboardUrl
).
toBe
(
mockUrl
);
});
});
});
spec/javascripts/monitoring/dashboard_spec.js
View file @
57f6be00
...
@@ -393,7 +393,7 @@ describe('Dashboard', () => {
...
@@ -393,7 +393,7 @@ describe('Dashboard', () => {
hasMetrics
:
true
,
hasMetrics
:
true
,
showPanels
:
false
,
showPanels
:
false
,
showTimeWindowDropdown
:
false
,
showTimeWindowDropdown
:
false
,
externalDashboard
Path
:
'
/mockPath
'
,
externalDashboard
Url
:
'
/mockUrl
'
,
},
},
store
,
store
,
});
});
...
@@ -419,7 +419,7 @@ describe('Dashboard', () => {
...
@@ -419,7 +419,7 @@ describe('Dashboard', () => {
hasMetrics
:
true
,
hasMetrics
:
true
,
showPanels
:
false
,
showPanels
:
false
,
showTimeWindowDropdown
:
false
,
showTimeWindowDropdown
:
false
,
externalDashboard
Path
:
''
,
externalDashboard
Url
:
''
,
},
},
store
,
store
,
});
});
...
...
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