Implemented SSE update across main front components (#17205)
This PR implements SSE update events across the main components of the application : tables, boards, calendars, show pages. There is still work to do on other event type and on making sure everything works fine, but this first implementation should be robust enough to start with. Some problems encountered along the way : - Events are returning raw Postgres output, because they are not normalized by the GraphQL layer, so we ended up with amountMicros as string values, which the frontend does not like, so I implemented a small util in our `formatResult` generic pipeline to turn amountMicros to a number if it's a string value. We could implement other formatters for composite fields if we see problems with events. -`action` property was missing in SSE events, which is required by the frontend to know what kind of event it is. # QA https://github.com/user-attachments/assets/393b45ac-59d2-48b0-855b-2ce9c4b8ae57 https://github.com/user-attachments/assets/cb214e7a-1595-4b85-bdb6-87630993d2e2
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { isPlainObject } from '@nestjs/common/utils/shared.utils';
|
||||
|
||||
import { isNull } from '@sniptt/guards';
|
||||
import { isNonEmptyString, isNull } from '@sniptt/guards';
|
||||
import {
|
||||
FieldActorSource,
|
||||
FieldMetadataType,
|
||||
@@ -155,7 +155,7 @@ export function formatResult<T>(
|
||||
compositeProperty.name,
|
||||
fieldMetadata,
|
||||
)
|
||||
: value;
|
||||
: formatCompositeFieldValue(value, compositeProperty.name, fieldMetadata);
|
||||
}
|
||||
|
||||
// After assembling composite fields, handle those with missing required subfields
|
||||
@@ -259,6 +259,26 @@ function transformCompositeFieldNullValue(
|
||||
);
|
||||
}
|
||||
|
||||
function formatCompositeFieldValue(
|
||||
value: unknown,
|
||||
compositePropertyName: string,
|
||||
fieldMetadata: FlatFieldMetadata,
|
||||
) {
|
||||
switch (fieldMetadata.type) {
|
||||
case FieldMetadataType.CURRENCY: {
|
||||
if (compositePropertyName === 'amountMicros') {
|
||||
if (isNonEmptyString(value)) {
|
||||
return parseInt(value);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles composite fields with missing required subfields.
|
||||
* - For nullable fields: sets to null if all required subfields are null
|
||||
|
||||
Reference in New Issue
Block a user