Skip to content

Conversation

@johnsimons
Copy link
Member

Migrating composables and a few vue component

Started adding typings for REST api resources

@johnsimons johnsimons self-assigned this Feb 6, 2024
Started adding typings for REST api resources
Copy link
Contributor

@PhilBastian PhilBastian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in general i'd prefer to have the assignation to undefined and returning from functions of undefined changed to assigning/returning null, since using undefined is 'overloading' the default meaning of undefined as set by JavaScript of "this thing hasn't been defined, or this function has no return statement".

Comparisons to undefined should be comparisons to undefined or null (i.e. use the shortcut == null)

const hourDuration = moment.duration(60 * 1000); //this ensure that we never use minute formatting
const dayDuration = moment.duration(24 * 60 * 60 * 1000);

export function useFormatTime(value) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these function's you haven't converted are used by monitoring and therefore will need to be converted

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I thought I could take a shortcut 😄

So I converted all the functions now, but unsure about the function parameter types, I went with value: string, decimals: number. Is this right?

const lic = await getLicense(license);
license = lic;
license = await getLicense();
license.licenseEdition = computed(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are these correct? Previously they held the reactive object that was the result of the computed, now they hold the value of the computed at the time of creation

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I refactor all this code, tried using the spread operator but did not work either.
Also, the usage of this data, does not need .value, see https://github.com/Particular/ServicePulse/pull/1697/files#diff-97592647a6c6f377fdd850bdb6229985b9a414d6956fcc86213ff71f695b94d6

I tested it, and it works, but i would appreciate if you also have a look to make sure I am not introducing a bug here 😄


export function useIsMonitoringDisabled() {
return monitoringUrl.value === null || monitoringUrl.value === "" || monitoringUrl.value === "!";
return monitoringUrl.value === undefined || monitoringUrl.value === "" || monitoringUrl.value === "!";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we want this first clause to be monitoringUrl.value == null, since it depends on how the form is handled whether the clearing of a value will result in an empty string or null, whereas it starts above as undefined.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

export function useFetchFromMonitoring(suffix: string) {
if (useIsMonitoringDisabled()) {
return Promise.resolve(null);
return Promise.resolve(undefined);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really don't like returning undefined from functions: should be null

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

const requestOptions: RequestInit = {
method: "POST",
};
if (payload !== undefined) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will also not want to add these headers if payload is null, so check should be if payload != null (i.e. it was wrong in the old version)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

console.debug(`ServiceControl Url found in QS and stored in local storage: ${serviceControlUrl.value}`);
} else if (window.localStorage.getItem("scu")) {
serviceControlUrl.value = window.localStorage.getItem("scu");
serviceControlUrl.value = window.localStorage.getItem("scu") || undefined;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

|| undefined doesn't make sense to me...? If the getItem doesn't find the key, won't it return undefined anyway?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

window.localStorage.removeItem("mu");

const newSearch = "?scu=" + newServiceControlUrl.value + "&mu=" + newMonitoringUrl.value;
let newSearch = "?scu=" + newServiceControlUrl.value + "&mu=" + newMonitoringUrl.value;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my bad, fixed


router.beforeEach((to, from, next) => {
document.title = to.meta.title || "ServicePulse";
document.title = `${to.meta.title} || "ServicePulse"`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is changing the title from what it previously was

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Copy link
Member Author

@johnsimons johnsimons left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I addressed all comments @PhilBastian let me know

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not needed

onMounted(() => {
interval = setInterval(function () {
interval = window.setInterval(function () {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so it doesn't get confused with Node Timer, since we are also referencing the node definitions

const textBody = await response.text();
failedMessage.value.messageBody = textBody;
try {
failedMessage.value.messageBody = await response.text();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed this could throw when no body, so I added a catch


router.beforeEach((to, from, next) => {
document.title = to.meta.title || "ServicePulse";
document.title = `${to.meta.title} || "ServicePulse"`;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed


export function useIsMonitoringDisabled() {
return monitoringUrl.value === null || monitoringUrl.value === "" || monitoringUrl.value === "!";
return monitoringUrl.value === undefined || monitoringUrl.value === "" || monitoringUrl.value === "!";
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

const requestOptions: RequestInit = {
method: "POST",
};
if (payload !== undefined) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

console.debug(`ServiceControl Url found in QS and stored in local storage: ${serviceControlUrl.value}`);
} else if (window.localStorage.getItem("scu")) {
serviceControlUrl.value = window.localStorage.getItem("scu");
serviceControlUrl.value = window.localStorage.getItem("scu") || undefined;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

window.localStorage.removeItem("mu");

const newSearch = "?scu=" + newServiceControlUrl.value + "&mu=" + newMonitoringUrl.value;
let newSearch = "?scu=" + newServiceControlUrl.value + "&mu=" + newMonitoringUrl.value;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my bad, fixed

const lic = await getLicense(license);
license = lic;
license = await getLicense();
license.licenseEdition = computed(() => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I refactor all this code, tried using the spread operator but did not work either.
Also, the usage of this data, does not need .value, see https://github.com/Particular/ServicePulse/pull/1697/files#diff-97592647a6c6f377fdd850bdb6229985b9a414d6956fcc86213ff71f695b94d6

I tested it, and it works, but i would appreciate if you also have a look to make sure I am not introducing a bug here 😄

const hourDuration = moment.duration(60 * 1000); //this ensure that we never use minute formatting
const dayDuration = moment.duration(24 * 60 * 60 * 1000);

export function useFormatTime(value) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I thought I could take a shortcut 😄

So I converted all the functions now, but unsure about the function parameter types, I went with value: string, decimals: number. Is this right?

const props = defineProps({
dateUtc: String,
default: function () {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from reading the doco, I think this was wrong.
It should have been:

{ 
  dateUtc: { type: String, default: ... },
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

anyway, I fixed it

const props = withDefaults(defineProps<{ dateUtc: string }>(), { dateUtc: emptyDate });
let interval = null;
let interval: number | undefined = undefined;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left this one as undefined @PhilBastian, mostly because the window.clearInterval takes a number or undefined

}

function round(num: number, decimals: number) {
return Math.round(num + Number(`e+${decimals}`)) + Number(`e-${decimals}`);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hope I got this right.
I wasn't sure why it needs to be this complex!

registered_to: "",
status: "",
license_status: LicenseStatus.Unavailable,
licenseEdition: computed(() => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decided to move the computed into the "empty/default" object, thoughts @PhilBastian ?


interface SemVer {
semver: string | undefined;
semver: string | null;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Going with null

}

return undefined;
return params.find((param) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this still need to be null aware? i.e. params?.find((param) => param.name === key)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good question, not sure

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The assumption here is that params should either be empty array or not, but not null.
I also checked the usages of this and they seem to always pass an array.

@johnsimons johnsimons merged commit 8e522c9 into master Feb 7, 2024
@johnsimons johnsimons deleted the john/worm branch February 7, 2024 02:12
@mikeminutillo mikeminutillo added the Type: Refactoring Type: Refactoring label Feb 7, 2024
@mikeminutillo mikeminutillo added this to the vNext milestone Feb 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Type: Refactoring Type: Refactoring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants