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
5 years ago
by
Adriel Santiago
Committed by
Fatih Acet
5 years ago
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
No related merge requests found
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 {
GlModalDirective
,
},
props
:
{
externalDashboard
Path
:
{
externalDashboard
Url
:
{
type
:
String
,
required
:
false
,
default
:
''
,
...
...
@@ -299,10 +299,11 @@ export default {
</gl-modal>
</div>
<gl-button
v-if=
"externalDashboard
Path
.length"
v-if=
"externalDashboard
Url
.length"
class=
"js-external-dashboard-link prepend-left-8"
variant=
"primary"
:href=
"externalDashboardPath"
:href=
"externalDashboardUrl"
target=
"_blank"
>
{{
__
(
'
View full dashboard
'
)
}}
<icon
name=
"external-link"
/>
...
...
This diff is collapsed.
Click to expand it.
app/assets/javascripts/operation_settings/components/external_dashboard.vue
View file @
57f6be00
<
script
>
import
{
mapState
,
mapActions
}
from
'
vuex
'
;
import
{
GlButton
,
GlFormGroup
,
GlFormInput
,
GlLink
}
from
'
@gitlab/ui
'
;
export
default
{
...
...
@@ -8,17 +9,24 @@ export default {
GlFormInput
,
GlLink
,
},
props
:
{
externalDashboardPath
:
{
type
:
String
,
required
:
false
,
default
:
''
,
computed
:
{
...
mapState
([
'
externalDashboardHelpPagePath
'
,
'
externalDashboardUrl
'
,
'
operationsSettingsEndpoint
'
,
]),
userDashboardUrl
:
{
get
()
{
return
this
.
externalDashboardUrl
;
},
externalDashboardHelpPagePath
:
{
type
:
String
,
required
:
true
,
set
(
url
)
{
this
.
setExternalDashboardUrl
(
url
);
},
},
},
methods
:
{
...
mapActions
([
'
setExternalDashboardUrl
'
,
'
updateExternalDashboardUrl
'
]),
},
};
</
script
>
...
...
@@ -45,11 +53,12 @@ export default {
:description=
"s__('ExternalMetrics|Enter the URL of the dashboard you want to link to')"
>
<gl-form-input
:value=
"externalDashboardPath
"
v-model=
"userDashboardUrl
"
placeholder=
"https://my-org.gitlab.io/my-dashboards"
@
keydown.enter.native.prevent=
"updateExternalDashboardUrl"
/>
</gl-form-group>
<gl-button
variant=
"success"
>
<gl-button
variant=
"success"
@
click=
"updateExternalDashboardUrl"
>
{{
__
(
'
Save Changes
'
)
}}
</gl-button>
</form>
...
...
This diff is collapsed.
Click to expand it.
app/assets/javascripts/operation_settings/index.js
View file @
57f6be00
import
Vue
from
'
vue
'
;
import
store
from
'
./store
'
;
import
ExternalDashboardForm
from
'
./components/external_dashboard.vue
'
;
export
default
()
=>
{
...
...
@@ -14,13 +15,9 @@ export default () => {
return
new
Vue
({
el
,
store
:
store
(
el
.
dataset
),
render
(
createElement
)
{
return
createElement
(
ExternalDashboardForm
,
{
props
:
{
...
el
.
dataset
,
expanded
:
false
,
},
});
return
createElement
(
ExternalDashboardForm
);
},
});
};
This diff is collapsed.
Click to expand it.
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
()
=>
{};
This diff is collapsed.
Click to expand it.
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
;
This diff is collapsed.
Click to expand it.
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
'
;
This diff is collapsed.
Click to expand it.
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
;
},
};
This diff is collapsed.
Click to expand it.
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
,
});
This diff is collapsed.
Click to expand it.
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'
)
}
}
}
This diff is collapsed.
Click to expand it.
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
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
'
;
jest
.
mock
(
'
~/lib/utils/axios_utils
'
);
jest
.
mock
(
'
~/lib/utils/url_utility
'
);
jest
.
mock
(
'
~/flash
'
);
describe
(
'
operation settings external dashboard component
'
,
()
=>
{
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`
;
beforeEach
(()
=>
{
wrapper
=
shallowMount
(
ExternalDashboard
,
{
propsData
:
{
externalDashboardPath
,
const
localVue
=
createLocalVue
();
const
mountComponent
=
(
shallow
=
true
)
=>
{
const
config
=
[
ExternalDashboard
,
{
localVue
,
store
:
store
({
operationsSettingsEndpoint
,
externalDashboardUrl
,
externalDashboardHelpPagePath
,
}),
},
});
];
wrapper
=
shallow
?
shallowMount
(...
config
)
:
mount
(...
config
);
};
afterEach
(()
=>
{
if
(
wrapper
.
destroy
)
{
wrapper
.
destroy
();
}
axios
.
patch
.
mockReset
();
refreshCurrentPage
.
mockReset
();
createFlash
.
mockReset
();
});
it
(
'
renders header text
'
,
()
=>
{
mountComponent
();
expect
(
wrapper
.
find
(
'
.js-section-header
'
).
text
()).
toBe
(
'
External Dashboard
'
);
});
...
...
@@ -33,6 +58,7 @@ describe('operation settings external dashboard component', () => {
let
subHeader
;
beforeEach
(()
=>
{
mountComponent
();
subHeader
=
wrapper
.
find
(
'
.js-section-sub-header
'
);
});
...
...
@@ -51,18 +77,12 @@ describe('operation settings external dashboard component', () => {
});
describe
(
'
form
'
,
()
=>
{
let
form
;
beforeEach
(()
=>
{
form
=
wrapper
.
find
(
'
form
'
);
});
describe
(
'
external dashboard url
'
,
()
=>
{
describe
(
'
input label
'
,
()
=>
{
let
formGroup
;
beforeEach
(()
=>
{
formGroup
=
form
.
find
(
GlFormGroup
);
mountComponent
();
formGroup
=
wrapper
.
find
(
GlFormGroup
);
});
it
(
'
uses label text
'
,
()
=>
{
...
...
@@ -80,11 +100,12 @@ describe('operation settings external dashboard component', () => {
let
input
;
beforeEach
(()
=>
{
input
=
form
.
find
(
GlFormInput
);
mountComponent
();
input
=
wrapper
.
find
(
GlFormInput
);
});
it
(
'
defaults to externalDashboardPath prop
'
,
()
=>
{
expect
(
input
.
attributes
().
value
).
toBe
(
externalDashboardPath
);
it
(
'
defaults to externalDashboardUrl
'
,
()
=>
{
expect
(
input
.
attributes
().
value
).
toBe
(
externalDashboardUrl
);
});
it
(
'
uses a placeholder
'
,
()
=>
{
...
...
@@ -93,15 +114,50 @@ describe('operation settings external dashboard component', () => {
});
describe
(
'
submit button
'
,
()
=>
{
let
submit
;
beforeEach
(()
=>
{
submit
=
form
.
find
(
GlButton
);
});
const
endpointRequest
=
[
operationsSettingsEndpoint
,
{
project
:
{
metrics_setting_attributes
:
{
external_dashboard_url
:
externalDashboardUrl
,
},
},
},
];
it
(
'
renders button label
'
,
()
=>
{
mountComponent
();
const
submit
=
wrapper
.
find
(
GlButton
);
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
'
,
),
);
});
});
});
...
...
This diff is collapsed.
Click to expand it.
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
);
});
});
});
This diff is collapsed.
Click to expand it.
spec/javascripts/monitoring/dashboard_spec.js
View file @
57f6be00
...
...
@@ -393,7 +393,7 @@ describe('Dashboard', () => {
hasMetrics
:
true
,
showPanels
:
false
,
showTimeWindowDropdown
:
false
,
externalDashboard
Path
:
'
/mockPath
'
,
externalDashboard
Url
:
'
/mockUrl
'
,
},
store
,
});
...
...
@@ -419,7 +419,7 @@ describe('Dashboard', () => {
hasMetrics
:
true
,
showPanels
:
false
,
showTimeWindowDropdown
:
false
,
externalDashboard
Path
:
''
,
externalDashboard
Url
:
''
,
},
store
,
});
...
...
This diff is collapsed.
Click to expand it.
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