Unverified Commit 9d73992b authored by christina stead's avatar christina stead Committed by GitHub

Update search results to include badges and display them (#398)

* update search to include badges

* fix test

* slight change

* remove mapping for badges

* fix lint

* remove badge as a search term since its not in the filters in ui

* update test, remove unneeded import
parent 2f7930d5
......@@ -3,7 +3,7 @@ import json
from http import HTTPStatus
from typing import Any, Dict, Optional # noqa: F401
from typing import Any, Dict # noqa: F401
from flask import Response, jsonify, make_response, request
from flask import current_app as app
......
from typing import Dict, List # noqa: F401
# These can move to a configuration when we have custom use cases outside of these default values
valid_search_fields = {
'column',
......@@ -19,6 +20,7 @@ def map_table_result(result: Dict) -> Dict:
'description': result.get('description', None),
'database': result.get('database', None),
'schema': result.get('schema', None),
'badges': result.get('badges', None),
'last_updated_timestamp': result.get('last_updated_timestamp', None),
}
......
......@@ -9,6 +9,7 @@ import BookmarkIcon from 'components/common/Bookmark/BookmarkIcon';
import { getDatabaseDisplayName, getDatabaseIconClass } from 'config/config-utils';
import { formatDate } from 'utils/dateUtils';
import BadgeList from 'components/common/BadgeList';
export interface TableListItemProps {
table: TableResource;
......@@ -53,11 +54,10 @@ class TableListItem extends React.Component<TableListItemProps, {}> {
</div>
<div className="resource-badges">
{
!!table.last_updated_timestamp &&
!!table.badges && table.badges.length > 0 &&
<div>
<div className="title-3">Last Updated</div>
<div className="body-secondary-3">
{ formatDate({ epochTimestamp: table.last_updated_timestamp }) }
<BadgeList badges={ table.badges } />
</div>
</div>
}
......
......@@ -5,10 +5,10 @@ import { shallow } from 'enzyme';
import { Link } from 'react-router-dom';
import BookmarkIcon from 'components/common/Bookmark/BookmarkIcon';
import TableListItem, { TableListItemProps } from '../';
import { ResourceType } from 'interfaces';
import { ResourceType, Badge, TagType } from 'interfaces';
import * as ConfigUtils from 'config/config-utils';
import { formatDate } from 'utils/dateUtils';
import BadgeList from 'components/common/BadgeList';
const MOCK_DISPLAY_NAME = 'displayName';
const MOCK_ICON_CLASS = 'test-class';
......@@ -33,6 +33,7 @@ describe('TableListItem', () => {
description: 'I am the description',
key: '',
last_updated_timestamp: 1553829681,
badges: [ { tag_name: 'badgeName', tag_type: TagType.BADGE } ],
name: 'tableName',
schema: 'tableSchema',
},
......@@ -126,26 +127,35 @@ describe('TableListItem', () => {
expect(resourceBadges.exists()).toBe(true);
});
describe('if props.table has last_updated_timestamp', () => {
it('renders Last Updated title', () => {
expect(resourceBadges.children().at(0).children().at(0).text()).toEqual('Last Updated');
describe('if props.table has badges', () => {
it('renders BadgeList for badges', () => {
expect(resourceBadges.find(BadgeList).props().badges).toEqual(props.table.badges);
});
});
it('renders getDateLabel value', () => {
const expectedString = formatDate({ epochTimestamp: props.table.last_updated_timestamp });
expect(resourceBadges.children().at(0).children().at(1).text()).toEqual(expectedString);
describe('if props.table does not have badges', () => {
it('does not render badges section', () => {
const { props, wrapper } = setup({ table: {
type: ResourceType.table,
cluster: '',
database: '',
description: 'I am the description',
key: '',
badges: null,
name: 'tableName',
schema: 'tableSchema',
}});
expect(wrapper.find('.resource-badges').children()).toHaveLength(1);
});
});
describe('if props.table does not have last_updated_timestamp', () => {
it('does not render Last Updated section', () => {
it('or if they are empty does not render badges section', () => {
const { props, wrapper } = setup({ table: {
type: ResourceType.table,
cluster: '',
database: '',
description: 'I am the description',
key: '',
last_updated_timestamp: null,
badges: [],
name: 'tableName',
schema: 'tableSchema',
}});
......
import { PeopleUser } from './User';
import { Badge } from './Tags';
export enum ResourceType {
table = "table",
......@@ -28,6 +29,7 @@ export interface TableResource extends Resource {
last_updated_timestamp?: number;
name: string;
schema: string;
badges?: Badge[];
};
export interface UserResource extends Resource, PeopleUser {
......
......@@ -27,6 +27,7 @@ MOCK_TABLE_RESULTS = {
'name': 'test_table',
'schema': 'test_schema',
'tags': [],
'badges': []
}
]
}
......@@ -41,6 +42,7 @@ MOCK_PARSED_TABLE_RESULTS = [
'last_updated_timestamp': 1527283287,
'name': 'test_table',
'schema': 'test_schema',
'badges': []
}
]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment