Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
8b00919
feat: add @tanstack/react-query package, custom QueryClientProvider, …
RohitRaj011 May 22, 2025
a138770
chore(version): bump to 1.14.0-beta-0
RohitRaj011 May 22, 2025
f9e42a1
feat: update react-query type definitions
RohitRaj011 May 22, 2025
fdc59c2
feat: update error handling flags in QueryClientProvider and default …
RohitRaj011 May 22, 2025
4cba97c
chore(version): bump to 1.14.0-beta-1
RohitRaj011 May 22, 2025
b5d97bc
chore: revert @types/react-dates to dependencies
RohitRaj011 May 22, 2025
89de0f2
Merge branch 'develop' of github.com:devtron-labs/devtron-fe-common-l…
RohitRaj011 Jun 2, 2025
91f3ab3
fix: move @types/react-dates to dev dependency
RohitRaj011 Jun 2, 2025
6c4a25f
chore(version): bump to 1.14.2-beta-0
RohitRaj011 Jun 2, 2025
861fe1a
Merge branch 'develop' of github.com:devtron-labs/devtron-fe-common-l…
RohitRaj011 Jul 11, 2025
8668f37
chore(version): bump to 1.17.0-beta-5
RohitRaj011 Jul 11, 2025
91f53d9
chore: add @tanstack/eslint-plugin-query to ESLint configuration and …
RohitRaj011 Jul 11, 2025
d9c5099
chore: rename useQueryClient -> reactQueryHooks
RohitRaj011 Jul 15, 2025
af2deef
Merge branch 'develop' of github.com:devtron-labs/devtron-fe-common-l…
RohitRaj011 Jul 15, 2025
ba91195
chore(version): bump to 1.17.0-pre-11
RohitRaj011 Jul 15, 2025
c4f0637
Merge branch 'develop' of github.com:devtron-labs/devtron-fe-common-l…
RohitRaj011 Jul 15, 2025
b7aa854
feat(CoreAPI): add mergeAbortSignals method for handling multiple Abo…
RohitRaj011 Jul 15, 2025
2a779db
fix(QueryClientProvider): remove contextSharing prop from RQQueryClie…
RohitRaj011 Jul 15, 2025
1cfa5c1
Merge branch 'develop' of github.com:devtron-labs/devtron-fe-common-l…
RohitRaj011 Jul 17, 2025
6a151ef
chore(version): bump to 1.17.0-pre-16
RohitRaj011 Jul 17, 2025
30ca3ec
feat: enhance mergeAbortSignals to include cleanup for event listeners
RohitRaj011 Jul 18, 2025
b1254c9
refactor: CoreAPI - update mergeAbortSignals
RohitRaj011 Jul 18, 2025
81998ce
chore(version): bump to 1.18.0
RohitRaj011 Jul 18, 2025
d16dee3
Merge pull request #825 from devtron-labs/rc-merge/v0.40.0
RohitRaj011 Jul 18, 2025
bf45e48
chore: error layout fix
shivani170 Jul 18, 2025
322af73
chore: util revert
shivani170 Jul 18, 2025
93f9b58
chore: navlink import
shivani170 Jul 18, 2025
1fb2683
chore: css fixes
shivani170 Jul 18, 2025
2ec77a7
chore: css fixes
shivani170 Jul 18, 2025
f3ee1f2
chore: Navlink added to header
shivani170 Jul 18, 2025
fb8646e
chore: css fixes
shivani170 Jul 18, 2025
3a8146b
chore: css fixes
shivani170 Jul 18, 2025
67284b6
chore: text replaced with Check Permission
shivani170 Jul 18, 2025
4f49b53
Merge pull request #829 from devtron-labs/fix/image-pull-message
shivani170 Jul 18, 2025
4064c82
Merge pull request #826 from devtron-labs/release-candidate-v0.40.0
RohitRaj011 Jul 18, 2025
85759b3
Merge branch 'main' of github.com:devtron-labs/devtron-fe-common-lib …
RohitRaj011 Jul 18, 2025
19bb9c0
chore(version): bump to 1.18.0-pre-0
RohitRaj011 Jul 18, 2025
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
4 changes: 3 additions & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@

const tsconfigPath = require('./tsconfig.json')


module.exports = {
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint', 'react', 'prettier', 'import', 'simple-import-sort'],
plugins: ['@typescript-eslint', 'react', 'prettier', 'import', 'simple-import-sort', '@tanstack/query'],
env: {
browser: true,
es2021: true,
Expand All @@ -42,6 +43,7 @@ module.exports = {
'airbnb',
'airbnb/hooks',
'prettier',
'plugin:@tanstack/query/recommended'
],
rules: {
'prettier/prettier': ['error'],
Expand Down
71 changes: 64 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@devtron-labs/devtron-fe-common-lib",
"version": "1.17.0-pre-15",
"version": "1.18.0-pre-0",
"description": "Supporting common component library",
"type": "module",
"main": "dist/index.js",
Expand Down Expand Up @@ -40,13 +40,15 @@
"@esbuild-plugins/node-globals-polyfill": "0.2.3",
"@laynezh/vite-plugin-lib-assets": "1.1.0",
"@sentry/browser": "^7.119.1",
"@tanstack/eslint-plugin-query": "<5",
"@testing-library/jest-dom": "^5.16.2",
"@testing-library/react": "^12.1.4",
"@tippyjs/react": "^4.2.0",
"@typeform/embed-react": "2.20.0",
"@types/dompurify": "^3.0.5",
"@types/json-schema": "^7.0.15",
"@types/react": "17.0.39",
"@types/react-dates": "^21.8.6",
"@types/react-dom": "17.0.13",
"@types/react-router-dom": "^5.3.3",
"@typescript-eslint/eslint-plugin": "8.3.0",
Expand Down Expand Up @@ -107,7 +109,7 @@
"@lezer/highlight": "1.2.1",
"@replit/codemirror-indentation-markers": "6.5.3",
"@replit/codemirror-vscode-keymap": "6.0.2",
"@types/react-dates": "^21.8.6",
"@tanstack/react-query": "<5",
"@uiw/codemirror-extensions-hyper-link": "4.23.10",
"@uiw/codemirror-theme-github": "4.23.7",
"@uiw/react-codemirror": "4.23.7",
Expand Down
56 changes: 52 additions & 4 deletions src/Common/API/CoreAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,50 @@ class CoreAPI {
)
}

/**
* Merges multiple AbortSignals into a single AbortSignal that aborts
* as soon as any of the input signals abort.
*
* This is useful when you want to race multiple async cancellation signals,
* for example, to support both a global timeout and a user-triggered abort.
*
* @param signals - AbortSignals to merge.
* @returns An AbortSignal that aborts if any input signal aborts.
*/
private static mergeAbortSignals(...signals: (AbortSignal | undefined)[]): AbortSignal {
const controller = new AbortController()

// If any signal is already aborted, abort immediately and don't add listeners
if (signals.some((s) => s?.aborted)) {
controller.abort()
return controller.signal
}

const onAbort = () => controller.abort()

// Keep track of listeners for cleanup later
const cleanupFns: (() => void)[] = []

signals.forEach((signal) => {
if (signal && !signal.aborted) {
signal.addEventListener('abort', onAbort)
cleanupFns.push(() => signal.removeEventListener('abort', onAbort))
}
})

// Ensure cleanup happens when merged signal is aborted (by any means)
controller.signal.addEventListener(
'abort',
() => {
cleanupFns.forEach((fn) => fn())
},
// This ensures the listener is only run once
{ once: true },
)

return controller.signal
}

private fetchInTime = <T = object>({
url,
type,
Expand All @@ -138,10 +182,13 @@ class CoreAPI {
isMultipartRequest,
}: FetchInTimeParamsType<T>): Promise<ResponseType> => {
const controller = options?.abortControllerRef?.current ?? new AbortController()
const signal = options?.abortControllerRef?.current?.signal || options?.signal || controller.signal
const timeoutPromise: Promise<ResponseType> = new Promise((resolve, reject) => {
const timeout = options?.timeout || this.timeout
const timeoutSignal = controller.signal
Comment thread
vivek-devtron marked this conversation as resolved.

const mergedSignal = CoreAPI.mergeAbortSignals(options?.signal, timeoutSignal)

const timeout = options?.timeout || this.timeout

const timeoutPromise: Promise<ResponseType> = new Promise((_, reject) => {
setTimeout(() => {
controller.abort()
if (options?.abortControllerRef?.current) {
Expand All @@ -165,12 +212,13 @@ class CoreAPI {
})
}, timeout)
})

return Promise.race([
this.fetchAPI({
url,
type,
data,
signal,
signal: mergedSignal,
preventAutoLogout: options?.preventAutoLogout || false,
preventLicenseRedirect: options?.preventLicenseRedirect || false,
shouldParseServerErrorForUnauthorizedUser: options?.shouldParseServerErrorForUnauthorizedUser,
Expand Down
44 changes: 44 additions & 0 deletions src/Common/API/QueryClientProvider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { PropsWithChildren } from 'react'
import {
MutationCache,
QueryCache,
QueryClient,
QueryClientProvider as RQQueryClientProvider,
} from '@tanstack/react-query'

import { showError } from '@Common/Helper'

const queryClient = new QueryClient({
defaultOptions: {
queries: {
cacheTime: 0,
refetchOnWindowFocus: false,
refetchOnReconnect: false,
retry: false,
meta: { showToastError: true },
},
mutations: {
cacheTime: 0,
retry: false,
meta: { showToastError: true },
},
},
queryCache: new QueryCache({
onError: (error, query) => {
if (query.meta.showToastError) {
showError(error)
}
},
}),
mutationCache: new MutationCache({
onError: (error, _variables, _context, mutation) => {
if (mutation.meta.showToastError) {
showError(error)
}
},
}),
})

export const QueryClientProvider = ({ children }: PropsWithChildren<{}>) => (
<RQQueryClientProvider client={queryClient}>{children}</RQQueryClientProvider>
)
2 changes: 2 additions & 0 deletions src/Common/API/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ const dashboardAPI = new CoreAPI({

export const { post, put, patch, get, trash } = dashboardAPI
export { default as CoreAPI } from './CoreAPI'
export { QueryClientProvider } from './QueryClientProvider'
export * from './reactQueryHooks'
export { abortPreviousRequests, getIsRequestAborted, handleRedirectToLicenseActivation } from './utils'
23 changes: 23 additions & 0 deletions src/Common/API/reactQueryHooks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {
QueryKey,
useMutation as rqUseMutation,
UseMutationOptions,
UseMutationResult,
useQuery as rqUseQuery,
useQueryClient,
UseQueryOptions,
UseQueryResult,
} from '@tanstack/react-query'

import { ServerErrors } from '@Common/ServerError'
import { ResponseType } from '@Common/Types'

export const useQuery = <TQueryFnData = unknown, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(
options: UseQueryOptions<ResponseType<TQueryFnData>, ServerErrors, TData, TQueryKey>,
): UseQueryResult<TData, ServerErrors> => rqUseQuery(options)

export const useMutation = <TData = unknown, TVariables = void, TContext = unknown>(
options: UseMutationOptions<ResponseType<TData>, ServerErrors, TVariables, TContext>,
): UseMutationResult<ResponseType<TData>, ServerErrors, TVariables, TContext> => rqUseMutation(options)

export { useQueryClient }
Loading