Skip to content

Commit

Permalink
chore: Cleanup Admin columns and default values (#2236)
Browse files Browse the repository at this point in the history
* Fixed columns for each app.

* Fixed default values for add screen modal.

* Handle error instead of ignoring it.

* Handle default object access better.

* Fix defaults so they use the header config the app supports.
  • Loading branch information
cmaddox5 authored Oct 8, 2024
1 parent fb8ffbd commit 857ebd8
Show file tree
Hide file tree
Showing 2 changed files with 181 additions and 273 deletions.
80 changes: 34 additions & 46 deletions assets/src/components/admin/admin_add_modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,13 @@ const fields = [
key: "app_id",
label: "App ID",
FormCell: buildFormSelect([
"bus_eink",
"bus_eink_v2",
"bus_shelter_v2",
"busway_v2",
"dup",
"dup_v2",
"gl_eink_double",
"gl_eink_single",
"gl_eink_v2",
"pre_fare_v2",
"solari",
"solari_large",
"solari_large_v2",
]),
},
{
Expand All @@ -42,66 +36,60 @@ const fields = [
{ key: "device_id", label: "Device ID", FormCell: FormTextCell },
];

const departuresWidgetParams = { sections: [] };
const footerWidgetParams = { stop_id: "" };
const alertsWidgetParams = { stop_id: "" };

const defaultAppParamsByAppId = {
bus_eink: { stop_id: "STOP_ID" },
bus_eink_v2: {
departures: {},
footer: {},
header: {},
alerts: {},
},
gl_eink_single: {
stop_id: "STOP_ID",
platform_id: "PLATFORM_ID",
route_id: "ROUTE_ID",
direction_id: -1,
},
gl_eink_double: {
stop_id: "STOP_ID",
platform_id: "PLATFORM_ID",
route_id: "ROUTE_ID",
direction_id: -1,
header: { stop_id: "" },
evergreen_content: [],
departures: departuresWidgetParams,
footer: footerWidgetParams,
alerts: alertsWidgetParams,
},
gl_eink_v2: {
departures: {},
footer: {},
header: {},
alerts: {},
header: { stop_id: "" },
evergreen_content: [],
departures: departuresWidgetParams,
footer: footerWidgetParams,
alerts: alertsWidgetParams,
},
solari: { station_name: "STATION_NAME" },
dup: { header: "STATION_NAME" },
dup_v2: {
header: { stop_id: "" },
evergreen_content: [],
primary_departures: departuresWidgetParams,
secondary_departures: departuresWidgetParams,
alerts: alertsWidgetParams,
},
bus_shelter_v2: {
departures: {},
footer: {},
header: {},
alerts: {},
header: { stop_id: "" },
evergreen_content: [],
departures: departuresWidgetParams,
footer: footerWidgetParams,
alerts: alertsWidgetParams,
},
busway_v2: {
departures: {},
header: {},
},
solari_large_v2: {
departures: {},
header: {},
header: { stop_name: "" },
evergreen_content: [],
departures: departuresWidgetParams,
},
pre_fare_v2: {
header: {
stop_name: "",
},
header: { stop_id: "" },
evergreen_content: [],
},
};

const initialFormValues = _.fromPairs(
fields.map(({ key }) => [key, undefined]),
);
const initialFormValues = _.fromPairs(fields.map(({ key }) => [key, ""]));

const AddModal = ({ setData, closeModal }): JSX.Element => {
const [formValues, setFormValues] = useState(initialFormValues);
const [formValues, setFormValues] =
useState<_.Dictionary<string>>(initialFormValues);

const addScreen = () => {
const newRow = {
app_id: formValues.app_id,
// @ts-expect-error
app_params: defaultAppParamsByAppId[formValues.app_id],
device_id: formValues.device_id,
disabled: false,
Expand Down
Loading

0 comments on commit 857ebd8

Please sign in to comment.