Skip to content
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

Datepicker bugfixes + theme support #35

Merged
merged 21 commits into from
Apr 24, 2020
Merged

Conversation

peterhass
Copy link
Contributor

Datepicker in 8.3.0 was missing nebenan-react-datepicker package (ÜBERRASCHUNG).

@peterhass peterhass requested a review from max-degterev April 20, 2020 17:34
package.json Outdated
@@ -87,6 +85,10 @@
"tiny-lr": "^1.1.1",
"vinyl-source-stream": "^2.0.0"
},
"dependencies": {
"nebenan-react-datepicker": "^1.0.0",
"nebenan-helpers": "^4.1.1"
Copy link
Contributor

Choose a reason for hiding this comment

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

-> peerDependencies

do we even need it?

Copy link
Contributor Author

@peterhass peterhass Apr 21, 2020

Choose a reason for hiding this comment

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

nebenan-helpers is used in datepicker (dom, keymanager, eventproxy).

Will add them to peerDependencies - but I don't fully get why. It's not like they are some kind of plugins. Wouldn't matter to have two different versions in dependency tree. (npm flattens dependencies by itself as far as I know, so as long it's not nebenan-react-datepicker ^2.x.x, every ^1.x.x should resolve to the same package)

@peterhass peterhass force-pushed the fix-datepicker-dependency branch from 9f9219f to 4ad6182 Compare April 21, 2020 06:59
@@ -1,2 +1,2 @@
@import 'nebenan-ui-kit/_index.scss';
@import 'src/**/*.scss';
@import 'src/**/index.scss';
Copy link
Contributor Author

@peterhass peterhass Apr 21, 2020

Choose a reason for hiding this comment

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

Preview in nebenan-form loaded datepickers theme.scss, nebenan-frontend didn't import it because it only imports index.scss files.

Note: All other scss files in nebenan-form/src/** are called index.scss.

@peterhass peterhass changed the title Fix dependencies Datepicker bugfixes Apr 21, 2020
package.json Outdated
@@ -84,12 +82,16 @@
"stylelint": "^13.2.1",
"stylelint-config-nebenan": "^1.6.0",
"terser": "^4.6.7",
"nebenan-react-datepicker": "^1.0.0",
Copy link
Contributor

Choose a reason for hiding this comment

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

nebenan-react-datepicker needs to be a direct dependency

nebenan-helpers needs to be a peer (loaded by multiple packages, need to insure single version)


const stripPrefix = (key, prefix) => {
const strippedKey = key.substring(prefix.length);
return strippedKey.charAt(0).toLowerCase() + strippedKey.slice(1);
Copy link
Contributor

Choose a reason for hiding this comment

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

key.replace(new RegExp(^${prefix}), '') ?
precompile regex out of the loop and you won't need the function?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Regex may even be slower and I would still need to convert first character to lower case

calendarRoot -> root
calendarSuperPicker -> superPicker

return strippedKey.charAt(0).toLowerCase() + strippedKey.slice(1);
};

export const getSubTheme = (theme, prefix) => (
Copy link
Contributor

Choose a reason for hiding this comment

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

theme = {} would reduce code


export const getSubTheme = (theme, prefix) => (
Object.entries(theme || {})
.reduce((acc, [key, value]) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

you seem to double check the key:

1 .startsWith
2 .substring

just generate 1 regex with prefix and run over all, if there aint no prefix it will just do nothing

Copy link
Contributor Author

@peterhass peterhass Apr 22, 2020

Choose a reason for hiding this comment

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

Won't work because ...

if (!otherTheme) return baseTheme;

const result = {};
Object.keys(baseTheme).forEach((key) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

if return an object why not reduce?

const baseValue = baseTheme[key];
const extendValue = otherTheme[key];

result[key] = [baseValue, extendValue].filter((v) => Boolean(v)).join(' ');
Copy link
Contributor

Choose a reason for hiding this comment

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

could use cslx or write so [baseValue, extendValue].filter(Boolean).join(' ')

@peterhass
Copy link
Contributor Author

@suprMax ready for next run

@@ -23,6 +24,7 @@ class Datepicker extends InputComponent {
'handleClick',
'handleClear',
);
this.getCalendarTheme = memorize(getCalendarTheme.bind(null, baseCalendarTheme));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

lodash memorize only uses first argument as cache key. Good thing I read the documentation twice.

lodash/lodash#2115 (comment)

@peterhass peterhass changed the title Datepicker bugfixes Datepicker bugfixes + theme support Apr 22, 2020
package.json Outdated
"peerDependencies": {
"@babel/runtime": "^7.9.2",
"clsx": "^1.1.0",
"nebenan-helpers": "^4.2.0-beta.0",
"tiny-lr": "^1.1.1",
Copy link
Contributor

Choose a reason for hiding this comment

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

@peterhass peterhass merged commit c291523 into master Apr 24, 2020
@peterhass peterhass deleted the fix-datepicker-dependency branch April 24, 2020 07:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants