Skip to content

Commit

Permalink
userdashboard/ModerationNotification//AIFeedback: add AI feedback com…
Browse files Browse the repository at this point in the history
…ponent and add to the ModerationNotification small a11y improvments
  • Loading branch information
philli-m committed Aug 14, 2023
1 parent 208f7c0 commit b6f4c96
Show file tree
Hide file tree
Showing 12 changed files with 186 additions and 19 deletions.
7 changes: 7 additions & 0 deletions adhocracy-plus/assets/scss/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ $font-size-base: 1.125rem !default; //18px
$font-size-sm: 1rem !default; // 16px
$font-size-xs: 0.8rem !default; // 12.8px

$h1-font-size: $font-size-xxxl;
$h2-font-size: $font-size-xxl;
$h3-font-size: $font-size-xl;
$h4-font-size: $font-size-lg;
$h5-font-size: $font-size-md;
$h6-font-size: $font-size-sm;

$mobile-headline-size: 0.8 !default;

$shadow: rgba(#000, 0.25) !default;
Expand Down
2 changes: 1 addition & 1 deletion adhocracy-plus/assets/scss/components/_alerts.scss
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ $messages-margin-bottom: 25px;

.alert--error,
.alert--danger {
background-color: lighten($brand-danger, 50);
background-color: lighten($brand-danger, 57);
color: $text-color;
}

Expand Down
19 changes: 16 additions & 3 deletions adhocracy-plus/assets/scss/components/_button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,15 @@

&:focus,
&:hover,
&:active {
&:active,
&:focus-within {
background-color: transparent !important;
text-decoration: underline;
}

&:focus-visible {
@include fake-focus-shadow;
}
}

.btn.btn--transparent--inverted {
Expand All @@ -115,11 +120,19 @@

&:focus,
&:hover,
&:active,
&:active {
box-shadow: none;
background-color: $bg-light;
}

&:focus-visible {
@include fake-focus-shadow;
}

&:disabled,
&.is-disabled {
box-shadow: none;
background-color: $bg-light;
color: $text-muted;
}

// needed for toggle switch
Expand Down
4 changes: 2 additions & 2 deletions adhocracy-plus/assets/scss/components/_header_upper.scss
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
}
}

.header-upper__user a {
color: $body-bg !important;
.header-upper__user .navi__item a {
color: $body-bg;
}

.header-upper__mobile-toggle {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import React, { useState } from 'react'
import django from 'django'

const translated = {
intro: django.gettext('This comment contains disinformation. Defakts uses an Artificial ' +
'Intelligence to scan content for disinformation. Disinformation often shows ' +
'certain characteristics that allow for a reliable identification.'),
ariaReadMore: django.gettext('Click to view the AI explanation for reporting this comment.'),
ariaReadLess: django.gettext('Click to hide the AI explanation for reporting this comment.'),
readMore: django.gettext('Read more'),
readLess: django.gettext('Read less')
}

export const AiReportExplanation = ({ AiReport }) => {
const [isExpanded, setIsExpanded] = useState()

const toggleExpand = () => {
setIsExpanded(!isExpanded)
}

return (
<li className="alert alert--danger d-flex text-start fs-6 mb-3">
<i
className="fas fa-exclamation-circle text-danger pt-1 pe-2"
aria-hidden="True"
/>
<p className="pe-4">
{translated.intro + ' '}
{isExpanded && AiReport + ' '}
<button
className="btn--link text-danger"
type="button"
onClick={toggleExpand}
aria-label={isExpanded ? translated.ariaReadLess : translated.ariaReadMore}
>
{isExpanded ? translated.readLess : translated.readMore}
</button>
</p>
</li>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const ModerationFeedback = (props) => {
}

return (
<div className="userdashboard-mod-feedback">
<li className="userdashboard-mod-feedback">
<div className="row">
<div className="col-7 col-md-8 userdashboard-mod-feedback__header">
<div>{translated.feedbackTitle}</div>
Expand Down Expand Up @@ -68,6 +68,6 @@ export const ModerationFeedback = (props) => {
<p>{feedbackText}</p>
</div>
</div>
</div>
</li>
)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useState } from 'react'
import django from 'django'
import api from './api'
import { AiReportExplanation } from './AiReportExplanation'
import { ModerationFeedbackForm } from './ModerationFeedbackForm'
import { ModerationFeedback } from './ModerationFeedback'
import { ModerationNotificationActionsBar } from './ModerationNotificationActionsBar'
Expand All @@ -21,7 +22,9 @@ const translated = {
notificationRead: django.gettext('Notification successfully marked as read.'),
notificationUnread: django.gettext('Notification successfully marked as unread.'),
aiClassified: django.gettext('AI'),
postedComment: django.gettext('posted a {}comment{}')
postedComment: django.gettext('posted a {}comment{}'),
dummyText: django.gettext('Dummy text')

}

export const ModerationNotification = (props) => {
Expand Down Expand Up @@ -257,8 +260,8 @@ export const ModerationNotification = (props) => {

return (
<li>
<div className="u-border p-4">
<div className="d-flex flex-wrap">
<ul className="u-border p-4 u-list-reset">
<li className="d-flex flex-wrap">
{userImageDiv}
<div>
<p className="mb-1">
Expand Down Expand Up @@ -291,17 +294,20 @@ export const ModerationNotification = (props) => {
</ul>
</div>
</div>
</div>
</li>

{numReports > 0 &&
<div>
<li>
<p>
<i className="fas fa-exclamation-circle me-1" aria-hidden="true" />
{getLink(translatedReportText(numReports), commentUrl)}
</p>
</div>}

<p>{commentText}</p>
</li>}
<li>
<p>{commentText}</p>
</li>
{/* FIXME add if once report added to serializer */}
<AiReportExplanation AiReport={translated.dummyText} />
<ModerationNotificationActionsBar
itemPk={notification.pk}
isEditing={notification.moderator_feedback}
Expand All @@ -320,7 +326,7 @@ export const ModerationNotification = (props) => {
setIsEditing(true)
}}
/>}
</div>
</ul>
{showFeedbackForm &&
<ModerationFeedbackForm
onSubmit={(payload) => handleFeedbackSubmit(payload)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const ModerationNotificationActionsBar = (props) => {
} = props

return (
<div className="d-flex flex-wrap justify-content-between">
<li className="d-flex flex-wrap justify-content-between">
<button
id={'moderation-notification-actions-bar-button-reply-' + itemPk}
className="btn px-0 userdashboard-mod-notification__btn"
Expand Down Expand Up @@ -62,6 +62,6 @@ export const ModerationNotificationActionsBar = (props) => {
textMouseOn={isBlocked ? translated.unblockText : translated.blockText}
/>
</div>
</div>
</li>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import React from 'react'
import { render, fireEvent, screen } from '@testing-library/react'
import '@testing-library/jest-dom'
import { AiReportExplanation } from '../AiReportExplanation'

test('Snapshot Read More <AiReportExplanation>', () => {
const { container } = render(
<AiReportExplanation AiReport="This is the ai report" />
)
expect(container).toMatchSnapshot()
})

test('Snapshot Read Less <AiReportExplanation>', () => {
const { container } = render(
<AiReportExplanation AiReport="This is the ai report" />
)
const button = screen.getByRole('button')
fireEvent.click(button)
expect(container).toMatchSnapshot()
})

test('Render <AiReportExplanation>', () => {
render(<AiReportExplanation AiReport="This is the ai report" />)
const comment = screen.getByText('Read more')
expect(comment).toBeTruthy()
})

test('Read More <AiReportExplanation>', () => {
render(<AiReportExplanation AiReport="This is the ai report" />)
const readMore = screen.getByText('Read more')
expect(readMore).toBeTruthy()
const button = screen.getByRole('button')
expect(button).toBeTruthy()
fireEvent.click(button)
const readLess = screen.getByText('Read less')
expect(readLess).toBeTruthy()
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Snapshot Read Less <AiReportExplanation> 1`] = `
<div>
<li
class="alert alert--danger d-flex text-start fs-6 mb-3"
>
<i
aria-hidden="True"
class="fas fa-exclamation-circle text-danger pt-1 pe-2"
/>
<p
class="pe-4"
>
This comment contains disinformation. Defakts uses an Artificial Intelligence to scan content for disinformation. Disinformation often shows certain characteristics that allow for a reliable identification.
This is the ai report
<button
aria-label="Click to hide the AI explanation for reporting this comment."
class="btn--link text-danger"
type="button"
>
Read less
</button>
</p>
</li>
</div>
`;
exports[`Snapshot Read More <AiReportExplanation> 1`] = `
<div>
<li
class="alert alert--danger d-flex text-start fs-6 mb-3"
>
<i
aria-hidden="True"
class="fas fa-exclamation-circle text-danger pt-1 pe-2"
/>
<p
class="pe-4"
>
This comment contains disinformation. Defakts uses an Artificial Intelligence to scan content for disinformation. Disinformation often shows certain characteristics that allow for a reliable identification.
<button
aria-label="Click to view the AI explanation for reporting this comment."
class="btn--link text-danger"
type="button"
>
Read more
</button>
</p>
</li>
</div>
`;
7 changes: 7 additions & 0 deletions changelog/7540.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
### Added

- react component to show AI report with dummy data for now

### Changed

- structure of ModerationNotification to be more a11y compliant
4 changes: 4 additions & 0 deletions docs/ai_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FIXME add docs for AI report, for now just list coresponding files

### React components
apps/userdashboard/assets/js/a4_candy_userdashboard/AiReportExplanation.jsx

0 comments on commit b6f4c96

Please sign in to comment.