refactor: improve code formatting and consistency across multiple files

- Standardized import statements and removed unnecessary line breaks for better readability in various components.
- Enhanced error handling and logging in the useElectronPrinter hook.
- Updated sample data formatting in AgGridShowcase for improved clarity.
- Refactored JSX elements for consistent indentation and structure in LandingSample, AuthPage, and EventsPage components.
- Consolidated and simplified conditional rendering logic in several components.

These changes aim to enhance code maintainability and readability throughout the project.
This commit is contained in:
shancheas
2026-08-25 17:50:48 +07:00
parent f2f0be111a
commit 67ae5b6c11
94 changed files with 1742 additions and 849 deletions
@@ -420,7 +420,7 @@ describe('BaseRemoteDataServices — Data Transformer Integration', () => {
id: '42',
bookingCode: 'BK042',
customerName: 'Alice',
}
},
});
expect(result.status).toBe(200);
});
@@ -432,7 +432,7 @@ describe('BaseRemoteDataServices — Data Transformer Integration', () => {
{ id: '1', booking_code: 'BK001', customer_name: 'Alice' },
{ id: '2', booking_code: 'BK002', customer_name: 'Bob' },
],
meta: { currentPage: 1, itemsPerPage: 15, totalItems: 2, totalPages: 1 }
meta: { currentPage: 1, itemsPerPage: 15, totalItems: 2, totalPages: 1 },
},
status: 200,
});
@@ -444,7 +444,7 @@ describe('BaseRemoteDataServices — Data Transformer Integration', () => {
{ id: '1', bookingCode: 'BK001', customerName: 'Alice' },
{ id: '2', bookingCode: 'BK002', customerName: 'Bob' },
],
meta: { page: 1, limit: 15, total: 2, totalPages: 1 }
meta: { page: 1, limit: 15, total: 2, totalPages: 1 },
});
});
@@ -458,7 +458,7 @@ describe('BaseRemoteDataServices — Data Transformer Integration', () => {
expect(result.data).toEqual({
data: [],
meta: { page: 1, limit: 10, total: 0, totalPages: 0 }
meta: { page: 1, limit: 10, total: 0, totalPages: 0 },
});
});
@@ -541,7 +541,7 @@ describe('BaseRemoteDataServices — Data Transformer Integration', () => {
id: '42',
bookingCode: 'BK042',
customerName: 'ALICE', // uppercased by custom hook
}
},
});
});
@@ -558,7 +558,7 @@ describe('BaseRemoteDataServices — Data Transformer Integration', () => {
expect(result.data).toEqual({
data: [{ id: '1', bookingCode: 'LIST-BK001', customerName: 'Alice' }],
meta: { page: 1, limit: 10, total: 1, totalPages: 1 }
meta: { page: 1, limit: 10, total: 1, totalPages: 1 },
});
});
@@ -280,7 +280,11 @@ export abstract class BaseRemoteDataServices<E extends BaseEntity = BaseEntity,
}
/** Delete multiple entities by IDs. Optionally sends form data as `meta` in the request body. */
batchDelete(ids: EntityId[], meta?: Record<string, unknown>, config?: AxiosRequestConfig): Promise<ApiResponse<void>> {
batchDelete(
ids: EntityId[],
meta?: Record<string, unknown>,
config?: AxiosRequestConfig,
): Promise<ApiResponse<void>> {
return this.execute<void>(DESCRIPTORS.batchDelete, {
config: { ...config, data: { ids, ...(meta ? { meta } : {}) } },
});
@@ -297,7 +301,11 @@ export abstract class BaseRemoteDataServices<E extends BaseEntity = BaseEntity,
}
/** Activate multiple entities. Optionally sends form data as `meta` in the request body. */
batchActivate(ids: EntityId[], meta?: Record<string, unknown>, config?: AxiosRequestConfig): Promise<ApiResponse<void>> {
batchActivate(
ids: EntityId[],
meta?: Record<string, unknown>,
config?: AxiosRequestConfig,
): Promise<ApiResponse<void>> {
return this.execute<void>(DESCRIPTORS.batchActivate, {
config: { ...config, data: { ids, ...(meta ? { meta } : {}) } },
});
@@ -312,7 +320,11 @@ export abstract class BaseRemoteDataServices<E extends BaseEntity = BaseEntity,
}
/** Deactivate multiple entities. Optionally sends form data as `meta` in the request body. */
batchDeactivate(ids: EntityId[], meta?: Record<string, unknown>, config?: AxiosRequestConfig): Promise<ApiResponse<void>> {
batchDeactivate(
ids: EntityId[],
meta?: Record<string, unknown>,
config?: AxiosRequestConfig,
): Promise<ApiResponse<void>> {
return this.execute<void>(DESCRIPTORS.batchDeactivate, {
config: { ...config, data: { ids, ...(meta ? { meta } : {}) } },
});
@@ -329,7 +341,11 @@ export abstract class BaseRemoteDataServices<E extends BaseEntity = BaseEntity,
}
/** Confirm processing of multiple data records. Optionally sends form data as `meta` in the request body. */
batchConfirmData(ids: EntityId[], meta?: Record<string, unknown>, config?: AxiosRequestConfig): Promise<ApiResponse<void>> {
batchConfirmData(
ids: EntityId[],
meta?: Record<string, unknown>,
config?: AxiosRequestConfig,
): Promise<ApiResponse<void>> {
return this.execute<void>(DESCRIPTORS.batchConfirmData, {
config: { ...config, data: { ids, ...(meta ? { meta } : {}) } },
});
@@ -344,7 +360,11 @@ export abstract class BaseRemoteDataServices<E extends BaseEntity = BaseEntity,
}
/** Cancel processing of multiple data records. Optionally sends form data as `meta` in the request body. */
batchCancelData(ids: EntityId[], meta?: Record<string, unknown>, config?: AxiosRequestConfig): Promise<ApiResponse<void>> {
batchCancelData(
ids: EntityId[],
meta?: Record<string, unknown>,
config?: AxiosRequestConfig,
): Promise<ApiResponse<void>> {
return this.execute<void>(DESCRIPTORS.batchCancelData, {
config: { ...config, data: { ids, ...(meta ? { meta } : {}) } },
});
@@ -361,7 +381,11 @@ export abstract class BaseRemoteDataServices<E extends BaseEntity = BaseEntity,
}
/** Rollback multiple transactions. Optionally sends form data as `meta` in the request body. */
batchRollbackData(ids: EntityId[], meta?: Record<string, unknown>, config?: AxiosRequestConfig): Promise<ApiResponse<void>> {
batchRollbackData(
ids: EntityId[],
meta?: Record<string, unknown>,
config?: AxiosRequestConfig,
): Promise<ApiResponse<void>> {
return this.execute<void>(DESCRIPTORS.batchRollbackData, {
config: { ...config, data: { ids, ...(meta ? { meta } : {}) } },
});
@@ -376,7 +400,11 @@ export abstract class BaseRemoteDataServices<E extends BaseEntity = BaseEntity,
}
/** Hold multiple transactions. Optionally sends form data as `meta` in the request body. */
batchHoldData(ids: EntityId[], meta?: Record<string, unknown>, config?: AxiosRequestConfig): Promise<ApiResponse<void>> {
batchHoldData(
ids: EntityId[],
meta?: Record<string, unknown>,
config?: AxiosRequestConfig,
): Promise<ApiResponse<void>> {
return this.execute<void>(DESCRIPTORS.batchHoldData, {
config: { ...config, data: { ids, ...(meta ? { meta } : {}) } },
});
@@ -52,8 +52,7 @@ import { BaseRemoteDataServices } from './base-remote.data-services';
* }
* ```
*/
export class CommonRemoteDataServices<
E extends BaseEntity = BaseEntity,
TDTO = E,
> extends BaseRemoteDataServices<E, TDTO> {}
export class CommonRemoteDataServices<E extends BaseEntity = BaseEntity, TDTO = E> extends BaseRemoteDataServices<
E,
TDTO
> {}
+5 -29
View File
@@ -33,13 +33,7 @@ export class ApiError extends Error {
/** The original Axios error, preserved for debugging. */
readonly cause: AxiosError | undefined;
constructor(
message: string,
code: ApiErrorCode,
status: number,
data?: unknown,
cause?: AxiosError,
) {
constructor(message: string, code: ApiErrorCode, status: number, data?: unknown, cause?: AxiosError) {
super(message);
this.name = 'ApiError';
this.code = code;
@@ -59,30 +53,12 @@ export class ApiError extends Error {
// Network error (no response received)
if (!error.response) {
if (error.code === 'ECONNABORTED') {
return new ApiError(
'Request timed out',
ApiErrorCode.TIMEOUT,
0,
undefined,
error,
);
return new ApiError('Request timed out', ApiErrorCode.TIMEOUT, 0, undefined, error);
}
if (error.code === 'ERR_CANCELED') {
return new ApiError(
'Request was cancelled',
ApiErrorCode.CANCELLED,
0,
undefined,
error,
);
return new ApiError('Request was cancelled', ApiErrorCode.CANCELLED, 0, undefined, error);
}
return new ApiError(
error.message || 'Network error',
ApiErrorCode.NETWORK_ERROR,
0,
undefined,
error,
);
return new ApiError(error.message || 'Network error', ApiErrorCode.NETWORK_ERROR, 0, undefined, error);
}
// Server responded with an error status
@@ -93,7 +69,7 @@ export class ApiError extends Error {
// Extract message from common server response formats
const serverMessage =
(data && typeof data === 'object' && 'message' in data)
data && typeof data === 'object' && 'message' in data
? String((data as Record<string, unknown>).message)
: `Request failed with status ${status}`;
+20 -10
View File
@@ -28,15 +28,25 @@ export enum ApiErrorCode {
*/
export function httpStatusToErrorCode(status: number): ApiErrorCode {
switch (status) {
case 400: return ApiErrorCode.BAD_REQUEST;
case 401: return ApiErrorCode.UNAUTHORIZED;
case 403: return ApiErrorCode.FORBIDDEN;
case 404: return ApiErrorCode.NOT_FOUND;
case 409: return ApiErrorCode.CONFLICT;
case 422: return ApiErrorCode.UNPROCESSABLE_ENTITY;
case 429: return ApiErrorCode.TOO_MANY_REQUESTS;
case 500: return ApiErrorCode.INTERNAL_SERVER_ERROR;
case 503: return ApiErrorCode.SERVICE_UNAVAILABLE;
default: return ApiErrorCode.UNKNOWN;
case 400:
return ApiErrorCode.BAD_REQUEST;
case 401:
return ApiErrorCode.UNAUTHORIZED;
case 403:
return ApiErrorCode.FORBIDDEN;
case 404:
return ApiErrorCode.NOT_FOUND;
case 409:
return ApiErrorCode.CONFLICT;
case 422:
return ApiErrorCode.UNPROCESSABLE_ENTITY;
case 429:
return ApiErrorCode.TOO_MANY_REQUESTS;
case 500:
return ApiErrorCode.INTERNAL_SERVER_ERROR;
case 503:
return ApiErrorCode.SERVICE_UNAVAILABLE;
default:
return ApiErrorCode.UNKNOWN;
}
}
@@ -37,10 +37,7 @@ import { ApiError } from '../errors/api-error';
* });
* ```
*/
export function createHttpClient(
config: HttpClientConfig,
hooks?: InterceptorHooks,
): AxiosInstance {
export function createHttpClient(config: HttpClientConfig, hooks?: InterceptorHooks): AxiosInstance {
const observability = config.observability ?? noopObservabilityAdapter;
// ── Create isolated instance ──────────────────────────────────
@@ -49,7 +46,7 @@ export function createHttpClient(
timeout: config.timeout ?? 15000,
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
Accept: 'application/json',
...(config.defaultHeaders ?? {}),
},
});
+5 -15
View File
@@ -1,8 +1,4 @@
import type {
AxiosError,
AxiosResponse,
InternalAxiosRequestConfig,
} from 'axios';
import type { AxiosError, AxiosResponse, InternalAxiosRequestConfig } from 'axios';
import type { IObservabilityAdapter } from '../observability/types';
// ─── Factory Configuration ──────────────────────────────────────
@@ -41,9 +37,7 @@ export interface InterceptorHooks {
* Called before every request is dispatched.
* Use this to inject authentication tokens, tenant headers, etc.
*/
onRequest?: (
config: InternalAxiosRequestConfig,
) => Promise<InternalAxiosRequestConfig> | InternalAxiosRequestConfig;
onRequest?: (config: InternalAxiosRequestConfig) => Promise<InternalAxiosRequestConfig> | InternalAxiosRequestConfig;
/**
* Called on every successful response (2xx status).
@@ -105,13 +99,7 @@ export interface TelemetryContext {
// ─── Re-export Axios types consumers frequently need ────────────
export type {
AxiosInstance,
AxiosError,
AxiosResponse,
AxiosRequestConfig,
InternalAxiosRequestConfig,
} from 'axios';
export type { AxiosInstance, AxiosError, AxiosResponse, AxiosRequestConfig, InternalAxiosRequestConfig } from 'axios';
// ─── Augment Axios to carry TelemetryContext ────────────────────
@@ -119,5 +107,7 @@ declare module 'axios' {
interface AxiosRequestConfig {
/** Per-request telemetry context for custom spans, tags, events. */
telemetryContext?: TelemetryContext;
/** Skip the 401 refresh-and-retry interceptor for this request. */
skipAuthRefresh?: boolean;
}
}
@@ -70,10 +70,7 @@ function makeRequestConfig(
} as InternalAxiosRequestConfig;
}
function makeAxiosResponse(
config: InternalAxiosRequestConfig,
overrides: Partial<AxiosResponse> = {},
): AxiosResponse {
function makeAxiosResponse(config: InternalAxiosRequestConfig, overrides: Partial<AxiosResponse> = {}): AxiosResponse {
return {
data: {},
status: 200,
@@ -43,9 +43,7 @@ function getTelemetryContext(config: unknown): TelemetryContext | undefined {
/** Convert TelemetryContext tags to a string record for Faro context. */
function tagsToFaroContext(tags?: Record<string, string | number | boolean>): Record<string, string> {
if (!tags) return {};
return Object.fromEntries(
Object.entries(tags).map(([k, v]) => [k, String(v)]),
);
return Object.fromEntries(Object.entries(tags).map(([k, v]) => [k, String(v)]));
}
/**
@@ -135,10 +133,7 @@ export const faroAdapter: IObservabilityAdapter = {
const faro = getFaro();
if (faro) {
const baseContext = buildBaseContext(method, url, moduleKey, action, ctx?.tags);
faro.api.pushLog(
[`[core-api] ${method} ${url}`],
{ level: LogLevel.DEBUG, context: baseContext },
);
faro.api.pushLog([`[core-api] ${method} ${url}`], { level: LogLevel.DEBUG, context: baseContext });
}
},
@@ -203,10 +198,10 @@ export const faroAdapter: IObservabilityAdapter = {
context: errorContext,
});
faro.api.pushLog(
[`[core-api] ERROR ${method} ${url}${status}`],
{ level: LogLevel.ERROR, context: errorContext },
);
faro.api.pushLog([`[core-api] ERROR ${method} ${url}${status}`], {
level: LogLevel.ERROR,
context: errorContext,
});
}
},
};
+2 -7
View File
@@ -17,11 +17,7 @@
* ```
*/
import {
getWebInstrumentations,
initializeFaro,
type Faro,
} from '@grafana/faro-react';
import { getWebInstrumentations, initializeFaro, type Faro } from '@grafana/faro-react';
import { TracingInstrumentation } from '@grafana/faro-web-tracing';
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';
import { BatchSpanProcessor } from '@opentelemetry/sdk-trace-web';
@@ -125,8 +121,7 @@ export function initTelemetry(config: TelemetryConfig): Faro {
new TracingInstrumentation({
...tracingOptions,
instrumentationOptions: {
propagateTraceHeaderCorsUrls:
config.propagateTraceHeaderCorsUrls ?? [/.*/],
propagateTraceHeaderCorsUrls: config.propagateTraceHeaderCorsUrls ?? [/.*/],
fetchInstrumentationOptions: {
applyCustomAttributesOnSpan(span) {
span.setAttribute('app.synthetic_request', 'false');