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 dynamically display columns #103

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

Conversation

KishoreKicha14
Copy link
Contributor

@KishoreKicha14 KishoreKicha14 commented Feb 7, 2025

Screenshot 2025-02-07 at 9 46 49 AM Screenshot 2025-02-07 at 9 46 43 AM Screenshot 2025-02-07 at 9 46 37 AM Screenshot 2025-02-07 at 9 46 29 AM

Description

Problem:
The Top N queries table can display:

Only queries
Only groups
Combination of queries/groups
Some columns are applicable to only queries (eg: indices) and others to only groups (eg: query count).

Table should dynamically display the applicable columns based on the data in the table and only display the applicable columns.

This PR ensures that even when no selection is made and all query types are groups, the applicable columns are dynamically displayed.

Issues Resolved

Closes: [#45]

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Kishore Kumaar Natarajan added 2 commits February 7, 2025 01:47
Signed-off-by: Kishore Kumaar Natarajan <[email protected]>
Signed-off-by: Kishore Kumaar Natarajan <[email protected]>
Signed-off-by: Kishore Kumaar Natarajan <[email protected]>
@deshsidd
Copy link
Collaborator

deshsidd commented Feb 7, 2025

Why are the latency, cpu and memory columns displayed twice in each screenshot? @KishoreKicha14

@deshsidd
Copy link
Collaborator

deshsidd commented Feb 7, 2025

If it’s not too big a change, we can debate about changing the column names to average latency, average cpu…… and so on for only groups? What do others think about this?

Copy link
Member

@ansjcy ansjcy left a comment

Choose a reason for hiding this comment

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

Other than the issues @deshsidd mentioned above, the rest of the logic looks good to me!
@KishoreKicha14 Thanks for the change, could you also add unit tests and cypress tests in this PR as well?

@@ -259,6 +275,15 @@ const QueryInsights = ({
truncateText: true,
},
];
const columnsToShow = selectedFilter === 'SIMILARITY' ? groupColumns : queryColumns;
const filteredQueries = queries.filter((query) => {
Copy link
Member

Choose a reason for hiding this comment

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

How about

const filteredQueries = queries.filter(query => 
  !selectedFilter || query.group_by === selectedFilter
);

?

@KishoreKicha14
Copy link
Contributor Author

KishoreKicha14 commented Feb 7, 2025

@deshsidd @ansjcy Updated the screenshots.

Kishore Kumaar Natarajan added 2 commits February 12, 2025 10:26
Signed-off-by: Kishore Kumaar Natarajan <[email protected]>
Signed-off-by: Kishore Kumaar Natarajan <[email protected]>
@@ -22,7 +22,7 @@ const clearAll = () => {
};

describe('Query Insights Dashboard', () => {
// Setup before each test
// // Setup before each test
Copy link
Member

Choose a reason for hiding this comment

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

please remove

cy.contains('.euiTableHeaderCell', header).should('exist');
});
});
beforeEach(() => {
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 need beforeEach here? this looks identical to

cy.get('.euiFilterSelectItem').contains('group').click();

// Wait for table update
cy.get('.euiTableHeaderCell').should('have.length.lessThan', 20);
Copy link
Member

Choose a reason for hiding this comment

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

Why dont we assert a fixed length here? The number of headers in each scenarios should be deterministic.

];

// Wait for the table to load by checking if headers are visible
cy.get('.euiTableHeaderCell').should('have.length.greaterThan', 6);
Copy link
Member

Choose a reason for hiding this comment

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

why greater then instead of equals?


await waitFor(() => expect(screen.getByRole('table')).toBeInTheDocument());
const headers = await waitFor(() => screen.getAllByRole('columnheader', { hidden: false }));
console.log(
Copy link
Member

Choose a reason for hiding this comment

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

Please remove the console log.

const expectedHeaders = ['ID', 'Type', 'Query Count', 'Latency', 'CPU Time', 'Memory Usage'];
expectedHeaders.forEach((header) => {
expect(
headers.some((h) => h.textContent?.trim().toLowerCase() === header.toLowerCase())
Copy link
Member

Choose a reason for hiding this comment

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

why headers.some?
we should also compare the actual value without ignoring the case.

renderQueryInsights();
await waitFor(() => expect(screen.getByRole('table')).toBeInTheDocument());
const typeElements = screen.getAllByText('Type');
const typeFilterButton = typeElements.find((el) => el.closest('button')); // Ensure it's a button
Copy link
Member

Choose a reason for hiding this comment

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

It is a button. why use closest?


await waitFor(() => {
expectedHeaders.forEach(async (header) => {
expect(await screen.findByText(header)).toBeInTheDocument();
Copy link
Member

Choose a reason for hiding this comment

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

instead of finding on the whole screen and assert to be in document, could you narrow down the test to that specific table?

];

await waitFor(() => {
expectedHeaders.forEach(async (header) => {
Copy link
Member

Choose a reason for hiding this comment

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

Also, the sequence matters here. let's also test the header sequence.


// Verify each expected header exists
expectedHeaders.forEach((header) => {
cy.contains('.euiTableHeaderCell', header).should('exist');
Copy link
Member

Choose a reason for hiding this comment

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

The sequence matters here. let's also test the header sequence.

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