-
Notifications
You must be signed in to change notification settings - Fork 12
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
new-log-viewer: Formalize config parameters and add management utilities. #51
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.
@Henry8192 Please help addressing the posted comments. I feel some design details could have been more clear to us if we added the function demos / tests.
decoderOptions: { | ||
// TODO: these shall come from config provider | ||
formatString: "%d{yyyy-MM-dd HH:mm:ss.SSS} [%process.thread.name] %log.level" + | ||
" %message%n", | ||
logLevelKey: "log.level", | ||
timestampKey: "@timestamp", | ||
formatString: DECODER_OPTIONS_DEFAULT.formatString, | ||
logLevelKey: DECODER_OPTIONS_DEFAULT.logLevelKey, | ||
timestampKey: DECODER_OPTIONS_DEFAULT.timestampKey, | ||
}, |
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 should now be getConfig(CONFIG_NAME.DECODER_OPTIONS)
, right?
new-log-viewer/src/utils/config.ts
Outdated
case CONFIG_NAME.THEME: | ||
return window.localStorage.getItem(LOCAL_STORAGE_KEY.THEME) as ConfigMap[T]; | ||
case CONFIG_NAME.PAGE_SIZE: | ||
return window.localStorage.getItem(LOCAL_STORAGE_KEY.PAGE_SIZE) as ConfigMap[T]; |
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.
To avoid returning value in undesired types, we previously discussed one possible solution to have TypeScript check the return types:
- We can create an object of type
Partial<>
of ConfigMap. - Then in the switch-cases, into the object we can assign values on different keys
code
. e.g.// TypeScript will show an error if we don't cast (parse) the localStorage value into a number result[CONFIG_NAME.PAGE_SIZE] = Number(window.localStorage.getItem(LOCAL_STORAGE_KEY.PAGE_SIZE));
return result[code] as ConfigMap[T];
since TypeScript assumes the values can be undefined in thePartial<>
type, although we should have assigned a value in the switch-cases.
I feel Step 1 & 3 may be optimized if we gain better knowledge of TypeScript. We can discuss more after you make the changes.
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.
Due to TypeScript's inability to validation the return type within the function body, the proposed approach is essentially a hack and a bit unclean. This is not implemented for now to avoid confusions.
…e size and default config values; improve validation and localStorage handling logic.
…ngs; update theme type in ConfigMap to THEME_NAME.
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.
Minor suggestions.
Co-authored-by: kirkrodrigues <2454684+kirkrodrigues@users.noreply.github.com>
…de review Co-authored-by: kirkrodrigues <2454684+kirkrodrigues@users.noreply.github.com>
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.
For the PR title, how about:
new-log-viewer: Formalize config parameters and add management utilities.
References
This PR follows #48.
Description
The new
utils/config.ts
provides 3 functions:getConfig
- takes in aCONFIG_NAME
(defined intypings/config.ts
) and returns the corresponding result defined inConfigMap
. If the code is invalid, returnnull
.testConfig
- validate aConfigUpdate
object (essentially a {code, value} pair). It is provided to users to test their configs, and is also used bysetConfig
to endorse inputs.setConfig
- takes in aConfigUpdate
object, validate the input usingtestConfig
, and store to localStorage.Validation performed