Skip to content

Commit d9b8214

Browse files
committed
Intoduce isReadonly flag at the AdvancedSearchResult page
This flag is used for hiding control components because this might be used at other pages to show its result as more simple style.
1 parent 184bbc6 commit d9b8214

File tree

2 files changed

+124
-101
lines changed

2 files changed

+124
-101
lines changed

frontend/src/components/entry/SearchResults.tsx

+18-11
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ interface Props {
6363
joinAttrs: AdvancedSearchJoinAttrInfo[];
6464
disablePaginationFooter: boolean;
6565
setSearchResults: () => void;
66+
isReadonly?: boolean;
6667
}
6768

6869
export const SearchResults: FC<Props> = ({
@@ -80,6 +81,7 @@ export const SearchResults: FC<Props> = ({
8081
joinAttrs,
8182
disablePaginationFooter,
8283
setSearchResults,
84+
isReadonly = false,
8385
}) => {
8486
// NOTE attrTypes are guessed by the first element on the results. So if it has no appropriate attr,
8587
// the type guess doesn't work well. We should improve attr type API if more accurate type is needed.
@@ -109,21 +111,26 @@ export const SearchResults: FC<Props> = ({
109111
searchAllEntities={searchAllEntities}
110112
joinAttrs={joinAttrs}
111113
refreshSearchResults={setSearchResults}
114+
isReadonly={isReadonly}
112115
/>
113116
<TableBody>
114117
{results.values?.map((result) => (
115118
<StyledTableRow key={result.entry.id}>
116-
<TableCell sx={{ padding: 0 }}>
117-
<Checkbox
118-
checked={bulkOperationEntryIds.includes(result.entry.id)}
119-
onChange={(e) =>
120-
handleChangeBulkOperationEntryId(
121-
result.entry.id,
122-
e.target.checked
123-
)
124-
}
125-
/>
126-
</TableCell>
119+
{/* Bulk operation checkbox would be invisible when Readonly mode is true */}
120+
{!isReadonly && (
121+
<TableCell sx={{ padding: 0 }}>
122+
<Checkbox
123+
checked={bulkOperationEntryIds.includes(result.entry.id)}
124+
onChange={(e) =>
125+
handleChangeBulkOperationEntryId(
126+
result.entry.id,
127+
e.target.checked
128+
)
129+
}
130+
/>
131+
</TableCell>
132+
)}
133+
127134
<TableCell>
128135
<Box
129136
component={Link}

frontend/src/components/entry/SearchResultsTableHead.tsx

+106-90
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ interface Props {
6161
searchAllEntities: boolean;
6262
joinAttrs: AdvancedSearchJoinAttrInfo[];
6363
refreshSearchResults: () => void;
64+
isReadonly?: boolean;
6465
}
6566

6667
export const SearchResultsTableHead: FC<Props> = ({
@@ -73,6 +74,7 @@ export const SearchResultsTableHead: FC<Props> = ({
7374
searchAllEntities,
7475
joinAttrs,
7576
refreshSearchResults,
77+
isReadonly = false,
7678
}) => {
7779
const location = useLocation();
7880
const navigate = useNavigate();
@@ -129,52 +131,52 @@ export const SearchResultsTableHead: FC<Props> = ({
129131

130132
const handleSelectFilterConditions =
131133
(attrName?: string) =>
132-
(
133-
attrFilter?: AttrFilter,
134-
overwriteEntryName?: string,
135-
overwriteReferral?: string
136-
) => {
137-
const _attrsFilter =
138-
attrName != null && attrFilter != null
139-
? { ...attrsFilter, [attrName]: attrFilter }
140-
: attrsFilter;
134+
(
135+
attrFilter?: AttrFilter,
136+
overwriteEntryName?: string,
137+
overwriteReferral?: string
138+
) => {
139+
const _attrsFilter =
140+
attrName != null && attrFilter != null
141+
? { ...attrsFilter, [attrName]: attrFilter }
142+
: attrsFilter;
141143

142-
const newParams = formatAdvancedSearchParams({
143-
attrsFilter: Object.keys(_attrsFilter)
144-
.filter((k) => _attrsFilter[k]?.joinedAttrname === undefined)
145-
.reduce((a, k) => ({ ...a, [k]: _attrsFilter[k] }), {}),
146-
entryName: overwriteEntryName ?? entryFilter,
147-
referralName: overwriteReferral ?? referralFilter,
148-
baseParams: new URLSearchParams(location.search),
149-
joinAttrs: Object.keys(_attrsFilter)
150-
.filter((k) => _attrsFilter[k]?.joinedAttrname !== undefined)
151-
.map((k) => ({
152-
name: _attrsFilter[k]?.baseAttrname ?? "",
153-
attrinfo: Object.keys(_attrsFilter)
154-
.filter(
155-
(j) =>
156-
_attrsFilter[j].baseAttrname === _attrsFilter[k].baseAttrname
157-
)
158-
.map((j) => ({
159-
name: _attrsFilter[j]?.joinedAttrname ?? "",
160-
filterKey: _attrsFilter[j].filterKey,
161-
keyword: _attrsFilter[j].keyword,
162-
})),
163-
}))
164-
// This removes duplicates
165-
.filter((v, i, a) => a.findIndex((t) => t.name === v.name) === i),
166-
});
144+
const newParams = formatAdvancedSearchParams({
145+
attrsFilter: Object.keys(_attrsFilter)
146+
.filter((k) => _attrsFilter[k]?.joinedAttrname === undefined)
147+
.reduce((a, k) => ({ ...a, [k]: _attrsFilter[k] }), {}),
148+
entryName: overwriteEntryName ?? entryFilter,
149+
referralName: overwriteReferral ?? referralFilter,
150+
baseParams: new URLSearchParams(location.search),
151+
joinAttrs: Object.keys(_attrsFilter)
152+
.filter((k) => _attrsFilter[k]?.joinedAttrname !== undefined)
153+
.map((k) => ({
154+
name: _attrsFilter[k]?.baseAttrname ?? "",
155+
attrinfo: Object.keys(_attrsFilter)
156+
.filter(
157+
(j) =>
158+
_attrsFilter[j].baseAttrname === _attrsFilter[k].baseAttrname
159+
)
160+
.map((j) => ({
161+
name: _attrsFilter[j]?.joinedAttrname ?? "",
162+
filterKey: _attrsFilter[j].filterKey,
163+
keyword: _attrsFilter[j].keyword,
164+
})),
165+
}))
166+
// This removes duplicates
167+
.filter((v, i, a) => a.findIndex((t) => t.name === v.name) === i),
168+
});
167169

168-
if (getIsFiltered(attrFilter?.filterKey, attrFilter?.keyword)) {
169-
refreshSearchResults();
170-
}
170+
if (getIsFiltered(attrFilter?.filterKey, attrFilter?.keyword)) {
171+
refreshSearchResults();
172+
}
171173

172-
// simply reload with the new params
173-
navigate({
174-
pathname: location.pathname,
175-
search: "?" + newParams.toString(),
176-
});
177-
};
174+
// simply reload with the new params
175+
navigate({
176+
pathname: location.pathname,
177+
search: "?" + newParams.toString(),
178+
});
179+
};
178180

179181
const handleUpdateAttrFilter =
180182
(attrName: string) => (attrFilter: AttrFilter) => {
@@ -187,33 +189,43 @@ export const SearchResultsTableHead: FC<Props> = ({
187189
return (
188190
<TableHead>
189191
<TableRow sx={{ backgroundColor: "primary.dark" }}>
190-
<TableCell sx={{ witdh: "80px" }} />
192+
{/* Bulk operation checkbox would be invisible when Readonly mode is true */}
193+
{!isReadonly && (
194+
<TableCell sx={{ witdh: "80px" }} />
195+
)}
191196
<StyledTableCell sx={{ outline: "1px solid #FFFFFF" }}>
192197
<HeaderBox>
193198
<Typography>アイテム名</Typography>
194-
<StyledIconButton
195-
onClick={(e) => {
196-
setEntryMenuEls(e.currentTarget);
197-
}}
198-
>
199-
{defaultEntryFilter ? <FilterAltIcon /> : <FilterListIcon />}
200-
</StyledIconButton>
201-
<SearchResultControlMenuForEntry
202-
entryFilter={entryFilter}
203-
anchorElem={entryMenuEls}
204-
handleClose={() => setEntryMenuEls(null)}
205-
entryFilterDispatcher={entryFilterDispatcher}
206-
handleSelectFilterConditions={handleSelectFilterConditions()}
207-
handleClear={() => handleSelectFilterConditions()(undefined, "")}
208-
/>
199+
200+
{/* SearchControlMenu would be invisible when Readonly Mode is True */}
201+
{!isReadonly && (
202+
<>
203+
<StyledIconButton
204+
onClick={(e) => {
205+
setEntryMenuEls(e.currentTarget);
206+
}}
207+
>
208+
{defaultEntryFilter ? <FilterAltIcon /> : <FilterListIcon />}
209+
</StyledIconButton>
210+
<SearchResultControlMenuForEntry
211+
entryFilter={entryFilter}
212+
anchorElem={entryMenuEls}
213+
handleClose={() => setEntryMenuEls(null)}
214+
entryFilterDispatcher={entryFilterDispatcher}
215+
handleSelectFilterConditions={handleSelectFilterConditions()}
216+
handleClear={() => handleSelectFilterConditions()(undefined, "")}
217+
/>
218+
</>
219+
)}
209220
</HeaderBox>
210221
</StyledTableCell>
211222
{attrNames.map((attrName) => (
212223
<StyledTableCell key={attrName}>
213224
<HeaderBox>
214225
<Typography>{attrName}</Typography>
215226

216-
{(attrTypes[attrName] & EntryAttributeTypeTypeEnum.OBJECT) > 0 &&
227+
{/* Bulk operation checkbox would be invisible when Readonly mode is true */}
228+
{(attrTypes[attrName] & EntryAttributeTypeTypeEnum.OBJECT) > 0 && !isReadonly &&
217229
attrsFilter[attrName]?.joinedAttrname === undefined && (
218230
<StyledIconButton onClick={() => setJoinAttrname(attrName)}>
219231
<AddIcon />
@@ -229,36 +241,40 @@ export const SearchResultsTableHead: FC<Props> = ({
229241
refreshSearchResults={refreshSearchResults}
230242
/>
231243
)}
232-
<StyledIconButton
233-
onClick={(e) => {
234-
setAttributeMenuEls({
235-
...attributeMenuEls,
236-
[attrName]: e.currentTarget,
237-
});
238-
}}
239-
sx={{ marginLeft: "auto" }}
240-
>
241-
{isFiltered[attrName] ?? false ? (
242-
<FilterAltIcon />
243-
) : (
244-
<FilterListIcon />
245-
)}
246-
</StyledIconButton>
247-
<SearchResultControlMenu
248-
attrFilter={attrsFilter[attrName]}
249-
anchorElem={attributeMenuEls[attrName]}
250-
handleClose={() =>
251-
setAttributeMenuEls({
252-
...attributeMenuEls,
253-
[attrName]: null,
254-
})
255-
}
256-
handleSelectFilterConditions={handleSelectFilterConditions(
257-
attrName
258-
)}
259-
handleUpdateAttrFilter={handleUpdateAttrFilter(attrName)}
260-
attrType={attrTypes[attrName]}
261-
/>
244+
{!isReadonly && (
245+
<>
246+
<StyledIconButton
247+
onClick={(e) => {
248+
setAttributeMenuEls({
249+
...attributeMenuEls,
250+
[attrName]: e.currentTarget,
251+
});
252+
}}
253+
sx={{ marginLeft: "auto" }}
254+
>
255+
{isFiltered[attrName] ?? false ? (
256+
<FilterAltIcon />
257+
) : (
258+
<FilterListIcon />
259+
)}
260+
</StyledIconButton>
261+
<SearchResultControlMenu
262+
attrFilter={attrsFilter[attrName]}
263+
anchorElem={attributeMenuEls[attrName]}
264+
handleClose={() =>
265+
setAttributeMenuEls({
266+
...attributeMenuEls,
267+
[attrName]: null,
268+
})
269+
}
270+
handleSelectFilterConditions={handleSelectFilterConditions(
271+
attrName
272+
)}
273+
handleUpdateAttrFilter={handleUpdateAttrFilter(attrName)}
274+
attrType={attrTypes[attrName]}
275+
/>
276+
</>
277+
)}
262278
</HeaderBox>
263279
</StyledTableCell>
264280
))}

0 commit comments

Comments
 (0)