Skip to content

Commit

Permalink
refactor(web): drop product registration code (#1499)
Browse files Browse the repository at this point in the history
At this moment, the code for working with product registration is not
used. Moreover, it has to be migrated to a TanStack Query approach
because reasons stated at #1439


Thus, we've agreed to drop it meanwhile in order to have less
dead/unused/pending to adapt code.

Please, note that changes were done on top of
#1498, reason why would be nice to
merge this after it. Additionally, it includes a removal of software
typedef comments that were forgotten at
#1483 and
#1496.
  • Loading branch information
imobachgs authored Jul 25, 2024
2 parents 4935eed + 93de748 commit 25c6814
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 486 deletions.
118 changes: 0 additions & 118 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,88 +58,6 @@ class ProductClient {
constructor(client) {
this.client = client;
}

/**
* 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 };
182 changes: 0 additions & 182 deletions web/src/client/software.test.js

This file was deleted.

Loading

0 comments on commit 25c6814

Please sign in to comment.