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
c82d6b42
Commit
c82d6b42
authored
Jan 24, 2022
by
Payton Burdette
Committed by
Marcel Amirault
Jan 24, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add polling docs
Add polling docs for merge request widget extensions.
parent
5c90a359
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
92 additions
and
0 deletions
+92
-0
doc/development/new_fe_guide/modules/widget_extensions.md
doc/development/new_fe_guide/modules/widget_extensions.md
+92
-0
No files found.
doc/development/new_fe_guide/modules/widget_extensions.md
View file @
c82d6b42
...
...
@@ -55,6 +55,98 @@ import issueExtension from '~/vue_merge_request_widget/extensions/issues';
registerExtension
(
issueExtension
);
```
## Polling
To enable polling for an extension, an options flag needs to be present in the extension.
For example:
```
javascript
export
default
{
//...
enablePolling
:
true
};
```
This flag tells the base component that we should poll the
`fetchCollapsedData()`
defined in the extension. Polling stops if the response has data or if an error is present.
When writing the logic for
`fetchCollapsedData()`
, a complete Axios response must be returned
from the method, due to the polling utility needing data like polling headers.
Otherwise, polling does not work correctly.
```
javascript
export
default
{
//...
enablePolling
:
true
methods
:
{
fetchCollapsedData
()
{
return
axios
.
get
(
this
.
reportPath
)
},
},
};
```
Most of the time the data returned from the extension's endpoint is not in the format
the UI needs. We must format the data before setting the collapsed data in the base component.
If the computed property
`summary`
can rely on
`collapsedData`
, you can format the data
when
`fetchFullData`
is invoked:
```
javascript
export
default
{
//...
enablePolling
:
true
methods
:
{
fetchCollapsedData
()
{
return
axios
.
get
(
this
.
reportPath
)
},
fetchFullData
()
{
return
Promise
.
resolve
(
this
.
prepareReports
());
},
// custom method
prepareReports
()
{
// unpack values from collapsedData
const
{
new_errors
,
existing_errors
,
resolved_errors
}
=
this
.
collapsedData
;
// perform data formatting
return
[...
newErrors
,
...
existingErrors
,
...
resolvedErrors
]
}
},
};
```
If the extension relies on
`collapsedData`
being formatted before invoking
`fetchFullData()`
,
then
`fetchCollapsedData()`
must return the Axios response as well as the formatted data:
```
javascript
export
default
{
//...
enablePolling
:
true
methods
:
{
fetchCollapsedData
()
{
return
axios
.
get
(
this
.
reportPath
).
then
(
res
=>
{
const
formattedData
=
this
.
prepareReports
(
res
.
data
)
return
{
...
res
,
data
:
formattedData
,
}
})
},
// custom method
prepareReports
()
{
// unpack values from collapsedData
const
{
new_errors
,
existing_errors
,
resolved_errors
}
=
this
.
collapsedData
;
// perform data formatting
return
[...
newErrors
,
...
existingErrors
,
...
resolvedErrors
]
}
},
};
```
## Fetching errors
If
`fetchCollapsedData()`
or
`fetchFullData()`
methods throw an error:
...
...
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