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

CB-3703 save product configuration from ui #2334

Merged

Conversation

yagudin10
Copy link
Member

No description provided.

@yagudin10 yagudin10 changed the title CB-4560 api for saving product configuration CB-3703 save product configuration from ui Jan 25, 2024
@Wroud Wroud marked this pull request as ready for review January 29, 2024 09:30
baseFeatures: [] as string[],
};
const settingsSchema = schema.object({
baseFeatures: schema.array(schema.string()).default([]),
Copy link
Contributor

Choose a reason for hiding this comment

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

should we use array of enums? so it is more typescript friendly

Copy link
Member

Choose a reason for hiding this comment

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

features is extendable entity, so we can't declare all possible values

if (typeof result === 'string') {
element.setCustomValidity(result);
return false;
} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

no need for this else you can just go with

element.setCustomValidity('');
return true;

Copy link
Member

Choose a reason for hiding this comment

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

fixed

const result = validation(value);

try {
if (typeof result === 'string') {
Copy link
Contributor

Choose a reason for hiding this comment

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

what is expected behavior in case where result is an empty string? feels like in this case we should go in else statement

so I suggest to add extra check

if (typeof result === 'string' && result)

Copy link
Member

Choose a reason for hiding this comment

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

empty string will be treated as invalid field but with no message = no message must be treated as a bug (validation function must not return empty strings)

if (target.value === '') {
return;
}
if (target.validity.valid === true) {
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we validate it if it is already valid?
probably, this should be
target.validity.valid === true

Copy link
Member

Choose a reason for hiding this comment

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

  1. we want to validate on blur
  2. browser validation focus first invalid field (so if it's invalid it will be impossible to focus other element)


constructor(readonly name: string, readonly parent?: SettingsGroup) {
this.id = uuid();
this.subGroups = [];
Copy link
Contributor

Choose a reason for hiding this comment

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

is strict order here required? may be we can go with Set (if not) or even create an OrderedSet like you did with OrderedMap (if yes). I just want this staff to be immutable so we don't mess up the settings and it has unique tabs and stuff

Copy link
Member

Choose a reason for hiding this comment

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

added better types

settings: ScopeSettingsItem[];

constructor() {
this.settings = [];
Copy link
Contributor

Choose a reason for hiding this comment

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

same here for Set if you think it is a valuable idea

Copy link
Member

Choose a reason for hiding this comment

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

added better typing

})),
);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Should supported languages always be appeared? If so, I suggest to add notification here. so if there are no supported languages, we can find a bug once it appeared

Copy link
Member

Choose a reason for hiding this comment

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

we can find it by trying to switch to another language (we will see only english option)
actually we don't want to display any notifications to users because we will try to fall back to english and give users access to application
they will notice that language is not as should be in case they use other langoages than english


useEffect(() => {
if (ref.current) {
ref.current.addEventListener('scroll', e => {
Copy link
Contributor

Choose a reason for hiding this comment

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

please, add removeEventListener

Copy link
Member

Choose a reason for hiding this comment

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

fixed

list.push({ group, settings: groupSettings || [] });
}

useEffect(() => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I would like to see this logic moved to the hook so it is easier to read this component

Copy link
Member

Choose a reason for hiding this comment

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

fixed

@sergeyteleshev
Copy link
Contributor

also do yarn install for EE to update lock files with new lib

}

return schema.parse(undefined);
Copy link
Member

Choose a reason for hiding this comment

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

Why do we want to parse undefined here?

Copy link
Member

Choose a reason for hiding this comment

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

to get default value from schema (there no better way to do it)

Copy link
Member

Choose a reason for hiding this comment

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

what about schema.shape[name].default?

Copy link
Member

Choose a reason for hiding this comment

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

it's same as schema.string().default('ass') (shape returns schema object) we can't get default value this way

import type { SettingsGroup } from './SettingsGroup';

export interface ISettingOptions {
id: string | number;
Copy link
Member

Choose a reason for hiding this comment

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

maybe we want to use one type for "id"?

Copy link
Member

Choose a reason for hiding this comment

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

agree

const changes = {};

for (const [key, value] of this.changes) {
setByPath(changes, key, value);
Copy link
Member

Choose a reason for hiding this comment

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

Probably we do not want to mutate object from util function

Copy link
Member

Choose a reason for hiding this comment

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

in this case it's expected, function accepts object, key and value and it will mutate object
we don't need immutable object here

options: this.localizationService.supportedLanguages.map(language => ({
id: language.isoCode,
name: language.displayName,
})) || [{ id: 'en', name: 'English' }],
Copy link
Member

Choose a reason for hiding this comment

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

Seems supportedLanguages are [] by default so the code will never fallback to the default object

const defaultOptions = [{ id: 'en', name: 'English' }];
const options = this.localizationService.supportedLanguages.length > 0 ? this.localizationService.supportedLanguages.map(language => ({
          id: language.isoCode,
          name: language.displayName,
        })) : defaultOptions

Copy link
Member

Choose a reason for hiding this comment

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

fixed in other way, now this.localizationService.supportedLanguages must never be empty

const changed = serverSettingsService.isChanged;

return (
<Form context={form} style={{ height: '100%', display: 'flex', flexDirection: 'column' }}>
Copy link
Member

Choose a reason for hiding this comment

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

Could you move inline styles to the css module?

Copy link
Member

Choose a reason for hiding this comment

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

fixed

type: ESettingsValueType;

group: SettingsGroup;
name: string;
Copy link
Member

Choose a reason for hiding this comment

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

TLocalizationToken instead of string for "name" and "description"

}

function handleClick(id: string) {
document.querySelector('#' + getSettingGroupId(id))?.scrollIntoView();
Copy link
Member

Choose a reason for hiding this comment

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

Can we do it in react way using ref?

Copy link
Member

Choose a reason for hiding this comment

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

we can but it will be rocketsciense


export const SettingsGroups = observer<Props>(function SettingsGroups({ treeData }) {
function getNodeHeight(id: string) {
return 24;
Copy link
Member

Choose a reason for hiding this comment

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

const NODE_HEIGHT= 24;

Copy link
Member

Choose a reason for hiding this comment

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

there is no need (used once, keep simple)

@sergeyteleshev sergeyteleshev self-requested a review January 30, 2024 09:30
@Wroud Wroud merged commit fdde434 into devel Jan 31, 2024
2 of 5 checks passed
@Wroud Wroud deleted the CB-3703-ability-to-edit-configuration-in-the-settings-panel branch January 31, 2024 17:33
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.

5 participants