Skip to content

Commit

Permalink
refactor: better typing of IntegrationKindByCategory
Browse files Browse the repository at this point in the history
  • Loading branch information
SeDemal committed Aug 15, 2024
1 parent 1ee663f commit 3c4e977
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
17 changes: 8 additions & 9 deletions packages/definitions/src/integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,20 +128,19 @@ export const getAllSecretKindOptions = (

export const integrationKinds = objectKeys(integrationDefs);

type CategoryFilterType<Condition extends IntegrationCategory> = {
[Key in keyof typeof integrationDefs]: Condition extends (typeof integrationDefs)[Key]["category"][number]
export type IntegrationKindByCategory<TCategory extends IntegrationCategory> = {
[Key in keyof typeof integrationDefs]: TCategory extends (typeof integrationDefs)[Key]["category"][number]
? Key
: never;
};

export type IntegrationKindByCategory<Condition extends IntegrationCategory> =
CategoryFilterType<Condition>[keyof typeof integrationDefs];
}[keyof typeof integrationDefs] extends infer U
//Needed to simplify the type when using it
? U
: never;

export const getIntegrationKindsByCategory = <TCategory extends IntegrationCategory>(category: TCategory) => {
const keys = objectKeys(integrationDefs).filter((integration) =>
return integrationKinds.filter((integration) =>
integrationDefs[integration].category.some((defCategory) => defCategory === category),
);
return keys as IntegrationKindByCategory<TCategory>[];
) as IntegrationKindByCategory<TCategory>[];
};

export type IntegrationSecretKind = (typeof integrationSecretKinds)[number];
Expand Down
2 changes: 1 addition & 1 deletion packages/widgets/src/downloads/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export default function DownloadClientsWidget({
//Use cyclical update to invalidate data older than 30 seconds from unresponsive integrations
const invalidIndexes = currentItems
//Don't update already invalid data (new Date (0))
.filter(({ timestamp }) => dayjs().diff(timestamp) > invalidateTime && timestamp !== new Date(0))
.filter(({ timestamp }) => dayjs().diff(timestamp) > invalidateTime && timestamp > new Date(0))
.map(({ integration }) => integration.id);
currentItemsHandlers.applyWhere(
({ integration }) => invalidIndexes.includes(integration.id),
Expand Down

0 comments on commit 3c4e977

Please sign in to comment.