Skip to content

Commit

Permalink
add filter company to ticket list (#408)
Browse files Browse the repository at this point in the history
* add filter company

* encode company name

* add multi and tbd to owner company

* change for EMPTY

* add empty owner company filter

* add tbd
  • Loading branch information
santipalenque authored May 16, 2024
1 parent 24be773 commit 419a7ce
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 43 deletions.
45 changes: 31 additions & 14 deletions src/actions/ticket-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,89 +172,106 @@ const parseFilters = (filters, term = null) => {

const filter = [];

if (filters.hasOwnProperty('showOnlyPendingRefundRequests') && filters.showOnlyPendingRefundRequests) {
if (filters?.showOnlyPendingRefundRequests) {
filter.push('has_requested_refund_requests==1');
}

if (filters.hasOwnProperty('showOnlyPrintable') && filters.showOnlyPrintable) {
if (filters?.showOnlyPrintable) {
filter.push('is_printable==1');
}

if (filters.hasOwnProperty('hasOwnerFilter') && filters.hasOwnerFilter) {
if (filters?.hasOwnerFilter) {
if (filters.hasOwnerFilter === 'HAS_OWNER')
filter.push(`has_owner==1`);
if (filters.hasOwnerFilter === 'HAS_NO_OWNER')
filter.push(`has_owner==0`)
}

if(filters.hasOwnProperty('hasBadgeFilter') && filters.hasBadgeFilter){
if (filters?.hasBadgeFilter) {
if (filters.hasBadgeFilter === 'HAS_BADGE')
filter.push(`has_badge==1`);
if (filters.hasBadgeFilter === 'HAS_NO_BADGE')
filter.push(`has_badge==0`)
}

if(filters.hasOwnProperty('ticketTypesFilter') && Array.isArray(filters.ticketTypesFilter) && filters.ticketTypesFilter.length > 0){
if (filters?.ticketTypesFilter?.length > 0) {
filter.push(filters.ticketTypesFilter.reduce(
(accumulator, tt) => accumulator +(accumulator !== '' ? ',':'') +`ticket_type_id==${tt.value}`,
''
));
}

if(filters.hasOwnProperty('badgeTypesFilter') && Array.isArray(filters.badgeTypesFilter) && filters.badgeTypesFilter.length > 0) {
if (filters?.badgeTypesFilter?.length > 0) {
filter.push(filters.badgeTypesFilter.reduce(
(accumulator, tt) => accumulator +(accumulator !== '' ? ',':'') +`badge_type_id==${tt.value}`,
''
));
}

if(filters.hasOwnProperty('viewTypesFilter') && Array.isArray(filters.viewTypesFilter) && filters.viewTypesFilter.length > 0){
if (filters?.viewTypesFilter?.length > 0) {
filter.push(filters.viewTypesFilter.reduce(
(accumulator, tt) => accumulator +(accumulator !== '' ? ',':'') +`view_type_id==${tt.value}`,
''
));
}

if(filters.promocodesFilter?.length > 0){
if (filters.promocodesFilter?.length > 0) {
filter.push(filters.promocodesFilter.reduce(
(accumulator, tt) => accumulator +(accumulator !== '' ? ',':'') +`promo_code_id==${tt.id}`,
''
));
}

if(filters.hasOwnProperty('completedFilter') && filters.completedFilter){
if (filters?.completedFilter) {
filter.push(`owner_status==${filters.completedFilter}`);
}

if (filters.hasOwnProperty('amountFilter') && filters.amountFilter) {
if (filters?.amountFilter) {
if (filters.amountFilter === 'Paid')
filter.push(`final_amount>0`);
if (filters.amountFilter === 'Free')
filter.push(`final_amount==0`)
}

if(filters.hasOwnProperty('ownerFullNameStartWithFilter') && Array.isArray(filters.ownerFullNameStartWithFilter) && filters.ownerFullNameStartWithFilter.length > 0){
if (filters.ownerFullNameStartWithFilter?.length > 0) {
filter.push(filters.ownerFullNameStartWithFilter.reduce(
(accumulator, alpha) => accumulator +(accumulator !== '' ? ',':'') +`owner_first_name@@${alpha.value}`,
''
));
}

if(filters.hasOwnProperty('audienceFilter') && Array.isArray(filters.audienceFilter) && filters.audienceFilter.length > 0){
if (filters?.ownerCompany?.length > 0) {
const nonTBD = filters?.ownerCompany.filter(of => of.id !== 'NULL');
let ownerCompany = [];

// has tbd
if (nonTBD.length < filters?.ownerCompany?.length) {
ownerCompany.push('has_owner_company==0');
}

if (nonTBD.length > 0) {
ownerCompany.push('owner_company=='+nonTBD.map(of => encodeURIComponent(of.name)).join('||'));
}

filter.push(ownerCompany.join(','));
}


if (filters.audienceFilter?.length > 0) {
filter.push(filters.audienceFilter.reduce(
(accumulator, aud) => accumulator +(accumulator !== '' ? ',':'') +`audience==${aud}`,
''
));
}

if(filters.promocodeTagsFilter?.length > 0){
if (filters.promocodeTagsFilter?.length > 0) {
filter.push(filters.promocodeTagsFilter.reduce(
(accumulator, t) => accumulator +(accumulator !== '' ? ',':'') +`promo_code_tag==${t.tag}`,
''
));
}

if(term) {
if (term) {
const escapedTerm = escapeFilterValue(term);
let searchString = `number=@${escapedTerm},owner_email=@${escapedTerm},owner_name=@${escapedTerm},owner_company=@${escapedTerm},promo_code=@${escapedTerm},promo_code_description=@${escapedTerm},promo_code_tag=@${escapedTerm}`;
searchString = isNumericString(escapedTerm) ? `${searchString},promo_code_tag_id==${escapedTerm}` : searchString;
Expand Down
1 change: 1 addition & 0 deletions src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1543,6 +1543,7 @@
"search_tickets": "Search by Ticket #, Buyer, Assignee, Promo Code, Promo Code Description",
"ticket_types": "Filter By Ticket Types ...",
"owner_first_name": "First name starts with ...",
"owner_company": "Select Company",
"view_types": "Filter by View Types ...",
"view_type": "Select a View Type ...",
"promocodes": "Select a Promo Code ...",
Expand Down
47 changes: 33 additions & 14 deletions src/pages/tickets/ticket-list-page.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/**
* Copyright 2018 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -20,7 +20,8 @@ import {
SelectableTable,
Dropdown,
PromocodeInput,
TagInput
TagInput,
CompanyInput
} from 'openstack-uicore-foundation/lib/components';
import { getSummitById } from '../../actions/summit-actions';
import {
Expand Down Expand Up @@ -100,6 +101,7 @@ class TicketListPage extends React.Component {
showOnlyPendingRefundRequests: false,
ticketTypesFilter : [],
ownerFullNameStartWithFilter:[],
ownerCompany: [],
viewTypesFilter: [],
hasOwnerFilter : null,
completedFilter : null,
Expand Down Expand Up @@ -260,6 +262,7 @@ class TicketListPage extends React.Component {
showOnlyPendingRefundRequests: false,
ticketTypesFilter : [],
ownerFullNameStartWithFilter:[],
ownerCompany: null,
viewTypesFilter: [],
hasOwnerFilter : null,
completedFilter : null,
Expand Down Expand Up @@ -371,6 +374,7 @@ class TicketListPage extends React.Component {
{label: 'Badge', value: 'hasBadgeFilter'},
{label: 'Amount', value: 'amountFilter'},
{label: 'Assignee Name', value: 'ownerFullNameStartWithFilter'},
{label: 'Owner Company', value: 'ownerCompany'},
{label: 'View Type', value: 'viewTypesFilter'},
{label: 'Ticket Type', value: 'ticketTypesFilter'},
{label: 'Promo Code', value: 'promocodesFilter'},
Expand Down Expand Up @@ -456,7 +460,9 @@ class TicketListPage extends React.Component {
/>
</div>
</div>
<div className="row">
{enabledFilters?.length > 0 &&
<div className="row filtersWrapper">
<hr />
{enabledFilters.includes('hasOwnerFilter') &&
<div className="col-md-6">
<SegmentedControl
Expand All @@ -467,7 +473,7 @@ class TicketListPage extends React.Component {
{ label: T.translate("ticket_list.has_no_owner"), value: "HAS_NO_OWNER",default: ticketFilters.hasOwnerFilter === "HAS_NO_OWNER" },
]}
setValue={val => this.handleFilterChange('hasOwnerFilter', val)}
className="ticket-list-segment"
className="segmentFilter"
/>
</div>
}
Expand All @@ -481,7 +487,7 @@ class TicketListPage extends React.Component {
{ label: T.translate("ticket_list.incomplete"), value: "Incomplete",default: ticketFilters.completedFilter === "Incomplete" },
]}
setValue={val => this.handleFilterChange('completedFilter', val)}
className="ticket-list-segment"
className="segmentFilter"
/>
</div>
}
Expand All @@ -495,7 +501,7 @@ class TicketListPage extends React.Component {
{ label: T.translate("ticket_list.has_no_badge"), value: "HAS_NO_BADGE",default: ticketFilters.hasBadgeFilter === "HAS_NO_BADGE" },
]}
setValue={newValue => this.handleFilterChange('hasBadgeFilter', newValue)}
className="ticket-list-segment"
className="segmentFilter"
/>
</div>
}
Expand All @@ -509,7 +515,7 @@ class TicketListPage extends React.Component {
{ label: T.translate("ticket_list.free"), value: "Free",default: ticketFilters.amountFilter === "Free" },
]}
setValue={val => this.handleFilterChange('amountFilter', val)}
className="ticket-list-segment"
className="segmentFilter"
/>
</div>
}
Expand All @@ -523,10 +529,23 @@ class TicketListPage extends React.Component {
options={alphabet}
isClearable={true}
isMulti
className="ticket-types-filter"
className="dropdownFilter"
/>
</div>
}
{enabledFilters.includes('ownerCompany') &&
<div className={'col-md-6'}>
<CompanyInput
id='ownerCompany'
className="dropdownFilter"
value={ticketFilters.ownerCompany}
placeholder={T.translate("ticket_list.placeholders.owner_company")}
onChange={ev => this.handleFilterChange('ownerCompany', ev.target.value)}
extraOptions={[{value: 'NULL', label: 'TBD'}]}
multi
/>
</div>
}
{enabledFilters.includes('viewTypesFilter') &&
<div className={'col-md-6'}>
<Select
Expand All @@ -537,7 +556,7 @@ class TicketListPage extends React.Component {
options={viewTypesOptions}
isClearable={true}
isMulti
className="view-types-filter"
className="dropdownFilter"
/>
</div>
}
Expand All @@ -551,7 +570,7 @@ class TicketListPage extends React.Component {
options={ticketTypesOptions}
isClearable={true}
isMulti
className="ticket-types-filter"
className="dropdownFilter"
/>
</div>
}
Expand All @@ -562,7 +581,7 @@ class TicketListPage extends React.Component {
value={ticketFilters.promocodesFilter}
onChange={ev => this.handleFilterChange('promocodesFilter', ev.target.value)}
summitId={currentSummit.id}
className="promocodes-filter"
className="dropdownFilter"
placeholder={T.translate('ticket_list.placeholders.promocodes')}
isClearable
multi
Expand All @@ -575,7 +594,7 @@ class TicketListPage extends React.Component {
id="promocodeTagsFilter"
value={ticketFilters.promocodeTagsFilter}
onChange={ev => this.handleFilterChange('promocodeTagsFilter', ev.target.value)}
className="promocodes-filter"
className="dropdownFilter"
placeholder={T.translate('ticket_list.placeholders.promocodes_tags')}
isClearable
multi
Expand Down Expand Up @@ -625,12 +644,12 @@ class TicketListPage extends React.Component {
options={badgeTypesOptions}
isClearable={true}
isMulti
className="badge-type-filter"
className="dropdownFilter"
/>
</div>
}
</div>

}
<hr/>

<div className={'row'} style={{marginBottom: 15}}>
Expand Down
2 changes: 1 addition & 1 deletion src/reducers/tickets/ticket-list-reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ const ticketListReducer = (state = DEFAULT_STATE, action) => {
bought_date: bought_date,
owner_name: t.owner && (t.owner.first_name && t.owner.last_name) ? t.owner.first_name + ' ' + t.owner.last_name : 'N/A',
owner_email: t.owner ? t.owner.email : 'N/A',
owner_company: t.owner && t.owner.company ? t.owner.company : '',
owner_company: t.owner?.company || 'TBD',
promo_code: t.promo_code ? t.promo_code.code : 'N/A',
status: t.status,
checked: selectedAll ? !excludedIds.includes(t.id) : selectedIds.includes(t.id),
Expand Down
35 changes: 21 additions & 14 deletions src/styles/ticket-list-page.less
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,6 @@
margin-top: 0.5em;
}

.ticket-types-filter, .view-types-filter, .promocodes-filter {
padding-top: 0.5em;
}

.abc-checkbox{
padding-top: 1em;
padding-bottom: 1em;
}

.search-section {
display: flex;

Expand All @@ -31,13 +22,29 @@
}
}

.ticket-list-segment {
width: 100%;
height: 40px;
color: #337ab7;
font-size: 10px;
.filtersWrapper {
margin-top: 10px;

.dropdownFilter {
padding-top: 10px;
padding-bottom: 5px;
}

.segmentFilter {
width: 100%;
color: #337ab7;
font-size: 10px;
margin: 10px auto 0;
}

.abc-checkbox{
padding-top: 16px;
padding-bottom: 15px;
}
}



.ticket-list-table {
overflow: auto;
max-height: 700px;
Expand Down

0 comments on commit 419a7ce

Please sign in to comment.