Skip to content

Commit

Permalink
Add reverse logic option
Browse files Browse the repository at this point in the history
  • Loading branch information
rafal-gorecki committed Jan 7, 2025
1 parent 768863b commit 3c67363
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -265,19 +265,21 @@ function ToggleSrvButtonContent(
}

try {
setSrvState({ status: "requesting", value: `Calling ${config.serviceName}...` });
const requestPayload = { data: buttonAction ?? true };
setButtonAction(undefined);
const response = await context.callService(config.serviceName, requestPayload) as { success?: boolean };
setSrvState({
status: "success",
value: JSON.stringify(response, (_key, value) => (typeof value === "bigint" ? value.toString() : value), 2) ?? "",
});
if (buttonAction != undefined) {
setSrvState({ status: "requesting", value: `Calling ${config.serviceName}...` });
const requestPayload = { data: config.reverseLogic ? !buttonAction : buttonAction };
setButtonAction(undefined);
const response = await context.callService(config.serviceName, requestPayload) as { success?: boolean };
setSrvState({
status: "success",
value: JSON.stringify(response, (_key, value) => (typeof value === "bigint" ? value.toString() : value), 2) ?? "",
});
}
} catch (err) {
setSrvState({ status: "error", value: (err as Error).message });
log.error(err);
}
}, [context, buttonAction, config.serviceName]);
}, [context, buttonAction, config]);

// Setting buttonAction based on state.latestMatchingQueriedData
useEffect(() => {
Expand Down
5 changes: 5 additions & 0 deletions packages/studio-base/src/panels/ToggleSrvButton/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ export function useSettingsTree(
error: pathParseError,
validTypes: supportedDataTypes,
},
reverseLogic: {
label: "Reverse state logic",
input: "boolean",
value: config.reverseLogic,
},
},
},
button: {
Expand Down
1 change: 1 addition & 0 deletions packages/studio-base/src/panels/ToggleSrvButton/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
export type Config = {
serviceName: string;
statusTopicName: string;
reverseLogic: boolean;
activationText: string;
activationColor: string;
deactivationText: string;
Expand Down

0 comments on commit 3c67363

Please sign in to comment.