Skip to content

Commit

Permalink
feat(map): add layer on incident creation
Browse files Browse the repository at this point in the history
  • Loading branch information
nimdanitro committed Feb 9, 2024
1 parent a8d2212 commit 614c5ac
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 24 deletions.
3 changes: 3 additions & 0 deletions ui/src/types/incident.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Division, Journal } from "./journal";
import { Layer } from "./layer";

export interface Location {
name: string;
Expand All @@ -16,6 +17,7 @@ export type Incident = {
location: Location;
divisions: Division[];
journals: Journal[];
layers: Layer[];
};

export interface IncidentListData {
Expand All @@ -39,6 +41,7 @@ export interface InsertIncidentVars {
location: string;
divisions: DivisionInput[];
journalName: string;
layerName: string;
}

export interface DivisionInput {
Expand Down
23 changes: 23 additions & 0 deletions ui/src/types/layer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { GeoJsonProperties, Geometry } from "geojson";
import { Incident } from "./incident";

export type Layer = {
id: string;
name: string;
incident: Incident;
features: Features[];
createdAt: Date;
updatedAt: Date;
deletedAt: Date;
};

export type Features = {
id: string;
name: string;
layer: Layer;
geometry: Geometry;
properties: GeoJsonProperties;
createdAt: Date;
updatedAt: Date;
deletedAt: Date;
};
46 changes: 22 additions & 24 deletions ui/src/views/incident/New.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
InsertIncidentData,
InsertIncidentVars,
UpdateIncidentData,
UpdateIncidentVars
UpdateIncidentVars,
} from "types/incident";
import { GetMessageForTriage } from "views/journal/graphql";
import { GetIncidentDetails, GetIncidents, InsertIncident, UpdateIncident } from "./graphql";
Expand All @@ -26,7 +26,7 @@ function New() {

return (
<>
<h3 className="title is-size-3 is-capitalized">{t('createIncident')}</h3>
<h3 className="title is-size-3 is-capitalized">{t("createIncident")}</h3>
<div className="box">
<IncidentForm incident={undefined} />
</div>
Expand All @@ -43,7 +43,7 @@ function IncidentForm(props: { incident: Incident | undefined }) {
{ id: "", name: "Karte", description: "Nachrichtenkarte" },
{ id: "", name: "Lage", description: "C Lage" },
{ id: "", name: "SC", description: "Stabchef" },
]
],
);
const [name, setName] = useState(incident?.name || "");
const [location, setLocation] = useState(incident?.location.name || "");
Expand All @@ -59,15 +59,12 @@ function IncidentForm(props: { incident: Incident | undefined }) {
refetchQueries: [{ query: GetIncidents }, { query: GetIncidentDetails }, { query: GetMessageForTriage }],
});

const [updateIncident, { error: errorUpdate }] = useMutation<UpdateIncidentData, UpdateIncidentVars>(
UpdateIncident,
{
onCompleted() {
navigate(`../journal/view`);
},
refetchQueries: [{ query: GetIncidents }, { query: GetIncidentDetails }],
}
);
const [updateIncident, { error: errorUpdate }] = useMutation<UpdateIncidentData, UpdateIncidentVars>(UpdateIncident, {
onCompleted() {
navigate(`../journal/view`);
},
refetchQueries: [{ query: GetIncidents }, { query: GetIncidentDetails }],
});

const handleSave = () => {
if (incident) {
Expand All @@ -89,6 +86,7 @@ function IncidentForm(props: { incident: Incident | undefined }) {
name: name,
location: location,
journalName: "Phase 1",
layerName: "Nachrichtenkarte",
divisions: assignments.map((d) => {
return { name: d.name, description: d.description };
}),
Expand All @@ -102,7 +100,7 @@ function IncidentForm(props: { incident: Incident | undefined }) {
{errorUpdate ? <div className="notification is-danger">{errorUpdate?.message}</div> : <></>}
<div className="field is-horizontal">
<div className="field-label is-normal">
<label className="label is-capitalized">{t('name')}</label>
<label className="label is-capitalized">{t("name")}</label>
</div>
<div className="field-body">
<div className="field is-grouped is-normal">
Expand All @@ -112,7 +110,7 @@ function IncidentForm(props: { incident: Incident | undefined }) {
type="text"
value={name}
onChange={(e) => setName(e.target.value)}
placeholder={t('name') as string}
placeholder={t("name") as string}
/>
<span className="icon is-small is-left">
<FontAwesomeIcon icon={faClipboard} />
Expand All @@ -123,7 +121,7 @@ function IncidentForm(props: { incident: Incident | undefined }) {
</div>
<div className="field is-horizontal">
<div className="field-label is-normal">
<label className="label is-capitalized">{t('location')}</label>
<label className="label is-capitalized">{t("location")}</label>
</div>
<div className="field-body">
<div className="field is-grouped is-normal">
Expand All @@ -133,7 +131,7 @@ function IncidentForm(props: { incident: Incident | undefined }) {
type="text"
value={location}
onChange={(e) => setLocation(e.target.value)}
placeholder={t('location') as string}
placeholder={t("location") as string}
/>
<span className="icon is-small is-left">
<FontAwesomeIcon icon={faLocationDot} />
Expand All @@ -144,7 +142,7 @@ function IncidentForm(props: { incident: Incident | undefined }) {
</div>
<div className="field is-horizontal">
<div className="field-label is-normal">
<label className="label is-capitalized">{t('divisions')}</label>
<label className="label is-capitalized">{t("divisions")}</label>
</div>
<div className="field-body">
<div className="field is-grouped is-grouped-multiline is-normal">
Expand Down Expand Up @@ -177,7 +175,7 @@ function IncidentForm(props: { incident: Incident | undefined }) {

<div className="field is-horizontal">
<div className="field-label is-small">
<label className="label">{t('devisionAdd')}</label>
<label className="label">{t("devisionAdd")}</label>
</div>
<div className="field-body">
<div className="field is-grouped is-grouped-multiline">
Expand All @@ -187,7 +185,7 @@ function IncidentForm(props: { incident: Incident | undefined }) {
type="text"
value={assignmentDescription}
onChange={(e) => setAssignmentDescription(e.target.value)}
placeholder={t('name') as string}
placeholder={t("name") as string}
/>
</p>
<p className="control">
Expand All @@ -196,7 +194,7 @@ function IncidentForm(props: { incident: Incident | undefined }) {
value={assignmentName}
type="text"
onChange={(e) => setAssignmentName(e.target.value)}
placeholder={t('short') as string}
placeholder={t("short") as string}
/>
</p>
<p className="control">
Expand All @@ -209,14 +207,14 @@ function IncidentForm(props: { incident: Incident | undefined }) {
unionBy(
assignments,
[{ id: "", name: assignmentName, description: assignmentDescription }],
iteratee("name")
)
iteratee("name"),
),
);
setAssignmentName("");
setAssignmentDescription("");
}}
>
{t('add')}
{t("add")}
</button>
</p>
</div>
Expand All @@ -225,7 +223,7 @@ function IncidentForm(props: { incident: Incident | undefined }) {
<div className="field">
<p className="control">
<button className="button is-primary is-rounded is-capitalized" onClick={handleSave}>
{t('save')}
{t("save")}
</button>
</p>
</div>
Expand Down
6 changes: 6 additions & 0 deletions ui/src/views/incident/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,14 @@ const INSERT_INCIDENT = gql`
$location: String
$divisions: [DivisionsInsertInput!]!
$journalName: String
$layerName: String
) {
insertIncidentsOne(
object: {
name: $name
location: { data: { name: $location } }
journals: { data: { name: $journalName } }
layers: { data: { name: $layerName } }
divisions: { data: $divisions }
}
) {
Expand All @@ -67,6 +69,10 @@ const INSERT_INCIDENT = gql`
id
description
}
layers {
name
id
}
}
}
`;
Expand Down

0 comments on commit 614c5ac

Please sign in to comment.