-
Notifications
You must be signed in to change notification settings - Fork 26
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
Toggle graphs in the training board olena #825
base: develop
Are you sure you want to change the base?
Toggle graphs in the training board olena #825
Conversation
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.
thanks for the work! a few comments on how to improve it, please also fix the tests/lint found by the CI
const props = defineProps({ | ||
initiallyOpen: { | ||
type: String, | ||
default: "true", //open by 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.
I personally find it clearer to use type-only props declarations. also, you can have a preciser type (only two value are possible here, true or false) and avoid JSON.parse
at all.
const props = defineProps({ | |
initiallyOpen: { | |
type: String, | |
default: "true", //open by default | |
}, | |
}); | |
const props = withDefaults( | |
defineProps<{ | |
initiallyOpen?: boolean; | |
}>(), | |
{ initiallyOpen: true }, | |
); |
onMounted(() => { | ||
opened.value = JSON.parse(props.initiallyOpen); | ||
}); |
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.
onMounted
is quite special, it doesn't get triggered when data change for example. better to watch for prop to change instead, so that if someone change the prop from the outside, it will behave as expected.
onMounted(() => { | |
opened.value = JSON.parse(props.initiallyOpen); | |
}); | |
watch(props, ({ initiallyOpen }) => { | |
opened.value = initiallyOpen; | |
}); |
@@ -186,6 +166,9 @@ import ModelExchangeIcon from "@/assets/svg/ModelExchangeIcon.vue"; | |||
import ModelUpdateIcon from "@/assets/svg/ModelUpdateIcon.vue"; | |||
import PeopleIcon from "@/assets/svg/PeopleIcon.vue"; | |||
import Contact from "@/assets/svg/Contact.vue"; | |||
import DropdownCard from "../containers/DropdownCard.vue"; | |||
|
|||
const currentOpen = ref(localStorage.getItem('initiallyOpen') || 'false'); |
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.
now that it is a boolean, parsing as to be updated, as close as the loading point you can. it helps with debugging because you know where the value is created. an easy parser is shown below.
also, the "or" op is quite unsafe (as many values can be falsy), better to use a nullish coaslescing which only check for null
and undefined
.
const currentOpen = ref(localStorage.getItem('initiallyOpen') || 'false'); | |
const currentOpen = ref(localStorage.getItem("initiallyOpen") === "true" ? true : false); |
one can even make it safer by checking for the full valid range, which would be the nicest (as it fails on unexpected values, which is always nice for finding logical bugs)
function loadCurrentOpen(): boolean {
const raw = localStorage.getItem("initiallyOpen");
switch (raw) {
case "true":
return true;
case "false":
case null:
return false;
default:
throw new Error(`unexpected loadCurrent stored value: ${raw}`);
}
}
const currentOpen = ref(loadCurrentOpen());
@@ -51,8 +51,9 @@ | |||
</IconCardSmall> | |||
</div> | |||
|
|||
<!-- Training and validation loss charts --> | |||
<div | |||
<DropdownCard :initiallyOpen="currentOpen" @click="toggleAdvancedInfo"> |
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.
consider renaming currentOpen
to initiallyOpen
, then you can use the short version of the attribute, which is a bit nicer
<DropdownCard :initiallyOpen="currentOpen" @click="toggleAdvancedInfo"> | |
<DropdownCard :initiallyOpen @click="toggleAdvancedInfo"> |
Client-side
Additions & Modifications:
Enhanced DropdownCard Component:
Refinements in the Training Information Section:
Removed Training Logs from Training Information: