From 3722ceecae717165d631ba96c4376a3a0c430213 Mon Sep 17 00:00:00 2001 From: Jeff Daley Date: Wed, 31 May 2023 20:16:29 -0400 Subject: [PATCH 1/3] Register GetProductID helper --- web/app/helpers/get-product-id.js | 5 ----- web/app/helpers/get-product-id.ts | 23 +++++++++++++++++++++++ 2 files changed, 23 insertions(+), 5 deletions(-) delete mode 100644 web/app/helpers/get-product-id.js create mode 100644 web/app/helpers/get-product-id.ts diff --git a/web/app/helpers/get-product-id.js b/web/app/helpers/get-product-id.js deleted file mode 100644 index 5e2fa0cdb..000000000 --- a/web/app/helpers/get-product-id.js +++ /dev/null @@ -1,5 +0,0 @@ -import { helper } from "@ember/component/helper"; -import getProductId from "hermes/utils/get-product-id"; -export default helper(([productName]) => { - return getProductId(productName); -}); diff --git a/web/app/helpers/get-product-id.ts b/web/app/helpers/get-product-id.ts new file mode 100644 index 000000000..87c48909d --- /dev/null +++ b/web/app/helpers/get-product-id.ts @@ -0,0 +1,23 @@ +import { helper } from "@ember/component/helper"; +import getProductId from "hermes/utils/get-product-id"; + +export interface GetProductIDSignature { + Args: { + Positional: [string | undefined]; + }; +} + +const getProductIDHelper = helper(([productName]) => { + if (!productName) { + return null; + } + return getProductId(productName); +}); + +export default getProductIDHelper; + +declare module "@glint/environment-ember-loose/registry" { + export default interface Registry { + "get-product-id": typeof getProductIDHelper; + } +} From c6f3c9d197c927616f3ffefb4d21c540c653471d Mon Sep 17 00:00:00 2001 From: Jeff Daley Date: Wed, 31 May 2023 20:53:00 -0400 Subject: [PATCH 2/3] Register helpers with Glint --- web/app/components/header/facet-dropdown.hbs | 4 +-- web/app/helpers/add.js | 7 ---- web/app/helpers/add.ts | 36 ++++++++++++++++++++ web/app/helpers/get-facet-query-hash.ts | 23 +++++++++---- web/app/helpers/get-first-letter.js | 10 ------ web/app/helpers/get-first-letter.ts | 25 ++++++++++++++ web/app/helpers/has-approved-doc.ts | 29 ++++++++++++---- web/app/helpers/html-element.ts | 23 +++++++++++-- web/app/helpers/lowercase.js | 7 ---- web/app/helpers/lowercase.ts | 22 ++++++++++++ web/app/helpers/parse-date.ts | 19 ++++++++++- 11 files changed, 162 insertions(+), 43 deletions(-) delete mode 100644 web/app/helpers/add.js create mode 100644 web/app/helpers/add.ts delete mode 100644 web/app/helpers/get-first-letter.js create mode 100644 web/app/helpers/get-first-letter.ts delete mode 100644 web/app/helpers/lowercase.js create mode 100644 web/app/helpers/lowercase.ts diff --git a/web/app/components/header/facet-dropdown.hbs b/web/app/components/header/facet-dropdown.hbs index b6f9b4518..83f263eeb 100644 --- a/web/app/components/header/facet-dropdown.hbs +++ b/web/app/components/header/facet-dropdown.hbs @@ -1,9 +1,9 @@ -{{! @glint-nocheck: not typesafe yet }} - +{{! @glint-ignore: not typesafe yet }} <:anchor as |dd|> diff --git a/web/app/helpers/add.js b/web/app/helpers/add.js deleted file mode 100644 index 3fbfb5878..000000000 --- a/web/app/helpers/add.js +++ /dev/null @@ -1,7 +0,0 @@ -import { helper } from "@ember/component/helper"; - -export default helper(function add([first, second]) { - const firstInt = parseInt(first); - const secondInt = parseInt(second); - return firstInt + secondInt; -}); diff --git a/web/app/helpers/add.ts b/web/app/helpers/add.ts new file mode 100644 index 000000000..0854106f9 --- /dev/null +++ b/web/app/helpers/add.ts @@ -0,0 +1,36 @@ +import { helper } from "@ember/component/helper"; + +interface AddHelperSignature { + Args: { + Positional: [first: string | number, second: string | number]; + Return: number; + }; +} + +const addHelper = helper( + ([first, second]: [string | number, string | number]) => { + let firstInteger = 0; + let secondInteger = 0; + + if (typeof first === "number") { + firstInteger = first; + } else { + firstInteger = parseInt(first); + } + + if (typeof second === "number") { + secondInteger = second; + } else { + secondInteger = parseInt(second); + } + return firstInteger + secondInteger; + } +); + +export default addHelper; + +declare module "@glint/environment-ember-loose/registry" { + export default interface Registry { + add: typeof addHelper; + } +} diff --git a/web/app/helpers/get-facet-query-hash.ts b/web/app/helpers/get-facet-query-hash.ts index 628c2a7f6..56d81a2ec 100644 --- a/web/app/helpers/get-facet-query-hash.ts +++ b/web/app/helpers/get-facet-query-hash.ts @@ -4,23 +4,26 @@ import { inject as service } from "@ember/service"; import { FacetName } from "hermes/components/header/toolbar"; import ActiveFiltersService from "hermes/services/active-filters"; +interface GetFacetQueryHashHelperSignature { + Args: { + Positional: [facetName: string, clickedFilter: string, isSelected: boolean]; + }; +} /** * Generates a query hash appropriate for the facet item. * If the facet is in the ActiveFiltersService index, it will * be removed from the query hash. Otherwise, it'll be added. * Used by the FacetDropdown to add/remove filters on click. */ -export default class GetFacetQueryHashHelper extends Helper { +export default class GetFacetQueryHashHelper extends Helper { @service declare activeFilters: ActiveFiltersService; - compute([facetName, clickedFilter, isSelected]: [ - string, - string, - boolean, - () => void - ]) { + compute( + positional: [facetName: string, clickedFilter: string, isSelected: boolean] + ) { // Translate the UI facetName to the one used in the query hash. let translatedFacetName; + let [facetName, clickedFilter, isSelected] = positional; switch (facetName) { case "Type": @@ -57,3 +60,9 @@ export default class GetFacetQueryHashHelper extends Helper { } } } + +declare module "@glint/environment-ember-loose/registry" { + export default interface Registry { + "get-facet-query-hash": typeof GetFacetQueryHashHelper; + } +} diff --git a/web/app/helpers/get-first-letter.js b/web/app/helpers/get-first-letter.js deleted file mode 100644 index c81168d1c..000000000 --- a/web/app/helpers/get-first-letter.js +++ /dev/null @@ -1,10 +0,0 @@ -import { helper } from "@ember/component/helper"; - -function getFirstLetter([string]) { - if (typeof string === "string") { - return string.match(/[a-zA-Z]/)[0] - } - return null; -} - -export default helper(getFirstLetter); diff --git a/web/app/helpers/get-first-letter.ts b/web/app/helpers/get-first-letter.ts new file mode 100644 index 000000000..5d87a7405 --- /dev/null +++ b/web/app/helpers/get-first-letter.ts @@ -0,0 +1,25 @@ +import { helper } from "@ember/component/helper"; + +export interface GetFirstLetterSignature { + Args: { + Positional: [maybeString: string | null | undefined]; + Return: string | null; + }; +} + +const getFirstLetter = helper( + ([maybeString]: [string | null | undefined | number]) => { + if (typeof maybeString === "string") { + return maybeString.match(/[a-zA-Z]/)?.[0] ?? null; + } + return null; + } +); + +export default getFirstLetter; + +declare module "@glint/environment-ember-loose/registry" { + export default interface Registry { + "get-first-letter": typeof getFirstLetter; + } +} diff --git a/web/app/helpers/has-approved-doc.ts b/web/app/helpers/has-approved-doc.ts index a221ca4e4..ee7beca16 100644 --- a/web/app/helpers/has-approved-doc.ts +++ b/web/app/helpers/has-approved-doc.ts @@ -1,10 +1,27 @@ import { helper } from "@ember/component/helper"; import { HermesDocument } from "hermes/types/document"; -export default helper(([document, approverEmail]: [HermesDocument, string]) => { - if (document.approvedBy) { - return document.approvedBy.some((email) => email === approverEmail); - } else { - return false; +interface HasApprovedDocHelperSignature { + Args: { + Positional: [document: HermesDocument, approverEmail: string]; + Return: boolean; + }; +} + +const hasApprovedDocHelper = helper( + ([document, approverEmail]: [HermesDocument, string]) => { + if (document.approvedBy) { + return document.approvedBy.some((email) => email === approverEmail); + } else { + return false; + } + } +); + +export default hasApprovedDocHelper; + +declare module "@glint/environment-ember-loose/registry" { + export default interface Registry { + "has-approved-doc": typeof hasApprovedDocHelper; } -}); +} diff --git a/web/app/helpers/html-element.ts b/web/app/helpers/html-element.ts index d0c69b887..cb4e7d174 100644 --- a/web/app/helpers/html-element.ts +++ b/web/app/helpers/html-element.ts @@ -1,6 +1,23 @@ import { helper } from "@ember/component/helper"; import htmlElement from "hermes/utils/html-element"; -export default helper(([selector]: [string]) => { - return htmlElement(selector); -}); +interface HtmlElementHelperSignature { + Args: { + Positional: [selector: string]; + Return: HTMLElement; + }; +} + +const htmlElementHelper = helper( + ([selector]: [string]) => { + return htmlElement(selector); + } +); + +export default htmlElementHelper; + +declare module "@glint/environment-ember-loose/registry" { + export default interface Registry { + "html-element": typeof htmlElementHelper; + } +} diff --git a/web/app/helpers/lowercase.js b/web/app/helpers/lowercase.js deleted file mode 100644 index 5b29b8ada..000000000 --- a/web/app/helpers/lowercase.js +++ /dev/null @@ -1,7 +0,0 @@ -import { helper } from "@ember/component/helper"; - -function lowercase(string) { - return string.toString().toLowerCase(); -} - -export default helper(lowercase); diff --git a/web/app/helpers/lowercase.ts b/web/app/helpers/lowercase.ts new file mode 100644 index 000000000..e5d819bdf --- /dev/null +++ b/web/app/helpers/lowercase.ts @@ -0,0 +1,22 @@ +import { helper } from "@ember/component/helper"; + +export interface LowercaseHelperSignature { + Args: { + Positional: [value: string | number | boolean | undefined]; + Return: string; + }; +} + +const lowercaseHelper = helper( + ([value]: [string | number | boolean | undefined]) => { + return value?.toString().toLowerCase() ?? ""; + } +); + +export default lowercaseHelper; + +declare module "@glint/environment-ember-loose/registry" { + export default interface Registry { + lowercase: typeof lowercaseHelper; + } +} diff --git a/web/app/helpers/parse-date.ts b/web/app/helpers/parse-date.ts index e492e86cd..8744063d0 100644 --- a/web/app/helpers/parse-date.ts +++ b/web/app/helpers/parse-date.ts @@ -1,7 +1,16 @@ import { helper } from "@ember/component/helper"; import parseDate from "hermes/utils/parse-date"; +export interface ParseDateHelperSignature { + Args: { + Positional: [ + time: string | number | Date | undefined, + monthFormat: "short" | "long" + ]; + Return: Date | undefined; + }; +} -export default helper( +const parseDateHelper = helper( ([time, monthFormat = "short"]: [ string | number | Date | undefined, "short" | "long" @@ -9,3 +18,11 @@ export default helper( return parseDate(time, monthFormat); } ); + +export default parseDateHelper; + +declare module "@glint/environment-ember-loose/registry" { + export default interface Registry { + "parse-date": typeof parseDateHelper; + } +} From 77b932442fc0fa5e3ea8e2956640d9355347271d Mon Sep 17 00:00:00 2001 From: Jeff Daley Date: Thu, 1 Jun 2023 20:39:00 -0400 Subject: [PATCH 3/3] Syntax tweak --- web/app/helpers/add.ts | 2 +- web/app/helpers/get-first-letter.ts | 2 +- web/app/helpers/html-element.ts | 2 +- web/app/helpers/lowercase.ts | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/web/app/helpers/add.ts b/web/app/helpers/add.ts index 0854106f9..8e6e3b873 100644 --- a/web/app/helpers/add.ts +++ b/web/app/helpers/add.ts @@ -3,8 +3,8 @@ import { helper } from "@ember/component/helper"; interface AddHelperSignature { Args: { Positional: [first: string | number, second: string | number]; - Return: number; }; + Return: number; } const addHelper = helper( diff --git a/web/app/helpers/get-first-letter.ts b/web/app/helpers/get-first-letter.ts index 5d87a7405..7ad095834 100644 --- a/web/app/helpers/get-first-letter.ts +++ b/web/app/helpers/get-first-letter.ts @@ -3,8 +3,8 @@ import { helper } from "@ember/component/helper"; export interface GetFirstLetterSignature { Args: { Positional: [maybeString: string | null | undefined]; - Return: string | null; }; + Return: string | null; } const getFirstLetter = helper( diff --git a/web/app/helpers/html-element.ts b/web/app/helpers/html-element.ts index cb4e7d174..1e563bf69 100644 --- a/web/app/helpers/html-element.ts +++ b/web/app/helpers/html-element.ts @@ -4,8 +4,8 @@ import htmlElement from "hermes/utils/html-element"; interface HtmlElementHelperSignature { Args: { Positional: [selector: string]; - Return: HTMLElement; }; + Return: HTMLElement; } const htmlElementHelper = helper( diff --git a/web/app/helpers/lowercase.ts b/web/app/helpers/lowercase.ts index e5d819bdf..9c391af49 100644 --- a/web/app/helpers/lowercase.ts +++ b/web/app/helpers/lowercase.ts @@ -3,8 +3,8 @@ import { helper } from "@ember/component/helper"; export interface LowercaseHelperSignature { Args: { Positional: [value: string | number | boolean | undefined]; - Return: string; }; + Return: string; } const lowercaseHelper = helper(