From 11798ceddac8f6d6170ed56dc1f289997ba32d72 Mon Sep 17 00:00:00 2001 From: Remko Date: Wed, 6 Mar 2024 11:12:32 +0100 Subject: [PATCH 1/2] added default values to filters --- .../workflows/opencatalogi-page-deploy.yml | 63 +++++++--- pwa/src/context/filters.ts | 108 +++++++++++++++++- pwa/src/hooks/useEnvironment.ts | 6 +- .../VerticalFiltersTemplate.tsx | 22 ++-- pwa/static/.env.development | 3 +- pwa/static/.env.production | 3 +- 6 files changed, 171 insertions(+), 34 deletions(-) diff --git a/.github/workflows/opencatalogi-page-deploy.yml b/.github/workflows/opencatalogi-page-deploy.yml index e9507963..a45ad567 100644 --- a/.github/workflows/opencatalogi-page-deploy.yml +++ b/.github/workflows/opencatalogi-page-deploy.yml @@ -1,4 +1,4 @@ -name: Deploy the Product Page to GitHub Pages +name: Deploy dev.opencatalogi.nl to GitHub Pages env: # Change these to your preferences any image url can also be a base encoded image GITHUB_PAGES_BRANCH: gh-pages @@ -17,7 +17,7 @@ env: # Change these to your preferences any image url can also be a base encoded LOGIN_REDIRECT: "vault" ADMIN_DASHBOARD_URL: "https://admin.opencatalogi.nl" - NL_DESIGN_THEME_CLASSNAME: rotterdam-theme + NL_DESIGN_THEME_CLASSNAME: opencatalogi-theme # GITHUB_ORGANIZATION_URL: "" FAVICON_URL: "https://dev.opencatalogi.nl/static/logo_OpenCatalogi-8b1b0a001c3f37dae4d3f69b5964ec72.png" PAGE_TITLE: "DevOpenCatalogi" @@ -42,9 +42,27 @@ env: # Change these to your preferences any image url can also be a base encoded FOOTER_SHOW_CREATOR: "true" FOOTER_LOGO_URL: "https://dev.opencatalogi.nl/static/logo_OpenCatalogi-8b1b0a001c3f37dae4d3f69b5964ec72.png" FOOTER_CONTENT: "https://raw.githubusercontent.com/OpenCatalogi/web-app/25995205e1dbb043822d1c58c5c23f8e6f77ff7e/pwa/src/templates/templateParts/footer/FooterContent.json" - # options: "heading-1" | "heading-2" | "heading-3" | "heading-4" | "heading-5" - # FOOTER_CONTENT_HEADER: "" - + # options: "heading-1" | "heading-2" | "heading-3" | "heading-4" | "heading-5" + # FOOTER_CONTENT_HEADER: "" + + FILTER_FORKS: "true" + # options: "false" | "OpenCatalogi" | "Commonground", default = "OpenCatalogi" + FILTER_RATING: "OpenCatalogi" + # options: "OpenCatalogi: (0-24)" | "Commonground": (0-4), default: "16" + FILTER_RATING_DEFAULT: "16" + # FILTER_LAYER: " " + # FILTER_UPL: " " + # FILTER_ORGANISATION: " " + # FILTER_CATEGORY: " " + # FILTER_PLATFORMS: " " + FILTER_STATUS: "stable" + # FILTER_MAINTENANCE_TYPES: " " + # FILTER_LICENSE: " " + # FILTER_BUSINESS_FUNCTIONS: " " + # FILTER_SOFTWARE_TYPE: " " + # FILTER_BUSINESS_SERVICES: " " + # FILTER_REFERENCE_COMPONENTS: " " + OPTIONAL_START_PAGE: "false" on: @@ -81,22 +99,37 @@ jobs: envkey_GATSBY_NL_DESIGN_THEME_CLASSNAME: ${{ env.NL_DESIGN_THEME_CLASSNAME }} # envkey_GATSBY_GITHUB_ORGANIZATION_URL: ${{ env.GITHUB_ORGANIZATION_URL }} envkey_GATSBY_FAVICON_URL: ${{ env.FAVICON_URL }} - envkey_GATSBY_PAGE_TITLE : ${{ env.PAGE_TITLE }} + envkey_GATSBY_PAGE_TITLE: ${{ env.PAGE_TITLE }} envkey_GATSBY_HEADER_LOGO_URL: ${{ env.HEADER_LOGO_URL }} - envkey_GATSBY_HEADER_SHOW_LOGIN : ${{ env.HEADER_SHOW_LOGIN }} - envkey_GATSBY_HEADER_CONTENT : ${{ env.HEADER_CONTENT }} + envkey_GATSBY_HEADER_SHOW_LOGIN: ${{ env.HEADER_SHOW_LOGIN }} + envkey_GATSBY_HEADER_CONTENT: ${{ env.HEADER_CONTENT }} # envkey_GATSBY_JUMBOTRON_TITLE: ${{ env.JUMBOTRON_TITLE }} # envkey_GATSBY_JUMBOTRON_SUBTITLE: ${{ env.JUMBOTRON_SUBTITLE }} - envkey_GATSBY_JUMBOTRON_IMAGE_PLACEMENT : ${{ env.JUMBOTRON_IMAGE_PLACEMENT }} + envkey_GATSBY_JUMBOTRON_IMAGE_PLACEMENT: ${{ env.JUMBOTRON_IMAGE_PLACEMENT }} # envkey_GATSBY_JUMBOTRON_IMAGE_URL : ${{ env.JUMBOTRON_IMAGE_URL }} # envkey_GATSBY_JUMBOTRON_DESCRIPTION : ${{ env.JUMBOTRON_DESCRIPTION }} - envkey_GATSBY_JUMBOTRON_ISCARD : ${{ env.JUMBOTRON_ISCARD }} - envkey_GATSBY_JUMBOTRON_SEARCHFORM : ${{ env.JUMBOTRON_SEARCHFORM }} - envkey_GATSBY_JUMBOTRON_CONTAINER : ${{ env.JUMBOTRON_CONTAINER }} - envkey_GATSBY_FOOTER_SHOW_CREATOR : ${{ env.FOOTER_SHOW_CREATOR }} - envkey_GATSBY_FOOTER_LOGO_URL : ${{ env.FOOTER_LOGO_URL }} - envkey_GATSBY_FOOTER_CONTENT : ${{ env.FOOTER_CONTENT }} + envkey_GATSBY_JUMBOTRON_ISCARD: ${{ env.JUMBOTRON_ISCARD }} + envkey_GATSBY_JUMBOTRON_SEARCHFORM: ${{ env.JUMBOTRON_SEARCHFORM }} + envkey_GATSBY_JUMBOTRON_CONTAINER: ${{ env.JUMBOTRON_CONTAINER }} + envkey_GATSBY_FOOTER_SHOW_CREATOR: ${{ env.FOOTER_SHOW_CREATOR }} + envkey_GATSBY_FOOTER_LOGO_URL: ${{ env.FOOTER_LOGO_URL }} + envkey_GATSBY_FOOTER_CONTENT: ${{ env.FOOTER_CONTENT }} # envkey_GATSBY_FOOTER_CONTENT_HEADER : ${{ env.FOOTER_CONTENT_HEADER }} + envkey_GATSBY_FILTER_FORKS: ${{ env.FILTER_FORKS }} + envkey_GATSBY_FILTER_RATING: ${{ env.FILTER_RATING }} + envkey_GATSBY_FILTER_RATING_DEFAULT: ${{ env.FILTER_RATING_DEFAULT }} + # envkey_GATSBY_FILTER_LAYER: ${{ env.FILTER_LAYER }} + # envkey_GATSBY_FILTER_UPL: ${{ env.FILTER_UPL }} + # envkey_GATSBY_FILTER_ORGANISATION: ${{ env.FILTER_ORGANISATION }} + # envkey_GATSBY_FILTER_CATEGORY: ${{ env.FILTER_CATEGORY }} + # envkey_GATSBY_FILTER_PLATFORMS: ${{ env.FILTER_PLATFORMS }} + envkey_GATSBY_FILTER_STATUS: ${{ env.FILTER_STATUS }} + # envkey_GATSBY_FILTER_MAINTENANCE_TYPES: ${{ env.FILTER_MAINTENANCE_TYPES }} + # envkey_GATSBY_FILTER_LICENSE: ${{ env.FILTER_LICENSE }} + # envkey_GATSBY_FILTER_BUSINESS_FUNCTIONS: ${{ env.FILTER_BUSINESS_FUNCTIONS }} + # envkey_GATSBY_FILTER_SOFTWARE_TYPE: ${{ env.FILTER_SOFTWARE_TYPE }} + # envkey_GATSBY_FILTER_BUSINESS_SERVICES: ${{ env.FILTER_BUSINESS_SERVICES }} + # envkey_GATSBY_FILTER_REFERENCE_COMPONENTS: ${{ env.FILTER_REFERENCE_COMPONENTS }} envkey_GATSBY_OPTIONAL_START_PAGE: ${{ env.OPTIONAL_START_PAGE }} directory: pwa/static file_name: .env.production diff --git a/pwa/src/context/filters.ts b/pwa/src/context/filters.ts index cb6634cd..b5aab8ea 100644 --- a/pwa/src/context/filters.ts +++ b/pwa/src/context/filters.ts @@ -5,10 +5,10 @@ export interface IFiltersContext { isForked: boolean; orderRating: boolean; rating: number; - organizationSearch?: string; ratingCommonground: number; _search?: string; + organizationSearch?: string; softwareType?: string; developmentStatus?: string; platforms?: string[]; @@ -28,14 +28,110 @@ export interface IFiltersContext { showMoreSupport?: boolean; } +const isWindow = typeof window !== "undefined"; + +export const ratingDefault = + isWindow && !isNaN(parseInt(window.sessionStorage.getItem("FILTER_RATING_DEFAULT") ?? "")) + ? parseInt(window.sessionStorage.getItem("FILTER_RATING_DEFAULT") ?? "") + : 0; + export const defaultFiltersContext: IFiltersContext = { + isForked: + isWindow && window.sessionStorage.getItem("FILTER_FORKS") + ? window.sessionStorage.getItem("FILTER_FORKS") === "true" + ? true + : false + : false, + + orderRating: + isWindow && window.sessionStorage.getItem("FILTER_RATING") + ? window.sessionStorage.getItem("FILTER_RATING") !== "false" + ? true + : false + : false, + rating: + isWindow && window.sessionStorage.getItem("FILTER_RATING") + ? window.sessionStorage.getItem("FILTER_RATING") !== "false" + ? ratingDefault + : 0 + : 0, + ratingCommonground: + isWindow && window.sessionStorage.getItem("FILTER_RATING") + ? window.sessionStorage.getItem("FILTER_RATING") !== "false" + ? ratingDefault + : 0 + : 0, + _search: "", organizationSearch: "", - isForked: true, - orderRating: true, - developmentStatus: "stable", - rating: 16, - ratingCommonground: 1, + softwareType: + isWindow && window.sessionStorage.getItem("FILTER_SOFTWARE_TYPE") + ? window.sessionStorage.getItem("FILTER_SOFTWARE_TYPE") !== "false" + ? window.sessionStorage.getItem("FILTER_SOFTWARE_TYPE") ?? "" + : "" + : "", + + developmentStatus: + isWindow && window.sessionStorage.getItem("FILTER_STATUS") + ? window.sessionStorage.getItem("FILTER_STATUS") !== "false" + ? window.sessionStorage.getItem("FILTER_STATUS") ?? "" + : "" + : "", + platforms: + isWindow && window.sessionStorage.getItem("FILTER_PLATFORMS") + ? window.sessionStorage.getItem("FILTER_PLATFORMS") !== "false" + ? [...JSON.parse(window.sessionStorage.getItem("FILTER_PLATFORMS") ?? "")] + : [] + : [], + category: + isWindow && window.sessionStorage.getItem("FILTER_CATEGORY") + ? window.sessionStorage.getItem("FILTER_CATEGORY") !== "false" + ? window.sessionStorage.getItem("FILTER_CATEGORY") ?? "" + : "" + : "", + "embedded.nl.embedded.commonground.layerType": + isWindow && window.sessionStorage.getItem("FILTER_LAYER") + ? window.sessionStorage.getItem("FILTER_LAYER") !== "false" + ? [...JSON.parse(window.sessionStorage.getItem("FILTER_LAYER") ?? "")] + : [] + : [], + "embedded.nl.embedded.gemma.bedrijfsfuncties": + isWindow && window.sessionStorage.getItem("FILTER_BUSINESS_FUNCTIONS") + ? window.sessionStorage.getItem("FILTER_BUSINESS_FUNCTIONS") !== "false" + ? [...JSON.parse(window.sessionStorage.getItem("FILTER_BUSINESS_FUNCTIONS") ?? "")] + : [] + : [], + "embedded.nl.embedded.gemma.bedrijfsservices": + isWindow && window.sessionStorage.getItem("FILTER_BUSINESS_SERVICES") + ? window.sessionStorage.getItem("FILTER_BUSINESS_SERVICES") !== "false" + ? [...JSON.parse(window.sessionStorage.getItem("FILTER_BUSINESS_SERVICES") ?? "")] + : [] + : [], + "embedded.nl.embedded.gemma.referentieComponenten": + isWindow && window.sessionStorage.getItem("FILTER_REFERENCE_COMPONENTS") + ? window.sessionStorage.getItem("FILTER_REFERENCE_COMPONENTS") !== "false" + ? [...JSON.parse(window.sessionStorage.getItem("FILTER_REFERENCE_COMPONENTS") ?? "")] + : [] + : [], + "embedded.nl.embedded.gemma.applicatiefunctie": "", + "embedded.nl.embedded.upl": + isWindow && window.sessionStorage.getItem("FILTER_UPL") + ? window.sessionStorage.getItem("FILTER_UPL") !== "false" + ? [...JSON.parse(window.sessionStorage.getItem("FILTER_UPL") ?? "")] + : [] + : [], + "embedded.maintenance.type": + isWindow && window.sessionStorage.getItem("FILTER_MAINTENANCE_TYPES") + ? window.sessionStorage.getItem("FILTER_MAINTENANCE_TYPES") !== "false" + ? window.sessionStorage.getItem("FILTER_MAINTENANCE_TYPES") ?? "" + : "" + : "", + "embedded.legal.license": + isWindow && window.sessionStorage.getItem("FILTER_LICENSE") + ? window.sessionStorage.getItem("FILTER_LICENSE") !== "false" + ? window.sessionStorage.getItem("FILTER_LICENSE") ?? "" + : "" + : "", }; export const useFiltersContext = () => { diff --git a/pwa/src/hooks/useEnvironment.ts b/pwa/src/hooks/useEnvironment.ts index 858c9467..0484d3c5 100644 --- a/pwa/src/hooks/useEnvironment.ts +++ b/pwa/src/hooks/useEnvironment.ts @@ -54,6 +54,7 @@ export const useEnvironment = () => { window.sessionStorage.setItem("FILTER_FORKS", process.env.GATSBY_FILTER_FORKS ?? ""); window.sessionStorage.setItem("FILTER_RATING", process.env.GATSBY_FILTER_RATING ?? "OpenCatalogi"); + window.sessionStorage.setItem("FILTER_RATING_DEFAULT", process.env.FILTER_RATING_DEFAULT ?? "16"); window.sessionStorage.setItem("FILTER_LAYER", process.env.GATSBY_FILTER_LAYER ?? ""); window.sessionStorage.setItem("FILTER_UPL", process.env.GATSBY_FILTER_UPL ?? ""); window.sessionStorage.setItem("FILTER_ORGANISATION", process.env.GATSBY_FILTER_ORGANISATION ?? ""); @@ -63,7 +64,7 @@ export const useEnvironment = () => { window.sessionStorage.setItem("FILTER_MAINTENANCE_TYPES", process.env.GATSBY_FILTER_MAINTENANCE_TYPES ?? ""); window.sessionStorage.setItem("FILTER_LICENSE", process.env.GATSBY_FILTER_LICENSE ?? ""); window.sessionStorage.setItem("FILTER_BUSINESS_FUNCTIONS", process.env.GATSBY_FILTER_BUSINESS_FUNCTIONS ?? ""); - window.sessionStorage.setItem("FILTER_SOFTWARE_TYPES", process.env.GATSBY_FILTER_SOFTWARE_TYPES ?? ""); + window.sessionStorage.setItem("FILTER_SOFTWARE_TYPE", process.env.GATSBY_FILTER_SOFTWARE_TYPE ?? ""); window.sessionStorage.setItem("FILTER_BUSINESS_SERVICES", process.env.GATSBY_FILTER_BUSINESS_SERVICES ?? ""); window.sessionStorage.setItem("FILTER_REFERENCE_COMPONENTS", process.env.GATSBY_FILTER_REFERENCE_COMPONENTS ?? ""); @@ -106,6 +107,7 @@ export const useEnvironment = () => { window.sessionStorage.setItem("FILTER_FORKS", config.GATSBY_FILTER_FORKS ?? ""); window.sessionStorage.setItem("FILTER_RATING", config.GATSBY_FILTER_RATING ?? "OpenCatalogi"); + window.sessionStorage.setItem("FILTER_RATING_DEFAULT", config.FILTER_RATING_DEFAULT ?? "16"); window.sessionStorage.setItem("FILTER_LAYER", config.GATSBY_FILTER_LAYER ?? ""); window.sessionStorage.setItem("FILTER_UPL", config.GATSBY_FILTER_UPL ?? ""); window.sessionStorage.setItem("FILTER_ORGANISATION", config.GATSBY_FILTER_ORGANISATION ?? ""); @@ -115,7 +117,7 @@ export const useEnvironment = () => { window.sessionStorage.setItem("FILTER_MAINTENANCE_TYPES", config.GATSBY_FILTER_MAINTENANCE_TYPES ?? ""); window.sessionStorage.setItem("FILTER_LICENSE", config.GATSBY_FILTER_LICENSE ?? ""); window.sessionStorage.setItem("FILTER_BUSINESS_FUNCTIONS", config.GATSBY_FILTER_BUSINESS_FUNCTIONS ?? ""); - window.sessionStorage.setItem("FILTER_SOFTWARE_TYPES", config.GATSBY_FILTER_SOFTWARE_TYPES ?? ""); + window.sessionStorage.setItem("FILTER_SOFTWARE_TYPE", config.GATSBY_FILTER_SOFTWARE_TYPE ?? ""); window.sessionStorage.setItem("FILTER_BUSINESS_SERVICES", config.GATSBY_FILTER_BUSINESS_SERVICES ?? ""); window.sessionStorage.setItem("FILTER_REFERENCE_COMPONENTS", config.GATSBY_FILTER_REFERENCE_COMPONENTS ?? ""); updateSessionStorage(); diff --git a/pwa/src/templates/templateParts/filters/verticalFilters/VerticalFiltersTemplate.tsx b/pwa/src/templates/templateParts/filters/verticalFilters/VerticalFiltersTemplate.tsx index d96ca9c3..82dd6f82 100644 --- a/pwa/src/templates/templateParts/filters/verticalFilters/VerticalFiltersTemplate.tsx +++ b/pwa/src/templates/templateParts/filters/verticalFilters/VerticalFiltersTemplate.tsx @@ -4,7 +4,7 @@ import clsx from "clsx"; import qs from "qs"; import _ from "lodash"; import { useForm } from "react-hook-form"; -import { IFiltersContext, defaultFiltersContext, useFiltersContext } from "../../../../context/filters"; +import { IFiltersContext, defaultFiltersContext, ratingDefault, useFiltersContext } from "../../../../context/filters"; import { InputCheckbox, SelectMultiple, SelectSingle } from "@conduction/components"; import { upls, @@ -54,10 +54,12 @@ export const VerticalFiltersTemplate: React.FC = ( const [statusRadioFilter, setStatusRadioFilter] = React.useState(""); const [maintenanceTypeRadioFilter, setMaintenanceTypeRadioFilter] = React.useState(""); - const [softwareTypeRadioFilter, setSoftwareTypeRadioFilter] = React.useState(""); + const [softwareTypeRadioFilter, setSoftwareTypeRadioFilter] = React.useState( + window.sessionStorage.getItem("FILTER_SOFTWARE_TYPE") ?? "", + ); - const [ratingFilter, setRatingFilter] = React.useState(16); - const [ratingFilterCommonground, setRatingFilterCommonground] = React.useState(1); + const [ratingFilter, setRatingFilter] = React.useState(ratingDefault); + const [ratingFilterCommonground, setRatingFilterCommonground] = React.useState(ratingDefault); const [isOpen, setIsOpen] = React.useState(false); @@ -342,11 +344,12 @@ export const VerticalFiltersTemplate: React.FC = ( isForked: window.sessionStorage.getItem("FILTER_FORKS") !== "false" && params.isForked ? params.isForked : false, orderRating: window.sessionStorage.getItem("FILTER_RATING") !== "false" && params.orderRating ? params.orderRating : false, - rating: window.sessionStorage.getItem("FILTER_RATING") !== "false" && params.rating ? params.rating : 16, + rating: + window.sessionStorage.getItem("FILTER_RATING") !== "false" && params.rating ? params.rating : ratingDefault, ratingCommonground: window.sessionStorage.getItem("FILTER_RATING") !== "false" && params.ratingCommonground ? params.ratingCommonground - : 1, + : ratingDefault, "embedded.nl.embedded.commonground.layerType": window.sessionStorage.getItem("FILTER_LAYER") !== "false" && params["embedded.nl.embedded.commonground.layerType"] @@ -382,7 +385,7 @@ export const VerticalFiltersTemplate: React.FC = ( ? [...params["embedded.nl.embedded.gemma.bedrijfsfuncties"]] : [], softwareType: - window.sessionStorage.getItem("FILTER_SOFTWARE_TYPES") !== "false" && params.softwareType + window.sessionStorage.getItem("FILTER_BUSINESS_FUNCTIONS") !== "false" && params.softwareType ? params.softwareType : "", "embedded.nl.embedded.gemma.bedrijfsservices": @@ -835,7 +838,7 @@ export const VerticalFiltersTemplate: React.FC = ( )} - {window.sessionStorage.getItem("FILTER_SOFTWARE_TYPES") !== "false" && ( + {window.sessionStorage.getItem("FILTER_SOFTWARE_TYPE") !== "false" && ( = ( trigger={
- Softwaretypes ({softwareTypes.length}) + {filters.softwareType} Softwaretypes{" "} + ({softwareTypes.length}) Date: Wed, 6 Mar 2024 11:18:34 +0100 Subject: [PATCH 2/2] cleanup --- .github/workflows/opencatalogi-page-deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/opencatalogi-page-deploy.yml b/.github/workflows/opencatalogi-page-deploy.yml index a45ad567..52b575ec 100644 --- a/.github/workflows/opencatalogi-page-deploy.yml +++ b/.github/workflows/opencatalogi-page-deploy.yml @@ -48,7 +48,7 @@ env: # Change these to your preferences any image url can also be a base encoded FILTER_FORKS: "true" # options: "false" | "OpenCatalogi" | "Commonground", default = "OpenCatalogi" FILTER_RATING: "OpenCatalogi" - # options: "OpenCatalogi: (0-24)" | "Commonground": (0-4), default: "16" + # options: "OpenCatalogi: (0-24)" | "Commonground": (0-4), default: "0" FILTER_RATING_DEFAULT: "16" # FILTER_LAYER: " " # FILTER_UPL: " "