Skip to content

Commit 9995a7a

Browse files
authored
Merge pull request #1058 from 10up/feature/improve-preview-highlighting
CSS updates to highlight terms in the previewer that are below the configured threshold
2 parents 27299e3 + 85fff98 commit 9995a7a

3 files changed

Lines changed: 70 additions & 2 deletions

File tree

src/js/settings/components/feature-additional-settings/classification-previewers/ibm-watson-nlu.js

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,21 @@ export function IBMWatsonNLUResults( { postId } ) {
104104
keywords: responseData.keywords,
105105
};
106106

107+
const hasAnyTags = Object.keys( renderData ).some(
108+
( taxSlug ) => renderData[ taxSlug ].length > 0
109+
);
110+
111+
const allBelowThreshold =
112+
hasAnyTags &&
113+
Object.keys( renderData ).every( ( taxSlug ) =>
114+
renderData[ taxSlug ].every( ( tag ) => {
115+
const threshold =
116+
settings[ `${ taxMap[ taxSlug ] }_threshold` ];
117+
const score = normalizeScore( tag.score || tag.relevance );
118+
return score < threshold;
119+
} )
120+
);
121+
107122
const card = Object.keys( renderData ).map( ( taxSlug ) => {
108123
const tags = renderData[ taxSlug ].map( ( tag, _index ) => {
109124
const threshold = settings[ `${ taxMap[ taxSlug ] }_threshold` ];
@@ -112,7 +127,7 @@ export function IBMWatsonNLUResults( { postId } ) {
112127
const scoreClass =
113128
score >= threshold
114129
? 'classifai__classification-previewer-result-tag--exceeds-threshold'
115-
: '';
130+
: 'classifai__classification-previewer-result-tag--below-threshold';
116131

117132
return (
118133
<div
@@ -179,6 +194,18 @@ export function IBMWatsonNLUResults( { postId } ) {
179194
'classifai'
180195
) }
181196
</Notice>
197+
{ allBelowThreshold && (
198+
<Notice
199+
status="warning"
200+
isDismissible={ false }
201+
className="classifai__classification-previewer-result-notice"
202+
>
203+
{ __(
204+
'None of the terms are above the configured threshold.',
205+
'classifai'
206+
) }
207+
</Notice>
208+
) }
182209
{ card }
183210
</>
184211
) : null;

src/js/settings/components/feature-additional-settings/classification-previewers/openai-embedding.js

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,20 @@ export function AzureOpenAIEmbeddingsResults( { postId } ) {
8585
} )();
8686
}, [ postId ] );
8787

88+
const hasAnyTags = Object.keys( responseData ).some(
89+
( taxSlug ) => responseData[ taxSlug ]?.data?.length > 0
90+
);
91+
92+
const allBelowThreshold =
93+
hasAnyTags &&
94+
Object.keys( responseData ).every( ( taxSlug ) =>
95+
( responseData[ taxSlug ]?.data || [] ).every( ( tag ) => {
96+
const threshold = settings[ `${ taxSlug }_threshold` ];
97+
const score = normalizeScore( tag.score );
98+
return score < threshold;
99+
} )
100+
);
101+
88102
const card = Object.keys( responseData ).map( ( taxSlug ) => {
89103
const tags = responseData[ taxSlug ]?.data.map( ( tag, _index ) => {
90104
const threshold = settings[ `${ taxSlug }_threshold` ];
@@ -93,7 +107,7 @@ export function AzureOpenAIEmbeddingsResults( { postId } ) {
93107
const scoreClass =
94108
score >= threshold
95109
? 'classifai__classification-previewer-result-tag--exceeds-threshold'
96-
: '';
110+
: 'classifai__classification-previewer-result-tag--below-threshold';
97111

98112
return (
99113
<div
@@ -160,6 +174,18 @@ export function AzureOpenAIEmbeddingsResults( { postId } ) {
160174
'classifai'
161175
) }
162176
</Notice>
177+
{ allBelowThreshold && (
178+
<Notice
179+
status="warning"
180+
isDismissible={ false }
181+
className="classifai__classification-previewer-result-notice"
182+
>
183+
{ __(
184+
'None of the terms are above the configured threshold.',
185+
'classifai'
186+
) }
187+
</Notice>
188+
) }
163189
{ card }
164190
</>
165191
) : null;

src/scss/settings.scss

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,21 @@
623623
}
624624
}
625625

626+
.classifai__classification-previewer-result-tag--below-threshold {
627+
border-color: #e74c3c;
628+
font-weight: bold;
629+
630+
.classifai__classification-previewer-result-tag-score {
631+
color: #f1f1f1;
632+
background-color: #e74c3c;
633+
border-right: 1px solid #e74c3c;
634+
}
635+
636+
.classifai__classification-previewer-result-tag-label {
637+
color: #e74c3c;
638+
}
639+
}
640+
626641
.components-button.classifai__classification-previewer-close-button.is-link {
627642
position: relative;
628643
margin: 0 auto;

0 commit comments

Comments
 (0)