Skip to content

Commit

Permalink
Merge branch 'staging' into 10339-story
Browse files Browse the repository at this point in the history
  • Loading branch information
nechama-krigsman committed Aug 14, 2024
2 parents 545e93e + 98ddfa1 commit 57c4c13
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 75 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
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
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

0 comments on commit 57c4c13

Please sign in to comment.