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

Feature/metrics chart #2

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open

Conversation

SivaprasadAluri
Copy link
Owner

Description

Added Metrics Charts Styles Panel

Issues Resolved

opensearch-project#872

Comment on lines 68 to 72
let listItem = { ...list[name][index] };
listItem = {
...listItem,
[field]: value,
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

These two statements can be combined


const updateList = (value: string, index: number, name: string, field: string) => {
let list = { ...configList };
let listItem = { ...list[name][index] };
Copy link
Collaborator

Choose a reason for hiding this comment

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

What is the type of data present in the list[name][index]?

]);

const updateList = (value: string, index: number, name: string, field: string) => {
let list = { ...configList };
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not const? I do not see you updating the list object later in the code.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I also do not see an objective to create a new variable from configlist. Everywhere in this method, you are creating a copy of list variable using spread operator. You could have done the same using configlist.

};

const updateListWithAgg = (value: string[], index: number, name: string, field: string) => {
const list = { ...configList };
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same as the comment above. What is the requirement of creating this new variable?

...list[name].slice(0, index),
{
...listItem,
[field]: value.map((val) => val),
Copy link
Collaborator

Choose a reason for hiding this comment

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

How is [field]: value.map((val) => val) different from [field]: value? In case you need to create a copy, you could have used a spread operator instead. map function executes callback functions for each item, which is significantly slower than just copying elements.

Comment on lines 135 to 136
const unselectedFields = fieldOptionList.filter((field) => !selectedFields[field.label]);
return unselectedFields.filter((field) => numericalTypes.includes(field.type));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could have been

return fieldOptionList
  .filter((field) => !selectedFields[field.label])
  .filter((field) => numericalTypes.includes(field.type))

const getCommonUI = (lists, sectionName: string) =>
lists &&
lists.map((singleField, index: number) => (
<>
Copy link
Collaborator

Choose a reason for hiding this comment

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

each map item should have a key. See, your map item is not the div, but the fragment itself.

@@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import React, { useState } from 'react';
import React, { useEffect, useState } from 'react';
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do you need useEffect here? I do not see any changes below. This is the only change github is showing.

(dataConfig?.colorTheme?.length > 0 &&
dataConfig.colorTheme.find((colorSelected) => colorSelected.name.name === field)?.color) ||
'#000';
const fontSize = dataConfig?.fontSize?.fontSize ? dataConfig?.fontSize?.fontSize : 48;
Copy link
Collaborator

Choose a reason for hiding this comment

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

dataConfig?.fontSize?.fontSize question marks not required in the if block. If the condition is satisfied, the fontsize exists already.

style={{ color: getSelectedColorTheme(metric.label, index) }}
key={index}
>
{metric.aggregation.length !== 0 && { metricLabel } &&
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do you need brackets around { metricLabel }? Am I missing anything?

Copy link
Collaborator

@spattnaik spattnaik left a comment

Choose a reason for hiding this comment

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

Looks good now. Few more comments. Let me know, if they look good to you.

Comment on lines 130 to 131
.filter((field) => !selectedFields[field.label])
.filter((field) => numericalTypes.includes(field.type));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of looping over the items multiple times, is it possible to do the check once? Something like:
.filter((field) => !selectedFields[field.label] && numericalTypes.includes(field.type)). Let me know.

}
>
<EuiComboBox
aria-label="Accessible screen reader label"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please mention proper label. Accessible screen reader label is a generic text (probably provided by the component vendor).

placeholder="Custom label"
value={singleField.custom_label}
onChange={(e) => updateList(e.target.value, index, sectionName, 'custom_label')}
aria-label="Use aria labels when no actual label is in use"
Copy link
Collaborator

Choose a reason for hiding this comment

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

aria-label is not proper here as well. Read about what they are.

Signed-off-by: SivaprasadAluri <[email protected]>
Signed-off-by: SivaprasadAluri <[email protected]>
Signed-off-by: SivaprasadAluri <[email protected]>
Signed-off-by: SivaprasadAluri <[email protected]>
Signed-off-by: SivaprasadAluri <[email protected]>
Signed-off-by: SivaprasadAluri <[email protected]>
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.

2 participants