Skip to content

Commit

Permalink
Migrate debug log viewer to feature library
Browse files Browse the repository at this point in the history
  • Loading branch information
paustint committed Jun 20, 2024
1 parent 5a83278 commit 8eec806
Show file tree
Hide file tree
Showing 17 changed files with 138 additions and 5 deletions.
2 changes: 1 addition & 1 deletion apps/jetstream/src/app/AppRoutes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const AnonymousApex = lazy(() => import('@jetstream/feature/anon-apex').then((mo

const SalesforceApi = lazy(() => import('./components/salesforce-api/SalesforceApi'));

const DebugLogViewer = lazy(() => import('./components/debug-log-viewer/DebugLogViewer'));
const DebugLogViewer = lazy(() => import('@jetstream/feature/debug-log-viewer').then((module) => ({ default: module.DebugLogViewer })));

const SObjectExport = lazy(() => import('./components/sobject-export/SObjectExport'));

Expand Down
12 changes: 12 additions & 0 deletions libs/features/debug-log-viewer/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"presets": [
[
"@nx/react/babel",
{
"runtime": "automatic",
"useBuiltIns": "usage"
}
]
],
"plugins": []
}
18 changes: 18 additions & 0 deletions libs/features/debug-log-viewer/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": ["plugin:@nx/react", "../../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
7 changes: 7 additions & 0 deletions libs/features/debug-log-viewer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# features-debug-log-viewer

This library was generated with [Nx](https://nx.dev).

## Running unit tests

Run `nx test features-debug-log-viewer` to execute the unit tests via [Jest](https://jestjs.io).
11 changes: 11 additions & 0 deletions libs/features/debug-log-viewer/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* eslint-disable */
export default {
displayName: 'features-debug-log-viewer',
preset: '../../../jest.preset.js',
transform: {
'^(?!.*\\.(js|jsx|ts|tsx|css|json)$)': '@nx/react/plugins/jest',
'^.+\\.[tj]sx?$': ['babel-jest', { presets: ['@nx/react/babel'] }],
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
coverageDirectory: '../../../coverage/libs/features/debug-log-viewer',
};
16 changes: 16 additions & 0 deletions libs/features/debug-log-viewer/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "features-debug-log-viewer",
"$schema": "../../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "libs/features/debug-log-viewer/src",
"projectType": "library",
"tags": [],
"targets": {
"test": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
"options": {
"jestConfig": "libs/features/debug-log-viewer/jest.config.ts"
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { css } from '@emotion/react';
import { MIME_TYPES, TITLES } from '@jetstream/shared/constants';
import { fetchActiveLog, saveFile, useNonInitialEffect, useObservable, useTitle } from '@jetstream/shared/ui-utils';
import { SplitWrapper as Split } from '@jetstream/splitjs';
import { ApexLogWithViewed, AsyncJob, SalesforceOrgUi } from '@jetstream/types';
import { ApexLogWithViewed, SalesforceOrgUi } from '@jetstream/types';
import {
AutoFullHeightContainer,
Card,
Expand All @@ -20,6 +20,7 @@ import {
RequireMetadataApiBanner,
applicationCookieState,
fromJetstreamEvents,
isAsyncJob,
selectSkipFrontdoorAuth,
selectedOrgState,
} from '@jetstream/ui-core';
Expand Down Expand Up @@ -60,7 +61,7 @@ export const DebugLogViewer: FunctionComponent<DebugLogViewerProps> = () => {
const activeOrgId = useRef(selectedOrg.uniqueId);
const [purgeModalOpen, setPurgeModalOpen] = useState(false);
const bulkDeleteJob = useObservable(
fromJetstreamEvents.getObservable('jobFinished').pipe(filter((ev: AsyncJob) => ev.type === 'BulkDelete'))
fromJetstreamEvents.getObservable('jobFinished').pipe(filter((ev) => isAsyncJob(ev) && ev.type === 'BulkDelete'))
);

const { togglePause, fetchLogs, isPaused, loading, lastChecked, logs, pollInterval } = useDebugLogs(selectedOrg, {
Expand Down
1 change: 1 addition & 0 deletions libs/features/debug-log-viewer/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './DebugLogViewer';
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { logger } from '@jetstream/shared/client-logger';
import { query } from '@jetstream/shared/data';
import { getApexLogsQuery, useInterval, useNonInitialEffect } from '@jetstream/shared/ui-utils';
import { groupByFlat } from '@jetstream/shared/utils';
import { getErrorMessage, groupByFlat } from '@jetstream/shared/utils';
import { ApexLog, SalesforceOrgUi, UseDebugLogsOptions } from '@jetstream/types';
import orderBy from 'lodash/orderBy';
import { useCallback, useEffect, useRef, useState } from 'react';
Expand Down Expand Up @@ -71,7 +71,7 @@ export function useDebugLogs(org: SalesforceOrgUi, { limit, pollInterval, userId
numPollErrors.current++;
if (fetchToken === currentFetchToken.current) {
// TODO: what should we do if we cannot fetch logs?
setErrorMessage(ex.message);
setErrorMessage(getErrorMessage(ex));
setLoading(false);
}
}
Expand Down
22 changes: 22 additions & 0 deletions libs/features/debug-log-viewer/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"extends": "../../../tsconfig.base.json",
"compilerOptions": {
"jsx": "react-jsx",
"jsxImportSource": "@emotion/react",
"allowJs": false,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"lib": ["DOM", "DOM.Iterable", "ESNext"],
"strict": true
},
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.lib.json"
},
{
"path": "./tsconfig.spec.json"
}
]
}
24 changes: 24 additions & 0 deletions libs/features/debug-log-viewer/tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../../dist/out-tsc",
"types": ["node"]
},
"exclude": [
"jest.config.ts",
"src/**/*.spec.ts",
"src/**/*.test.ts",
"src/**/*.spec.tsx",
"src/**/*.test.tsx",
"src/**/*.spec.js",
"src/**/*.test.js",
"src/**/*.spec.jsx",
"src/**/*.test.jsx"
],
"include": ["src/**/*.js", "src/**/*.jsx", "src/**/*.ts", "src/**/*.tsx"],
"files": [
"../../../node_modules/@nx/react/typings/cssmodule.d.ts",
"../../../node_modules/@nx/react/typings/image.d.ts",
"../../../custom-typings/index.d.ts"
]
}
20 changes: 20 additions & 0 deletions libs/features/debug-log-viewer/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node"]
},
"include": [
"jest.config.ts",
"src/**/*.test.ts",
"src/**/*.spec.ts",
"src/**/*.test.tsx",
"src/**/*.spec.tsx",
"src/**/*.test.js",
"src/**/*.spec.js",
"src/**/*.test.jsx",
"src/**/*.spec.jsx",
"src/**/*.d.ts"
]
}
1 change: 1 addition & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"@jetstream/feature/anon-apex": ["libs/features/anon-apex/src/index.ts"],
"@jetstream/feature/automation-control": ["libs/features/automation-control/src/index.ts"],
"@jetstream/feature/create-object-and-fields": ["libs/features/create-object-and-fields/src/index.ts"],
"@jetstream/feature/debug-log-viewer": ["libs/features/debug-log-viewer/src/index.ts"],
"@jetstream/feature/platform-event-monitor": ["libs/features/platform-event-monitor/src/index.ts"],
"@jetstream/feature/query": ["libs/features/query/src/index.ts"],
"@jetstream/icon-factory": ["libs/icon-factory/src/index.ts"],
Expand Down

0 comments on commit 8eec806

Please sign in to comment.