Skip to content

Commit bf05f25

Browse files
New Feature Pagination (#4704)
* common pagination component * Pagination for Doc Store Dashboard * Pagination for Executions Dashboard * Pagination Support for Tables * lint fixes * update view message dialog UI * initial loading was ignoring the pagination counts * 1) default page size change 2) ensure page limits are passed on load 3) co-pilot review comments (n+1 query) 4) * 1) default page size change 2) ensure page limits are passed on load 3) co-pilot review comments (n+1 query) 4) refresh lists after insert/delete. * Enhancement: Improve handling of empty responses in DocumentStore and API key services - Added check for empty entities in DocumentStoreDTO.fromEntities to return an empty array. - Updated condition in getAllDocumentStores to handle total count correctly, allowing for zero total. - Refined logic in getAllApiKeys to check for empty keys and ensure correct API key retrieval. - Adjusted UI components to safely handle potential undefined apiKeys array. * Refresh API key list on pagination change * Enhancement: Update pagination and filter handling across components - Increased default items per page in AgentExecutions from 10 to 12. - Improved JSON parsing for chat type and feedback type filters in ViewMessagesDialog. - Enhanced execution filtering logic in AgentExecutions to ensure proper pagination and state management. - Refactored filter section in AgentExecutions for better readability and functionality. - Updated refresh logic in Agentflows to use the correct agentflow version. * add workspaceId to removeAllChatMessages * Refactor chat message retrieval logic for improved efficiency and maintainability - Introduced a new `handleFeedbackQuery` function to streamline feedback-related queries. - Enhanced pagination handling for session-based queries in `getMessagesWithFeedback`. - Updated `ViewMessagesDialog` to sort messages in descending order by default. - Simplified image rendering logic in `DocumentStoreTable` for better readability. * - Update `validateChatflowAPIKey` and `validateAPIKey` functions to get the correct keys array - Enhanced error handling in the `sanitizeExecution` function to ensure safe access to nested properties * Refactor API key validation logic for improved accuracy and error handling - Consolidated API key validation in `validateAPIKey` to return detailed validation results. - Updated `validateFlowAPIKey` to streamline flow API key validation. - Introduced `getApiKeyById` function in the API key service for better key retrieval. - Removed unused function `getAllChatSessionsFromChatflow` from the chat message API. --------- Co-authored-by: Henry <hzj94@hotmail.com>
1 parent 6baec93 commit bf05f25

File tree

55 files changed

+2584
-1549
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+2584
-1549
lines changed

packages/server/src/Interface.DocumentStore.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,9 @@ export class DocumentStoreDTO {
290290
}
291291

292292
static fromEntities(entities: DocumentStore[]): DocumentStoreDTO[] {
293+
if (entities.length === 0) {
294+
return []
295+
}
293296
return entities.map((entity) => this.fromEntity(entity))
294297
}
295298

packages/server/src/controllers/apikey/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ import { Request, Response, NextFunction } from 'express'
22
import { StatusCodes } from 'http-status-codes'
33
import { InternalFlowiseError } from '../../errors/internalFlowiseError'
44
import apikeyService from '../../services/apikey'
5+
import { getPageAndLimitParams } from '../../utils/pagination'
56

67
// Get api keys
78
const getAllApiKeys = async (req: Request, res: Response, next: NextFunction) => {
89
try {
910
const autoCreateNewKey = true
10-
const apiResponse = await apikeyService.getAllApiKeys(req.user?.activeWorkspaceId, autoCreateNewKey)
11+
const { page, limit } = getPageAndLimitParams(req)
12+
const apiResponse = await apikeyService.getAllApiKeys(req.user?.activeWorkspaceId, autoCreateNewKey, page, limit)
1113
return res.json(apiResponse)
1214
} catch (error) {
1315
next(error)

packages/server/src/controllers/chat-messages/index.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { ChatMessage } from '../../database/entities/ChatMessage'
99
import { InternalFlowiseError } from '../../errors/internalFlowiseError'
1010
import { StatusCodes } from 'http-status-codes'
1111
import { utilGetChatMessage } from '../../utils/getChatMessage'
12+
import { getPageAndLimitParams } from '../../utils/pagination'
1213

1314
const getFeedbackTypeFilters = (_feedbackTypeFilters: ChatMessageRatingType[]): ChatMessageRatingType[] | undefined => {
1415
try {
@@ -71,6 +72,9 @@ const getAllChatMessages = async (req: Request, res: Response, next: NextFunctio
7172
const startDate = req.query?.startDate as string | undefined
7273
const endDate = req.query?.endDate as string | undefined
7374
const feedback = req.query?.feedback as boolean | undefined
75+
76+
const { page, limit } = getPageAndLimitParams(req)
77+
7478
let feedbackTypeFilters = req.query?.feedbackType as ChatMessageRatingType[] | undefined
7579
if (feedbackTypeFilters) {
7680
feedbackTypeFilters = getFeedbackTypeFilters(feedbackTypeFilters)
@@ -93,7 +97,9 @@ const getAllChatMessages = async (req: Request, res: Response, next: NextFunctio
9397
messageId,
9498
feedback,
9599
feedbackTypeFilters,
96-
activeWorkspaceId
100+
activeWorkspaceId,
101+
page,
102+
limit
97103
)
98104
return res.json(parseAPIResponse(apiResponse))
99105
} catch (error) {
@@ -202,7 +208,8 @@ const removeAllChatMessages = async (req: Request, res: Response, next: NextFunc
202208
startDate,
203209
endDate,
204210
feedback: isFeedback,
205-
feedbackTypes: feedbackTypeFilters
211+
feedbackTypes: feedbackTypeFilters,
212+
activeWorkspaceId: workspaceId
206213
})
207214
const messageIds = messages.map((message) => message.id)
208215

packages/server/src/controllers/chatflows/index.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import chatflowsService from '../../services/chatflows'
88
import { getRunningExpressApp } from '../../utils/getRunningExpressApp'
99
import { checkUsageLimit } from '../../utils/quotaUsage'
1010
import { RateLimiterManager } from '../../utils/rateLimit'
11+
import { getPageAndLimitParams } from '../../utils/pagination'
1112

1213
const checkIfChatflowIsValidForStreaming = async (req: Request, res: Response, next: NextFunction) => {
1314
try {
@@ -67,7 +68,14 @@ const deleteChatflow = async (req: Request, res: Response, next: NextFunction) =
6768

6869
const getAllChatflows = async (req: Request, res: Response, next: NextFunction) => {
6970
try {
70-
const apiResponse = await chatflowsService.getAllChatflows(req.query?.type as ChatflowType, req.user?.activeWorkspaceId)
71+
const { page, limit } = getPageAndLimitParams(req)
72+
73+
const apiResponse = await chatflowsService.getAllChatflows(
74+
req.query?.type as ChatflowType,
75+
req.user?.activeWorkspaceId,
76+
page,
77+
limit
78+
)
7179
return res.json(apiResponse)
7280
} catch (error) {
7381
next(error)

packages/server/src/controllers/dataset/index.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ import { Request, Response, NextFunction } from 'express'
22
import { InternalFlowiseError } from '../../errors/internalFlowiseError'
33
import datasetService from '../../services/dataset'
44
import { StatusCodes } from 'http-status-codes'
5+
import { getPageAndLimitParams } from '../../utils/pagination'
56

67
const getAllDatasets = async (req: Request, res: Response, next: NextFunction) => {
78
try {
8-
const apiResponse = await datasetService.getAllDatasets(req.user?.activeWorkspaceId)
9+
const { page, limit } = getPageAndLimitParams(req)
10+
const apiResponse = await datasetService.getAllDatasets(req.user?.activeWorkspaceId, page, limit)
911
return res.json(apiResponse)
1012
} catch (error) {
1113
next(error)
@@ -17,7 +19,8 @@ const getDataset = async (req: Request, res: Response, next: NextFunction) => {
1719
if (typeof req.params === 'undefined' || !req.params.id) {
1820
throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Error: datasetService.getDataset - id not provided!`)
1921
}
20-
const apiResponse = await datasetService.getDataset(req.params.id)
22+
const { page, limit } = getPageAndLimitParams(req)
23+
const apiResponse = await datasetService.getDataset(req.params.id, page, limit)
2124
return res.json(apiResponse)
2225
} catch (error) {
2326
next(error)

packages/server/src/controllers/documentstore/index.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { InternalFlowiseError } from '../../errors/internalFlowiseError'
66
import { DocumentStoreDTO } from '../../Interface'
77
import { getRunningExpressApp } from '../../utils/getRunningExpressApp'
88
import { FLOWISE_COUNTER_STATUS, FLOWISE_METRIC_COUNTERS } from '../../Interface.Metrics'
9+
import { getPageAndLimitParams } from '../../utils/pagination'
910

1011
const createDocumentStore = async (req: Request, res: Response, next: NextFunction) => {
1112
try {
@@ -37,8 +38,17 @@ const createDocumentStore = async (req: Request, res: Response, next: NextFuncti
3738

3839
const getAllDocumentStores = async (req: Request, res: Response, next: NextFunction) => {
3940
try {
40-
const apiResponse = await documentStoreService.getAllDocumentStores(req.user?.activeWorkspaceId)
41-
return res.json(DocumentStoreDTO.fromEntities(apiResponse))
41+
const { page, limit } = getPageAndLimitParams(req)
42+
43+
const apiResponse: any = await documentStoreService.getAllDocumentStores(req.user?.activeWorkspaceId, page, limit)
44+
if (apiResponse?.total >= 0) {
45+
return res.json({
46+
total: apiResponse.total,
47+
data: DocumentStoreDTO.fromEntities(apiResponse.data)
48+
})
49+
} else {
50+
return res.json(DocumentStoreDTO.fromEntities(apiResponse))
51+
}
4252
} catch (error) {
4353
next(error)
4454
}

packages/server/src/controllers/evaluations/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Request, Response, NextFunction } from 'express'
22
import { InternalFlowiseError } from '../../errors/internalFlowiseError'
33
import { StatusCodes } from 'http-status-codes'
44
import evaluationsService from '../../services/evaluations'
5+
import { getPageAndLimitParams } from '../../utils/pagination'
56

67
const createEvaluation = async (req: Request, res: Response, next: NextFunction) => {
78
try {
@@ -81,7 +82,8 @@ const deleteEvaluation = async (req: Request, res: Response, next: NextFunction)
8182

8283
const getAllEvaluations = async (req: Request, res: Response, next: NextFunction) => {
8384
try {
84-
const apiResponse = await evaluationsService.getAllEvaluations(req.user?.activeWorkspaceId)
85+
const { page, limit } = getPageAndLimitParams(req)
86+
const apiResponse = await evaluationsService.getAllEvaluations(req.user?.activeWorkspaceId, page, limit)
8587
return res.json(apiResponse)
8688
} catch (error) {
8789
next(error)

packages/server/src/controllers/evaluators/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ import { Request, Response, NextFunction } from 'express'
22
import { InternalFlowiseError } from '../../errors/internalFlowiseError'
33
import { StatusCodes } from 'http-status-codes'
44
import evaluatorService from '../../services/evaluator'
5+
import { getPageAndLimitParams } from '../../utils/pagination'
56

67
const getAllEvaluators = async (req: Request, res: Response, next: NextFunction) => {
78
try {
8-
const apiResponse = await evaluatorService.getAllEvaluators(req.user?.activeWorkspaceId)
9+
const { page, limit } = getPageAndLimitParams(req)
10+
const apiResponse = await evaluatorService.getAllEvaluators(req.user?.activeWorkspaceId, page, limit)
911
return res.json(apiResponse)
1012
} catch (error) {
1113
next(error)

packages/server/src/controllers/stats/index.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,16 @@ const getChatflowStats = async (req: Request, res: Response, next: NextFunction)
4545
return res.status(500).send(e)
4646
}
4747
}
48-
const apiResponse = await statsService.getChatflowStats(chatflowid, chatTypes, startDate, endDate, '', true, feedbackTypeFilters)
48+
const apiResponse = await statsService.getChatflowStats(
49+
chatflowid,
50+
chatTypes,
51+
startDate,
52+
endDate,
53+
'',
54+
true,
55+
feedbackTypeFilters,
56+
req.user?.activeWorkspaceId
57+
)
4958
return res.json(apiResponse)
5059
} catch (error) {
5160
next(error)

packages/server/src/controllers/tools/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { NextFunction, Request, Response } from 'express'
22
import toolsService from '../../services/tools'
33
import { InternalFlowiseError } from '../../errors/internalFlowiseError'
44
import { StatusCodes } from 'http-status-codes'
5+
import { getPageAndLimitParams } from '../../utils/pagination'
56

67
const createTool = async (req: Request, res: Response, next: NextFunction) => {
78
try {
@@ -40,7 +41,8 @@ const deleteTool = async (req: Request, res: Response, next: NextFunction) => {
4041

4142
const getAllTools = async (req: Request, res: Response, next: NextFunction) => {
4243
try {
43-
const apiResponse = await toolsService.getAllTools(req.user?.activeWorkspaceId)
44+
const { page, limit } = getPageAndLimitParams(req)
45+
const apiResponse = await toolsService.getAllTools(req.user?.activeWorkspaceId, page, limit)
4446
return res.json(apiResponse)
4547
} catch (error) {
4648
next(error)

0 commit comments

Comments
 (0)