Skip to content
This repository was archived by the owner on Feb 8, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions packages/shared/utils/pipe.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* pipe takes an array of unary functions as an argument. It returns a function that accepts a value
* that's going to be passed through the supplied functions.
*
* @example
* // Without pipe.
* const add1ThenDouble = (x) => double(add1(x));
*
* // With pipe.
* const add1ThenDouble = pipe(add1, double);
*/
export const pipe =
<PipeSubject>(...fns: Array<(pipeSubject: PipeSubject) => PipeSubject>) =>
(x: PipeSubject) =>
fns.reduce((v, f) => f(v), x);
23 changes: 14 additions & 9 deletions packages/teleterm/src/ui/services/clusters/clustersService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { makeLabelTag } from 'teleport/components/formatters';
import { Label } from 'teleport/types';
import { formatDatabaseInfo } from 'teleport/services/databases/makeDatabase';
import { DbProtocol, DbType } from 'teleport/services/databases';
import { pipe } from 'shared/utils/pipe';

import { routing } from 'teleterm/ui/uri';
import { NotificationsService } from 'teleterm/ui/services/notifications';
Expand Down Expand Up @@ -713,16 +714,20 @@ export class ClustersService extends ImmutableStore<ClustersServiceState> {
clusterUri
)
: undefined;
const mergeAssumedRequests = (cluster: Cluster) => ({
...cluster,
loggedInUser: cluster.loggedInUser && {
...cluster.loggedInUser,
assumedRequests,
},
});
const processCluster = pipe(
this.removeInternalLoginsFromCluster,
mergeAssumedRequests
);

this.setState(draft => {
draft.clusters.set(clusterUri, {
...this.removeInternalLoginsFromCluster(cluster),
loggedInUser: cluster.loggedInUser
? {
...cluster.loggedInUser,
assumedRequests,
}
: undefined,
});
draft.clusters.set(clusterUri, processCluster(cluster));
});
}

Expand Down