Skip to content

Commit 2d52cfd

Browse files
committed
fix: change overview
1 parent ed319c8 commit 2d52cfd

File tree

28 files changed

+478
-267
lines changed

28 files changed

+478
-267
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2024 Siemens AG
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*
6+
* This source code is licensed under the MIT license found in the
7+
* LICENSE file in the root directory of this source tree.
8+
*/
9+
import { showMessage } from "@siemens/ix";
10+
import { iconInfo } from "@siemens/ix-icons/icons";
11+
import { useCallback } from "react";
12+
import { useTranslation } from "react-i18next";
13+
14+
export default function useShowDemoMessage() {
15+
const { t } = useTranslation();
16+
const show = useCallback(() => {
17+
showMessage({
18+
message: t("demo-message"),
19+
icon: iconInfo,
20+
actions: [
21+
{
22+
id: "cancel",
23+
text: t("cancel"),
24+
type: "cancel",
25+
},
26+
{
27+
id: "okay",
28+
text: t("okay"),
29+
type: "okay",
30+
},
31+
],
32+
messageTitle: "Demo app",
33+
});
34+
}, [t]);
35+
36+
return show;
37+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2024 Siemens AG
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*
6+
* This source code is licensed under the MIT license found in the
7+
* LICENSE file in the root directory of this source tree.
8+
*/
9+
10+
import { themeSwitcher } from "@siemens/ix";
11+
import { convertThemeName } from "@siemens/ix-echarts";
12+
import { useLayoutEffect, useState } from "react";
13+
14+
export const useEChartsTheme = () => {
15+
const [echartsTheme, setEchartsTheme] = useState(
16+
convertThemeName(themeSwitcher.getCurrentTheme()),
17+
);
18+
19+
useLayoutEffect(() => {
20+
const { dispose } = themeSwitcher.themeChanged.on((theme) =>
21+
setEchartsTheme(convertThemeName(theme)),
22+
);
23+
return dispose;
24+
}, []);
25+
26+
return echartsTheme;
27+
};

apps/react-starter/src/locales/de/translation.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,5 +93,9 @@
9393
"title": "Einstellungen",
9494
"user-settings": "Benutzereinstellungen"
9595
},
96-
"toggle-theme": "Theme wechseln"
96+
"toggle-theme": "Theme wechseln",
97+
"search": "Suchen",
98+
"demo-message": "Diese Funktion ist in der Demo-Version derzeit nicht verfügbar.",
99+
"cancel": "Abbrechen",
100+
"okay": "Okay"
97101
}

apps/react-starter/src/locales/en/translation.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,5 +94,9 @@
9494
"title": "Settings",
9595
"user-settings": "User Settings"
9696
},
97-
"toggle-theme": "Toggle theme"
97+
"toggle-theme": "Toggle theme",
98+
"search": "Search",
99+
"demo-message": "This feature is currently unavailable in the demo version.",
100+
"cancel": "Cancel",
101+
"okay": "Okay"
98102
}

apps/react-starter/src/pages/devices/components/ag-grid-table/ag-grid-table.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { IxEmptyState } from "@siemens/ix-react";
1414
import QuickActionsCellRenderer from "./quick-actions-cell-renderet.tsx";
1515
import { CellClickedEvent, ColDef, ColGroupDef, IRowNode } from "ag-grid-community";
1616
import { useDataStore, useFilterStore, useOverviewPaneStore } from "../../../store/device-store.ts";
17-
import { MockData } from "../../../../types";
17+
import { Device } from "../../../../types";
1818
import { useCallback, useEffect, useRef, useState } from "react";
1919
import { LogicalFilterOperator } from "@siemens/ix";
2020
import CustomDeviceCellRenderer from "./device-cell-renderer.tsx";
@@ -23,13 +23,13 @@ import DeviceNameCellRenderer from "./device-name-cell-renderer.tsx";
2323

2424
function AgGridTable() {
2525
const { t } = useTranslation();
26-
const gridRef = useRef<AgGridReact<MockData>>(null);
26+
const gridRef = useRef<AgGridReact<Device>>(null);
2727
const { setExpanded, setSelectedData } = useOverviewPaneStore();
2828
const { filter, resetFilter } = useFilterStore();
2929
const [showEmptyState, setShowEmptyState] = useState(false);
3030
const { devices, editDevice } = useDataStore();
3131

32-
function onCellClick(event: CellClickedEvent<MockData, string>) {
32+
function onCellClick(event: CellClickedEvent<Device, string>) {
3333
if (event.column.getColId() === "quickActions") {
3434
return;
3535
}
@@ -95,14 +95,14 @@ function AgGridTable() {
9595
return true;
9696
}, []);
9797

98-
function doesExternalFilterPass(node: IRowNode<MockData>): boolean {
98+
function doesExternalFilterPass(node: IRowNode<Device>): boolean {
9999
if (filter.length) {
100100
return filter.every(({ id, value, operator }) => {
101101
switch (operator) {
102102
case LogicalFilterOperator.EQUAL:
103-
return node.data![id as keyof MockData] === value;
103+
return node.data![id as keyof Device] === value;
104104
case LogicalFilterOperator.NOT_EQUAL:
105-
return node.data![id as keyof MockData] !== value;
105+
return node.data![id as keyof Device] !== value;
106106
default:
107107
return true;
108108
}
@@ -130,7 +130,7 @@ function AgGridTable() {
130130
onCellClicked={(e) => onCellClick(e)}
131131
onCellValueChanged={(e) => editDevice(e.data)}
132132
isExternalFilterPresent={isExternalFilterPresent}
133-
doesExternalFilterPass={(e) => doesExternalFilterPass(e as IRowNode<MockData>)}
133+
doesExternalFilterPass={(e) => doesExternalFilterPass(e as IRowNode<Device>)}
134134
/>
135135
</div>
136136
) : (

apps/react-starter/src/pages/devices/components/device-details/index.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import styles from "./styles.module.css";
1111
import { IxPane, IxTypography, IxButton, IxDivider } from "@siemens/ix-react";
1212
import FirmwareCard from "./firmware-card.tsx";
1313
import { toKebabCase } from "../../../../util/util.ts";
14-
import { MockData } from "../../../../types";
14+
import { Device } from "../../../../types";
1515
import { useDataStore, useOverviewPaneStore } from "../../../store/device-store.ts";
1616
import { useTranslation } from "react-i18next";
1717

@@ -48,7 +48,7 @@ const DeviceDetails = ({ ...props }) => {
4848
{t(`device-details.${toKebabCase(key)}`)}
4949
</IxTypography>
5050
<IxTypography format="body" textColor="std">
51-
{selectedData[key as keyof MockData]}
51+
{selectedData[key as keyof Device]}
5252
</IxTypography>
5353
<IxDivider className={styles.Divider} />
5454
</div>
@@ -68,7 +68,7 @@ const DeviceDetails = ({ ...props }) => {
6868
...selectedData!,
6969
status: (selectedData!.status = "Maintenance"),
7070
};
71-
editDevice(updatedDevice as MockData);
71+
editDevice(updatedDevice as Device);
7272
props.api.onFilterChanged();
7373
}}
7474
>
@@ -81,7 +81,7 @@ const DeviceDetails = ({ ...props }) => {
8181
status: (selectedData!.status =
8282
selectedData!.status === "Offline" ? "Online" : "Offline"),
8383
};
84-
editDevice(updatedDevice as MockData);
84+
editDevice(updatedDevice as Device);
8585
props.api.onFilterChanged();
8686
}}
8787
>

apps/react-starter/src/pages/devices/components/modal/add-device-modal.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import styles from "./styles.module.css";
2222
import FormField from "./form-field";
2323
import { useForm } from "react-hook-form";
2424
import { useDataStore } from "../../../store/device-store";
25-
import { MockData } from "../../../../types";
25+
import { Device } from "../../../../types";
2626
import { useTranslation } from "react-i18next";
2727
import { showSuccessToast } from "../../../../util/util.ts";
2828

@@ -39,7 +39,7 @@ export default function AddDeviceModal() {
3939
modalRef.current?.dismiss("dismiss payload");
4040
};
4141

42-
const { register, setValue, handleSubmit } = useForm<MockData>({
42+
const { register, setValue, handleSubmit } = useForm<Device>({
4343
defaultValues: {
4444
deviceName: "",
4545
vendor: "",
@@ -57,7 +57,7 @@ export default function AddDeviceModal() {
5757
register("status");
5858
}, [register]);
5959

60-
const onSubmit = (data: MockData) => {
60+
const onSubmit = (data: Device) => {
6161
addDevice(data);
6262
showSuccessToast(t("device-add-modal.success"));
6363
close();
@@ -89,7 +89,7 @@ export default function AddDeviceModal() {
8989
id="status"
9090
value="Online"
9191
i18nSelectListHeader={t("device-add-modal.list-header")}
92-
onValueChange={(e) => setValue("status", e.detail as MockData["status"])}
92+
onValueChange={(e) => setValue("status", e.detail as Device["status"])}
9393
>
9494
<IxSelectItem label="Online" value="Online" />
9595
<IxSelectItem label="Offline" value="Offline" />

apps/react-starter/src/pages/devices/components/modal/form-field.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@
88
*/
99

1010
import { UseFormRegister } from "react-hook-form";
11-
import { MockData } from "../../../../types";
11+
import { Device } from "../../../../types";
1212

1313
type FormFieldProps = {
1414
id: string;
1515
label: string;
16-
register: UseFormRegister<MockData>;
16+
register: UseFormRegister<Device>;
1717
};
1818

1919
const FormField = ({ id, label, register }: FormFieldProps) => {
2020
return (
2121
<div>
2222
<label htmlFor={id}>{label}</label>
23-
<input type="text" id={id} {...register(id as keyof MockData)} />
23+
<input type="text" id={id} {...register(id as keyof Device)} />
2424
</div>
2525
);
2626
};

apps/react-starter/src/pages/devices/components/quick-actions/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import styles from "./styles.module.css";
1212
import { IxActionCard, IxCard, IxCardContent, IxTypography } from "@siemens/ix-react";
1313
import AlertCard from "./alert-card/alert-card.tsx";
1414
import { iconAddCircle } from "@siemens/ix-icons/icons";
15-
import type { MockData } from "../../../../types";
15+
import type { Device } from "../../../../types";
1616
import { useDataStore } from "../../../store/device-store.ts";
1717
import { useTranslation } from "react-i18next";
1818

@@ -25,9 +25,9 @@ function QuickActions({ show }: QuickActionsProps) {
2525

2626
const { devices } = useDataStore();
2727

28-
function getDevicesCountByStatus(data: MockData[], status: MockData["status"]): number {
28+
function getDevicesCountByStatus(data: Device[], status: Device["status"]): number {
2929
if (data) {
30-
return data!.filter((device: MockData) => device.status === status).length;
30+
return data!.filter((device: Device) => device.status === status).length;
3131
}
3232
return 0;
3333
}

apps/react-starter/src/pages/devices/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import DeviceDetails from "./components/device-details";
1616

1717
import show from "./components/modal/index.tsx";
1818
import { useDataStore, useFilterStore } from "../store/device-store.ts";
19-
import { MockData } from "../../types";
19+
import { Device } from "../../types";
2020
import { FilterState } from "@siemens/ix";
2121
import { useTranslation } from "react-i18next";
2222
import { toKebabCase } from "../../util/util.ts";
@@ -29,8 +29,8 @@ type Categories = Record<
2929
}
3030
>;
3131

32-
function createUniqueValueArray(devices: MockData[], key: string) {
33-
return Array.from(new Set(devices.map<string>((device) => device[key as keyof MockData] ?? "")));
32+
function createUniqueValueArray(devices: Device[], key: string) {
33+
return Array.from(new Set(devices.map<string>((device) => device[key as keyof Device] ?? "")));
3434
}
3535

3636
const useCategories = () => {

0 commit comments

Comments
 (0)