Skip to content

Commit 1a92994

Browse files
authored
Merge pull request #1142 from userlocalhost/bugfix/join_attr/enable_to_search_whole_items_using_join_attr_2
Fixed implementation to be able to grow advanced search result context
2 parents 6b94e4b + 073e271 commit 1a92994

15 files changed

+556
-393
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
### Added
66

77
### Changed
8+
* Enable to get search advanced_search results sequentially and check its progres
9+
when join_attr parameter is specified.
10+
Contributed by @userlocalhost, @hinashi
811

912
### Fixed
1013

apiclient/typescript-fetch/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@dmm-com/airone-apiclient-typescript-fetch",
3-
"version": "0.0.16",
3+
"version": "0.0.17",
44
"description": "AirOne APIv2 client in TypeScript",
55
"main": "src/autogenerated/index.ts",
66
"scripts": {

entry/api_v2/serializers.py

+1
Original file line numberDiff line numberDiff line change
@@ -1162,6 +1162,7 @@ class AdvancedSearchResultValueSerializer(serializers.Serializer):
11621162
class AdvancedSearchResultSerializer(serializers.Serializer):
11631163
count = serializers.IntegerField()
11641164
values = AdvancedSearchResultValueSerializer(many=True)
1165+
total_count = serializers.IntegerField()
11651166

11661167

11671168
class AdvancedSearchResultExportSerializer(serializers.Serializer):

entry/api_v2/views.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,8 @@ def _get_ref_id_from_es_result(attrinfo):
373373
is_output_all,
374374
offset=entry_offset,
375375
)
376+
# save total population number
377+
total_count = deepcopy(resp["ret_count"])
376378

377379
for join_attr in join_attrs:
378380
(will_filter_by_joined_attr, joined_resp) = _get_joined_resp(
@@ -501,7 +503,11 @@ def _get_typed_value(type: int) -> str:
501503
]
502504

503505
serializer = AdvancedSearchResultSerializer(
504-
data={"count": resp["ret_count"], "values": resp["ret_values"]}
506+
data={
507+
"count": resp["ret_count"],
508+
"values": resp["ret_values"],
509+
"total_count": total_count,
510+
}
505511
)
506512

507513
# TODO validate response data strictly, like below.

entry/tests/test_api_v2.py

+1
Original file line numberDiff line numberDiff line change
@@ -2990,6 +2990,7 @@ def test_advanced_search(self):
29902990
resp.json(),
29912991
{
29922992
"count": 2,
2993+
"total_count": 2,
29932994
"values": [
29942995
{
29952996
"entity": {"id": self.entity.id, "name": "test-entity"},

frontend/src/components/entry/AdvancedSearchJoinModal.tsx

+5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ interface Props {
1717
targetAttrname: string;
1818
joinAttrs: AdvancedSearchJoinAttrInfo[];
1919
handleClose: () => void;
20+
setSearchResults: (isJoinSearching: boolean) => void;
2021
}
2122

2223
export const AdvancedSearchJoinModal: FC<Props> = ({
@@ -25,6 +26,7 @@ export const AdvancedSearchJoinModal: FC<Props> = ({
2526
targetAttrname,
2627
joinAttrs,
2728
handleClose,
29+
setSearchResults,
2830
}) => {
2931
const history = useHistory();
3032
// This is join attributes that have been already been selected before.
@@ -67,6 +69,9 @@ export const AdvancedSearchJoinModal: FC<Props> = ({
6769
joinAttrs: newJoinAttrs,
6870
});
6971

72+
// update page by changing joined Attribute filter condition
73+
setSearchResults(true);
74+
7075
// Update Page URL parameters
7176
history.push({
7277
pathname: location.pathname,

frontend/src/components/entry/SearchResults.test.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ test("should render a component with essential props", function () {
1515
results={{
1616
count: 0,
1717
values: [],
18+
totalCount: 0,
1819
}}
1920
page={1}
2021
changePage={() => {
@@ -27,7 +28,9 @@ test("should render a component with essential props", function () {
2728
hasReferral={false}
2829
entityIds={[]}
2930
joinAttrs={[]}
31+
disablePaginationFooter={false}
3032
searchAllEntities={false}
33+
setSearchResults={() => {}}
3134
/>,
3235
{ wrapper: TestWrapper }
3336
)

frontend/src/components/entry/SearchResults.tsx

+13-6
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ interface Props {
6161
entityIds: number[];
6262
searchAllEntities: boolean;
6363
joinAttrs: AdvancedSearchJoinAttrInfo[];
64+
disablePaginationFooter: boolean;
65+
setSearchResults: () => void;
6466
}
6567

6668
export const SearchResults: FC<Props> = ({
@@ -76,6 +78,8 @@ export const SearchResults: FC<Props> = ({
7678
entityIds,
7779
searchAllEntities,
7880
joinAttrs,
81+
disablePaginationFooter,
82+
setSearchResults,
7983
}) => {
8084
// NOTE attrTypes are guessed by the first element on the results. So if it has no appropriate attr,
8185
// the type guess doesn't work well. We should improve attr type API if more accurate type is needed.
@@ -104,6 +108,7 @@ export const SearchResults: FC<Props> = ({
104108
entityIds={entityIds}
105109
searchAllEntities={searchAllEntities}
106110
joinAttrs={joinAttrs}
111+
setSearchResults={setSearchResults}
107112
/>
108113
<TableBody>
109114
{results.values?.map((result) => (
@@ -169,12 +174,14 @@ export const SearchResults: FC<Props> = ({
169174
</Table>
170175
</TableContainer>
171176

172-
<PaginationFooter
173-
count={results.count}
174-
maxRowCount={AdvancedSerarchResultList.MAX_ROW_COUNT}
175-
page={page}
176-
changePage={changePage}
177-
/>
177+
{!disablePaginationFooter && (
178+
<PaginationFooter
179+
count={results.count}
180+
maxRowCount={AdvancedSerarchResultList.MAX_ROW_COUNT}
181+
page={page}
182+
changePage={changePage}
183+
/>
184+
)}
178185
</StyledBox>
179186
</Box>
180187
);

frontend/src/components/entry/SearchResultsTableHead.tsx

+18-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import {
22
AdvancedSearchJoinAttrInfo,
3-
AdvancedSearchResultAttrInfoFilterKeyEnum,
43
EntryAttributeTypeTypeEnum,
54
} from "@dmm-com/airone-apiclient-typescript-fetch";
65
import AddIcon from "@mui/icons-material/Add";
@@ -23,6 +22,7 @@ import { SearchResultControlMenu } from "./SearchResultControlMenu";
2322
import { SearchResultControlMenuForEntry } from "./SearchResultControlMenuForEntry";
2423
import { SearchResultControlMenuForReferral } from "./SearchResultControlMenuForReferral";
2524

25+
import { getIsFiltered } from "pages/AdvancedSearchResultsPage";
2626
import {
2727
AttrFilter,
2828
AttrsFilter,
@@ -53,6 +53,7 @@ interface Props {
5353
entityIds: number[];
5454
searchAllEntities: boolean;
5555
joinAttrs: AdvancedSearchJoinAttrInfo[];
56+
setSearchResults: (isJoinSearching: boolean) => void;
5657
}
5758

5859
export const SearchResultsTableHead: FC<Props> = ({
@@ -64,6 +65,7 @@ export const SearchResultsTableHead: FC<Props> = ({
6465
entityIds,
6566
searchAllEntities,
6667
joinAttrs,
68+
setSearchResults,
6769
}) => {
6870
const location = useLocation();
6971
const history = useHistory();
@@ -105,17 +107,10 @@ export const SearchResultsTableHead: FC<Props> = ({
105107
Object.fromEntries(
106108
Object.keys(defaultAttrsFilter ?? {}).map((attrName: string) => {
107109
const attrFilter = defaultAttrsFilter[attrName];
108-
switch (attrFilter?.filterKey) {
109-
case AdvancedSearchResultAttrInfoFilterKeyEnum.EMPTY:
110-
case AdvancedSearchResultAttrInfoFilterKeyEnum.NON_EMPTY:
111-
case AdvancedSearchResultAttrInfoFilterKeyEnum.DUPLICATED:
112-
return [attrName, true];
113-
case AdvancedSearchResultAttrInfoFilterKeyEnum.TEXT_CONTAINED:
114-
return [attrName, attrFilter.keyword !== ""];
115-
case AdvancedSearchResultAttrInfoFilterKeyEnum.TEXT_NOT_CONTAINED:
116-
return [attrName, attrFilter.keyword !== ""];
117-
}
118-
return [attrName, false];
110+
return [
111+
attrName,
112+
getIsFiltered(attrFilter.filterKey, attrFilter.keyword),
113+
];
119114
})
120115
),
121116
[defaultAttrsFilter]
@@ -159,6 +154,9 @@ export const SearchResultsTableHead: FC<Props> = ({
159154
.filter((v, i, a) => a.findIndex((t) => t.name === v.name) === i),
160155
});
161156

157+
setSearchResults(
158+
getIsFiltered(attrFilter?.filterKey, attrFilter?.keyword)
159+
);
162160
// simply reload with the new params
163161
history.push({
164162
pathname: location.pathname,
@@ -216,6 +214,14 @@ export const SearchResultsTableHead: FC<Props> = ({
216214
targetAttrname={joinAttrName}
217215
joinAttrs={joinAttrs}
218216
handleClose={() => setJoinAttrname("")}
217+
setSearchResults={() =>
218+
setSearchResults(
219+
getIsFiltered(
220+
attrsFilter[attrName].filterKey,
221+
attrsFilter[attrName].keyword
222+
)
223+
)
224+
}
219225
/>
220226
)}
221227
<StyledIconButton

frontend/src/pages/AdvancedSearchResultsPage.test.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ test("should match snapshot", async () => {
6363
Promise.resolve({
6464
count: 1,
6565
values: results,
66+
totalCount: 1,
6667
})
6768
);
6869
jest

0 commit comments

Comments
 (0)