Skip to content

Commit

Permalink
Fixed number type handling in tinker
Browse files Browse the repository at this point in the history
  • Loading branch information
SindriTh committed Nov 21, 2023
1 parent dda16fd commit 898964a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 20 deletions.
4 changes: 2 additions & 2 deletions cockpit/IPC/src/Components/IOList/ListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ const ListItem: React.FC<ListItemProps> = ({
*/
function getSecondaryContent(interfaceData: any): ReactElement | null {
const internals = (secData: any) => {
switch (secData.type) {
switch (secData.typeJson.type[0]) {
case 'boolean':
return handleBoolContent(data);

Expand Down Expand Up @@ -153,7 +153,7 @@ const ListItem: React.FC<ListItemProps> = ({
*/
function getTinkerInterface(interfaceData: any): React.ReactElement | null {
const internals = (interfacedata: any) => {
switch (interfacedata.type) {
switch (interfacedata.typeJson.type[0]) {
case 'boolean':
return <BoolTinker interfaceData={interfacedata} isChecked={isChecked} />;

Expand Down
21 changes: 4 additions & 17 deletions cockpit/IPC/src/Components/Tinker/NumberTinker.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable react/function-component-definition */
import React, { useCallback, useMemo, useState } from 'react';
import React, { useCallback, useState } from 'react';
import { TFC_DBUS_DOMAIN, TFC_DBUS_ORGANIZATION } from 'src/variables';
import { AlertVariant, TextInput } from '@patternfly/react-core';
import { useAlertContext } from '../Alert/AlertContext';
Expand All @@ -12,26 +12,13 @@ interface NumberTinkerIface {
const NumberTinker: React.FC<NumberTinkerIface> = ({ interfaceData, isChecked }) => {
const [error, setError] = useState<string | undefined>(undefined);
const { addAlert } = useAlertContext();
const [typeJson, setTypeJson] = useState<{ type: string[], minimum: number | null, maximum: number | null }>();
function getType(): void {
const proxy = window.cockpit.dbus(interfaceData.process)
.proxy(interfaceData.interfaceName, `/${TFC_DBUS_DOMAIN}/${TFC_DBUS_ORGANIZATION}/Slots`);
proxy.wait().then(() => {
try {
setTypeJson(JSON.parse(proxy.data.Type));
} catch (e) {
setTypeJson({ type: ['integer'], minimum: null, maximum: null });
}
});
}
const { typeJson } = interfaceData;

const slotPath = `/${TFC_DBUS_DOMAIN}/${TFC_DBUS_ORGANIZATION}/Slots`;
const signalPath = `/${TFC_DBUS_DOMAIN}/${TFC_DBUS_ORGANIZATION}/Signals`;

useMemo(() => {
getType();
}, [interfaceData]);

const handleInputChange = (value: string) => {
console.log(typeJson);
if (!typeJson) {
return { value: undefined, error: 'Unknown type' };
}
Expand Down
2 changes: 1 addition & 1 deletion cockpit/IPC/src/views/IODebug.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ const IODebug: React.FC<DarkModeType> = ({ isDark }) => {
data: proxy.data.Value,
process,
interfaceName: interfaceData.name,
type: JSON.parse(proxy.Type).type[0] ?? interfaceData.valueType,
typeJson: JSON.parse(proxy.Type) ?? interfaceData.valueType,
direction,
hidden: false,
listener: false,
Expand Down

0 comments on commit 898964a

Please sign in to comment.