From ee85edd6bbe478089be11744f063b3167ab002e2 Mon Sep 17 00:00:00 2001 From: Jacob Pihl Date: Mon, 11 Nov 2024 14:42:25 +0100 Subject: [PATCH 1/5] Upgrade Typescript --- package.json | 2 +- yarn.lock | 39 +++++++-------------------------------- 2 files changed, 8 insertions(+), 33 deletions(-) diff --git a/package.json b/package.json index 6d5370bc5b..6f485aa882 100644 --- a/package.json +++ b/package.json @@ -134,7 +134,7 @@ "stylelint-webpack-plugin": "^5.0.1", "svg-url-loader": "^8.0.0", "ts-node": "^10.9.2", - "typescript": "^4.6.4", + "typescript": "^5.6.0", "vitest": "^0.28.5", "webpack": "^5.96.1", "webpack-cli": "^5.1.4", diff --git a/yarn.lock b/yarn.lock index 82be324070..9aafef48c7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -12682,7 +12682,7 @@ string-env-interpolation@1.0.1, string-env-interpolation@^1.0.1: resolved "https://registry.npmjs.org/string-env-interpolation/-/string-env-interpolation-1.0.1.tgz" integrity sha512-78lwMoCcn0nNu8LszbP1UA7g55OeE4v7rCeWnM5B453rnNr4aq+5it3FEYtZrSEiMvHZOZ9Jlqb0OD0M2VInqg== -"string-width-cjs@npm:string-width@^4.2.0": +"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3: version "4.2.3" resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== @@ -12717,15 +12717,6 @@ string-width@^3.0.0, string-width@^3.1.0: is-fullwidth-code-point "^2.0.0" strip-ansi "^5.1.0" -string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3: - version "4.2.3" - resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" - integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== - dependencies: - emoji-regex "^8.0.0" - is-fullwidth-code-point "^3.0.0" - strip-ansi "^6.0.1" - string-width@^5.0.0, string-width@^5.0.1, string-width@^5.1.2: version "5.1.2" resolved "https://registry.yarnpkg.com/string-width/-/string-width-5.1.2.tgz#14f8daec6d81e7221d2a357e668cab73bdbca794" @@ -12820,7 +12811,7 @@ string_decoder@~1.1.1: dependencies: safe-buffer "~5.1.0" -"strip-ansi-cjs@npm:strip-ansi@^6.0.1": +"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1: version "6.0.1" resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== @@ -12848,13 +12839,6 @@ strip-ansi@^5.0.0, strip-ansi@^5.1.0, strip-ansi@^5.2.0: dependencies: ansi-regex "^4.1.0" -strip-ansi@^6.0.0, strip-ansi@^6.0.1: - version "6.0.1" - resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" - integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== - dependencies: - ansi-regex "^5.0.1" - strip-ansi@^7.0.1, strip-ansi@^7.1.0: version "7.1.0" resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-7.1.0.tgz#d5b6568ca689d8561370b0707685d22434faff45" @@ -13596,10 +13580,10 @@ typedarray@^0.0.6: resolved "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz" integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c= -typescript@^4.6.4: - version "4.6.4" - resolved "https://registry.npmjs.org/typescript/-/typescript-4.6.4.tgz" - integrity sha512-9ia/jWHIEbo49HfjrLGfKbZSuWo9iTMwXO+Ca3pRsSpbsMbc7/IU8NKdCZVRRBafVPGnoJeFL76ZOAA84I9fEg== +typescript@^5.6.0: + version "5.6.3" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.6.3.tgz#5f3449e31c9d94febb17de03cc081dd56d81db5b" + integrity sha512-hjcS1mhfuyi4WW8IWtjP7brDrG2cuDZukyrYrSauoXGNgx0S7zceP07adYkJycEr56BOUTNPzbInooiN3fn1qw== ua-parser-js@^0.7.30: version "0.7.36" @@ -14281,7 +14265,7 @@ wildcard@^2.0.0: resolved "https://registry.npmjs.org/wildcard/-/wildcard-2.0.0.tgz" integrity sha512-JcKqAHLPxcdb9KM49dufGXn2x3ssnfjbcaQdLlfZsL9rH9wgDQjUtDxbo8NE0F6SFvydeu1VhZe7hZuHsB2/pw== -"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0": +"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0: version "7.0.0" resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== @@ -14316,15 +14300,6 @@ wrap-ansi@^6.2.0: string-width "^4.1.0" strip-ansi "^6.0.0" -wrap-ansi@^7.0.0: - version "7.0.0" - resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" - integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== - dependencies: - ansi-styles "^4.0.0" - string-width "^4.1.0" - strip-ansi "^6.0.0" - wrap-ansi@^8.1.0: version "8.1.0" resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214" From 2426f89d83faf31dee02a3150e547f6abcadb091 Mon Sep 17 00:00:00 2001 From: Jacob Pihl Date: Mon, 11 Nov 2024 14:51:18 +0100 Subject: [PATCH 2/5] Remove duplicate Cypress command --- cypress/support/index.ts | 9 --------- 1 file changed, 9 deletions(-) diff --git a/cypress/support/index.ts b/cypress/support/index.ts index c78909c807..bc5e11094f 100644 --- a/cypress/support/index.ts +++ b/cypress/support/index.ts @@ -23,14 +23,6 @@ Cypress.Commands.add("createFakeAuthenticatedSession", () => { window.sessionStorage.setItem(TOKEN_USER_KEY, "999"); }); -Cypress.Commands.add("createFakeLibrarySession", () => { - // Since the user token is shared in storybook by setting it in sessionStorage - // we can use that and fake that we have a inlogged user session - // by using the same principle. - // See userToken handling in .storybbok/preview.js. - window.sessionStorage.setItem(TOKEN_LIBRARY_KEY, "random-token"); -}); - /** * interceptGraphql is used to make a graphQLrequest that returns fixture data * @@ -123,7 +115,6 @@ declare global { */ createFakeLibrarySession(): void; createFakeAuthenticatedSession(): void; - createFakeLibrarySession(): void; interceptGraphql(prams: InterceptGraphqlParams): void; interceptRest(params: InterceptRestParams): void; getBySel( From 8cac7ae505b1dcfa1f2d70af39678bf1ce92ade3 Mon Sep 17 00:00:00 2001 From: Jacob Pihl Date: Mon, 11 Nov 2024 15:18:23 +0100 Subject: [PATCH 3/5] Remove args from custom Cypress commands The `cy.get` command in Cypress does not accept additional arguments after the selector string. --- cypress/support/index.ts | 33 ++++++++++----------------------- 1 file changed, 10 insertions(+), 23 deletions(-) diff --git a/cypress/support/index.ts b/cypress/support/index.ts index bc5e11094f..7dda58205c 100644 --- a/cypress/support/index.ts +++ b/cypress/support/index.ts @@ -86,22 +86,18 @@ Cypress.Commands.add( // Data cy attribute selector helpers. const visible = (checkVisible: boolean) => (checkVisible ? ":visible" : ""); -Cypress.Commands.add("getBySel", (selector, checkVisible = false, ...args) => { - return cy.get(`[data-cy="${selector}"]${visible(checkVisible)}`, ...args); +Cypress.Commands.add("getBySel", (selector, checkVisible = false) => { + return cy.get(`[data-cy="${selector}"]${visible(checkVisible)}`); +}); +Cypress.Commands.add("getBySelLike", (selector, checkVisible = false) => { + return cy.get(`[data-cy*="${selector}"]${visible(checkVisible)}`); }); -Cypress.Commands.add( - "getBySelLike", - (selector, checkVisible = false, ...args) => { - return cy.get(`[data-cy*="${selector}"]${visible(checkVisible)}`, ...args); - } -); Cypress.Commands.add( "getBySelStartEnd", - (startSelector, endSelector, checkVisible = false, ...args) => { + (startSelector, endSelector, checkVisible = false) => { const v = visible(checkVisible); return cy.get( - `[data-cy^="${startSelector}"]${v}[data-cy$="${endSelector}"]${v}`, - ...args + `[data-cy^="${startSelector}"]${v}[data-cy$="${endSelector}"]${v}` ); } ); @@ -117,21 +113,12 @@ declare global { createFakeAuthenticatedSession(): void; interceptGraphql(prams: InterceptGraphqlParams): void; interceptRest(params: InterceptRestParams): void; - getBySel( - selector: string, - checkVisible?: boolean, - ...args: unknown[] - ): Chainable; - getBySelLike( - selector: string, - checkVisible?: boolean, - ...args: unknown[] - ): Chainable; + getBySel(selector: string, checkVisible?: boolean): Chainable; + getBySelLike(selector: string, checkVisible?: boolean): Chainable; getBySelStartEnd( startSelector: string, endSelector: string, - checkVisible?: boolean, - ...args: unknown[] + checkVisible?: boolean ): Chainable; } } From 57a4d5f90a2eaf4852e30d09063b485d312c4536 Mon Sep 17 00:00:00 2001 From: Jacob Pihl Date: Mon, 11 Nov 2024 15:20:27 +0100 Subject: [PATCH 4/5] Fix operator in conditional --- src/apps/advanced-search/AdvancedSearchHeader.tsx | 2 +- src/apps/advanced-search/PreviewSection.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/apps/advanced-search/AdvancedSearchHeader.tsx b/src/apps/advanced-search/AdvancedSearchHeader.tsx index e85b44c1dd..ef1d2d0525 100644 --- a/src/apps/advanced-search/AdvancedSearchHeader.tsx +++ b/src/apps/advanced-search/AdvancedSearchHeader.tsx @@ -239,7 +239,7 @@ const AdvancedSearchHeader: React.FC = ({ type="button" className="link-tag advanced-search__back-button cursor-pointer" onClick={() => setIsFormMode(true)} - onKeyUp={(e) => e.key === "Enter" ?? setIsFormMode(!true)} + onKeyUp={(e) => e.key === "Enter" && setIsFormMode(!true)} > {t("toAdvancedSearchButtonText")} diff --git a/src/apps/advanced-search/PreviewSection.tsx b/src/apps/advanced-search/PreviewSection.tsx index fcdb81635d..7f6a03ece1 100644 --- a/src/apps/advanced-search/PreviewSection.tsx +++ b/src/apps/advanced-search/PreviewSection.tsx @@ -90,7 +90,7 @@ const PreviewSection: React.FC = ({ type="button" className="link-tag link-tag cursor-pointer capitalize-first" onClick={() => setIsFormMode(false)} - onKeyUp={(e) => e.key === "Enter" ?? setIsFormMode(false)} + onKeyUp={(e) => e.key === "Enter" && setIsFormMode(false)} data-cy="advanced-search-edit-cql" > {t("advancedSearchEditCqlText")} From f0acea95830b7cf218689f300014df94fb855249 Mon Sep 17 00:00:00 2001 From: Jacob Pihl Date: Mon, 11 Nov 2024 16:04:26 +0100 Subject: [PATCH 5/5] Fix type errors --- src/core/utils/config.tsx | 4 +++- src/core/utils/helpers/currency.ts | 5 ++++- src/core/utils/text.tsx | 4 +++- src/core/utils/url.tsx | 4 +++- src/core/utils/withSuffix.tsx | 8 +++++--- 5 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/core/utils/config.tsx b/src/core/utils/config.tsx index bf35c98321..318cf62321 100644 --- a/src/core/utils/config.tsx +++ b/src/core/utils/config.tsx @@ -58,7 +58,9 @@ export const useConfig = (): UseConfigFunction => { }; }; -export const withConfig = (Component: React.ComponentType) => { +export const withConfig = ( + Component: React.ComponentType +) => { return withSuffix(Component, "Config", addConfigEntries); }; diff --git a/src/core/utils/helpers/currency.ts b/src/core/utils/helpers/currency.ts index 8c7e2bd21d..19019a2539 100644 --- a/src/core/utils/helpers/currency.ts +++ b/src/core/utils/helpers/currency.ts @@ -1,6 +1,9 @@ // Formats a number as a Danish Krone (DKK) currency string using the "da-DK" locale. export function formatCurrency(number: number): string { - const options = { style: "currency", currency: "DKK" }; + const options: Intl.NumberFormatOptions = { + style: "currency", + currency: "DKK" + }; return number.toLocaleString("da-DK", options); } diff --git a/src/core/utils/text.tsx b/src/core/utils/text.tsx index 9f14ed4d58..5994892e88 100644 --- a/src/core/utils/text.tsx +++ b/src/core/utils/text.tsx @@ -147,6 +147,8 @@ export const useText = (): UseTextFunction => { }; }; -export const withText = (Component: React.ComponentType) => { +export const withText = ( + Component: React.ComponentType +) => { return withSuffix(Component, "Text", addTextEntries); }; diff --git a/src/core/utils/url.tsx b/src/core/utils/url.tsx index 499bd80f60..e6489fde67 100644 --- a/src/core/utils/url.tsx +++ b/src/core/utils/url.tsx @@ -19,7 +19,9 @@ export const useUrls = () => { return urls[name]; }; }; -export const withUrls = (Component: React.ComponentType) => { +export const withUrls = ( + Component: React.ComponentType +) => { return withSuffix(Component, "Url", addUrlEntries); }; diff --git a/src/core/utils/withSuffix.tsx b/src/core/utils/withSuffix.tsx index 20bc09be2d..6ffab9fb00 100644 --- a/src/core/utils/withSuffix.tsx +++ b/src/core/utils/withSuffix.tsx @@ -2,13 +2,14 @@ import { ActionCreatorWithPayload } from "@reduxjs/toolkit"; import React from "react"; import { store } from "../store"; -export default ( +export default function withSuffix( Component: React.ComponentType, suffix: string, reduxAction: ActionCreatorWithPayload -) => { +) { return (props: T) => { const pattern = new RegExp(`.*${suffix}$`, "g"); + // Match all props that ends with suffix. const suffixEntries = Object.fromEntries( Object.entries(props).filter(([prop]) => { @@ -30,10 +31,11 @@ export default ( }) ); } + // Since this is a High Order Functional Component // we do not know what props we are dealing with. // That is a part of the design. // eslint-disable-next-line react/jsx-props-no-spreading return ; }; -}; +}