-
Notifications
You must be signed in to change notification settings - Fork 26
Migrating composables and a few vue component #1697
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
Conversation
Started adding typings for REST api resources
PhilBastian
left a comment
There was a problem hiding this 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) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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(() => { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 === "!"; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why?
There was a problem hiding this comment.
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"`; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
johnsimons
left a comment
There was a problem hiding this 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
There was a problem hiding this comment.
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 () { |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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"`; |
There was a problem hiding this comment.
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 === "!"; |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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(() => { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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 () { |
There was a problem hiding this comment.
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: ... },
}There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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}`); |
There was a problem hiding this comment.
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(() => { |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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) => { |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good question, not sure
There was a problem hiding this comment.
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.
Migrating composables and a few vue component
Started adding typings for REST api resources