Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(web): drop product registration code #1499

Merged
merged 3 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
168 changes: 0 additions & 168 deletions web/src/client/software.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,42 +25,6 @@ import { WithProgress, WithStatus } from "./mixins";

const SOFTWARE_SERVICE = "org.opensuse.Agama.Software1";

/**
* @typedef {object} Product
* @property {string} id - Product ID (e.g., "Leap")
* @property {string} name - Product name (e.g., "openSUSE Leap 15.4")
* @property {string} description - Product description
*/

/**
* @typedef {object} ActionResult
* @property {boolean} success - Whether the action was successfully done.
* @property {string} message - Result message.
*/

/**
* @typedef {object} SoftwareProposal
* @property {string} size - Used space in human-readable form.
* @property {Object.<string, number>} patterns - Selected patterns and the reason.
*/

/**
* @typedef {object} SoftwareConfig
* @propery {Object.<string, boolean>} patterns - An object where the keys are the pattern names
* and the values whether to install them or not.
* @property {string|undefined} product - Product to install.
*/

/**
* @typedef {Object} Pattern
* @property {string} name - Pattern name (internal ID).
* @property {string} category - Pattern category.
* @property {string} summary - User visible pattern name.
* @property {string} description - Long description of the pattern.
* @property {number} order - Display order (string!).
* @property {string} icon - Icon name (not path or file name!).
*/

/**
* Software client
*
Expand Down Expand Up @@ -94,138 +58,6 @@ class ProductClient {
constructor(client) {
this.client = client;
}

/**
* Returns the list of available products.
*
* @return {Promise<Array<Product>>}
*/
async getAll() {
const response = await this.client.get("/software/products");
if (!response.ok) {
console.log("Failed to get software products: ", response);
}
return response.json();
}

/**
* Returns the identifier of the selected product.
*
* @return {Promise<string>} Selected identifier.
*/
async getSelected() {
const response = await this.client.get("/software/config");
if (!response.ok) {
console.log("Failed to get software config: ", response);
}
const config = await response.json();
return config.product;
}

/**
* Selects a product for installation.
*
* @param {string} id - Product ID.
*/
async select(id) {
await this.client.put("/software/config", { product: id });
}

/**
* Registers a callback to run when the select product changes.
*
* @param {(id: string) => void} handler - Callback function.
* @return {import ("./http").RemoveFn} Function to remove the callback.
*/
onChange(handler) {
return this.client.onEvent("ProductChanged", ({ id }) => {
if (id) {
handler(id);
}
});
}

/**
* Returns the registration of the selected product.
*
* @return {Promise<import('~/types/registration').Registration>}
*/
async getRegistration() {
const response = await this.client.get("/software/registration");
if (!response.ok) {
console.log("Failed to get registration config:", response);
return { requirement: "unknown", code: null, email: null };
}
const config = await response.json();

const { requirement, key: code, email } = config;

const registration = { requirement, code, email };
if (code.length === 0) registration.code = null;
if (email.length === 0) registration.email = null;

return registration;
}

/**
* Tries to register the selected product.
*
* @param {string} code
* @param {string} [email]
* @returns {Promise<ActionResult>}
*/
async register(code, email = "") {
const response = await this.client.post("/software/registration", { key: code, email });
if (response.status === 422) {
/** @type import('~/types/registration').RegistrationFailure */
const body = await response.json();
return {
success: false,
message: body.message,
};
}

return {
success: response.ok, // still we can fail 400 due to dbus issue or 500 if backend stop working. maybe some message for this case?
message: "",
};
}

/**
* Tries to deregister the selected product.
*
* @returns {Promise<ActionResult>}
*/
async deregister() {
const response = await this.client.delete("/software/registration");

if (response.status === 422) {
/** @type import('~/types/registration').RegistrationFailure */
const body = await response.json();
return {
success: false,
message: body.message,
};
}

return {
success: response.ok, // still we can fail 400 due to dbus issue or 500 if backend stop working. maybe some message for this case?
message: "",
};
}

/**
* Registers a callback to run when the registration changes.
*
* @param {(registration: import('~/types/registration').Registration) => void} handler - Callback function.
*/
onRegistrationChange(handler) {
return this.client.ws().onEvent((event) => {
if (event.type === "RegistrationChanged" || event.type === "RegistrationRequirementChanged") {
this.getRegistration().then(handler);
}
});
}
}

export { ProductClient, SoftwareClient };
205 changes: 0 additions & 205 deletions web/src/client/software.test.js

This file was deleted.

Loading
Loading