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
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
Hide 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"
/>
...
...
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
:
''
,
},
externalDashboardHelpPagePath
:
{
type
:
String
,
required
:
true
,
computed
:
{
...
mapState
([
'
externalDashboardHelpPagePath
'
,
'
externalDashboardUrl
'
,
'
operationsSettingsEndpoint
'
,
]),
userDashboardUrl
:
{
get
()
{
return
this
.
externalDashboardUrl
;
},
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>
...
...
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
);
},
});
};
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'
)
}
}
}
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
,
externalDashboardHelpPagePath
,
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,57 +77,87 @@ describe('operation settings external dashboard component', () => {
});
describe
(
'
form
'
,
()
=>
{
let
form
;
describe
(
'
input label
'
,
()
=>
{
let
formGroup
;
beforeEach
(()
=>
{
form
=
wrapper
.
find
(
'
form
'
);
});
beforeEach
(()
=>
{
mountComponent
();
formGroup
=
wrapper
.
find
(
GlFormGroup
);
});
describe
(
'
external dashboard url
'
,
()
=>
{
describe
(
'
input label
'
,
()
=>
{
let
formGroup
;
it
(
'
uses label text
'
,
()
=>
{
expect
(
formGroup
.
attributes
().
label
).
toBe
(
'
Full dashboard URL
'
);
})
;
beforeEach
(()
=>
{
formGroup
=
form
.
find
(
GlFormGroup
);
});
it
(
'
uses description text
'
,
()
=>
{
expect
(
formGroup
.
attributes
().
description
).
toBe
(
'
Enter the URL of the dashboard you want to link to
'
,
);
});
});
it
(
'
uses label text
'
,
()
=>
{
expect
(
formGroup
.
attributes
().
label
).
toBe
(
'
Full dashboard URL
'
);
});
describe
(
'
input field
'
,
()
=>
{
let
input
;
it
(
'
uses description text
'
,
()
=>
{
expect
(
formGroup
.
attributes
().
description
).
toBe
(
'
Enter the URL of the dashboard you want to link to
'
,
);
});
beforeEach
(()
=>
{
mountComponent
();
input
=
wrapper
.
find
(
GlFormInput
);
});
describe
(
'
input field
'
,
()
=>
{
let
input
;
beforeEach
(()
=>
{
input
=
form
.
find
(
GlFormInput
);
});
it
(
'
defaults to externalDashboardUrl
'
,
()
=>
{
expect
(
input
.
attributes
().
value
).
toBe
(
externalDashboardUrl
);
});
it
(
'
defaults to externalDashboardPath prop
'
,
()
=>
{
expect
(
input
.
attributes
().
value
).
toBe
(
externalDashboardPath
);
});
it
(
'
uses a placeholder
'
,
()
=>
{
expect
(
input
.
attributes
().
placeholder
).
toBe
(
'
https://my-org.gitlab.io/my-dashboards
'
);
});
});
it
(
'
uses a placeholder
'
,
()
=>
{
expect
(
input
.
attributes
().
placeholder
).
toBe
(
'
https://my-org.gitlab.io/my-dashboards
'
);
});
describe
(
'
submit button
'
,
()
=>
{
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
'
);
});
describe
(
'
submit button
'
,
()
=>
{
let
submit
;
it
(
'
submits form on click
'
,
()
=>
{
mountComponent
(
false
);
axios
.
patch
.
mockResolvedValue
();
wrapper
.
find
(
GlButton
).
trigger
(
'
click
'
);
expect
(
axios
.
patch
).
toHaveBeenCalledWith
(...
endpointRequest
);
beforeEach
(()
=>
{
submit
=
form
.
find
(
GlButton
);
});
return
wrapper
.
vm
.
$nextTick
().
then
(()
=>
expect
(
refreshCurrentPage
).
toHaveBeenCalled
());
});
it
(
'
renders button label
'
,
()
=>
{
expect
(
submit
.
text
()).
toBe
(
'
Save Changes
'
);
});
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', () => {
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
,
});
...
...
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