Преглед изворни кода

Add an optional Updated column to the work order list (#669)

Bernt Christian Egeland пре 5 дана
родитељ
комит
989c287ab5

+ 1 - 0
messages/bg/workOrders.json

@@ -33,6 +33,7 @@
       "date": "Дата",
       "total": "Общо",
       "promised": "Обещан срок",
+      "updated": "Обновено",
       "promisedOverdue": "Обещан срок: {date}, просрочен"
     },
     "emailSubject": "Актуализация на статуса на превозното средство: {status}",

+ 1 - 0
messages/de/workOrders.json

@@ -33,6 +33,7 @@
       "date": "Datum",
       "total": "Gesamt",
       "promised": "Zugesagt",
+      "updated": "Geändert",
       "promisedOverdue": "Zugesagt {date}, überfällig"
     },
     "emailSubject": "Fahrzeugstatusupdate: {status}",

+ 1 - 0
messages/en/workOrders.json

@@ -33,6 +33,7 @@
       "date": "Date",
       "total": "Total",
       "promised": "Promised",
+      "updated": "Updated",
       "promisedOverdue": "Promised {date}, overdue"
     },
     "emailSubject": "Vehicle Status Update: {status}",

+ 1 - 0
messages/es/workOrders.json

@@ -33,6 +33,7 @@
       "date": "Fecha",
       "total": "Total",
       "promised": "Prometido",
+      "updated": "Actualizado",
       "promisedOverdue": "Prometido {date}, retrasado"
     },
     "emailSubject": "Actualización de Estado del Vehículo: {status}",

+ 1 - 0
messages/fr/workOrders.json

@@ -33,6 +33,7 @@
       "date": "Date",
       "total": "Total",
       "promised": "Promis",
+      "updated": "Modifié",
       "promisedOverdue": "Promis {date}, en retard"
     },
     "emailSubject": "Mise à jour du Statut du Véhicule: {status}",

+ 1 - 0
messages/it/workOrders.json

@@ -33,6 +33,7 @@
       "date": "Data",
       "total": "Totale",
       "promised": "Promesso",
+      "updated": "Aggiornato",
       "promisedOverdue": "Promesso {date}, in ritardo"
     },
     "emailSubject": "Aggiornamento Stato Veicolo: {status}",

+ 1 - 0
messages/lt/workOrders.json

@@ -33,6 +33,7 @@
       "date": "Data",
       "total": "Suma",
       "promised": "Pažadėta",
+      "updated": "Atnaujinta",
       "promisedOverdue": "Pažadėta {date}, vėluoja"
     },
     "emailSubject": "Transporto priemonės būsenos atnaujinimas: {status}",

+ 1 - 0
messages/nb/workOrders.json

@@ -33,6 +33,7 @@
       "date": "Dato",
       "total": "Total",
       "promised": "Lovet",
+      "updated": "Endret",
       "promisedOverdue": "Lovet {date}, forsinket"
     },
     "emailSubject": "Kjøretøystatus oppdatert: {status}",

+ 1 - 0
messages/nl/workOrders.json

@@ -33,6 +33,7 @@
       "date": "Datum",
       "total": "Totaal",
       "promised": "Beloofd",
+      "updated": "Gewijzigd",
       "promisedOverdue": "Beloofd {date}, te laat"
     },
     "emailSubject": "Voertuigstatus bijgewerkt: {status}",

+ 1 - 0
messages/pl/workOrders.json

@@ -33,6 +33,7 @@
       "date": "Data",
       "total": "Razem",
       "promised": "Obiecane",
+      "updated": "Zmienione",
       "promisedOverdue": "Obiecane {date}, po terminie"
     },
     "emailSubject": "Aktualizacja Statusu Pojazdu: {status}",

+ 1 - 0
messages/pt-BR/workOrders.json

@@ -33,6 +33,7 @@
       "date": "Data",
       "total": "Total",
       "promised": "Prometido",
+      "updated": "Atualizado",
       "promisedOverdue": "Prometido {date}, atrasado"
     },
     "emailSubject": "Atualização de Status do Veículo: {status}",

+ 1 - 0
messages/pt-PT/workOrders.json

@@ -33,6 +33,7 @@
       "date": "Data",
       "total": "Total",
       "promised": "Prometido",
+      "updated": "Atualizado",
       "promisedOverdue": "Prometido {date}, atrasado"
     },
     "emailSubject": "Ponto de situação da sua viatura: {status}",

+ 1 - 0
messages/ru/workOrders.json

@@ -33,6 +33,7 @@
       "date": "Дата",
       "total": "Итого",
       "promised": "Обещано",
+      "updated": "Изменено",
       "promisedOverdue": "Обещано {date}, просрочено"
     },
     "emailSubject": "Обновление статуса транспортного средства: {status}",

+ 1 - 0
messages/tr/workOrders.json

@@ -33,6 +33,7 @@
       "date": "Tarih",
       "total": "Toplam",
       "promised": "Söz verilen",
+      "updated": "Güncellendi",
       "promisedOverdue": "{date} için söz verildi, gecikti"
     },
     "emailSubject": "Araç Durum Güncellemesi: {status}",

+ 7 - 0
src/__tests__/features/vehicles/work-orders-promised-sort.test.ts

@@ -65,6 +65,13 @@ beforeEach(() => {
   findMany.mockClear()
 })
 
+describe('the updated column', () => {
+  it('sorts by when the job was last saved, either way round', async () => {
+    expect(await orderByFor('updatedAt', 'desc')).toEqual({ updatedAt: 'desc' })
+    expect(await orderByFor('updatedAt', 'asc')).toEqual({ updatedAt: 'asc' })
+  })
+})
+
 describe('the promised column', () => {
   it('sorts by the promise, soonest first when ascending', async () => {
     expect(await orderByFor('promisedAt', 'asc')).toEqual({

+ 2 - 0
src/__tests__/lib/list-columns.test.ts

@@ -22,6 +22,8 @@ describe('the work order columns', () => {
   it('start with everything but the promise', () => {
     expect(defaultColumns(WORK_ORDER_COLUMNS)).toEqual(['invoice', 'customer', 'tech'])
     expect(WORK_ORDER_COLUMNS.promised).toBe(false)
+    // "Last changed" is there to be switched on, not shown to everyone.
+    expect(WORK_ORDER_COLUMNS.updated).toBe(false)
   })
 })
 

+ 49 - 4
src/app/(authenticated)/work-orders/work-orders-client.tsx

@@ -82,6 +82,8 @@ interface WorkOrder {
   startDateTime: Date | null
   /** When the customer was told the vehicle would be ready. */
   promisedAt: Date | null
+  /** When the job was last saved. */
+  updatedAt: Date
   techName: string | null
   invoiceNumber: string | null
   /** The customer's reference / PO; null unless the workshop uses the field. */
@@ -186,9 +188,24 @@ export function WorkOrdersClient({
   // Filtering by the promise and then hiding it would answer the question
   // without showing the answer, so the column comes along while it is on.
   const showsPromised = shows('promised') || dueToday
-  const visibleColumns = [shows('invoice'), shows('customer'), showsPromised, shows('tech')].filter(
-    Boolean
-  ).length
+  /**
+   * When the job was last changed: the time alone for a change made today,
+   * the date otherwise, in the workshop's own format. The full moment sits on
+   * the tooltip.
+   */
+  const updatedLabel = (r: WorkOrder) => {
+    const updated = new Date(r.updatedAt)
+    return formatDate(updated) === formatDate(new Date())
+      ? formatTime(updated)
+      : formatDate(updated)
+  }
+  const visibleColumns = [
+    shows('invoice'),
+    shows('customer'),
+    showsPromised,
+    shows('updated'),
+    shows('tech'),
+  ].filter(Boolean).length
   const t = useTranslations('workOrders.list')
   const tc = useTranslations('common')
   const serviceLabel = useServiceLabels()
@@ -239,7 +256,11 @@ export function WorkOrdersClient({
 
   const handleSort = useCallback(
     (column: string) => {
-      const newOrder = sortBy === column && sortOrder === 'asc' ? 'desc' : 'asc'
+      // "Last changed" is asked newest first: its first click sorts that way,
+      // the second turns it round. Every other column starts ascending.
+      const first = column === 'updatedAt' ? 'desc' : 'asc'
+      const second = first === 'asc' ? 'desc' : 'asc'
+      const newOrder = sortBy === column && sortOrder === first ? second : first
       navigate({ sortBy: column, sortOrder: newOrder })
     },
     [navigate, sortBy, sortOrder]
@@ -591,6 +612,20 @@ export function WorkOrdersClient({
                   </button>
                 </TableHead>
               )}
+              {/* When the job was last changed. Off unless asked for; its
+                  first click sorts the newest change to the top. */}
+              {shows('updated') && (
+                <TableHead className="w-[84px]">
+                  <button
+                    type="button"
+                    className="flex items-center hover:text-foreground"
+                    onClick={() => handleSort('updatedAt')}
+                  >
+                    {t('table.updated')}
+                    <SortIcon column="updatedAt" />
+                  </button>
+                </TableHead>
+              )}
               <TableHead className="w-[90px] text-right">
                 <button
                   type="button"
@@ -709,6 +744,16 @@ export function WorkOrdersClient({
                             )}
                           </TableCell>
                         )}
+                        {shows('updated') && (
+                          <TableCell className="text-xs text-muted-foreground">
+                            <span
+                              suppressHydrationWarning
+                              title={formatDateTime(new Date(r.updatedAt))}
+                            >
+                              {updatedLabel(r)}
+                            </span>
+                          </TableCell>
+                        )}
                         <TableCell className="text-right font-semibold">
                           <span className="inline-flex items-center gap-2">
                             {navigatingId === r.id && (

+ 3 - 0
src/features/vehicles/Actions/serviceActions.ts

@@ -1448,6 +1448,9 @@ export async function getWorkOrders(params: {
                 return {
                   promisedAt: { sort: dir, nulls: 'last' as const },
                 }
+              // When the job itself was last saved, newest first by default.
+              case 'updatedAt':
+                return { updatedAt: dir }
               // Column shows "year make model"; sort make, model, year so
               // identical models group together
               case 'vehicle':

+ 5 - 0
src/lib/list-columns.ts

@@ -25,6 +25,11 @@ export const WORK_ORDER_COLUMNS = {
    * the columns that are read on every job.
    */
   promised: false,
+  /**
+   * When the job was last changed, for finding the one just worked on. Off by
+   * default for the same reason: one more timestamp in every row.
+   */
+  updated: false,
 } as const
 
 export type WorkOrderColumn = keyof typeof WORK_ORDER_COLUMNS