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