Skip to content

Commit

Permalink
Tidy up prior to pushing
Browse files Browse the repository at this point in the history
  • Loading branch information
SludgeGirl committed Sep 19, 2024
1 parent 89535e0 commit b0f7cad
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 28 deletions.
4 changes: 3 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"no-var": "error",
"lines-between-class-members": ["error", "always", { "exceptAfterSingleLine": true }],
"prefer-promise-reject-errors": ["error", { "allowEmptyReject": true }],
"react/jsx-indent": ["error", 4],
"react/jsx-indent": "off",
"semi": ["error", "always", { "omitLastInOneLineBlock": true }],

"react-hooks/rules-of-hooks": "error",
Expand All @@ -36,6 +36,8 @@
"no-console": "off",
"quotes": "off",
"react/jsx-curly-spacing": "off",
"react/jsx-closing-tag-location": "off",
"react/jsx-handler-names": "off",
"react/jsx-indent-props": "off",
"react/jsx-no-useless-fragment": "error",
"react/prop-types": "off",
Expand Down
12 changes: 6 additions & 6 deletions src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const Application = () => {
updateSubscriptions();
}, [updateSubscriptions, backend]);

const registerProduct = async (): Promise<[boolean, string]> => {
const registerProduct = useCallback(async (): Promise<[boolean, string]> => {
console.debug("registering", formData);
const result = await backend?.register(formData.registrationCode, formData.email, formData.product).then((result) => {
if (result[0]) {
Expand All @@ -76,9 +76,9 @@ export const Application = () => {
});

return result || [false, ""];
};
}, [backend, Dialogs, formData, updateSubscriptions]);

const deactivateProduct = (subscription: Subscription | Extension): void => {
const deactivateProduct = useCallback((subscription: Subscription | Extension): void => {
console.log("deregistering", subscription.identifier);
setLoadingSubscriptions(true);
backend?.deregister([subscription.identifier, subscription.version, subscription.arch].join("/"))
Expand All @@ -96,9 +96,9 @@ export const Application = () => {
setLoadingSubscriptions(false);
updateSubscriptions();
});
};
}, [backend, Dialogs, updateSubscriptions]);

const activateProduct = (subscription: Subscription | Extension): void => {
const activateProduct = useCallback((subscription: Subscription | Extension): void => {
console.log("activating", subscription.identifier);
setLoadingExtensions(true);
backend?.register("", "", [subscription.identifier, subscription.version, subscription.arch].join("/"))
Expand All @@ -113,7 +113,7 @@ export const Application = () => {
setLoadingExtensions(false);
updateSubscriptions();
});
};
}, [backend, Dialogs, updateSubscriptions]);

return (
<Page>
Expand Down
4 changes: 2 additions & 2 deletions src/backends/backend.tsx → src/backends/backend.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type Extension = {
expires_at?: string,
}

enum SubscriptionStatus {
declare enum SubscriptionStatus {
Active = "Active",
Expired = "Expired",
Unregistered = "Unregistered",
Expand Down Expand Up @@ -39,7 +39,7 @@ type CockpitSpawnError = {
exit_signal: string | null,
}

enum SUSEConnectExitCodes {
declare enum SUSEConnectExitCodes {
ZyppBusy = 7,
}

Expand Down
14 changes: 10 additions & 4 deletions src/backends/suseconnect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Backend, Subscription, CockpitSpawnError, SUSEConnectExitCodes, Extensi

export class SuseConnect implements Backend {
async getSubscriptions(): Promise<Subscription[]> {
let result;
let result = null;
let retry = true;
let tries = 0;

Expand All @@ -23,7 +23,10 @@ export class SuseConnect implements Backend {
});
}

return result || [];
if (result)
return result;

throw new Error("Unable to get subscriptions");
}

async getSubscriptionsStatus(): Promise<string> {
Expand All @@ -33,7 +36,7 @@ export class SuseConnect implements Backend {
}

async getExtensions(): Promise<Extension[]> {
let result;
let result = null;
let retry = true;
let tries = 0;

Expand All @@ -53,7 +56,10 @@ export class SuseConnect implements Backend {
});
}

return result || [];
if (result)
return result;

throw new Error("Unable to get extensions");
}

async getAvailableExtensions(): Promise<string> {
Expand Down
10 changes: 8 additions & 2 deletions src/backends/transactional-update.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ export class TransactionalUpdate implements Backend {
});
}

return result || [];
if (result)
return result;

throw new Error("Unable to get subscriptions");
}

async getSubscriptionsStatus(): Promise<string> {
Expand Down Expand Up @@ -56,7 +59,10 @@ export class TransactionalUpdate implements Backend {
});
}

return result || [];
if (result)
return result;

throw new Error("Unable to get extensions");
}

async getAvailableExtensions(): Promise<string> {
Expand Down
2 changes: 1 addition & 1 deletion src/components/reboot_dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const RebootDialog = () => {
const Dialogs = useDialogs();

const reboot = () => {
cockpit.spawn(["reboot"], { superuser: "try" });
cockpit.spawn(["reboot"], { superuser: "require" });
};

return (
Expand Down
12 changes: 6 additions & 6 deletions src/components/register_code_form.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import cockpit from 'cockpit';
import { Form, Grid, FormGroup, TextInput, GridItem, ActionGroup, Button } from "@patternfly/react-core";
import React, { useState } from "react";
import React, { Dispatch, SetStateAction, useState } from "react";
import { EmptyStatePanel } from 'cockpit-components-empty-state';

const _ = cockpit.gettext;
Expand All @@ -12,22 +12,22 @@ type RegisterFormData = {
};

type Props = {
submitCallback: any,
submitCallback: () => Promise<[boolean, string]>,
formData: RegisterFormData,
setFormData: any,
setFormData: Dispatch<SetStateAction<RegisterFormData>>,
};

const RegisterCodeForm = ({ submitCallback, formData, setFormData }: Props) => {
const [submitting, setSubmitting] = useState<boolean>(false);

const onValueChange = (fieldName: string, value: any) => {
const onValueChange = (fieldName: string, value: string|number) => {
setFormData({ ...formData, [fieldName]: value });
};

const submit = () => {
setSubmitting(true);
submitCallback().then((success: boolean) => {
if (success) {
submitCallback().then((result: [boolean, string]) => {
if (result[0]) {
setFormData({
registrationCode: "",
email: "",
Expand Down
12 changes: 6 additions & 6 deletions src/components/subscription_list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,20 @@ export const SubscriptionList = ({ subscriptions, loading, deactivate, activate
</Badge>
{item.expires_at
? <Badge key="expires" className="pf-v5-u-mx-xs">
Expires: {format_date(item.expires_at)}
</Badge>
Expires: {format_date(item.expires_at)}
</Badge>
: ""}
</FlexItem>
<FlexItem align={{ default: "alignRight" }}>
{deactivate
? <Button onClick={() => deactivate(item)}>
Deactivate
</Button>
Deactivate
</Button>
: ""}
{activate
? <Button onClick={() => activate(item)}>
Activate
</Button>
Activate
</Button>
: ""}
</FlexItem>
</Flex>
Expand Down

0 comments on commit b0f7cad

Please sign in to comment.