Skip to content

Commit

Permalink
Merge branch 'staging' into 10102-story
Browse files Browse the repository at this point in the history
  • Loading branch information
jimlerza authored Aug 15, 2024
2 parents d70e32e + 43cc135 commit 047c5d5
Show file tree
Hide file tree
Showing 15 changed files with 93 additions and 144 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: Typescript Untouched File Check
name: Typescript File Check

on:
pull_request:

jobs:
CheckUntouchedFiles:
CheckAllFilesForTypeErrorCount:
runs-on: ubuntu-latest

steps:
Expand Down Expand Up @@ -40,4 +40,4 @@ jobs:
run: npm ci

- name: Check untouched files
run: npx ts-node scripts/checkUntouchedFiles.ts
run: npx ts-node scripts/checkAllFilesForTypeErrorCount.ts
2 changes: 1 addition & 1 deletion esbuildHelper.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export default async function ({
copy({
assets: [
{
from: ['web-client/src/favicons'],
from: ['web-client/src/favicons/**/*'],
keepStructure: true,
to: ['.'],
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { execSync, spawnSync } from 'child_process';
import { spawnSync } from 'child_process';

function runTypescriptCommand(cwd: string): { stdout: string } {
return spawnSync(
Expand Down Expand Up @@ -34,56 +34,9 @@ function getTypescriptErrorMap(cwd: string): { [fileName: string]: number } {
return createTypescriptErrorMap(stdout);
}

function getHashForDirectory(cwd: string) {
return spawnSync('git', ['log', '-n', '1', '--pretty=format:"%H"'], {
cwd,
encoding: 'utf-8',
}).stdout;
}

function getDifferencesBetweenHashes(
branchDirPath: string,
currentBranchHash: string,
targetBranchHash: string,
): { [fileName: string]: boolean } {
return execSync(
`git diff --name-only ${currentBranchHash} ${targetBranchHash}`,
{
cwd: branchDirPath,
encoding: 'utf-8',
},
)
.split('\n')
.map(line => line.trim())
.reduce(
(accumulator, fileName) => {
accumulator[fileName] = true;
return accumulator;
},
{} as { [fileName: string]: boolean },
);
}

function getModifiedFiles(
branchDirPath: string,
targetRepoPath: string,
): {
[fileName: string]: boolean;
} {
const currentBranchHash = getHashForDirectory(branchDirPath);
const targetBranchHash = getHashForDirectory(targetRepoPath);

return getDifferencesBetweenHashes(
branchDirPath,
currentBranchHash,
targetBranchHash,
);
}

function getFilesToCheck(
branchTypescriptErrorMap: { [fileName: string]: number },
targetTypescriptErrorMap: { [fileName: string]: number },
modifiedFiles: { [fileName: string]: boolean },
): {
[fileName: string]: {
targetCount: number;
Expand All @@ -98,7 +51,6 @@ function getFilesToCheck(
} = {};
Object.entries(branchTypescriptErrorMap).forEach(
([fileName, branchCount]) => {
if (modifiedFiles[fileName]) return;
const targetCount = targetTypescriptErrorMap[fileName] || 0;
if (targetCount < branchCount)
fileToCheck[fileName] = { branchCount, targetCount };
Expand All @@ -111,12 +63,10 @@ const branchDirPath = './';
const targetDirPath = './targetBranch';
const branchTypescriptErrorMap = getTypescriptErrorMap(branchDirPath);
const targetTypescriptErrorMap = getTypescriptErrorMap(targetDirPath);
const modifiedFiles = getModifiedFiles(branchDirPath, targetDirPath);

const fileToCheck = getFilesToCheck(
branchTypescriptErrorMap,
targetTypescriptErrorMap,
modifiedFiles,
);

function logSmartTable(dataObject: {
Expand Down
2 changes: 1 addition & 1 deletion scripts/jest-scripts.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const config: Config = {
collectCoverage: true,
collectCoverageFrom: [
'**/*.{js,ts}',
'!checkUntouchedFiles.ts',
'!checkAllFilesForTypeErrorCount.ts',
'!circleci/*.ts',
'!circleci/judge/bulkImportJudgeUsers.ts',
'!circleci/judge/bulkImportJudgeUsers.helpers.ts',
Expand Down
9 changes: 4 additions & 5 deletions web-api/src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@ const console = () =>
handleRejections: true,
}));

export const logger =
(transport = console()) =>
(req, res, next) => {
const createdLogger = createLogger({ transports: [transport] });

export const logger = (transport = console()) => {
const createdLogger = createLogger({ transports: [transport] });
return (req, res, next) => {
if (process.env.NODE_ENV === 'production') {
const requestBody = cloneDeep(req.body);

Expand Down Expand Up @@ -66,6 +64,7 @@ export const logger =

return next();
};
};

function redactPasswordFields(obj) {
const passwordRegex = /password/i;
Expand Down
18 changes: 0 additions & 18 deletions web-client/src/presenter/actions/cancelUploadsAction.test.ts

This file was deleted.

7 changes: 0 additions & 7 deletions web-client/src/presenter/actions/cancelUploadsAction.ts

This file was deleted.

19 changes: 18 additions & 1 deletion web-client/src/presenter/computeds/caseDetailHelper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,23 @@ describe('case detail computed', () => {
expect(result.showPetitionProcessingAlert).toEqual(false);
});

it('should show petition processing alert if user is an external user and the case does not allow service', () => {
it('should not show petition processing alert if user is not associated with the case', () => {
const user = petitionerUser;

const result = runCompute(caseDetailHelper, {
state: {
...getBaseState(user),
caseDetail: {
docketEntries: [{ documentType: 'Petition' }],
screenMetadata: { isAssociated: false },
status: CASE_STATUS_TYPES.generalDocket,
},
},
});
expect(result.showPetitionProcessingAlert).toEqual(false);
});

it('should show petition processing alert if user is an external user and the case does not allow service and user is associated with the case', () => {
const user = petitionerUser;

const result = runCompute(caseDetailHelper, {
Expand All @@ -459,6 +475,7 @@ describe('case detail computed', () => {
docketEntries: [{ documentType: 'Petition' }],
status: CASE_STATUS_TYPES.new,
},
screenMetadata: { isAssociated: true },
},
});
expect(result.showPetitionProcessingAlert).toEqual(true);
Expand Down
41 changes: 24 additions & 17 deletions web-client/src/presenter/computeds/caseDetailHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ export const caseDetailHelper = (
const isExternalUser = applicationContext
.getUtilities()
.isExternalUser(user.role);
const userAssociatedWithCase = get(state.screenMetadata.isAssociated);
const showJudgesNotes = permissions.JUDGES_NOTES;
const userIsAssociatedWithCase = get(state.screenMetadata.isAssociated);

let showFileDocumentButton =
permissions.FILE_EXTERNAL_DOCUMENT && ['CaseDetail'].includes(currentPage);
Expand All @@ -34,7 +33,7 @@ export const caseDetailHelper = (
let showQcWorkItemsUntouchedState = false;

if (isExternalUser) {
if (userAssociatedWithCase) {
if (userIsAssociatedWithCase) {
userHasAccessToCase = true;
showFileDocumentButton = true;

Expand Down Expand Up @@ -71,22 +70,34 @@ export const caseDetailHelper = (
.getUtilities()
.isSealedCase(caseDetail);

const userCanViewCase =
(isExternalUser && userAssociatedWithCase) || !isSealedCase;
const showConsolidatedCasesCard =
permissions.VIEW_CONSOLIDATED_CASES_CARD && !!caseDetail.leadDocketNumber;

const showFilingFeeExternal =
isExternalUser &&
user.role !== USER_ROLES.irsPractitioner &&
user.role !== USER_ROLES.irsSuperuser;

const showJudgesNotes = permissions.JUDGES_NOTES;

const showPetitionProcessingAlert =
isExternalUser &&
!canAllowDocumentServiceForCase &&
userIsAssociatedWithCase;

const showPractitionerSection = !isExternalUser || hasPrivatePractitioners;

const isPractitioner =
user.role === USER_ROLES.irsPractitioner ||
user.role === USER_ROLES.privatePractitioner;

const isPetitioner = user.role === USER_ROLES.petitioner;

const showSealedCaseView =
(isPractitioner || isPetitioner) &&
!!isSealedCase &&
!userAssociatedWithCase;
!userIsAssociatedWithCase;

const showConsolidatedCasesCard =
permissions.VIEW_CONSOLIDATED_CASES_CARD && !!caseDetail.leadDocketNumber;
const userCanViewCase =
(isExternalUser && userIsAssociatedWithCase) || !isSealedCase;

return {
caseDeadlines,
Expand All @@ -105,14 +116,10 @@ export const caseDetailHelper = (
showDocketRecordInProgressState: !isExternalUser,
showEditCaseDetailsButton: permissions.EDIT_CASE_DETAILS,
showFileDocumentButton,
showFilingFeeExternal:
isExternalUser &&
user.role !== USER_ROLES.irsPractitioner &&
user.role !== USER_ROLES.irsSuperuser,
showFilingFeeExternal,
showJudgesNotes,
showPetitionProcessingAlert:
isExternalUser && !canAllowDocumentServiceForCase,
showPractitionerSection: !isExternalUser || hasPrivatePractitioners,
showPetitionProcessingAlert,
showPractitionerSection,
showPreferredTrialCity: caseDetail.preferredTrialCity,
showQcWorkItemsUntouchedState,
showSealedCaseView,
Expand Down
4 changes: 0 additions & 4 deletions web-client/src/presenter/computeds/fileUploadStatusHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ export const fileUploadStatusHelper = (get: Get): any => {
);
const shouldThrottle = !get(state.fileUploadProgress.noThrottle); // results WILL be throttled unless explicitly set to false

const isCancelable = !!(
Number.isFinite(timeRemaining) && percentComplete < 100
);
let statusMessage;

if (percentComplete === 100) {
Expand All @@ -39,7 +36,6 @@ export const fileUploadStatusHelper = (get: Get): any => {
}

return {
isCancelable,
isHavingSystemIssues,
statusMessage: shouldThrottle
? throttledStatus(statusMessage)
Expand Down
2 changes: 0 additions & 2 deletions web-client/src/presenter/presenter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import { canEditContactInformationSequence } from './sequences/canEditContactInf
import { cancelAddDraftDocumentSequence } from './sequences/cancelAddDraftDocumentSequence';
import { cancelAddStatisticSequence } from './sequences/cancelAddStatisticSequence';
import { cancelAndNavigateToCorrespondenceSequence } from './sequences/cancelAndNavigateToCorrespondenceSequence';
import { cancelFileUploadSequence } from './sequences/cancelFileUploadSequence';
import { cancelRemovePetitionerSequence } from './sequences/cancelRemovePetitionerSequence';
import { caseDetailPrimaryTabChangeSequence } from './sequences/caseDetailPrimaryTabChangeSequence';
import { caseInventoryReportLoadMoreSequence } from './sequences/caseInventoryReportLoadMoreSequence';
Expand Down Expand Up @@ -670,7 +669,6 @@ export const presenterSequences = {
cancelAddStatisticSequence: cancelAddStatisticSequence as unknown as Function,
cancelAndNavigateToCorrespondenceSequence:
cancelAndNavigateToCorrespondenceSequence as unknown as Function,
cancelFileUploadSequence: cancelFileUploadSequence as unknown as Function,
cancelRemovePetitionerSequence:
cancelRemovePetitionerSequence as unknown as Function,
caseDetailPrimaryTabChangeSequence:
Expand Down

This file was deleted.

36 changes: 35 additions & 1 deletion web-client/src/views/CreateOrder/TextEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/* eslint-disable react/prop-types */
import 'react-quill/dist/quill.snow.css';
import { DomUtils, parseDocument } from 'htmlparser2';
import { QuillDeltaToHtmlConverter } from 'quill-delta-to-html';
import { render as renderHtml } from 'dom-serializer';
import React, { Suspense, useEffect, useRef } from 'react';
import reactQuill from 'react-quill';

Expand All @@ -19,13 +21,40 @@ const ReactQuill = React.lazy(async () => {
return { default: reactQuill };
});

// Quill does two things to render indentations:
// 1) Adds padding-left so that the richText (and therefore the pdf) has indentations.
// 2) Adds custom ql-indent-{level} classes to display the indentation in the Quill editor itself.
// As part of the richText, 1 is automatically preserved across save and reload.
// As part of the client-side Quill text rendering, 2 is *not* preserved across save and reload,
// so even though the indentations are "there" in the richText, the user won't see them in the editor.
// We call addQuillIndentationClasses on loading the text into the editor in order to correct that.
const addQuillIndentationClasses = (html: string) => {
const dom = parseDocument(html);
// Traverse the DOM and add the appropriate ql-indent-{level} class corresponding to any elements with padding-left
DomUtils.findAll(elem => {
if (elem.name === 'p' && elem.attribs && elem.attribs.style) {
const { style } = elem.attribs;
const paddingLeftMatch = style.match(/padding-left:([0-9]+)em/);
if (paddingLeftMatch) {
const paddingLeftValue = parseInt(paddingLeftMatch[1]);
const indentLevel = paddingLeftValue / 3;
elem.attribs.class = `ql-indent-${indentLevel}`;
}
}
return true;
}, dom.children);

return renderHtml(dom);
};

export const TextEditor = ({
defaultValue,
editorDelta,
updateFormValueSequence,
updateScreenMetadataSequence,
}) => {
const quillEscapeRef = useRef(null);
const defaultValueWithIndentation = addQuillIndentationClasses(defaultValue);

const onKeyboard = event => {
const pressedESC = event.keyCode === 27;
Expand All @@ -51,7 +80,7 @@ export const TextEditor = ({
<>
<Suspense fallback={<div>Loading...</div>}>
<ReactQuill
defaultValue={editorDelta || defaultValue}
defaultValue={editorDelta || defaultValueWithIndentation}
formats={[
'size',
'bold',
Expand Down Expand Up @@ -82,6 +111,11 @@ export const TextEditor = ({
const fullDelta = editor.getContents();
const documentContents = editor.getText();
const converter = new QuillDeltaToHtmlConverter(fullDelta.ops, {
// We add custom CSS styles to maintain tabbing across save and reload.
// (Note that preserveWhitespace does not work: https://github.com/ustaxcourt/ef-cms/pull/1408.)
customCssStyles: () => {
return 'white-space: pre-wrap !important';
},
inlineStyles: {
size: inlineStylesFontSizes,
},
Expand Down
Loading

0 comments on commit 047c5d5

Please sign in to comment.