All files / src/resources reports.tsx

92.85% Statements 13/14
100% Branches 2/2
83.33% Functions 5/6
100% Lines 12/12

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114                                                    2x   2x 1x 1x                                                                                         2x 1x   1x                       2x   2x 1x                     2x         2x        
import PageviewIcon from "@mui/icons-material/Pageview";
import ViewListIcon from "@mui/icons-material/ViewList";
import ReportIcon from "@mui/icons-material/Warning";
import {
  DataTable,
  DateField,
  DeleteButton,
  List,
  ListProps,
  NumberField,
  Pagination,
  ReferenceField,
  ResourceProps,
  Show,
  ShowProps,
  Tab,
  TabbedShowLayout,
  TextField,
  TopToolbar,
  useRecordContext,
  useTranslate,
} from "react-admin";
 
import { DATE_FORMAT } from "../components/date";
import { MXCField } from "../components/media";
 
const ReportPagination = () => <Pagination rowsPerPageOptions={[10, 25, 50, 100, 500, 1000]} />;
 
export const ReportShow = (props: ShowProps) => {
  const translate = useTranslate();
  return (
    <Show {...props} actions={<ReportShowActions />}>
      <TabbedShowLayout>
        <Tab
          label={translate("synapseadmin.reports.tabs.basic", {
            smart_count: 1,
          })}
          icon={<ViewListIcon />}
        >
          <DateField source="received_ts" showTime options={DATE_FORMAT} sortable={true} />
          <ReferenceField source="user_id" reference="users">
            <TextField source="id" />
          </ReferenceField>
          <NumberField source="score" />
          <TextField source="reason" />
          <TextField source="name" />
          <TextField source="canonical_alias" label="resources.rooms.fields.canonical_alias" />
          <ReferenceField source="room_id" reference="rooms" link="show" label="resources.rooms.fields.room_id">
            <TextField source="id" />
          </ReferenceField>
        </Tab>
 
        <Tab label="synapseadmin.reports.tabs.detail" icon={<PageviewIcon />} path="detail">
          <DateField source="event_json.origin_server_ts" showTime options={DATE_FORMAT} sortable={true} />
          <ReferenceField source="sender" reference="users">
            <TextField source="id" />
          </ReferenceField>
          <TextField source="sender" label="Sender (raw user ID)" />
          <TextField source="event_id" />
          <TextField source="event_json.origin" />
          <TextField source="event_json.type" />
          <TextField source="event_json.content.msgtype" />
          <TextField source="event_json.content.body" />
          <TextField source="event_json.content.info.mimetype" />
          <MXCField source="event_json.content.url" />
          <TextField source="event_json.content.format" />
          <TextField source="event_json.content.formatted_body" />
          <TextField source="event_json.content.algorithm" />
          <TextField source="event_json.content.device_id" label="resources.devices.fields.device_id" />
        </Tab>
      </TabbedShowLayout>
    </Show>
  );
};
 
const ReportShowActions = () => {
  const record = useRecordContext();
 
  return (
    <TopToolbar>
      <DeleteButton
        record={record}
        mutationMode="pessimistic"
        confirmTitle="resources.reports.action.erase.title"
        confirmContent="resources.reports.action.erase.content"
      />
    </TopToolbar>
  );
};
 
const ReceivedTsField = (props: any) => <DateField {...props} showTime options={DATE_FORMAT} />;
 
export const ReportList = (props: ListProps) => (
  <List {...props} pagination={<ReportPagination />} sort={{ field: "received_ts", order: "DESC" }}>
    <DataTable rowClick="show" bulkActionButtons={false}>
      <DataTable.Col source="id" />
      <DataTable.Col source="received_ts" field={ReceivedTsField} />
      <DataTable.Col source="user_id" />
      <DataTable.NumberCol source="score" />
      <DataTable.Col source="name" />
    </DataTable>
  </List>
);
 
const resource = {
  name: "reports",
  icon: ReportIcon,
  list: ReportList,
  show: ReportShow,
  recordRepresentation: (record: { id: string; room_id?: string }) => record.room_id || record.id,
} satisfies ResourceProps;
 
export default resource;