From 662929b7caabb8782f965d0ef107669d0f538c6b Mon Sep 17 00:00:00 2001 From: piedicianni Date: Wed, 20 Oct 2021 17:55:53 +0200 Subject: [PATCH 1/4] Show lexiQA styleguide list --- .../cat_source/es6/actions/SegmentActions.js | 7 +++ .../lexiqaTooltipwarnings.js | 46 ++++++++++++++++++- public/js/cat_source/es6/components.js | 3 ++ .../segments/SegmentFooterTabMessages.js | 14 ++++++ .../components/segments/SegmentsContainer.js | 2 - .../es6/constants/SegmentConstants.js | 1 + .../js/cat_source/es6/stores/SegmentStore.js | 18 ++++++++ public/js/cat_source/es6/utils/lxq.main.js | 21 ++++++++- 8 files changed, 106 insertions(+), 6 deletions(-) diff --git a/public/js/cat_source/es6/actions/SegmentActions.js b/public/js/cat_source/es6/actions/SegmentActions.js index 7656637583..22633d539a 100644 --- a/public/js/cat_source/es6/actions/SegmentActions.js +++ b/public/js/cat_source/es6/actions/SegmentActions.js @@ -365,6 +365,13 @@ const SegmentActions = { type: type, }) }, + addLexiqaStyleGuideMessages: function (sid, styleGuideMessages) { + AppDispatcher.dispatch({ + actionType: SegmentConstants.ADD_LXQ_STYLE_GUIDE_MESSAGES, + sid, + styleGuideMessages, + }) + }, selectNextSegmentDebounced: _.debounce(() => { SegmentActions.selectNextSegment() }, 100), diff --git a/public/js/cat_source/es6/api/lexiqaTooltipwarnings/lexiqaTooltipwarnings.js b/public/js/cat_source/es6/api/lexiqaTooltipwarnings/lexiqaTooltipwarnings.js index 02354595a6..ef250b815b 100644 --- a/public/js/cat_source/es6/api/lexiqaTooltipwarnings/lexiqaTooltipwarnings.js +++ b/public/js/cat_source/es6/api/lexiqaTooltipwarnings/lexiqaTooltipwarnings.js @@ -7,7 +7,7 @@ import {getQueryStringFromProps} from '../../utils/queryString' * @param {string} [options.lexiqaDomain=config.lexiqaServer] * @returns {Promise} */ -export const lexiqaTooltipwarnings = async ({ +/* export const lexiqaTooltipwarnings = async ({ lexiqaDomain = config.lexiqaServer, } = {}) => { const response = await fetch( @@ -20,6 +20,48 @@ export const lexiqaTooltipwarnings = async ({ if (errors && errors.length > 0) return Promise.reject(errors) return data -} +} */ export const pluginOptions = {} + +// TEMP MOCK lexiQA response +export const lexiqaTooltipwarnings = async ({ + lexiqaDomain = config.lexiqaServer, +} = {}) => { + const response = await fetch( + `${lexiqaDomain}/tooltipwarnings${getQueryStringFromProps(pluginOptions)}`, + ) + + if (!response.ok) return Promise.reject(response) + + const {errors, ...data} = await response.json() + if (errors && errors.length > 0) return Promise.reject(errors) + + return { + ...data, + styleGuideMessages: { + uber_itIT_sd1: { + msg: 'Test message 1', + }, + uber_itIT_sd2: { + msg: 'Test message 2', + }, + uber_itIT_sd3: { + msg: 'Test message 3', + }, + }, + } +} + +$(document).ready(function () { + const superDoLexiQA = $.lexiqaAuthenticator.doLexiQA + $.lexiqaAuthenticator.doLexiQA = function (options, callback) { + const callbackModified = (error, result) => { + callback(error, { + ...result, + styleGuideMessages: ['uber_itIT_sd1', 'uber_itIT_sd2', 'uber_itIT_sd3'], + }) + } + superDoLexiQA.call($.lexiqaAuthenticator, options, callbackModified) + } +}) diff --git a/public/js/cat_source/es6/components.js b/public/js/cat_source/es6/components.js index ceb469055f..cf1614869b 100644 --- a/public/js/cat_source/es6/components.js +++ b/public/js/cat_source/es6/components.js @@ -28,6 +28,7 @@ import CursorUtils from './utils/cursorUtils' import OfflineUtils from './utils/offlineUtils' import Shortcuts from './utils/shortcuts' import SegmentFooterTabMatches from './components/segments/SegmentFooterTabMatches' +import {pluginOptions as lexiqaTooltipWarningPluginOptions} from './api/lexiqaTooltipwarnings' window.MC = {} @@ -66,3 +67,5 @@ window.OfflineUtils = OfflineUtils window.Shortcuts = Shortcuts window.SegmentFooterTabMatches = SegmentFooterTabMatches + +window.lexiqaTooltipWarningPluginOptions = lexiqaTooltipWarningPluginOptions diff --git a/public/js/cat_source/es6/components/segments/SegmentFooterTabMessages.js b/public/js/cat_source/es6/components/segments/SegmentFooterTabMessages.js index 59b2b96783..d53dcc4783 100644 --- a/public/js/cat_source/es6/components/segments/SegmentFooterTabMessages.js +++ b/public/js/cat_source/es6/components/segments/SegmentFooterTabMessages.js @@ -10,6 +10,7 @@ class SegmentFooterTabMessages extends React.Component { } getNotes() { + console.log(this.props.segment.styleGuideMessages) let notesHtml = [] let self = this if (this.props.notes) { @@ -108,6 +109,19 @@ class SegmentFooterTabMessages extends React.Component { ) } + getStyleGuideMessages(messages) { + return ( +
+ Style guide: +
    + {messages.map((style, index) => ( +
  • {style}
  • + ))} +
+
+ ) + } + componentDidMount() {} componentWillUnmount() {} diff --git a/public/js/cat_source/es6/components/segments/SegmentsContainer.js b/public/js/cat_source/es6/components/segments/SegmentsContainer.js index 647118e1f6..3c88a3d2cb 100644 --- a/public/js/cat_source/es6/components/segments/SegmentsContainer.js +++ b/public/js/cat_source/es6/components/segments/SegmentsContainer.js @@ -89,7 +89,6 @@ class SegmentsContainer extends React.Component { renderSegments(segments) { // VirtualList.prototype.animateScroll = false; // Update previous last segment height inside segmentsHeightsMap - if (this.state.segments.size !== segments.size) { const oldLastSegment = this.getSegmentByIndex( this.state.segments.size - 1, @@ -243,7 +242,6 @@ class SegmentsContainer extends React.Component { getSegment(segment, segImmutable, currentFileId, collectionTypeSeparator) { let isReviewExtended = !!this.props.isReviewExtended - let item = ( { Object.keys(warnings[key].Categories).map((key2) => { @@ -1671,6 +1679,16 @@ AppDispatcher.register(function (action) { SegmentStore._segments, ) break + case SegmentConstants.ADD_LXQ_STYLE_GUIDE_MESSAGES: + SegmentStore.addLexiqaStyleGuideMessages( + action.sid, + action.styleGuideMessages, + ) + SegmentStore.emitChange( + SegmentConstants.RENDER_SEGMENTS, + SegmentStore._segments, + ) + break case SegmentConstants.ADD_SEARCH_RESULTS: SegmentStore.addSearchResult( action.occurrencesList, diff --git a/public/js/cat_source/es6/utils/lxq.main.js b/public/js/cat_source/es6/utils/lxq.main.js index 3523fa5ec7..14620192f7 100644 --- a/public/js/cat_source/es6/utils/lxq.main.js +++ b/public/js/cat_source/es6/utils/lxq.main.js @@ -8,6 +8,14 @@ import {lexiqaIgnoreError} from '../api/lexiqaIgnoreError' import SegmentStore from '../stores/SegmentStore' import {lexiqaTooltipwarnings} from '../api/lexiqaTooltipwarnings' +const styleGuideManager = (() => { + let map = {} + function getMessage(id) { + return this.map[id].msg ?? '' + } + return {map, getMessage} +})() + const LXQ = { enabled: function () { return !!config.lxq_enabled @@ -93,7 +101,6 @@ const LXQ = { function (err, result) { if (!err) { var noVisibleErrorsFound = false - if (result.hasOwnProperty('qaData') && result.qaData.length > 0) { //highlight the segments // source_val = $( ".source", segment ).html(); @@ -164,7 +171,13 @@ const LXQ = { LXQ.lxqRemoveSegmentFromWarningList(id_segment) } } //there was no error - else { + // style guides + if (result.styleGuideMessages) { + const messages = result.styleGuideMessages.map((style) => + styleGuideManager.getMessage(style), + ) + SegmentActions.addLexiqaStyleGuideMessages(id_segment, messages) + } else { if (callback != null) callback() } //error in doQA }, //end lexiqaAuthenticator callback @@ -784,6 +797,10 @@ LXQ.init = function () { modulesNoHighlight = Object.entries(data) .filter(([key]) => key[key.length - 1] === 'g') .map(([key]) => key) + + styleGuideManager.map = { + ...(data?.styleGuideMessages ?? {}), + } }) } // Interfaces From a968ce514008ddceb2362d796d356aee63cfe0cb Mon Sep 17 00:00:00 2001 From: piedicianni Date: Wed, 20 Oct 2021 17:59:05 +0200 Subject: [PATCH 2/4] Removed mock lexiQA response --- .../lexiqaTooltipwarnings.js | 46 +------------------ 1 file changed, 2 insertions(+), 44 deletions(-) diff --git a/public/js/cat_source/es6/api/lexiqaTooltipwarnings/lexiqaTooltipwarnings.js b/public/js/cat_source/es6/api/lexiqaTooltipwarnings/lexiqaTooltipwarnings.js index ef250b815b..02354595a6 100644 --- a/public/js/cat_source/es6/api/lexiqaTooltipwarnings/lexiqaTooltipwarnings.js +++ b/public/js/cat_source/es6/api/lexiqaTooltipwarnings/lexiqaTooltipwarnings.js @@ -7,24 +7,6 @@ import {getQueryStringFromProps} from '../../utils/queryString' * @param {string} [options.lexiqaDomain=config.lexiqaServer] * @returns {Promise} */ -/* export const lexiqaTooltipwarnings = async ({ - lexiqaDomain = config.lexiqaServer, -} = {}) => { - const response = await fetch( - `${lexiqaDomain}/tooltipwarnings${getQueryStringFromProps(pluginOptions)}`, - ) - - if (!response.ok) return Promise.reject(response) - - const {errors, ...data} = await response.json() - if (errors && errors.length > 0) return Promise.reject(errors) - - return data -} */ - -export const pluginOptions = {} - -// TEMP MOCK lexiQA response export const lexiqaTooltipwarnings = async ({ lexiqaDomain = config.lexiqaServer, } = {}) => { @@ -37,31 +19,7 @@ export const lexiqaTooltipwarnings = async ({ const {errors, ...data} = await response.json() if (errors && errors.length > 0) return Promise.reject(errors) - return { - ...data, - styleGuideMessages: { - uber_itIT_sd1: { - msg: 'Test message 1', - }, - uber_itIT_sd2: { - msg: 'Test message 2', - }, - uber_itIT_sd3: { - msg: 'Test message 3', - }, - }, - } + return data } -$(document).ready(function () { - const superDoLexiQA = $.lexiqaAuthenticator.doLexiQA - $.lexiqaAuthenticator.doLexiQA = function (options, callback) { - const callbackModified = (error, result) => { - callback(error, { - ...result, - styleGuideMessages: ['uber_itIT_sd1', 'uber_itIT_sd2', 'uber_itIT_sd3'], - }) - } - superDoLexiQA.call($.lexiqaAuthenticator, options, callbackModified) - } -}) +export const pluginOptions = {} From 6d683ff1c0d2f803dffd515cc236ac0a3847e703 Mon Sep 17 00:00:00 2001 From: Mauro Cassani Date: Thu, 21 Oct 2021 17:32:40 +0200 Subject: [PATCH 3/4] getStatusCode --- lib/Utils/MultiCurlHandler.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/Utils/MultiCurlHandler.php b/lib/Utils/MultiCurlHandler.php index b8864ff681..160f0c17a1 100644 --- a/lib/Utils/MultiCurlHandler.php +++ b/lib/Utils/MultiCurlHandler.php @@ -399,6 +399,15 @@ public function getErrors() { return array_filter( $map ); // <- remove null array entries } + /** + * @param $tokenHash + * + * @return int + */ + public function getStatusCode( $tokenHash ) { + return (int)$this->multi_curl_info[ $tokenHash ][ 'http_code' ]; + } + public function clear(){ $this->multiCurlCloseAll(); $this->curl_headers_requests = []; @@ -428,4 +437,4 @@ protected function _callbackExecute( $record, Callable $function = null ){ return $record; } -} +} From 37ba06e58a1459a709cde8b28db0062b1dac88f0 Mon Sep 17 00:00:00 2001 From: piedicianni Date: Mon, 25 Oct 2021 15:11:04 +0200 Subject: [PATCH 4/4] Styling style guide messages list --- public/css/sass/segment-notes.scss | 6 ++++++ .../es6/components/segments/SegmentFooterTabMessages.js | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/public/css/sass/segment-notes.scss b/public/css/sass/segment-notes.scss index 902913d877..0fa36aea2e 100644 --- a/public/css/sass/segment-notes.scss +++ b/public/css/sass/segment-notes.scss @@ -85,6 +85,12 @@ div.segment-notes ul.graysmall li span.note-label { font-weight: bold; } +.segments-notes-container div.note-style-guide > ul { + list-style-type: square; + padding-left: 14px; + margin-top: 6px; +} + .tab-preview-screenshot { text-align: center; padding-top: 10px; diff --git a/public/js/cat_source/es6/components/segments/SegmentFooterTabMessages.js b/public/js/cat_source/es6/components/segments/SegmentFooterTabMessages.js index d53dcc4783..c6345d856c 100644 --- a/public/js/cat_source/es6/components/segments/SegmentFooterTabMessages.js +++ b/public/js/cat_source/es6/components/segments/SegmentFooterTabMessages.js @@ -111,7 +111,7 @@ class SegmentFooterTabMessages extends React.Component { getStyleGuideMessages(messages) { return ( -
+
Style guide:
    {messages.map((style, index) => (