Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Static Templates #567

Merged
merged 27 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
be2f71a
Added modules and struct for fetching static templates.
cmaddox5 Nov 13, 2024
d2f6932
Added endpoint for getting static templates.
cmaddox5 Nov 13, 2024
03cde30
Added client fetch for static templates.
cmaddox5 Nov 13, 2024
92ebd75
Added a page for static templates table.
cmaddox5 Nov 13, 2024
6c39d5a
Fix line breaks.
cmaddox5 Nov 13, 2024
7e15c69
Render static templates in a table.
cmaddox5 Nov 13, 2024
9d08cc8
Adjusted UI to allow selecting a template.
cmaddox5 Nov 14, 2024
ba8797d
Save message_type to DB.
cmaddox5 Nov 14, 2024
2f28e6d
Clear appropriate state when clearing selected template.
cmaddox5 Nov 15, 2024
eecb163
Use new column for template linking.
cmaddox5 Nov 15, 2024
dd8f4e1
Add IDs to templates.
cmaddox5 Nov 15, 2024
45b193a
Keep message_type as an Enum.
cmaddox5 Nov 15, 2024
f523976
Add template and alert to show response.
cmaddox5 Nov 15, 2024
06cad5d
Serialize alert if not nil.
cmaddox5 Nov 18, 2024
b9d6639
Simplified return.
cmaddox5 Nov 18, 2024
6540ddb
Remove unused endpoint.
cmaddox5 Nov 18, 2024
5c1346e
Move cache seeding logic.
cmaddox5 Nov 19, 2024
8b97c5d
Tests and credo.
cmaddox5 Nov 19, 2024
700d63e
Ignore sobelow false positive.
cmaddox5 Nov 19, 2024
c2ac797
Remove unused imports.
cmaddox5 Nov 19, 2024
cfbb109
Fix message type formatting.
cmaddox5 Nov 19, 2024
198c3fc
Added an archived field to static templates.
cmaddox5 Nov 19, 2024
fc2fda3
Added tests for static templates.
cmaddox5 Nov 19, 2024
2c4d2e3
Move static template file from server to client.
cmaddox5 Nov 19, 2024
87549ed
Revert some unnecessarily changed code.
cmaddox5 Nov 19, 2024
97ba765
Address feedback from QA.
cmaddox5 Nov 21, 2024
9807490
Address PR feedback.
cmaddox5 Nov 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 32 additions & 56 deletions assets/css/dashboard/new-pa-message/new-pa-message-page.scss
Original file line number Diff line number Diff line change
Expand Up @@ -258,31 +258,25 @@
}
}

.unassociated-alert-header {
margin-top: 40px;
font-size: 20px;
font-weight: 500;

button {
font-size: 20px;
margin-bottom: 14px;
}
}

.associated-alert-header {
.associated-alert-header,
.selected-template-header,
.alert-template-header {
margin: 40px 0px 0px 16px;
font-size: 20px;
font-weight: 500;
}

button {
.associated-alert-header,
.selected-template-header,
.alert-template-container {
.clear-button {
padding: 0;
color: $text-secondary;
margin-left: 16px;
margin-bottom: 6px;
width: auto;
padding: 0px;
height: 24px;
margin: auto 0 auto 16px;
}
}

.associated-alert-header {
.effect-period,
.alert-ended {
margin-top: 4px;
Expand All @@ -296,57 +290,39 @@
}
}

.associate-alert-button {
color: $text-link-primary;
font-family: Inter;
font-size: 20;
font-weight: 500;
height: 30px;
margin-bottom: 8px;
}
.alert-template-container {
display: flex;
align-items: center;
padding: 0;

.unassociated-alert-header {
margin-top: 40px;
font-size: 20px;
font-weight: 500;
.associate-alert-button {
padding-left: 0px;
}

button {
.associate-alert-button,
.psa-emergency-button {
height: 30px;
display: flex;
align-items: center;
margin: 0;
color: $text-link-primary;
font-size: 20px;
margin-bottom: 14px;
font-weight: 500;
text-decoration: none;
}
}

.associated-alert-header {
margin: 40px 0px 0px 16px;
.unassociated-alert-header {
margin-top: 40px;
font-size: 20px;
font-weight: 500;

button {
color: $text-secondary;
margin-left: 16px;
margin-bottom: 6px;
width: auto;
padding: 0px;
height: 24px;
}

.effect-period {
margin-top: 4px;
font-size: 14px;
font-weight: 400;
width: 100%;
font-size: 20px;
margin-bottom: 14px;
}
}

.associate-alert-button {
color: $text-link-primary;
font-family: Inter;
font-size: 20;
font-weight: 500;
height: 30px;
margin-bottom: 8px;
}

input[type="time"],
input[type="date"] {
position: relative;
Expand Down
88 changes: 88 additions & 0 deletions assets/css/dashboard/new-pa-message/static-template-page.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
.static-template-page {
padding: 24px 48px;

.header-container {
padding-right: 48px;
max-width: 1380px;
max-height: 48px;
margin-bottom: 40px;

.header,
.cancel-button-col,
.cancel-button {
height: 48px;
}

.cancel-button-col {
flex: none;
width: 100px;

.cancel-button {
color: $text-link-primary;
text-decoration: none;

&:hover {
color: $text-link-primary;
background-color: $cool-gray-15;
}
}
}
}

.static-template-page-body {
.filter-group-col {
max-width: 200px;
margin-right: 48px;
}

.static-template-table-container {
max-width: 1096px;

.table-header {
font-size: 32px;
}

.static-template-table {
width: 100%;

.header-row {
height: 55px;
vertical-align: bottom;
border-bottom: 1px solid $border-primary;

.message-column-header {
padding-bottom: 8px;
padding-left: 16px;
}
}

.template-row {
background-color: $cool-gray-15;
border-bottom: 1px solid $divider-secondary;

.title {
font-weight: 700;
}

.message-cell {
padding: 8px 16px;

.message {
white-space: pre-line;
}
}

.select-button-cell {
vertical-align: top;
padding: 16px 38px 0 16px;

.select-button {
padding: 0;
color: $text-secondary;
}
}
}
}
}
}
}
1 change: 1 addition & 0 deletions assets/css/screenplay.scss
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ $form-feedback-invalid-color: $text-error;
@import "dashboard/toast.scss";
@import "dashboard/kebab-menu.scss";
@import "dashboard/filter-group.scss";
@import "dashboard/new-pa-message/static-template-page.scss";

html {
font-size: 16px;
Expand Down
2 changes: 2 additions & 0 deletions assets/css/variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,5 @@ $text-button-blue-hover-color: #c1e4ff14;
$text-button-grey-hover-color: #f8f9fa14;
$alert-yellow: #ffdd00;
$accessibility-blue: #165c96;

$divider-secondary: #495057;
73 changes: 28 additions & 45 deletions assets/js/components/Dashboard/EditPaMessage/EditPaMessage.tsx
Original file line number Diff line number Diff line change
@@ -1,74 +1,55 @@
import React, { useEffect, useMemo, useState } from "react";
import React, { useEffect, useState } from "react";
import useSWR, { mutate } from "swr";
import { useNavigate, useParams } from "react-router-dom";
import { PaMessage } from "Models/pa_message";
import PaMessageForm from "../PaMessageForm";
import { updateExistingPaMessage } from "Utils/api";
import { Alert } from "Models/alert";
import { AudioPreview } from "Components/PaMessageForm/types";
import { StaticTemplate } from "Models/static_template";

const useAlert = (id: string | null | undefined) => {
const { data: alerts, isLoading } = useSWR<Array<Alert>>(
id ? "/api/alerts/non_access_alerts" : null,
async (url: string | null) => {
if (url == null) return [];
interface PaMessageResponse {
pa_message: PaMessage;
alert: Alert | null;
template: StaticTemplate | null;
}

const usePaMessage = (id: string | number) => {
const { data, isLoading, error } = useSWR<PaMessageResponse>(
`/api/pa-messages/${id}`,
async (url: string) => {
const response = await fetch(url);
const { alerts } = await response.json();
return alerts;
const body = await response.json();

if (400 <= response.status) throw response;
return body;
},
);

const alert = useMemo(() => {
if (id == null) return null;
return alerts?.find((a) => a.id === id);
}, [id, alerts]);

return {
alert,
isLoading,
};
};

const usePaMessage = (id: string | number) => {
const {
data: paMessage,
isLoading,
error,
} = useSWR<PaMessage>(`/api/pa-messages/${id}`, async (url: string) => {
const response = await fetch(url);
const body = await response.json();

if (400 <= response.status) throw response;
return body;
});

return {
paMessage,
data,
isLoading,
error,
};
};

const FetchPaMessage = ({ id }: { id: string | number }) => {
const navigate = useNavigate();
const { paMessage, isLoading, error } = usePaMessage(id);
const { data, isLoading, error } = usePaMessage(id);

useEffect(() => {
if (error?.status === 404) navigate("/pa-messages");
}, [error, navigate]);

if (isLoading || error || paMessage == null) return null;

return <FetchAlert paMessage={paMessage} />;
};

const FetchAlert = ({ paMessage }: { paMessage: PaMessage }) => {
const { alert, isLoading } = useAlert(paMessage.alert_id);

if (isLoading) return null;
if (isLoading || error || data?.pa_message == null) return null;

return <EditPaMessage paMessage={paMessage} alert={alert} />;
return (
<EditPaMessage
paMessage={data.pa_message}
alert={data.alert}
template={data.template}
/>
);
};

const EditPaMessageContainer = () => {
Expand All @@ -87,9 +68,10 @@ const EditPaMessageContainer = () => {
interface Props {
paMessage: PaMessage;
alert?: Alert | null;
template?: StaticTemplate | null;
}

const EditPaMessage = ({ paMessage, alert }: Props) => {
const EditPaMessage = ({ paMessage, alert, template }: Props) => {
const navigate = useNavigate();
const [errorMessage, setErrorMessage] = useState<string | null>(null);
const [errors, setErrors] = useState<string[]>([]);
Expand All @@ -104,6 +86,7 @@ const EditPaMessage = ({ paMessage, alert }: Props) => {
onErrorsChange={setErrors}
defaultValues={paMessage}
defaultAlert={alert ?? paMessage.alert_id}
defaultTemplate={template}
defaultAudioState={AudioPreview.Reviewed}
paused={paMessage.paused}
onSubmit={async (data) => {
Expand Down
3 changes: 3 additions & 0 deletions assets/js/components/Dashboard/MessageTextBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ interface Props {
required?: boolean;
validationText?: string;
validated?: boolean;
readonly?: boolean;
}

const MessageTextBox = ({
Expand All @@ -23,11 +24,13 @@ const MessageTextBox = ({
required,
validationText,
validated,
readonly,
}: Props) => {
return (
<Form.Group className="message-text-box">
<Form.Label htmlFor={id}>{label}</Form.Label>
<Form.Control
readOnly={readonly}
required={required}
id={id}
className="text-input"
Expand Down
Loading
Loading