Skip to content

Commit 418c66f

Browse files
committed
Merge origin/main, bump client/shared to nra-client#50 (lastSentMessage unsortable fix)
origin/main had independently bumped client/shared (a2f2768) and server/shared (332a24f) since this branch forked - a real 3-way divergence on both gitlinks, not just a stale-cache mergeable_state. Resolved by taking this branch's newer client/shared descendant (172c1b0, includes #49 and the #50 sortable fix) and main's newer server/shared (unrelated teacher-email-array work, untouched by this branch). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QtUC1hhZBNwRYmjMmWPvon
2 parents e489846 + 18c46e5 commit 418c66f

8 files changed

Lines changed: 66 additions & 14 deletions

File tree

‎client/shared‎

‎client/src/entities/teacher-reported-today.jsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ const List = ({ filter = {} }) => {
155155
filterDefaultValues={filterDefaultValues}
156156
exporter={false}
157157
empty={<EmptyPage />}
158-
sort={{ field: 'reportDate', order: 'DESC' }}
158+
sort={{ field: 'reportHour', order: 'ASC' }}
159159
configurable={false}
160160
perPage={LIST_PAGE_SIZE}
161161
pagination={false}
@@ -171,7 +171,7 @@ const entity = {
171171
filterDefaultValues,
172172
exporter: false,
173173
configurable: false,
174-
sort: { field: 'reportDate', order: 'DESC' },
174+
sort: { field: 'reportHour', order: 'ASC' },
175175
};
176176

177177
export default { ...getResourceComponents(entity), list: List };

‎client/src/entities/teacher.jsx‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
import {
2+
ArrayInput,
23
DateField,
34
DateInput,
45
DateTimeInput,
6+
email,
57
EmailField,
8+
FunctionField,
69
maxLength,
710
ReferenceField,
811
required,
12+
SimpleFormIterator,
913
TextField,
1014
TextInput,
1115
} from 'react-admin';
@@ -34,7 +38,14 @@ const Datagrid = ({ isAdmin, children, ...props }) => {
3438
<TextField source="number" />
3539
<TextField source="phone" />
3640
<TextField source="phone2" />
37-
<EmailField source="email" />
41+
<FunctionField
42+
source="email"
43+
render={(record) => [].concat(record.email ?? []).map((addr) => (
44+
<div key={addr}>
45+
<EmailField record={{ email: addr }} source="email" />
46+
</div>
47+
))}
48+
/>
3849
<TextField source="comment" />
3950
{isAdmin && <DateField showDate showTime source="createdAt" />}
4051
{isAdmin && <DateField showDate showTime source="updatedAt" />}
@@ -54,7 +65,11 @@ const Inputs = ({ isCreate, isAdmin }) => {
5465
<TextInput source="number" validate={[maxLength(10), unique()]} />
5566
<TextInput source="phone" validate={maxLength(10)} />
5667
<TextInput source="phone2" validate={maxLength(10)} />
57-
<TextInput source="email" validate={maxLength(500)} />
68+
<ArrayInput source="email">
69+
<SimpleFormIterator>
70+
<TextInput source="" label={false} type="email" validate={email()} />
71+
</SimpleFormIterator>
72+
</ArrayInput>
5873
<TextInput source="comment" validate={maxLength(1000)} />
5974
{!isCreate && isAdmin && <DateTimeInput source="createdAt" disabled />}
6075
{!isCreate && isAdmin && <DateTimeInput source="updatedAt" disabled />}

‎server/src/db/entities/Teacher.entity.ts‎

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { BeforeInsert, BeforeUpdate, Column, Entity, Index, JoinColumn, ManyToOne, PrimaryGeneratedColumn } from 'typeorm';
22
import { IHasUserId } from '@shared/base-entity/interface';
33
import { User } from 'src/db/entities/User.entity';
4-
import { IsOptional } from 'class-validator';
4+
import { IsArray, IsEmail, IsOptional } from 'class-validator';
5+
import { Transform } from 'class-transformer';
56
import { CrudValidationGroups } from '@dataui/crud';
67
import { IsNotEmpty, IsUniqueCombination, MaxLength } from '@shared/utils/validation/class-validator-he';
78
import { StringType } from '@shared/utils/entity/class-transformer';
@@ -17,8 +18,9 @@ import { CreatedAtColumn, UpdatedAtColumn } from '@shared/utils/entity/column-ty
1718
export class Teacher implements IHasUserId {
1819
@BeforeInsert()
1920
@BeforeUpdate()
20-
normalizeNumber() {
21+
normalizeFields() {
2122
if (this.number === '') this.number = null;
23+
this.email = splitEmails(this.email);
2224
}
2325

2426
@PrimaryGeneratedColumn({ type: 'int', name: 'id' })
@@ -65,10 +67,11 @@ export class Teacher implements IHasUserId {
6567
number: string | null;
6668

6769
@IsOptional({ always: true })
68-
@StringType
69-
@MaxLength(500, { always: true })
70-
@Column('varchar', { name: 'email', nullable: true, length: 500 })
71-
email: string | null;
70+
@IsArray({ always: true })
71+
@IsEmail({}, { each: true, always: true })
72+
@Transform(({ value }) => splitEmails(value))
73+
@Column('simple-array', { name: 'email', nullable: true })
74+
email: string[] | null;
7275

7376
@IsOptional({ always: true })
7477
@StringType
@@ -95,3 +98,11 @@ export class Teacher implements IHasUserId {
9598
@JoinColumn([{ name: 'user_id', referencedColumnName: 'id' }])
9699
user: User;
97100
}
101+
102+
function splitEmails(value: unknown): string[] | null {
103+
if (typeof value !== 'string') return value as string[] | null;
104+
return value
105+
.split(',')
106+
.map((e) => e.trim())
107+
.filter(Boolean);
108+
}

‎server/src/entity-modules/__tests__/teacher.config.spec.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,17 @@ describe('TeacherConfig', () => {
1616
{ value: 'name', label: 'שם' },
1717
{ value: 'phone', label: 'טלפון' },
1818
{ value: 'phone2', label: 'טלפון 2' },
19-
{ value: 'email', label: 'כתובת מייל' },
19+
{ value: expect.any(Function), label: 'כתובת מייל' },
2020
{ value: 'displayName', label: 'שם לתצוגה' },
2121
]),
2222
);
2323
});
24+
25+
it('should join teacher emails into a comma separated string for export', () => {
26+
const headers = teacherConfig.exporter.getExportHeaders([]);
27+
const emailHeader = headers.find((h: any) => h.label === 'כתובת מייל') as any;
28+
29+
expect(emailHeader.value({ email: ['a@example.com', 'b@example.com'] })).toBe('a@example.com, b@example.com');
30+
expect(emailHeader.value({ email: null })).toBe('');
31+
});
2432
});

‎server/src/entity-modules/teacher.config.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function getConfig(): BaseEntityModuleOptions {
1313
{ value: 'number', label: 'מספר מורה' },
1414
{ value: 'phone', label: 'טלפון' },
1515
{ value: 'phone2', label: 'טלפון 2' },
16-
{ value: 'email', label: 'כתובת מייל' },
16+
{ value: (record: any) => (record.email ?? []).join(', '), label: 'כתובת מייל' },
1717
{ value: 'displayName', label: 'שם לתצוגה' },
1818
];
1919
},
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { MigrationInterface, QueryRunner } from "typeorm";
2+
3+
export class ConvertTeacherEmailToArray1788633251783 implements MigrationInterface {
4+
name = 'ConvertTeacherEmailToArray1788633251783'
5+
6+
public async up(queryRunner: QueryRunner): Promise<void> {
7+
await queryRunner.query(`
8+
ALTER TABLE \`teachers\` MODIFY COLUMN \`email\` text NULL
9+
`);
10+
}
11+
12+
public async down(queryRunner: QueryRunner): Promise<void> {
13+
await queryRunner.query(`
14+
ALTER TABLE \`teachers\` MODIFY COLUMN \`email\` varchar(500) NULL
15+
`);
16+
}
17+
18+
}

0 commit comments

Comments
 (0)