Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
31 changes: 29 additions & 2 deletions src/actions/devices.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as actionTypes from "../constants/actionTypes";
import { DeviceModel, ExhibitionDevice, ExhibitionDeviceGroup } from "../generated/client";
import { DeviceModel, DeviceType, ExhibitionDevice, ExhibitionDeviceGroup } from "../generated/client";
import { ActionCreator } from "redux";

/**
Expand All @@ -26,6 +26,14 @@ export interface SetDeviceModelsAction {
deviceModels: DeviceModel[];
}

/**
* Interface for set device types action type
*/
export interface SetDeviceTypesAction {
type: actionTypes.SET_DEVICE_TYPES;
deviceTypes: DeviceType[];
}

/**
* Function for dispatching devices
*
Expand All @@ -52,6 +60,20 @@ export const setDeviceGroups: ActionCreator<SetDeviceGroupsAction> = (
};
};

/**
* Function for dispatching device types
*
* @param deviceTypes device types being dispatched
*/
export const setDeviceTypes: ActionCreator<SetDeviceTypesAction> = (
deviceTypes: DeviceType[]
) => {
return {
type: actionTypes.SET_DEVICE_TYPES,
deviceTypes: deviceTypes
};
};

/**
* Function for dispatching device models
*
Expand All @@ -66,4 +88,9 @@ export const setDeviceModels: ActionCreator<SetDeviceModelsAction> = (
};
};

export type DevicesAction = SetDevicesAction | SetDeviceGroupsAction | SetDeviceModelsAction;
export type DevicesAction =
| SetDevicesAction
| SetDeviceGroupsAction
| SetDeviceModelsAction
| SetDeviceTypesAction;

8 changes: 5 additions & 3 deletions src/components/content-editor/page-event-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ class PageEventDialog extends React.Component<Props, State> {
<MenuItem value={ExhibitionPageEventActionType.Navigate}>
{strings.contentEditor.editor.eventTriggers.actionTypes.navigate}
</MenuItem>
<MenuItem value={ExhibitionPageEventActionType.Triggerdevicegroupevent}>
{strings.contentEditor.editor.eventTriggers.actionTypes.triggerdevicegroupevent}
</MenuItem>
</TextField>
</Box>
);
Expand Down Expand Up @@ -318,15 +321,14 @@ class PageEventDialog extends React.Component<Props, State> {
const { classes } = this.props;

const event = this.state.pageEvent;

if (!event) {
return null;
return null;
}

const deviceGroupEventNameProperty = event
? event.properties.find((property) => property.name === "name")
: undefined;

return (
<div style={{ marginTop: theme.spacing(2) }}>
<Typography variant="h6">
Expand Down
52 changes: 49 additions & 3 deletions src/components/fleet-management/edit-device-drawer.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Device, DeviceApprovalStatus, DeviceModel } from "../../generated/client";
import { Device, DeviceApprovalStatus, DeviceModel, DeviceType } from "../../generated/client";
import strings from "../../localization/strings";
import theme from "../../styles/theme";
import GenericUtils from "../../utils/generic-utils";
Expand Down Expand Up @@ -27,18 +27,19 @@ import { ChangeEvent, ReactNode, useState } from "react";
interface Props {
selectedDevice?: Device;
deviceModels: DeviceModel[];
deviceTypes: DeviceType[];
onSave: (device: Device) => Promise<void>;
onClose: () => void;
}

/**
* Edit Device Drawer component
*/
const EditDeviceDrawer = ({ selectedDevice, deviceModels, onSave, onClose }: Props) => {
const EditDeviceDrawer = ({ selectedDevice, deviceModels, deviceTypes, onSave, onClose }: Props) => {
if (!selectedDevice?.id) return null;

const [tempDevice, setTempDevice] = useState(selectedDevice);

/**
* Event handler for device property change events
*
Expand Down Expand Up @@ -199,6 +200,42 @@ const EditDeviceDrawer = ({ selectedDevice, deviceModels, onSave, onClose }: Pro
</MenuItem>
);

/**
* Renders device types select box options
*
* @param deviceType device type
*/
const renderDeviceTypeSelectBoxOptions = (deviceType: DeviceType) => (

<MenuItem key={deviceType} value={deviceType}>
{getDeviceTypeLabel(deviceType)}
</MenuItem>

);

/**
* Returns a user-friendly label for device type
*
* @param deviceType device type
* @returns label
*/
const getDeviceTypeLabel = (deviceType: DeviceType): string => {
switch (deviceType) {
case DeviceType.NohevaAndroid:
return strings.fleetManagement.properties.deviceTypeValues.nohevaAndroid;
case DeviceType.NohevaMacos:
return strings.fleetManagement.properties.deviceTypeValues.nohevaMacos
case DeviceType.MuistiAndroid:
return strings.fleetManagement.properties.deviceTypeValues.muistiAndroid;
case DeviceType.Custom:
return strings.fleetManagement.properties.deviceTypeValues.custom;

default:
return deviceType;

}
};

/**
* Renders device models select box
*
Expand Down Expand Up @@ -266,6 +303,13 @@ const EditDeviceDrawer = ({ selectedDevice, deviceModels, onSave, onClose }: Pro
"select",
deviceModels.map(renderDeviceModelSelectBoxOptions)
)}
{renderDevicePropertyField(
"deviceType",
strings.fleetManagement.properties.deviceType,
false,
"select",
deviceTypes.map(renderDeviceTypeSelectBoxOptions)
)}
{renderDevicePropertyField(
"serialNumber",
strings.fleetManagement.properties.serialNumber,
Expand Down Expand Up @@ -329,7 +373,9 @@ const EditDeviceDrawer = ({ selectedDevice, deviceModels, onSave, onClose }: Pro
</Button>
</PropertyBox>
</Drawer>

);

};

export default EditDeviceDrawer;
16 changes: 13 additions & 3 deletions src/components/screens/fleet-management-screen.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Api from "../../api/api";
import { Device, DeviceModel, Exhibition } from "../../generated/client";
import { Device, DeviceModel, DeviceType, Exhibition } from "../../generated/client";
import strings from "../../localization/strings";
import { ReduxState } from "../../store";
import { AccessToken } from "../../types";
Expand All @@ -21,12 +21,13 @@ interface Props {
accessToken: AccessToken;
exhibitions: Exhibition[];
deviceModels: DeviceModel[];
deviceTypes: DeviceType[];
}

/**
* Fleet Management Screen component
*/
const FleetManagementScreen = ({ history, keycloak, accessToken, deviceModels }: Props) => {
const FleetManagementScreen = ({ history, keycloak, accessToken, deviceModels, deviceTypes }: Props) => {
const [devices, setDevices] = useState<Device[]>([]);
const [loading, setLoading] = useState(false);
const [selectedDevice, setSelectedDevice] = useState<Device>();
Expand Down Expand Up @@ -69,6 +70,12 @@ const FleetManagementScreen = ({ history, keycloak, accessToken, deviceModels }:
setLoading(false);
};

/**
* Retrieves all possible values from the DeviceType enum
* to be used as selectable options in dropdowns or other UI elements.
*/
const allDeviceTypes = Object.values(DeviceType);

/**
* Handler for delete device button click
*
Expand Down Expand Up @@ -125,6 +132,7 @@ const FleetManagementScreen = ({ history, keycloak, accessToken, deviceModels }:
<EditDeviceDrawer
selectedDevice={selectedDevice}
deviceModels={deviceModels}
deviceTypes={allDeviceTypes}
onSave={handleSaveDevice}
onClose={() => setSelectedDevice(undefined)}
/>
Expand All @@ -147,7 +155,9 @@ const mapStateToProps = (state: ReduxState) => {
keycloak: state.auth.keycloak as KeycloakInstance,
accessToken: state.auth.accessToken as AccessToken,
exhibitions: state.exhibitions.exhibitions,
deviceModels: state.devices.deviceModels
deviceModels: state.devices.deviceModels,
deviceTypes: state.devices.deviceTypes

};
};

Expand Down
6 changes: 6 additions & 0 deletions src/constants/actionTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ export type SET_DEVICE_GROUPS = typeof SET_DEVICE_GROUPS;
export const SET_DEVICE_MODELS = "SET_DEVICE_MODELS";
export type SET_DEVICE_MODELS = typeof SET_DEVICE_MODELS;

/**
* Set device types action
*/
export const SET_DEVICE_TYPES = "SET_DEVICE_TYPES";
export type SET_DEVICE_TYPES = typeof SET_DEVICE_TYPES;

/**
* Set layouts action
*/
Expand Down
9 changes: 8 additions & 1 deletion src/localization/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1221,7 +1221,14 @@
},
"serialNumber": "Serial number",
"lastSeen": "Last seen",
"model": "Device model"
"model": "Device model",
"deviceType": "Device type",
"deviceTypeValues": {
"nohevaAndroid": "Noheva Android",
"nohevaMacos": "Noheva macOS",
"muistiAndroid": "Muisti Android",
"custom": "Custom"
}
},
"deleteDialog": {
"title": "Delete device",
Expand Down
10 changes: 9 additions & 1 deletion src/localization/fi.json
Original file line number Diff line number Diff line change
Expand Up @@ -1221,8 +1221,16 @@
},
"serialNumber": "Sarjanumero",
"lastSeen": "Nähty",
"model": "Laitemalli"
"model": "Laitemalli",
"deviceType": "Laite tyyppi",
"deviceTypeValues": {
"nohevaAndroid": "Noheva Android",
"nohevaMacos": "Noheva macOS",
"muistiAndroid": "Muisti Android",
"custom": "Custom"
}
},

"deleteDialog": {
"title": "Poista laite",
"description": "Kirjoita poistettavan laitteen nimi vahvistaaksesi poisto.",
Expand Down
7 changes: 7 additions & 0 deletions src/localization/strings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1243,6 +1243,13 @@ export interface IStrings extends LocalizedStringsMethods {
serialNumber: string;
lastSeen: string;
model: string;
deviceType: string;
deviceTypeValues: {
nohevaAndroid: string;
nohevaMacos: string;
muistiAndroid: string;
custom: string;
};
};
deleteDialog: {
title: string;
Expand Down
13 changes: 10 additions & 3 deletions src/reducers/devices.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DevicesAction } from "../actions/devices";
import { SET_DEVICES, SET_DEVICE_GROUPS, SET_DEVICE_MODELS } from "../constants/actionTypes";
import { DeviceModel, ExhibitionDevice, ExhibitionDeviceGroup } from "../generated/client";
import { SET_DEVICES, SET_DEVICE_GROUPS, SET_DEVICE_MODELS, SET_DEVICE_TYPES } from "../constants/actionTypes";
import { DeviceModel, DeviceType, ExhibitionDevice, ExhibitionDeviceGroup } from "../generated/client";
import { Reducer } from "redux";

/**
Expand All @@ -10,6 +10,7 @@ interface DevicesState {
devices: ExhibitionDevice[];
deviceGroups: ExhibitionDeviceGroup[];
deviceModels: DeviceModel[];
deviceTypes: DeviceType[];
}

/**
Expand All @@ -18,7 +19,8 @@ interface DevicesState {
const initialState: DevicesState = {
devices: [],
deviceGroups: [],
deviceModels: []
deviceModels: [],
deviceTypes: []
};

/**
Expand Down Expand Up @@ -48,6 +50,11 @@ export const devicesReducer: Reducer<DevicesState, DevicesAction> = (
...state,
deviceModels: action.deviceModels
};
case SET_DEVICE_TYPES:
return {
...state,
deviceTypes: action.deviceTypes
};
default:
return state;
}
Expand Down
Loading