Skip to content

Commit

Permalink
Functional form for autoGenCorrelationIds (#3882)
Browse files Browse the repository at this point in the history
* Support functional form for FetchService.autoGenCorrelationIds

* Support functional form for FetchService.autoGenCorrelationIds

* Dash canvas resize handles (#3881)

---------

Co-authored-by: Greg Solomon <[email protected]>
  • Loading branch information
lbwexler and ghsolomon authored Dec 31, 2024
1 parent 9ebd5a4 commit 8a645ca
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
relying on third-party cookies.
* Updated sorting on grouped grids to place ungrouped items at the bottom.
* `DashCanvas` views can now be resized left and up in addition to right and down.
* `FetchService.autoGenCorrelationIds` now supports a functional form for per-request behavior.

### 🐞 Bug Fixes

Expand Down
21 changes: 13 additions & 8 deletions svc/FetchService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ import ShortUniqueId from 'short-unique-id';
* the most common use-cases. The Fetch API will be called with CORS enabled, credentials
* included, and redirects followed.
*
* Set {@link autoGenCorrelationIds} to true on this service to enable auto-generation of UUID
* Correlation IDs for all requests issued by this service. Can also be set on a per-request basis
* Set {@link autoGenCorrelationIds} on this service to enable auto-generation of UUID
* Correlation IDs for requests issued by this service. Can also be set on a per-request basis
* via {@link FetchOptions.correlationId}.
*
* Custom headers can be set on a request via {@link FetchOptions.headers}. Default headers for all
Expand All @@ -52,8 +52,11 @@ export class FetchService extends HoistService {
//-----------------------------------
// Public properties, Getters/Setters
//------------------------------------
/** True to auto-generate a Correlation ID for each request unless otherwise specified. */
autoGenCorrelationIds = false;
/**
* Should hoist auto-generate a Correlation ID for a request when not otherwise specified?
* Set to `true` or a dynamic per-request function to enable. Default false.
*/
autoGenCorrelationIds: boolean | ((opts: FetchOptions) => boolean) = false;

/**
* Method for generating Correlation ID's. Defaults to a 16 character random string with
Expand Down Expand Up @@ -253,10 +256,12 @@ export class FetchService extends HoistService {

// Resolve convenience options for Correlation ID to server-ready string
private withCorrelationId(opts: FetchOptions): FetchOptions {
const {correlationId} = opts;
if (isString(correlationId)) return opts;
if (correlationId === false || correlationId === null) return omit(opts, 'correlationId');
if (correlationId === true || this.autoGenCorrelationIds) {
const cid = opts.correlationId,
autoCid = this.autoGenCorrelationIds;

if (isString(cid)) return opts;
if (cid === false || cid === null) return omit(opts, 'correlationId');
if (cid === true || autoCid === true || (isFunction(autoCid) && autoCid(opts))) {
return {...opts, correlationId: this.genCorrelationId()};
}
return opts;
Expand Down

0 comments on commit 8a645ca

Please sign in to comment.