From e6f30ed371bafaa32ae146e92bced35791cd8e4c Mon Sep 17 00:00:00 2001 From: Christian Maddox Date: Fri, 15 Nov 2024 09:12:57 -0500 Subject: [PATCH] refactor: Create common FilterGroup component (#560) * Refactored out filter group into a reusable component. * Address PR feedback. --- assets/css/dashboard/filter-group.scss | 23 +++++ .../new-pa-message/associate-alert-page.scss | 33 ++----- assets/css/dashboard/pa-messages-page.scss | 10 +-- assets/css/screenplay.scss | 1 + .../js/components/Dashboard/FilterGroup.tsx | 47 ++++++++++ .../PaMessageForm/AssociateAlert.tsx | 75 +++++----------- .../components/Dashboard/PaMessagesPage.tsx | 89 ++++++++----------- 7 files changed, 136 insertions(+), 142 deletions(-) create mode 100644 assets/css/dashboard/filter-group.scss create mode 100644 assets/js/components/Dashboard/FilterGroup.tsx diff --git a/assets/css/dashboard/filter-group.scss b/assets/css/dashboard/filter-group.scss new file mode 100644 index 000000000..e2fbd3699 --- /dev/null +++ b/assets/css/dashboard/filter-group.scss @@ -0,0 +1,23 @@ +.filter-group { + width: 200px; + + .header { + font-size: 16px; + margin-bottom: 8px; + line-height: 24px; + } + + .button-group { + .filter-button { + height: 38px; + min-width: 200px; + color: $text-secondary; + background-color: $cool-gray-20; + } + + .selected { + color: #ffffff; + background: #d9d9d93d; + } + } +} diff --git a/assets/css/dashboard/new-pa-message/associate-alert-page.scss b/assets/css/dashboard/new-pa-message/associate-alert-page.scss index 248be3bff..5a01a696a 100644 --- a/assets/css/dashboard/new-pa-message/associate-alert-page.scss +++ b/assets/css/dashboard/new-pa-message/associate-alert-page.scss @@ -11,6 +11,7 @@ .associate-alert-page-header { padding-right: 48px; max-width: 1380px; + height: 48px; &__cancel { flex: none; @@ -33,40 +34,16 @@ .associate-alert-page-body { flex-wrap: nowrap; padding-right: 48px; + margin-top: 40px; } .associate-alert-filter-selection { - flex: none; - font-size: 20px; - width: 200px; - padding: 0px 12px; - margin-top: 40px; - - &__label { - margin-bottom: 8px; - } - - &__button-group { - margin-bottom: 48px; - } - - &__selected { - color: #ffffff !important; - background: #d9d9d93d !important; - } - - button { - text-align: left; - height: 38px; - min-width: 200px; - color: $text-secondary; - background-color: $cool-gray-20; - border: none; - } + max-width: 200px; + padding: 0; } .associate-alert-table { - margin: 40px; + margin: 0 40px; max-width: 1096px; th, diff --git a/assets/css/dashboard/pa-messages-page.scss b/assets/css/dashboard/pa-messages-page.scss index 982f1a605..005089694 100644 --- a/assets/css/dashboard/pa-messages-page.scss +++ b/assets/css/dashboard/pa-messages-page.scss @@ -16,7 +16,6 @@ padding-right: 0px; display: flex; flex-direction: column; - gap: 48px; .add-new-button, .system-log-link { @@ -44,7 +43,7 @@ .system-log-link { text-decoration: none; - margin-top: 8px; + margin-top: 16px; color: $text-secondary; .link-text { text-decoration: underline; @@ -56,12 +55,7 @@ section { display: flex; flex-direction: column; - gap: 8px; - - header { - font-size: 16px; - line-height: 24px; - } + margin-bottom: 48px; } } diff --git a/assets/css/screenplay.scss b/assets/css/screenplay.scss index ad97c06a6..7082771ce 100644 --- a/assets/css/screenplay.scss +++ b/assets/css/screenplay.scss @@ -45,6 +45,7 @@ $form-feedback-invalid-color: $text-error; @import "dashboard/picker.scss"; @import "dashboard/toast.scss"; @import "dashboard/kebab-menu.scss"; +@import "dashboard/filter-group.scss"; html { font-size: 16px; diff --git a/assets/js/components/Dashboard/FilterGroup.tsx b/assets/js/components/Dashboard/FilterGroup.tsx new file mode 100644 index 000000000..ed352ad61 --- /dev/null +++ b/assets/js/components/Dashboard/FilterGroup.tsx @@ -0,0 +1,47 @@ +import React from "react"; +import { Button, ButtonGroup } from "react-bootstrap"; +import classNames from "classnames"; + +type Filter = { + label: string; + value: any; +}; + +interface Props { + header: string; + filters: Filter[]; + selectedFilter: string; + onFilterSelect: (value: string) => void; + className?: string; +} + +const FilterGroup = ({ + header, + filters, + selectedFilter, + onFilterSelect, + className, +}: Props) => { + return ( +
+
{header}
+ + {filters.map((filter) => { + return ( + + ); + })} + +
+ ); +}; + +export default FilterGroup; diff --git a/assets/js/components/Dashboard/PaMessageForm/AssociateAlert.tsx b/assets/js/components/Dashboard/PaMessageForm/AssociateAlert.tsx index 11e7444ae..8536c08f8 100644 --- a/assets/js/components/Dashboard/PaMessageForm/AssociateAlert.tsx +++ b/assets/js/components/Dashboard/PaMessageForm/AssociateAlert.tsx @@ -1,18 +1,10 @@ import React, { useState, useEffect } from "react"; -import { - Button, - Container, - Row, - Col, - ButtonGroup, - Modal, - Form, -} from "react-bootstrap"; +import { Button, Container, Row, Col, Modal, Form } from "react-bootstrap"; +import moment from "moment"; +import FilterGroup from "Components/FilterGroup"; import { fetchActiveAndFutureAlerts } from "Utils/api"; import { Alert } from "Models/alert"; -import classNames from "classnames"; import { getAlertEarliestStartLatestEnd } from "../../../util"; -import moment from "moment"; interface AssociateAlertPageProps { onApply: ( @@ -67,51 +59,24 @@ const AssociateAlert = ({ onApply, onCancel }: AssociateAlertPageProps) => { -
- Message state -
- - - - -
- Service type -
- - {serviceTypes.map((serviceType) => { - return ( - - ); + + { + return { label: serviceType, value: serviceType }; })} - + /> { -
-
Filter by message state
- - - - - -
-
-
Filter by service type
- - - {SERVICE_TYPES.map((serviceType) => ( - - ))} - -
+ + setStateFilter(selected as StateFilter) + } + selectedFilter={stateFilter.toLowerCase()} + filters={[ + { label: "Now", value: "current" }, + { label: "Future", value: "future" }, + { label: "Done", value: "past" }, + ]} + /> + { + const serviceType = selected as ServiceType; + if (serviceType === "All") { + setServiceTypes([]); + } else { + setServiceTypes([serviceType]); + } + }} + selectedFilter={ + serviceTypes.length === 0 ? "All" : serviceTypes[0] + } + filters={[ + { label: "All", value: "All" }, + ...SERVICE_TYPES.map((serviceType) => { + return { + label: getServiceLabel(serviceType), + value: serviceType, + }; + }), + ]} + />