Skip to content

Commit

Permalink
fix: pass 100% on TS checks, deprecated SDK usage, minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
klausborges committed Dec 17, 2024
1 parent 514fc5a commit 5c04082
Show file tree
Hide file tree
Showing 58 changed files with 496 additions and 615 deletions.
59 changes: 59 additions & 0 deletions packages/console/biome.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"$schema": "https://biomejs.dev/schemas/1.9.3/schema.json",
"vcs": {
"enabled": false,
"clientKind": "git",
"useIgnoreFile": false
},
"files": {
"ignoreUnknown": false,
"ignore": ["build", "build-tsc", "standalone-plugins", "standalone"]
},
"formatter": {
"enabled": true,
"indentStyle": "space",
"indentWidth": 2
},
"organizeImports": {
"enabled": true
},
"linter": {
"enabled": true,
"rules": {
"recommended": true,
"style": {
"useNodejsImportProtocol": "error",
"noParameterAssign": "off"
},
"nursery": {
"noCommonJs": "error"
},
"correctness": {
"useImportExtensions": "error"
},
"suspicious": {
"noExplicitAny": "off",
"noArrayIndexKey": "off",
"noAssignInExpressions": "off",
"noConsoleLog": "error"
},
"complexity": {
"noForEach": "off"
},
"a11y": {
"useKeyWithClickEvents": "off",
"noSvgWithoutTitle": "off",
"useIframeTitle": "off",
"noLabelWithoutControl": "off",
"useAltText": "off"
}
}
},
"javascript": {
"formatter": {
"quoteStyle": "double",
"semicolons": "always",
"trailingCommas": "all"
}
}
}
1 change: 1 addition & 0 deletions packages/console/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"build": "vite build",
"build-watch": "vite build --watch",
"test": "vitest",
"check-types": "tsc --noEmit",
"lint": "biome check .",
"format": "biome format . --write",
"lint-fix": "biome check . --write"
Expand Down
1 change: 0 additions & 1 deletion packages/console/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ const WrappedStoreRoutes = observer(() => {
) {
// not configured, go to setup
setReadyToRender(true);
console.log("navigatin");
navigate("/console/setup");
} else {
// configured, validate token
Expand Down
10 changes: 9 additions & 1 deletion packages/console/src/Components/Action/Edit/ActionEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,10 @@ function ActionEdit() {
* Saves the Action.
*/
const save = useCallback(async () => {
if (!id) {
return;
}

const formatted = convertActionToAPI(
data,
action,
Expand All @@ -301,6 +305,10 @@ function ActionEdit() {
* Deletes the Action.
*/
const deleteData = useCallback(async () => {
if (!id) {
return;
}

await deleteAction(id);
}, [id]);

Expand All @@ -309,7 +317,7 @@ function ActionEdit() {
* This will apply the change to the data state.
*/
const onChangeData = useCallback(
(field: keyof IAction, value) => {
(field: keyof IAction, value: any) => {
setData({ ...data, [field]: value });
},
[data],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const CronInputContainer = styled.div`
padding-top: 1rem;
`;

const CronInput = styled(InputStyle.Container)`\
const CronInput = styled(InputStyle.Container)`
font-size: 2.5rem;
border-radius: 10px;
text-align: center;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ import type { IScheduleData } from "../../../Action.interface";
import { spreadCronToScheduleData } from "../../Logic/spreadCronToScheduleData.ts";
import * as Style from "./AdvancedCron.style";

/**
* Props.
*/
interface IAdvancedCron {
/**
* Error of the fields.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,55 +4,34 @@ import getAnalysisInfo from "../../../../Requests/getAnalysisInfo.ts";
import getAnalysisList from "../../../../Requests/getAnalysisList.ts";
import OptionsPicker from "../../../OptionsPicker/OptionsPicker.tsx";

/**
* Props.
*/
interface IAnalysisPicker {
/**
* Device object.
*/
/** Selected Analysis object. */
value: IAnalysis | undefined;
/**
* Called when a new device gets picked.
*/
onChange: (value: IAnalysis) => void;
/**
* Indicates if the this field has an error.
*/
error?: boolean;
/**
* Position of the options container. Default is `bottom`.
* Position of the options container.
*
* @default "bottom"
*/
optionsPosition?: "top" | "bottom";
error?: boolean;
onChange: (value: IAnalysis) => void;
}

/**
*/
function AnalysisPicker(props: IAnalysisPicker) {
const { error, optionsPosition } = props;

/**
* Retrieves the options.
*/
const onGetOptions = useCallback(async (query: string, page: number) => {
const result = await getAnalysisList(page, 20, { name: `*${query}*` });
return result;
}, []);

/**
* Resolves an option by an ID.
* This transforms the ID into an object.
*/
const resolveOptionByID = useCallback(async (id: string | number) => {
const analysis = await getAnalysisInfo(id as TGenericID);
return analysis;
}, []);

/**
* Renders a single option row.
*/
const renderOption = useCallback((i) => {
return i.name;
const renderOption = useCallback((analysis: IAnalysis) => {
return analysis.name;
}, []);

return (
Expand Down
9 changes: 3 additions & 6 deletions packages/console/src/Components/Button/Button.style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ import styled, { css, type DefaultTheme } from "styled-components";
import * as IconStyle from "../Icon/Icon.style";
import { EButton } from "./Button.types";

/**
* Props for the container.
*/
export interface IButtonContainerProps {
$buttonType?: EButton;
theme: DefaultTheme;
Expand All @@ -26,7 +23,7 @@ export const Container = styled.button<IButtonContainerProps>`
justify-content: center;
align-items: center;
:disabled {
&:disabled {
pointer-events: none;
opacity: 0.7;
color: ${(props) => props.theme.buttonDisabledFont} !important;
Expand Down Expand Up @@ -121,7 +118,7 @@ function applyTypeCss(props: IButtonContainerProps) {
color: ${color};
}
:hover {
&:hover {
background-color: ${hoverBackground};
color: ${hoverColor};
Expand All @@ -131,7 +128,7 @@ function applyTypeCss(props: IButtonContainerProps) {
}
}
:active {
&:active {
background-color: ${activeBackground};
}
`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,52 +4,28 @@ import getDeviceInfo from "../../../../Requests/getDeviceInfo.ts";
import getDeviceList from "../../../../Requests/getDeviceList.ts";
import OptionsPicker from "../../../OptionsPicker/OptionsPicker.tsx";

/**
* Props.
*/
interface IDevicePicker {
/**
* Device object.
*/
value?: IDevice;
/**
* Called when a new device gets picked.
*/
onChange: (value: IDevice) => void;
/**
* Indicates if this component has invalid data.
* If this is set to `true`, this component will get a red border.
*/
/** Selected Device object. */
value: IDevice | undefined;
error?: boolean;
onChange: (value: IDevice) => void;
}

/**
*/
function DevicePicker(props: IDevicePicker) {
const { value, error } = props;

/**
* Retrieves the options.
*/
const onGetOptions = useCallback(async (query: string, page: number) => {
const devices = await getDeviceList(page, 20, query);
return devices;
}, []);

/**
* Resolves an option by an ID.
* This transforms the ID into an object.
*/
const resolveOptionByID = useCallback(async (id: string | number) => {
const device = await getDeviceInfo(id as TGenericID);
return device;
}, []);

/**
* Renders a single option row.
*/
const renderOption = useCallback((i) => {
return i.name;
const renderOption = useCallback((device: IDevice) => {
return device.name;
}, []);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,17 @@ import RowManipulatorTable from "../../../RowManipulatorTable/RowManipulatorTabl
import Switch from "../../../Switch/Switch.tsx";
import { ESwitchSize } from "../../../Switch/Switch.types";

/**
* Props.
*/
interface IConfigParametersTabProps {
/**
* Array of parameters from the device.
*/
params?: IDeviceParameter[];
/**
* Device's form errors.
*/
errors: any;
/**
* Called when the params change.
*/
onChangeParams: (value: IDeviceParameter[]) => void;
}

/**
* The device's `Configuration Parameters` tab.
*/
function ConfigParametersTab(props: IConfigParametersTabProps) {
const { errors, onChangeParams } = props;
const params = props.params || [];
const theme = useTheme();

/**
* Called when a field gets modified.
*/
const onChangeField = (
field: keyof IDeviceParameter,
value: string | boolean,
Expand All @@ -48,14 +30,11 @@ function ConfigParametersTab(props: IConfigParametersTabProps) {
onChangeParams([...params]);
};

/**
* Renders the status switch.
*/
const renderStatus = (item: IDeviceParameter, index: number) => {
const renderStatusSwitch = (item: IDeviceParameter, index: number) => {
return (
<div>
<Switch
value={item.sent || false}
value={!!item.sent || false}
onChange={(e) => onChangeField("sent", e, index)}
size={ESwitchSize.big}
selectedText="Read"
Expand All @@ -67,10 +46,7 @@ function ConfigParametersTab(props: IConfigParametersTabProps) {
);
};

/**
* Renders the key of the parameter.
*/
const renderKey = (item: IDeviceParameter, index: number) => {
const renderKeyInput = (item: IDeviceParameter, index: number) => {
const error = errors?.parameters?.[index]?.key;
return (
<Input
Expand All @@ -82,10 +58,7 @@ function ConfigParametersTab(props: IConfigParametersTabProps) {
);
};

/**
* Renders the value input.
*/
const renderValue = (item: IDeviceParameter, index: number) => {
const renderValueInput = (item: IDeviceParameter, index: number) => {
const error = errors?.parameters?.[index]?.value;
return (
<Input
Expand All @@ -97,15 +70,11 @@ function ConfigParametersTab(props: IConfigParametersTabProps) {
);
};

/**
*/
const addItem = () => {
params.push({ key: "", value: "", sent: false } as any);
onChangeParams([...params]);
};

/**
*/
const removeItem = (index: number) => {
params.splice(index, 1);
onChangeParams([...params]);
Expand All @@ -128,15 +97,15 @@ function ConfigParametersTab(props: IConfigParametersTabProps) {
label: "Status",
flex: "none",
width: "105px",
onRender: renderStatus,
onRender: renderStatusSwitch,
},
{
label: "Key",
onRender: renderKey,
onRender: renderKeyInput,
},
{
label: "Value",
onRender: renderValue,
onRender: renderValueInput,
},
]}
/>
Expand Down
Loading

0 comments on commit 5c04082

Please sign in to comment.