Requested changes

This commit is contained in:
Daniel Hougaard
2024-09-20 22:51:44 +04:00
parent 31ff6d3c17
commit 449e7672f9
3 changed files with 18 additions and 5 deletions

View File

@@ -48,6 +48,10 @@ export const auditLogDALFactory = (db: TDbClient) => {
},
tx?: Knex
) => {
if (!orgId && !projectId) {
throw new Error("Either orgId or projectId must be provided");
}
try {
// Find statements
const sqlQuery = (tx || db.replicaNode())(TableName.AuditLog)
@@ -59,11 +63,12 @@ export const auditLogDALFactory = (db: TDbClient) => {
} else if (projectId) {
void this.where(`${TableName.AuditLog}.projectId`, projectId);
}
if (userAgentType) {
void this.where(`${TableName.AuditLog}.userAgentType`, userAgentType);
}
});
if (userAgentType) {
void sqlQuery.where("userAgentType", userAgentType);
}
// Select statements
void sqlQuery
.select(selectAllTableCols(TableName.AuditLog))

View File

@@ -231,7 +231,7 @@ export const LogsFilter = ({
)}
/>
{isOrgAuditLogs && workspaces.length && (
{isOrgAuditLogs && workspaces.length > 0 && (
<Controller
control={control}
name="projectId"

View File

@@ -41,8 +41,16 @@ export const LogsTable = ({
}: Props) => {
const { currentWorkspace } = useWorkspace();
// Determine the project ID for filtering
const filterProjectId =
filter?.projectId ?? (!isOrgAuditLogs ? currentWorkspace?.id ?? "" : null);
// Use the projectId from the filter if it exists
filter?.projectId ??
// Otherwise, if we're not looking at org-wide audit logs
(!isOrgAuditLogs
? // Use the current workspace ID (or an empty string if that's null)
currentWorkspace?.id ?? ""
: // For org-wide audit logs, use null (no specific project filter)
null);
const { data, isLoading, isFetchingNextPage, hasNextPage, fetchNextPage } = useGetAuditLogs(
{