Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Show blob divert event #33

Merged
merged 3 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/actions/ModActionPanel/BlobList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function BlobList(props: {
const displayActionType = subjectStatus?.takendown ? 'Taken down' : ''
return (
<div key={blob.cid} className="relative flex items-start">
<div className="flex h-5 items-center">
<div className="flex h-5 items-center ml-1">
<input
id={`blob-${blob.cid}`}
name={name}
Expand All @@ -37,7 +37,7 @@ export function BlobList(props: {
<div className="ml-3 text-sm min-w-0 text-ellipsis overflow-hidden whitespace-nowrap">
<label
htmlFor={`blob-${blob.cid}`}
className="font-medium text-gray-700"
className="font-medium text-gray-700 dark:text-gray-100"
>
{subjectStatus && (
<>
Expand Down
49 changes: 32 additions & 17 deletions app/actions/ModActionPanel/QuickAction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ import {
LabelListEmpty,
diffLabels,
displayLabel,
getLabelGroupInfo,
getLabelsForSubject,
toLabelVal,
unFlagSelfLabel,
isSelfLabel,
LabelGroupInfo,
} from '@/common/labels'
import { FullScreenActionPanel } from '@/common/FullScreenActionPanel'
import { PreviewCard } from '@/common/PreviewCard'
Expand All @@ -46,6 +46,7 @@ import { getProfileUriForDid } from '@/reports/helpers/subject'
import { Dialog } from '@headlessui/react'
import { SubjectSwitchButton } from '@/common/SubjectSwitchButton'
import { diffTags } from 'components/tags/utils'
import { ActionError } from '@/reports/ModerationForm/ActionError'

const FORM_ID = 'mod-action-panel'
const useBreakpoint = createBreakpoint({ xs: 340, sm: 640 })
Expand Down Expand Up @@ -153,7 +154,10 @@ function Form(
replaceFormWithEvents,
...others
} = props
const [submitting, setSubmitting] = useState(false)
const [submission, setSubmission] = useState<{
isSubmitting: boolean
error: string
}>({ isSubmitting: false, error: '' })
const { data: subjectStatus, refetch: refetchSubjectStatus } = useQuery({
// subject of the report
queryKey: ['modSubjectStatus', { subject }],
Expand All @@ -179,6 +183,7 @@ function Form(
)
const isTagEvent = modEventType === MOD_EVENTS.TAG
const isLabelEvent = modEventType === MOD_EVENTS.LABEL
const isDivertEvent = modEventType === MOD_EVENTS.DIVERT
const isMuteEvent = modEventType === MOD_EVENTS.MUTE
const isCommentEvent = modEventType === MOD_EVENTS.COMMENT
const shouldShowDurationInHoursField =
Expand Down Expand Up @@ -234,7 +239,7 @@ function Form(
) => {
ev.preventDefault()
try {
setSubmitting(true)
setSubmission({ isSubmitting: true, error: '' })
const formData = new FormData(ev.currentTarget)
const nextLabels = String(formData.get('labels'))!.split(',')
const coreEvent: Parameters<typeof onSubmit>[0]['event'] = {
Expand Down Expand Up @@ -266,6 +271,14 @@ function Form(
const { subject: subjectInfo, record: recordInfo } =
await createSubjectFromId(subject)

const subjectBlobCids = formData
.getAll('subjectBlobCids')
.map((cid) => String(cid))

if (isDivertEvent && !subjectBlobCids.length) {
throw new Error('blob-selection-required')
}

// This block handles an edge case where a label may be applied to profile record and then the profile record is updated by the user.
// In that state, if the moderator reverts the label, the event is emitted for the latest CID of the profile entry which does NOT revert
// the label applied to the old CID.
Expand Down Expand Up @@ -351,9 +364,7 @@ function Form(
await onSubmit({
subject: subjectInfo,
createdBy: client.session.did,
subjectBlobCids: formData
.getAll('subjectBlobCids')
.map((cid) => String(cid)),
subjectBlobCids,
event: coreEvent,
})
}
Expand All @@ -379,10 +390,9 @@ function Form(
// This state is not kept in the form and driven by state so we need to reset it manually after submission
setModEventType(MOD_EVENTS.ACKNOWLEDGE)
shouldMoveToNextSubject && navigateQueue(1)
setSubmission({ error: '', isSubmitting: false })
} catch (err) {
throw err
} finally {
setSubmitting(false)
setSubmission({ error: (err as Error).message, isSubmitting: false })
}
}
// Keyboard shortcuts for action types
Expand Down Expand Up @@ -525,12 +535,10 @@ function Form(
<LabelList className="-ml-1">
{!currentLabels.length && <LabelListEmpty className="ml-1" />}
{currentLabels.map((label) => {
const labelGroup = getLabelGroupInfo(unFlagSelfLabel(label))

return (
<LabelChip
key={label}
style={{ color: labelGroup.color }}
style={{ color: LabelGroupInfo[label]?.color }}
>
{displayLabel(label)}
</LabelChip>
Expand Down Expand Up @@ -561,6 +569,7 @@ function Form(
<ModEventSelectorButton
subjectStatus={subjectStatus}
selectedAction={modEventType}
hasBlobs={!!record?.blobs?.length}
setSelectedAction={(action) => setModEventType(action)}
/>
</div>
Expand Down Expand Up @@ -654,6 +663,12 @@ function Form(
/>
)}

{submission.error && (
<div className="my-2">
<ActionError error={submission.error} />
</div>
)}

<div className="mt-auto flex flex-row justify-between">
<div>
<input
Expand All @@ -664,7 +679,7 @@ function Form(
/>
<ButtonSecondary
className="px-2 sm:px-4 sm:mr-2"
disabled={submitting}
disabled={submission.isSubmitting}
onClick={onCancel}
>
<span className="text-sm sm:text-base">(C)ancel</span>
Expand All @@ -674,14 +689,14 @@ function Form(
<ButtonPrimary
ref={submitButton}
type="submit"
disabled={submitting}
disabled={submission.isSubmitting}
className="mx-1 px-2 sm:px-4"
>
<span className="text-sm sm:text-base">(S)ubmit</span>
</ButtonPrimary>
<ButtonPrimary
type="button"
disabled={submitting}
disabled={submission.isSubmitting}
onClick={submitAndGoNext}
className="px-2 sm:px-4"
>
Expand All @@ -705,14 +720,14 @@ function Form(
<div className="flex justify-between mt-auto">
<ButtonSecondary
onClick={() => navigateQueue(-1)}
disabled={submitting}
disabled={submission.isSubmitting}
>
<ArrowLeftIcon className="h-4 w-4 inline-block align-text-bottom" />
</ButtonSecondary>

<ButtonSecondary
onClick={() => navigateQueue(1)}
disabled={submitting}
disabled={submission.isSubmitting}
>
<ArrowRightIcon className="h-4 w-4 inline-block align-text-bottom" />
</ButtonSecondary>
Expand Down
19 changes: 19 additions & 0 deletions components/common/Card.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from 'react'

export type Variation = 'default' | 'error'

export const Card = ({
children,
variation = 'default',
}: {
children: React.ReactNode
variation?: Variation
}) => {
let className = 'shadow rounded-sm p-2'
if (variation === 'error') {
className += ' bg-red-100 dark:bg-red-600 border-red-400 text-red-700 dark:text-red-100'
} else {
className += ' dark:shadow-slate-700 bg-white dark:bg-slate-800'
}
return <div className={className}>{children}</div>
}
30 changes: 7 additions & 23 deletions components/common/labels/Grid.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import { useState } from 'react'
import Select from 'react-tailwindcss-select'
import {
labelOptions,
displayLabel,
groupLabelList,
getLabelGroupInfo,
buildAllLabelOptions,
} from './util'
import { buildAllLabelOptions, ALL_LABELS, LabelGroupInfo } from './util'

const EMPTY_ARR = []
type SelectProps = React.ComponentProps<typeof Select>
Expand All @@ -17,7 +11,7 @@
formId,
name,
defaultLabels = EMPTY_ARR,
options = labelOptions,
options = Object.keys(ALL_LABELS),
disabled,
onChange,
} = props
Expand All @@ -28,19 +22,10 @@
})),
)
const allOptions = buildAllLabelOptions(defaultLabels, options)
const groupedLabelList = groupLabelList(allOptions)
const selectorOptions = Object.entries(groupedLabelList).map(
([group, groupInfo]) => ({
label: group,
options: groupInfo.labels.map((label) => {
const labelText = typeof label === 'string' ? label : label.id
return {
label: labelText,
value: labelText,
}
}),
}),
)
const selectorOptions = Object.values(ALL_LABELS).map((labelOption) => ({
label: labelOption.identifier,

Check failure on line 26 in components/common/labels/Grid.tsx

View workflow job for this annotation

GitHub Actions / Build

Property 'identifier' does not exist on type 'LabelDefinition'.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any idea what this new type error is?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I assume this is related to @atproto/api updates.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, cleaning it up now. I was referencing a local version of the api package so had to adjust things to get the app to run.

value: labelOption.identifier,

Check failure on line 27 in components/common/labels/Grid.tsx

View workflow job for this annotation

GitHub Actions / Build

Property 'identifier' does not exist on type 'LabelDefinition'.
}))

// TODO: selected label text doesn't feel very nice here
return (
Expand All @@ -62,11 +47,10 @@
value={selectedLabels}
options={selectorOptions}
formatOptionLabel={(data) => {
const labelGroup = getLabelGroupInfo(data.label)
return (
<li
className={`block transition duration-200 py-1 cursor-pointer select-none truncate`}
style={{ color: labelGroup.color }}
style={{ color: LabelGroupInfo[data.label]?.color }}
>
{data.label}
</li>
Expand Down
Loading
Loading