mirror of https://github.com/msgbyte/tailchat
				
				
				
			feat: 增加更多的资源(message/group/file)
							parent
							
								
									96292a23ba
								
							
						
					
					
						commit
						bacb5b3031
					
				@ -0,0 +1,26 @@
 | 
			
		||||
import React from 'react';
 | 
			
		||||
import {
 | 
			
		||||
  BooleanField,
 | 
			
		||||
  Datagrid,
 | 
			
		||||
  DateField,
 | 
			
		||||
  List,
 | 
			
		||||
  ReferenceField,
 | 
			
		||||
  TextField,
 | 
			
		||||
  SearchInput,
 | 
			
		||||
} from 'react-admin';
 | 
			
		||||
 | 
			
		||||
export const MessageList: React.FC = () => (
 | 
			
		||||
  <List filters={[<SearchInput key="search" source="q" alwaysOn />]}>
 | 
			
		||||
    <Datagrid rowClick="show">
 | 
			
		||||
      <TextField source="id" label="ID" sortable={true} sortByOrder="DESC" />
 | 
			
		||||
      <TextField source="content" label="内容" />
 | 
			
		||||
      <TextField source="author" label="作者" />
 | 
			
		||||
      <ReferenceField source="groupId" reference="groups" label="群组ID" />
 | 
			
		||||
      <TextField source="converseId" label="会话ID" />
 | 
			
		||||
      <BooleanField source="hasRecall" label="撤回" />
 | 
			
		||||
      <TextField source="reactions" label="消息反应" />
 | 
			
		||||
      <DateField source="createdAt" label="创建时间" />
 | 
			
		||||
    </Datagrid>
 | 
			
		||||
  </List>
 | 
			
		||||
);
 | 
			
		||||
MessageList.displayName = 'MessageList';
 | 
			
		||||
@ -0,0 +1,51 @@
 | 
			
		||||
import {
 | 
			
		||||
  Datagrid,
 | 
			
		||||
  DateField,
 | 
			
		||||
  List,
 | 
			
		||||
  TextField,
 | 
			
		||||
  ShowButton,
 | 
			
		||||
  EditButton,
 | 
			
		||||
  SearchInput,
 | 
			
		||||
  ArrayField,
 | 
			
		||||
  SingleFieldList,
 | 
			
		||||
  ChipField,
 | 
			
		||||
} from 'react-admin';
 | 
			
		||||
import React from 'react';
 | 
			
		||||
import { Box } from '@mui/material';
 | 
			
		||||
 | 
			
		||||
const PostListActionToolbar = ({ children, ...props }) => (
 | 
			
		||||
  <Box sx={{ alignItems: 'center', display: 'flex' }}>{children}</Box>
 | 
			
		||||
);
 | 
			
		||||
 | 
			
		||||
export const GroupList: React.FC = () => (
 | 
			
		||||
  <List filters={[<SearchInput key="search" source="q" alwaysOn />]}>
 | 
			
		||||
    <Datagrid>
 | 
			
		||||
      <TextField
 | 
			
		||||
        source="id"
 | 
			
		||||
        label="群组ID"
 | 
			
		||||
        sortable={true}
 | 
			
		||||
        sortByOrder="DESC"
 | 
			
		||||
      />
 | 
			
		||||
      <TextField source="name" label="群组名称" />
 | 
			
		||||
      <TextField source="owner" label="管理员" />
 | 
			
		||||
      <TextField source="members.length" label="成员数量" />
 | 
			
		||||
      <ArrayField source="panels" label="面板">
 | 
			
		||||
        <SingleFieldList>
 | 
			
		||||
          <ChipField source="name" />
 | 
			
		||||
        </SingleFieldList>
 | 
			
		||||
      </ArrayField>
 | 
			
		||||
      <ArrayField source="roles" label="角色">
 | 
			
		||||
        <SingleFieldList>
 | 
			
		||||
          <ChipField source="name" />
 | 
			
		||||
        </SingleFieldList>
 | 
			
		||||
      </ArrayField>
 | 
			
		||||
      <TextField source="fallbackPermissions" label="默认权限" />
 | 
			
		||||
      <DateField source="createdAt" label="创建时间" />
 | 
			
		||||
      <PostListActionToolbar>
 | 
			
		||||
        <ShowButton />
 | 
			
		||||
        <EditButton />
 | 
			
		||||
      </PostListActionToolbar>
 | 
			
		||||
    </Datagrid>
 | 
			
		||||
  </List>
 | 
			
		||||
);
 | 
			
		||||
GroupList.displayName = 'GroupList';
 | 
			
		||||
@ -0,0 +1,32 @@
 | 
			
		||||
import { Router } from 'express';
 | 
			
		||||
import raExpressMongoose from 'express-mongoose-ra-json-server';
 | 
			
		||||
 | 
			
		||||
const router = Router();
 | 
			
		||||
 | 
			
		||||
router.use(
 | 
			
		||||
  '/users',
 | 
			
		||||
  raExpressMongoose(require('../../../models/user/user').default, {
 | 
			
		||||
    q: ['nickname', 'email'],
 | 
			
		||||
  })
 | 
			
		||||
);
 | 
			
		||||
router.use(
 | 
			
		||||
  '/messages',
 | 
			
		||||
  raExpressMongoose(require('../../../models/chat/message').default, {
 | 
			
		||||
    q: ['content'],
 | 
			
		||||
    allowedRegexFields: ['content'],
 | 
			
		||||
  })
 | 
			
		||||
);
 | 
			
		||||
router.use(
 | 
			
		||||
  '/groups',
 | 
			
		||||
  raExpressMongoose(require('../../../models/group/group').default, {
 | 
			
		||||
    q: ['name'],
 | 
			
		||||
  })
 | 
			
		||||
);
 | 
			
		||||
router.use(
 | 
			
		||||
  '/file',
 | 
			
		||||
  raExpressMongoose(require('../../../models/file').default, {
 | 
			
		||||
    q: ['objectName'],
 | 
			
		||||
  })
 | 
			
		||||
);
 | 
			
		||||
 | 
			
		||||
export { router };
 | 
			
		||||
					Loading…
					
					
				
		Reference in New Issue