From 6323c7e0725775ab57f486d6129cbbdc7f1d7f51 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 2 Sep 2026 05:37:13 +0000 Subject: [PATCH 1/3] Show missing girls count badge on lesson chip in teacher-reported view - add missingGirlsCount aggregate to teacher_reported_today view - render count as MUI Badge on each lesson chip in the client Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_011UFsJW6shPwXgjbXDm6kRG --- .../src/entities/teacher-reported-today.jsx | 10 +++++---- .../TeacherReportedToday.entity.ts | 7 ++++++ ...ingGirlsCountToTeacherReportedTodayView.ts | 22 +++++++++++++++++++ 3 files changed, 35 insertions(+), 4 deletions(-) create mode 100644 server/src/migrations/1787700000000-AddMissingGirlsCountToTeacherReportedTodayView.ts diff --git a/client/src/entities/teacher-reported-today.jsx b/client/src/entities/teacher-reported-today.jsx index ba418c45..1af95d56 100644 --- a/client/src/entities/teacher-reported-today.jsx +++ b/client/src/entities/teacher-reported-today.jsx @@ -1,5 +1,5 @@ import { ChipField, DateInput, ReferenceField, RecordContextProvider, TextField, useListContext } from 'react-admin'; -import { Box, Card, CardContent, Typography } from '@mui/material'; +import { Badge, Box, Card, CardContent, Typography } from '@mui/material'; import { getResourceComponents } from '@shared/components/crudContainers/CommonEntity'; import { adminUserFilter } from '@shared/components/fields/PermissionFilter'; @@ -94,9 +94,11 @@ const TeacherReportCards = ({ isAdmin }) => { {group.lessonRows.length > 0 ? ( group.lessonRows.map((row) => ( - - - + + + + + )) ) : ( diff --git a/server/src/db/view-entities/TeacherReportedToday.entity.ts b/server/src/db/view-entities/TeacherReportedToday.entity.ts index dc596f8d..5f0fc2c1 100644 --- a/server/src/db/view-entities/TeacherReportedToday.entity.ts +++ b/server/src/db/view-entities/TeacherReportedToday.entity.ts @@ -19,6 +19,10 @@ import { AttReport } from '../entities/AttReport.entity'; 'MIN(MIN(att_report.createdAt)) OVER (PARTITION BY att_report.userId, att_report.teacherReferenceId, att_report.reportDate, att_report.klassReferenceId)', 'reportHour', ) + .addSelect( + 'COUNT(DISTINCT CASE WHEN att_report.absCount > 0 THEN att_report.studentReferenceId END)', + 'missingGirlsCount', + ) .from(AttReport, 'att_report') .where('att_report.teacherReferenceId IS NOT NULL') .groupBy('att_report.userId') @@ -48,4 +52,7 @@ export class TeacherReportedToday implements IHasUserId { @Column() reportHour: Date; + + @Column() + missingGirlsCount: number; } diff --git a/server/src/migrations/1787700000000-AddMissingGirlsCountToTeacherReportedTodayView.ts b/server/src/migrations/1787700000000-AddMissingGirlsCountToTeacherReportedTodayView.ts new file mode 100644 index 00000000..8b092039 --- /dev/null +++ b/server/src/migrations/1787700000000-AddMissingGirlsCountToTeacherReportedTodayView.ts @@ -0,0 +1,22 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class AddMissingGirlsCountToTeacherReportedTodayView1787700000000 implements MigrationInterface { + name = 'AddMissingGirlsCountToTeacherReportedTodayView1787700000000' + + public async up(queryRunner: QueryRunner): Promise { + const dbName = queryRunner.connection.options.database; + await queryRunner.query(`DELETE FROM \`${dbName}\`.\`typeorm_metadata\` WHERE \`type\` = ? AND \`name\` = ? AND \`schema\` = ?`, ["VIEW","teacher_reported_today",dbName]); + await queryRunner.query(`DROP VIEW IF EXISTS \`teacher_reported_today\``); + await queryRunner.query(`CREATE OR REPLACE VIEW \`teacher_reported_today\` AS SELECT \`att_report\`.\`user_id\` AS \`userId\`, \`att_report\`.\`teacherReferenceId\` AS \`teacherReferenceId\`, \`att_report\`.\`lessonReferenceId\` AS \`lessonReferenceId\`, \`att_report\`.\`klassReferenceId\` AS \`klassReferenceId\`, \`att_report\`.\`report_date\` AS \`reportDate\`, CONCAT(\`att_report\`.\`user_id\`, '_', \`att_report\`.\`teacherReferenceId\`, '_', \`att_report\`.\`report_date\`, '_', COALESCE(\`att_report\`.\`lessonReferenceId\`, 'null'), '_', COALESCE(\`att_report\`.\`klassReferenceId\`, 'null')) AS \`id\`, MIN(MIN(\`att_report\`.\`created_at\`)) OVER (PARTITION BY \`att_report\`.\`user_id\`, \`att_report\`.\`teacherReferenceId\`, \`att_report\`.\`report_date\`, \`att_report\`.\`klassReferenceId\`) AS \`reportHour\`, COUNT(DISTINCT CASE WHEN \`att_report\`.\`abs_count\` > 0 THEN \`att_report\`.\`studentReferenceId\` END) AS \`missingGirlsCount\` FROM \`att_reports\` \`att_report\` WHERE \`att_report\`.\`teacherReferenceId\` IS NOT NULL GROUP BY \`att_report\`.\`user_id\`, \`att_report\`.\`teacherReferenceId\`, \`att_report\`.\`report_date\`, \`att_report\`.\`lessonReferenceId\`, \`att_report\`.\`klassReferenceId\``); + await queryRunner.query(`INSERT INTO \`${dbName}\`.\`typeorm_metadata\`(\`database\`, \`schema\`, \`table\`, \`type\`, \`name\`, \`value\`) VALUES (DEFAULT, ?, DEFAULT, ?, ?, ?)`, [dbName,"VIEW","teacher_reported_today","SELECT `att_report`.`user_id` AS `userId`, `att_report`.`teacherReferenceId` AS `teacherReferenceId`, `att_report`.`lessonReferenceId` AS `lessonReferenceId`, `att_report`.`klassReferenceId` AS `klassReferenceId`, `att_report`.`report_date` AS `reportDate`, CONCAT(`att_report`.`user_id`, '_', `att_report`.`teacherReferenceId`, '_', `att_report`.`report_date`, '_', COALESCE(`att_report`.`lessonReferenceId`, 'null'), '_', COALESCE(`att_report`.`klassReferenceId`, 'null')) AS `id`, MIN(MIN(`att_report`.`created_at`)) OVER (PARTITION BY `att_report`.`user_id`, `att_report`.`teacherReferenceId`, `att_report`.`report_date`, `att_report`.`klassReferenceId`) AS `reportHour`, COUNT(DISTINCT CASE WHEN `att_report`.`abs_count` > 0 THEN `att_report`.`studentReferenceId` END) AS `missingGirlsCount` FROM `att_reports` `att_report` WHERE `att_report`.`teacherReferenceId` IS NOT NULL GROUP BY `att_report`.`user_id`, `att_report`.`teacherReferenceId`, `att_report`.`report_date`, `att_report`.`lessonReferenceId`, `att_report`.`klassReferenceId`"]); + } + + public async down(queryRunner: QueryRunner): Promise { + const dbName = queryRunner.connection.options.database; + await queryRunner.query(`DELETE FROM \`${dbName}\`.\`typeorm_metadata\` WHERE \`type\` = ? AND \`name\` = ? AND \`schema\` = ?`, ["VIEW","teacher_reported_today",dbName]); + await queryRunner.query(`DROP VIEW IF EXISTS \`teacher_reported_today\``); + await queryRunner.query(`CREATE OR REPLACE VIEW \`teacher_reported_today\` AS SELECT \`att_report\`.\`user_id\` AS \`userId\`, \`att_report\`.\`teacherReferenceId\` AS \`teacherReferenceId\`, \`att_report\`.\`lessonReferenceId\` AS \`lessonReferenceId\`, \`att_report\`.\`klassReferenceId\` AS \`klassReferenceId\`, \`att_report\`.\`report_date\` AS \`reportDate\`, CONCAT(\`att_report\`.\`user_id\`, '_', \`att_report\`.\`teacherReferenceId\`, '_', \`att_report\`.\`report_date\`, '_', COALESCE(\`att_report\`.\`lessonReferenceId\`, 'null'), '_', COALESCE(\`att_report\`.\`klassReferenceId\`, 'null')) AS \`id\`, MIN(MIN(\`att_report\`.\`created_at\`)) OVER (PARTITION BY \`att_report\`.\`user_id\`, \`att_report\`.\`teacherReferenceId\`, \`att_report\`.\`report_date\`, \`att_report\`.\`klassReferenceId\`) AS \`reportHour\` FROM \`att_reports\` \`att_report\` WHERE \`att_report\`.\`teacherReferenceId\` IS NOT NULL GROUP BY \`att_report\`.\`user_id\`, \`att_report\`.\`teacherReferenceId\`, \`att_report\`.\`report_date\`, \`att_report\`.\`lessonReferenceId\`, \`att_report\`.\`klassReferenceId\``); + await queryRunner.query(`INSERT INTO \`${dbName}\`.\`typeorm_metadata\`(\`database\`, \`schema\`, \`table\`, \`type\`, \`name\`, \`value\`) VALUES (DEFAULT, ?, DEFAULT, ?, ?, ?)`, [dbName,"VIEW","teacher_reported_today","SELECT `att_report`.`user_id` AS `userId`, `att_report`.`teacherReferenceId` AS `teacherReferenceId`, `att_report`.`lessonReferenceId` AS `lessonReferenceId`, `att_report`.`klassReferenceId` AS `klassReferenceId`, `att_report`.`report_date` AS `reportDate`, CONCAT(`att_report`.`user_id`, '_', `att_report`.`teacherReferenceId`, '_', `att_report`.`report_date`, '_', COALESCE(`att_report`.`lessonReferenceId`, 'null'), '_', COALESCE(`att_report`.`klassReferenceId`, 'null')) AS `id`, MIN(MIN(`att_report`.`created_at`)) OVER (PARTITION BY `att_report`.`user_id`, `att_report`.`teacherReferenceId`, `att_report`.`report_date`, `att_report`.`klassReferenceId`) AS `reportHour` FROM `att_reports` `att_report` WHERE `att_report`.`teacherReferenceId` IS NOT NULL GROUP BY `att_report`.`user_id`, `att_report`.`teacherReferenceId`, `att_report`.`report_date`, `att_report`.`lessonReferenceId`, `att_report`.`klassReferenceId`"]); + } + +} From a6565604f73a4982410cb78fe8d5c46d9528fd01 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 2 Sep 2026 08:15:04 +0000 Subject: [PATCH 2/3] Use real timestamp for migration; show all rows on teacher-reported-today - rename the missing-girls-count view migration to a real epoch timestamp - give teacher-reported-today its own list with a high perPage cap and no pagination footer, since it's a card view rather than a table Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_011UFsJW6shPwXgjbXDm6kRG --- .../src/entities/teacher-reported-today.jsx | 33 +++++++++++++++++-- ...ngGirlsCountToTeacherReportedTodayView.ts} | 4 +-- 2 files changed, 33 insertions(+), 4 deletions(-) rename server/src/migrations/{1787700000000-AddMissingGirlsCountToTeacherReportedTodayView.ts => 1788336876049-AddMissingGirlsCountToTeacherReportedTodayView.ts} (96%) diff --git a/client/src/entities/teacher-reported-today.jsx b/client/src/entities/teacher-reported-today.jsx index 1af95d56..6291b8f0 100644 --- a/client/src/entities/teacher-reported-today.jsx +++ b/client/src/entities/teacher-reported-today.jsx @@ -1,7 +1,14 @@ -import { ChipField, DateInput, ReferenceField, RecordContextProvider, TextField, useListContext } from 'react-admin'; +import { ChipField, DateInput, ReferenceField, RecordContextProvider, TextField, useListContext, usePermissions } from 'react-admin'; import { Badge, Box, Card, CardContent, Typography } from '@mui/material'; import { getResourceComponents } from '@shared/components/crudContainers/CommonEntity'; +import { CommonList } from '@shared/components/crudContainers/CommonList'; +import { EmptyPage } from '@shared/components/crudContainers/EmptyPage'; import { adminUserFilter } from '@shared/components/fields/PermissionFilter'; +import { filterArrayByParams } from '@shared/utils/filtersUtil'; +import { useIsAdmin } from '@shared/utils/permissionsUtil'; + +// This is a card view, not a table, so cap high rather than paginate at 10 rows. +const LIST_PAGE_SIZE = 1000; const ISRAEL_TIMEZONE = 'Asia/Jerusalem'; const todayDateOnly = new Date().toLocaleDateString('en-CA', { timeZone: ISRAEL_TIMEZONE }); @@ -118,6 +125,28 @@ const TeacherReportCards = ({ isAdmin }) => { const Datagrid = ({ isAdmin }) => ; +// Card view has no pagination footer, so fetch everything up front instead of the default 10-row page. +const List = () => { + const isAdmin = useIsAdmin(); + const { permissions } = usePermissions(); + const filtersArr = filterArrayByParams(filters, { isAdmin, permissions }); + + return ( + } + sort={{ field: 'reportDate', order: 'DESC' }} + configurable={false} + perPage={LIST_PAGE_SIZE} + pagination={false} + > + + + ); +}; + const entity = { Datagrid, filters, @@ -127,4 +156,4 @@ const entity = { sort: { field: 'reportDate', order: 'DESC' }, }; -export default getResourceComponents(entity); +export default { ...getResourceComponents(entity), list: List }; diff --git a/server/src/migrations/1787700000000-AddMissingGirlsCountToTeacherReportedTodayView.ts b/server/src/migrations/1788336876049-AddMissingGirlsCountToTeacherReportedTodayView.ts similarity index 96% rename from server/src/migrations/1787700000000-AddMissingGirlsCountToTeacherReportedTodayView.ts rename to server/src/migrations/1788336876049-AddMissingGirlsCountToTeacherReportedTodayView.ts index 8b092039..1855123b 100644 --- a/server/src/migrations/1787700000000-AddMissingGirlsCountToTeacherReportedTodayView.ts +++ b/server/src/migrations/1788336876049-AddMissingGirlsCountToTeacherReportedTodayView.ts @@ -1,7 +1,7 @@ import { MigrationInterface, QueryRunner } from "typeorm"; -export class AddMissingGirlsCountToTeacherReportedTodayView1787700000000 implements MigrationInterface { - name = 'AddMissingGirlsCountToTeacherReportedTodayView1787700000000' +export class AddMissingGirlsCountToTeacherReportedTodayView1788336876049 implements MigrationInterface { + name = 'AddMissingGirlsCountToTeacherReportedTodayView1788336876049' public async up(queryRunner: QueryRunner): Promise { const dbName = queryRunner.connection.options.database; From 9d15dbf2a32013379b71570ef3846f90f7a79425 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 2 Sep 2026 15:50:38 +0000 Subject: [PATCH 3/3] Forward filter prop through custom teacher-reported-today List Matches the shared CommonEntity List's own contract, per Copilot review. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_011UFsJW6shPwXgjbXDm6kRG --- client/src/entities/teacher-reported-today.jsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/client/src/entities/teacher-reported-today.jsx b/client/src/entities/teacher-reported-today.jsx index 6291b8f0..13224eca 100644 --- a/client/src/entities/teacher-reported-today.jsx +++ b/client/src/entities/teacher-reported-today.jsx @@ -126,13 +126,15 @@ const TeacherReportCards = ({ isAdmin }) => { const Datagrid = ({ isAdmin }) => ; // Card view has no pagination footer, so fetch everything up front instead of the default 10-row page. -const List = () => { +// Mirrors CommonEntity's own List wiring, which likewise only forwards `filter`. +const List = ({ filter = {} }) => { const isAdmin = useIsAdmin(); const { permissions } = usePermissions(); const filtersArr = filterArrayByParams(filters, { isAdmin, permissions }); return (