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 -- handle uncategorized owners #2268

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,17 @@
import AvatarLabel from 'components/AvatarLabel';

import { ResourceType } from 'interfaces';
import { getOwnersSectionConfig } from 'config/config-utils';

Check failure on line 10 in frontend/amundsen_application/static/js/components/OwnerEditor/index.spec.tsx

View workflow job for this annotation

GitHub Actions / test-unit-frontend (12.x)

'getOwnersSectionConfig' is defined but never used

import { OwnerEditor, OwnerEditorProps } from '.';
import { OwnerCategory } from 'interfaces/OwnerCategory';

Check failure on line 13 in frontend/amundsen_application/static/js/components/OwnerEditor/index.spec.tsx

View workflow job for this annotation

GitHub Actions / test-unit-frontend (12.x)

'OwnerCategory' is defined but never used
// import { renderOwnersSection } from './OwnerEditor';
import { OwnersSectionConfig } from 'config/config-types';

Check failure on line 15 in frontend/amundsen_application/static/js/components/OwnerEditor/index.spec.tsx

View workflow job for this annotation

GitHub Actions / test-unit-frontend (12.x)

'OwnersSectionConfig' is defined but never used

import * as Constants from './constants';

import * as ConfigUtils from 'config/config-utils';

const setup = (propOverrides?: Partial<OwnerEditorProps>) => {
const props: OwnerEditorProps = {
errorText: null,
Expand Down Expand Up @@ -74,4 +81,58 @@
});
});
});

describe('renderOwnersList', () => {
it('renders list of owners when categories not configured', () => {
const { wrapper } = setup({
itemProps: { owner1: {}, owner2: {}, owner3: {} },
});

expect(wrapper.find(AvatarLabel).length).toBe(3);
});

// getOwnersSectionConfig.mockReturnValue({ section: 'mocked config' });

it('renders owners grouped by category when categories configured', () => {
const { wrapper } = setup({
itemProps: {
owner1: { additionalOwnerInfo: { owner_category: 'label1' } },
// owner2: {},
// owner3: {},
},
});

jest.spyOn(ConfigUtils, 'getOwnersSectionConfig').mockReturnValue({
categories: [{ label: 'label1', definition: 'label1 definition' }],
});

console.log(wrapper.debug());

expect(wrapper.find(AvatarLabel).length).toBe(1);
// expect(wrapper.find(AvatarLabel).additionalOwnerInfo).toContain('label1');
// expect(wrapper.find('.owner-category-label').text()).toContain('label1');
});
});

// describe('renderOwnersList', () => {
// const { wrapper } = setup({
// itemProps: { owner1: {}, owner2: {}, owner3: {} },
// });

// jest.spyOn(ConfigUtils, 'getOwnersSectionConfig').mockReturnValue({
// categories: [{ label: 'label1', definition: 'label1 definition' }],
// });
// });

// describe('renderOwnersSection', () => {
// it('renders section for each category', () => {
// const section: OwnerCategory = {
// label: 'label1',
// definition: 'label1 definition',
// };
// const result = renderOwnersSection(section);

// expect(result.length).toBe(1);
// });
// });
});
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,18 @@ export class OwnerEditor extends React.Component<
// check if rendering an owner category that lacks any entries
let isEmptySection = false;

if (section) {
// if any owners uncategorized, set section to null to render an uncategorized owners list
Object.keys(itemProps).forEach((key) => {
if (!itemProps[key].additionalOwnerInfo?.owner_category) {
section = null;
}
});
Comment on lines +251 to +256
Copy link
Contributor

Choose a reason for hiding this comment

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

is this needed if you do the other check before this function is called? this feels like it might be more complicated than it needs to be


if (section !== null) {
isEmptySection = Object.keys(itemProps).every(
(key) =>
itemProps[key].additionalOwnerInfo.owner_category.toLowerCase() !==
section.label.toLowerCase()
section?.label?.toLowerCase()
);
}

Expand Down Expand Up @@ -313,8 +320,15 @@ export class OwnerEditor extends React.Component<

renderOwnersList = () => {
const sections = getOwnersSectionConfig().categories;
const { itemProps } = this.state;

if (sections.length > 0) {
if (
sections.length > 0 &&
// render default way if there are any uncategorized owners
Object.keys(itemProps).every((key) => {
return itemProps[key].additionalOwnerInfo?.owner_category;
})
) {
return (
<div>
{sections.map((section) => this.renderOwnersSection(section))}
Expand Down
Loading