diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-12-20 16:37:47 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-12-20 16:37:47 +0300 |
commit | aee0a117a889461ce8ced6fcf73207fe017f1d99 (patch) | |
tree | 891d9ef189227a8445d83f35c1b0fc99573f4380 /app/assets/javascripts/issues/show/utils | |
parent | 8d46af3258650d305f53b819eabf7ab18d22f59e (diff) |
Add latest changes from gitlab-org/gitlab@14-6-stable-eev14.6.0-rc42
Diffstat (limited to 'app/assets/javascripts/issues/show/utils')
-rw-r--r-- | app/assets/javascripts/issues/show/utils/parse_data.js | 23 | ||||
-rw-r--r-- | app/assets/javascripts/issues/show/utils/update_description.js | 36 |
2 files changed, 59 insertions, 0 deletions
diff --git a/app/assets/javascripts/issues/show/utils/parse_data.js b/app/assets/javascripts/issues/show/utils/parse_data.js new file mode 100644 index 00000000000..f1e6bd2419a --- /dev/null +++ b/app/assets/javascripts/issues/show/utils/parse_data.js @@ -0,0 +1,23 @@ +import * as Sentry from '@sentry/browser'; +import { sanitize } from '~/lib/dompurify'; + +// We currently load + parse the data from the issue app and related merge request +let cachedParsedData; + +export const parseIssuableData = (el) => { + try { + if (cachedParsedData) return cachedParsedData; + + const parsedData = JSON.parse(el.dataset.initial); + parsedData.initialTitleHtml = sanitize(parsedData.initialTitleHtml); + parsedData.initialDescriptionHtml = sanitize(parsedData.initialDescriptionHtml); + + cachedParsedData = parsedData; + + return parsedData; + } catch (e) { + Sentry.captureException(e); + + return {}; + } +}; diff --git a/app/assets/javascripts/issues/show/utils/update_description.js b/app/assets/javascripts/issues/show/utils/update_description.js new file mode 100644 index 00000000000..c5811290e61 --- /dev/null +++ b/app/assets/javascripts/issues/show/utils/update_description.js @@ -0,0 +1,36 @@ +/** + * Function that replaces the open attribute for the <details> element. + * + * @param {String} descriptionHtml - The html string passed back from the server as a result of polling + * @param {Array} details - All detail nodes inside of the issue description. + */ + +const updateDescription = (descriptionHtml = '', details) => { + let detailNodes = details; + + if (!details.length) { + detailNodes = []; + } + + const placeholder = document.createElement('div'); + placeholder.innerHTML = descriptionHtml; + + const newDetails = placeholder.getElementsByTagName('details'); + + if (newDetails.length !== detailNodes.length) { + return descriptionHtml; + } + + Array.from(newDetails).forEach((el, i) => { + /* + * <details> has an open attribute that can have a value, "", "true", "false" + * and will show the dropdown, which is why we are setting the attribute + * explicitly to true. + */ + if (detailNodes[i].open) el.setAttribute('open', true); + }); + + return placeholder.innerHTML; +}; + +export default updateDescription; |