mirror of
https://github.com/ansible/awx.git
synced 2026-03-21 02:47:35 -02:30
Replace Lookup tags with pf-react Chip component
This commit is contained in:
@@ -114,8 +114,7 @@ describe('<Lookup />', () => {
|
|||||||
removeIcon.simulate('click');
|
removeIcon.simulate('click');
|
||||||
expect(spy).toHaveBeenCalled();
|
expect(spy).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
test('"wrapTags" method properly handles data', () => {
|
test('renders chips from prop value', () => {
|
||||||
const spy = jest.spyOn(Lookup.prototype, 'wrapTags');
|
|
||||||
mockData = [{ name: 'foo', id: 0 }, { name: 'bar', id: 1 }];
|
mockData = [{ name: 'foo', id: 0 }, { name: 'bar', id: 1 }];
|
||||||
const wrapper = mount(
|
const wrapper = mount(
|
||||||
<I18nProvider>
|
<I18nProvider>
|
||||||
@@ -130,9 +129,10 @@ describe('<Lookup />', () => {
|
|||||||
/>
|
/>
|
||||||
</I18nProvider>
|
</I18nProvider>
|
||||||
);
|
);
|
||||||
expect(spy).toHaveBeenCalled();
|
const chip = wrapper.find('li.pf-c-chip');
|
||||||
const pill = wrapper.find('span.awx-c-tag--pill');
|
const overflowChip = wrapper.find('.pf-c-chip.pf-m-overflow');
|
||||||
expect(pill).toHaveLength(2);
|
expect(chip).toHaveLength(1);
|
||||||
|
expect(overflowChip).toHaveLength(1);
|
||||||
});
|
});
|
||||||
test('toggleSelected successfully adds/removes row from lookupSelectedItems state', () => {
|
test('toggleSelected successfully adds/removes row from lookupSelectedItems state', () => {
|
||||||
mockData = [{ name: 'foo', id: 1 }];
|
mockData = [{ name: 'foo', id: 1 }];
|
||||||
|
|||||||
16
src/app.scss
16
src/app.scss
@@ -228,26 +228,10 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.awx-c-icon--remove {
|
|
||||||
padding-left: 10px;
|
|
||||||
&:hover {
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.awx-c-list {
|
.awx-c-list {
|
||||||
border-bottom: 1px solid #d7d7d7;
|
border-bottom: 1px solid #d7d7d7;
|
||||||
}
|
}
|
||||||
|
|
||||||
.awx-c-tag--pill {
|
|
||||||
color: var(--pf-global--BackgroundColor--light-100);
|
|
||||||
background-color: rgb(0, 123, 186);
|
|
||||||
border-radius: 3px;
|
|
||||||
margin: 1px 2px;
|
|
||||||
padding: 0 10px;
|
|
||||||
display: inline-block;
|
|
||||||
}
|
|
||||||
|
|
||||||
.at-c-listCardBody {
|
.at-c-listCardBody {
|
||||||
--pf-c-card__footer--PaddingX: 0;
|
--pf-c-card__footer--PaddingX: 0;
|
||||||
--pf-c-card__footer--PaddingY: 0;
|
--pf-c-card__footer--PaddingY: 0;
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ import React, { Fragment } from 'react';
|
|||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { SearchIcon, CubesIcon } from '@patternfly/react-icons';
|
import { SearchIcon, CubesIcon } from '@patternfly/react-icons';
|
||||||
import {
|
import {
|
||||||
|
Chip,
|
||||||
|
ChipGroup,
|
||||||
Modal,
|
Modal,
|
||||||
Button,
|
Button,
|
||||||
EmptyState,
|
EmptyState,
|
||||||
@@ -134,17 +136,6 @@ class Lookup extends React.Component {
|
|||||||
this.handleModalToggle();
|
this.handleModalToggle();
|
||||||
}
|
}
|
||||||
|
|
||||||
wrapTags (tags = []) {
|
|
||||||
return tags.map(tag => (
|
|
||||||
<span className="awx-c-tag--pill" key={tag.id}>
|
|
||||||
{tag.name}
|
|
||||||
<Button className="awx-c-icon--remove" id={tag.id} onClick={() => this.toggleSelected(tag)}>
|
|
||||||
x
|
|
||||||
</Button>
|
|
||||||
</span>
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
const {
|
const {
|
||||||
isModalOpen,
|
isModalOpen,
|
||||||
@@ -159,6 +150,19 @@ class Lookup extends React.Component {
|
|||||||
} = this.state;
|
} = this.state;
|
||||||
const { lookupHeader = 'items', value, columns } = this.props;
|
const { lookupHeader = 'items', value, columns } = this.props;
|
||||||
|
|
||||||
|
let chips = null;
|
||||||
|
if (value) {
|
||||||
|
chips = (
|
||||||
|
<ChipGroup>
|
||||||
|
{value.map(chip => (
|
||||||
|
<Chip key={chip.id} onClick={() => this.toggleSelected(chip)}>
|
||||||
|
{chip.name}
|
||||||
|
</Chip>
|
||||||
|
))}
|
||||||
|
</ChipGroup>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<I18n>
|
<I18n>
|
||||||
{({ i18n }) => (
|
{({ i18n }) => (
|
||||||
@@ -166,7 +170,7 @@ class Lookup extends React.Component {
|
|||||||
<Button className="pf-c-input-group__text" aria-label="search" id="search" onClick={this.handleModalToggle}>
|
<Button className="pf-c-input-group__text" aria-label="search" id="search" onClick={this.handleModalToggle}>
|
||||||
<SearchIcon />
|
<SearchIcon />
|
||||||
</Button>
|
</Button>
|
||||||
<div className="pf-c-form-control">{this.wrapTags(value)}</div>
|
<div className="pf-c-form-control">{chips}</div>
|
||||||
<Modal
|
<Modal
|
||||||
className="awx-c-modal"
|
className="awx-c-modal"
|
||||||
title={`Select ${lookupHeader}`}
|
title={`Select ${lookupHeader}`}
|
||||||
|
|||||||
Reference in New Issue
Block a user