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

feat(TimeRangeSelector): added new input Time Range Selector #216

Merged
merged 9 commits into from
Aug 12, 2024

Conversation

NasgulNexus
Copy link
Contributor

No description provided.

@gravity-ui-bot
Copy link
Contributor

Preview is ready.

@gravity-ui-bot
Copy link
Contributor

Playwright Test Component is ready.

return times.filter(({value: time}) => time > cutoff);
}

return times.filter(({value: time}) => time < cutoff);
Copy link
Collaborator

Choose a reason for hiding this comment

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

let's remove the code duplication

just like that
return times.filter(({value: time}) => direction === 'greater' ? time > cutoff : time < cutoff)

import {ObjectIndependentView, ViewController, isStringSpec} from '../../../../core';

const START_TIME = 'start';
const END_TIME = 'end';
Copy link
Collaborator

Choose a reason for hiding this comment

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

I have seen similar constants in TimeRangeSelector 👀


_spec.viewSpec.layout = 'row';

endTimeSpec = _spec;
Copy link
Collaborator

@bocembocem bocembocem Aug 9, 2024

Choose a reason for hiding this comment

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

code is duplicated
let's do something like this

const [startTimeSpec, endTimeSpec] = [START_TIME, END_TIME].map((key) => {
   if (spec.properties?.[key] && isStringSpec(spec.properties[key])) {
            const spec = cloneDeep(spec.properties[key]);

            spec.viewSpec.layout = 'row';

            return spec;
        }
        
        return;
});


if (input.value?.[END_TIME] && isString(input.value[END_TIME])) {
startTimeOptions = filterTimeArray(defaultTimeOptions, input.value[END_TIME], 'less');
}
Copy link
Collaborator

@bocembocem bocembocem Aug 9, 2024

Choose a reason for hiding this comment

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

same comment about duplication

const _spec = cloneDeep(spec.properties[END_TIME]);

endTimeSpec = _spec;
}
Copy link
Collaborator

@bocembocem bocembocem Aug 9, 2024

Choose a reason for hiding this comment

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

same comment about duplication

const property = spec.properties?.[key];

if (isStringSpec(property)) {
const _spec = cloneDeep(property);
Copy link
Collaborator

Choose a reason for hiding this comment

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

you have no reason to clone this spec

it looks like this memo might be like this

const [startTimeSpec, endTimeSpec] = React.useMemo(() =>
   [START_TIME, END_TIME].map(
      (key) => isStringSpec(spec.properties?.[key]) ? spec.properties?.[key] : undefined)
, [spec.properties]);

@NasgulNexus NasgulNexus merged commit 2acde25 into main Aug 12, 2024
4 checks passed
@NasgulNexus NasgulNexus deleted the time-input branch August 12, 2024 12:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants