mirror of
https://github.com/Stirling-Tools/Stirling-PDF.git
synced 2026-09-02 21:03:34 +03:00
refactor(frontend): decouple signature status logic from PDF color palette (#6992)
# Description of Changes - Moved the signature status-to-color mapping from `signatureStatus.ts` to `pdfPalette.ts`. - Removed the PDF palette dependency from the pure signature status calculation module. - Updated the PDF signature report to import the color mapping from the palette module. - Prevented signature status unit tests from initializing browser-dependent CSS colors unnecessarily. - Eliminated fallback warnings caused by unavailable theme CSS variables in the Vitest environment. - Preserved the existing signature status calculation and PDF report color behavior. ```sh [frontend:test:editor] stderr | src/core/hooks/tools/validateSignature/utils/signatureStatus.test.ts [frontend:test:editor] CSS variable --pdf-light-header-bg not found, using fallback [frontend:test:editor] CSS variable --pdf-light-accent not found, using fallback [frontend:test:editor] CSS variable --pdf-light-text-primary not found, using fallback [frontend:test:editor] CSS variable --pdf-light-text-muted not found, using fallback [frontend:test:editor] CSS variable --pdf-light-box-bg not found, using fallback [frontend:test:editor] CSS variable --pdf-light-box-border not found, using fallback [frontend:test:editor] CSS variable --pdf-light-warning not found, using fallback [frontend:test:editor] CSS variable --pdf-light-danger not found, using fallback [frontend:test:editor] CSS variable --pdf-light-success not found, using fallback [frontend:test:editor] CSS variable --pdf-light-neutral not found, using fallback ``` --- ## Checklist ### General - [ ] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [ ] I have read the [Stirling-PDF Developer Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md) (if applicable) - [ ] I have read the [How to add new languages to Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md) (if applicable) - [ ] I have performed a self-review of my own code - [ ] My changes generate no new warnings ### Documentation - [ ] I have updated relevant docs on [Stirling-PDF's doc repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/) (if functionality has heavily changed) - [ ] I have read the section [Add New Translation Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md#add-new-translation-tags) (for new translation tags only) ### Translations (if applicable) - [ ] I ran [`scripts/counter_translation.py`](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/docs/counter_translation.md) ### UI Changes (if applicable) - [ ] Screenshots or videos demonstrating the UI changes are attached (e.g., as comments or direct attachments in the PR) ### Testing (if applicable) - [ ] I have run `task check` to verify linters, typechecks, and tests pass - [ ] I have tested my changes locally. Refer to the [Testing Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md#7-testing) for more details.
This commit is contained in:
+5
-5
@@ -3,12 +3,12 @@ import { PdfiumFont, PdfiumPage } from "@app/services/pdfiumDocBuilder";
|
||||
import { SignatureValidationSignature } from "@app/types/validateSignature";
|
||||
import { drawFieldBox } from "@app/hooks/tools/validateSignature/outputtedPDFSections/FieldBoxSection";
|
||||
import { drawStatusBadge } from "@app/hooks/tools/validateSignature/outputtedPDFSections/StatusBadgeSection";
|
||||
import {
|
||||
computeSignatureStatus,
|
||||
statusKindToPdfColor,
|
||||
} from "@app/hooks/tools/validateSignature/utils/signatureStatus";
|
||||
import { computeSignatureStatus } from "@app/hooks/tools/validateSignature/utils/signatureStatus";
|
||||
import { formatDate } from "@app/hooks/tools/validateSignature/utils/pdfText";
|
||||
import { colorPalette } from "@app/hooks/tools/validateSignature/utils/pdfPalette";
|
||||
import {
|
||||
colorPalette,
|
||||
statusKindToPdfColor,
|
||||
} from "@app/hooks/tools/validateSignature/utils/pdfPalette";
|
||||
|
||||
interface DrawSignatureSectionOptions {
|
||||
page: PdfiumPage;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { rgb } from "@app/services/pdfiumDocBuilder";
|
||||
import type { SignatureStatusKind } from "@app/hooks/tools/validateSignature/utils/signatureStatus";
|
||||
|
||||
type RgbTuple = [number, number, number];
|
||||
|
||||
@@ -93,3 +94,16 @@ export const colorPalette = {
|
||||
defaultLightPalette.neutral,
|
||||
),
|
||||
};
|
||||
|
||||
export const statusKindToPdfColor = (kind: SignatureStatusKind) => {
|
||||
switch (kind) {
|
||||
case "valid":
|
||||
return colorPalette.success;
|
||||
case "warning":
|
||||
return colorPalette.warning;
|
||||
case "invalid":
|
||||
return colorPalette.danger;
|
||||
default:
|
||||
return colorPalette.neutral;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import type { TFunction } from "i18next";
|
||||
import type { SignatureValidationSignature } from "@app/types/validateSignature";
|
||||
import { colorPalette } from "@app/hooks/tools/validateSignature/utils/pdfPalette";
|
||||
|
||||
export type SignatureStatusKind = "valid" | "warning" | "invalid" | "neutral";
|
||||
|
||||
@@ -131,16 +130,3 @@ export const computeSignatureStatus = (
|
||||
details: issues,
|
||||
};
|
||||
};
|
||||
|
||||
export const statusKindToPdfColor = (kind: SignatureStatusKind) => {
|
||||
switch (kind) {
|
||||
case "valid":
|
||||
return colorPalette.success;
|
||||
case "warning":
|
||||
return colorPalette.warning;
|
||||
case "invalid":
|
||||
return colorPalette.danger;
|
||||
default:
|
||||
return colorPalette.neutral;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user