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

fix: properly handle all formats of options sources #963

Merged
merged 1 commit into from
Jan 3, 2024

Conversation

Skaiir
Copy link
Contributor

@Skaiir Skaiir commented Dec 29, 2023

Closes #960

@bpmn-io-tasks bpmn-io-tasks bot added the needs review Review pending label Dec 29, 2023
@Skaiir Skaiir changed the base branch from develop to master December 29, 2023 07:34
@github-actions github-actions bot temporarily deployed to demo-960-fix-dynamic-options January 2, 2024 16:56 Destroyed
Copy link
Contributor

@vsgoulart vsgoulart left a comment

Choose a reason for hiding this comment

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

It worked fine while testing, I have some minor comments though

export function useLabelCorrelation(options) {

// This allows us to retrieve the label from a value in linear time
const labelMap = useMemo(() => Object.assign({}, ...options.map((o) => ({ [_getValueHash(o.value)]: o.label }))), [ options ]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you have any performance issues? It's not a good idea to abuse useMemo,useCallback, etc because of memory leaks

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, this is why it's here and it's always been that way. I've just brought this pattern into a hook because we use it a few places. Otherwise the complexity is n^2 and we want the components to deal with values of n > 1000

* This hook allows us to retrieve the label from a value in linear time by caching it in a map
* @param {Array} options
*/
export function useLabelCorrelation(options) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
export function useLabelCorrelation(options) {
export function useGetLabelCorrelation(options) {

@@ -64,8 +66,7 @@ export default function Taglist(props) {
onChange: props.onChange
});

// We cache a map of option values to their index so that we don't need to search the whole options array every time to correlate the label
const valueToOptionMap = useMemo(() => Object.assign({}, ...options.map((o, x) => ({ [o.value]: options[x] }))), [ options ]);
const correlateLabel = useLabelCorrelation(options);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const correlateLabel = useLabelCorrelation(options);
const getLabelCorrelation = useLabelCorrelation(options);

@@ -19,6 +20,15 @@ export function sanitizeDateTimePickerValue(options) {
return value;
}

export function isDeepIncluded(value, array) {
Copy link
Contributor

Choose a reason for hiding this comment

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

The name is not very descriptive, I think we can improve it

Suggested change
export function isDeepIncluded(value, array) {
export function hasEqualValue(value, array) {

@@ -1,4 +1,5 @@
import { useRef } from 'preact/hooks';
import isDeepEqual from 'lodash/isEqual';
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's not rename it unless it's necessary

Suggested change
import isDeepEqual from 'lodash/isEqual';
import isEqual from 'lodash/isEqual';

@github-actions github-actions bot temporarily deployed to demo-960-fix-dynamic-options January 3, 2024 13:27 Destroyed
@github-actions github-actions bot temporarily deployed to demo-960-fix-dynamic-options January 3, 2024 13:52 Destroyed
@Skaiir Skaiir merged commit 571c67a into master Jan 3, 2024
10 of 11 checks passed
@Skaiir Skaiir deleted the 960-fix-dynamic-options branch January 3, 2024 13:54
@bpmn-io-tasks bpmn-io-tasks bot removed the needs review Review pending label Jan 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

Dynamic options aren't reliable
2 participants