Skip to content

Commit b17bfaa

Browse files
committed
merge the working of search and refresh button in one function
1 parent dc80a9d commit b17bfaa

File tree

2 files changed

+23
-16
lines changed

2 files changed

+23
-16
lines changed

outlook/src/taskpane/api.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ const api = {
1414
searchPartner: '/mail_plugin/partner/search',
1515
getTranslations: '/mail_plugin/get_translations',
1616
searchProject: '/mail_plugin/project/search',
17-
getLeads: '/mail/plugin/leads/search',
18-
getTasks: '/mail/plugin/tasks/search',
19-
getTickets: '/mail/plugin/tickets/search',
17+
Leads: '/mail/plugin/leads',
18+
Tasks: '/mail/plugin/tasks',
19+
Tickets: '/mail/plugin/tickets',
2020

2121
// Authentication
2222
loginPage: '/web/login', // Should be the usual Odoo login page.

outlook/src/taskpane/components/SearchRefrech/SearchRefrech.tsx

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ class SearchRefrech extends React.Component<SearchRefrechProps, SearchRefrechSta
4242
fontSize: 'medium',
4343
color: '#787878',
4444
fontWeight: 600,
45-
marginRight: '10px',
4645
};
4746

4847
const onBackClick = () => {
@@ -51,6 +50,10 @@ class SearchRefrech extends React.Component<SearchRefrechProps, SearchRefrechSta
5150
this.props.setIsSearching(false);
5251
};
5352

53+
const onRefrechClick = () => {
54+
searchData();
55+
};
56+
5457
const onSearchClick = () => {
5558
this.setState({ isSearching: true });
5659
this.props.setIsSearching(true);
@@ -65,22 +68,26 @@ class SearchRefrech extends React.Component<SearchRefrechProps, SearchRefrechSta
6568
}
6669
};
6770

68-
const onRefrechClick = () => {
69-
if (this.state.query) {
70-
searchData(this.state.query);
71+
const getEndPoint = (params: string) => {
72+
let endPoint = '';
73+
if (this.props.searchType === 'lead') {
74+
endPoint = api.Leads;
75+
} else if (this.props.searchType === 'task') {
76+
endPoint = api.Tasks;
77+
} else {
78+
endPoint = api.Tickets;
7179
}
80+
return endPoint + `/${params}`;
7281
};
7382

74-
const searchData = async (query: string) => {
83+
const searchData = async (query?: string) => {
7584
this.props.setIsLoading(true);
7685

7786
let endPoint = '';
78-
if (this.props.searchType === 'lead') {
79-
endPoint = api.getLeads;
80-
} else if (this.props.searchType === 'task') {
81-
endPoint = api.getTasks;
87+
if (query) {
88+
endPoint = getEndPoint('search');
8289
} else {
83-
endPoint = api.getTickets;
90+
endPoint = getEndPoint('refresh');
8491
}
8592

8693
try {
@@ -89,7 +96,7 @@ class SearchRefrech extends React.Component<SearchRefrechProps, SearchRefrechSta
8996
api.baseURL + endPoint,
9097
ContentType.Json,
9198
this.context.getConnectionToken(),
92-
{ query: query, partner_id: this.props.partner.id },
99+
{ query: query, partner: this.props.partner },
93100
true,
94101
);
95102

@@ -160,7 +167,7 @@ class SearchRefrech extends React.Component<SearchRefrechProps, SearchRefrechSta
160167
}
161168

162169
let refrechButton = null;
163-
if (this.state.isSearching) {
170+
if (!this.state.isSearching) {
164171
refrechButton = (
165172
<TooltipHost content={_t('Refresh search')}>
166173
<div className="odoo-muted-button" onClick={onRefrechClick} style={{ border: 'none' }}>
@@ -174,8 +181,8 @@ class SearchRefrech extends React.Component<SearchRefrechProps, SearchRefrechSta
174181
<div style={broadCampStyle}>
175182
{backButton}
176183
{searchButton}
177-
{searchBar}
178184
{refrechButton}
185+
{searchBar}
179186
</div>
180187
);
181188
}

0 commit comments

Comments
 (0)