Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce isReadonly flag at the AdvancedSearchResult page #1321

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 20 additions & 11 deletions frontend/src/components/entry/SearchResults.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ interface Props {
joinAttrs: AdvancedSearchJoinAttrInfo[];
disablePaginationFooter: boolean;
setSearchResults: () => void;
isReadonly?: boolean;
}

export const SearchResults: FC<Props> = ({
Expand All @@ -80,6 +81,7 @@ export const SearchResults: FC<Props> = ({
joinAttrs,
disablePaginationFooter,
setSearchResults,
isReadonly = false,
}) => {
// NOTE attrTypes are guessed by the first element on the results. So if it has no appropriate attr,
// the type guess doesn't work well. We should improve attr type API if more accurate type is needed.
Expand Down Expand Up @@ -109,21 +111,28 @@ export const SearchResults: FC<Props> = ({
searchAllEntities={searchAllEntities}
joinAttrs={joinAttrs}
refreshSearchResults={setSearchResults}
isReadonly={isReadonly}
/>
<TableBody>
{results.values?.map((result) => (
<StyledTableRow key={result.entry.id}>
<TableCell sx={{ padding: 0 }}>
<Checkbox
checked={bulkOperationEntryIds.includes(result.entry.id)}
onChange={(e) =>
handleChangeBulkOperationEntryId(
result.entry.id,
e.target.checked
)
}
/>
</TableCell>
{/* Bulk operation checkbox would be invisible when Readonly mode is true */}
{!isReadonly && (
<TableCell sx={{ padding: 0 }}>
<Checkbox
checked={bulkOperationEntryIds.includes(
result.entry.id
)}
onChange={(e) =>
handleChangeBulkOperationEntryId(
result.entry.id,
e.target.checked
)
}
/>
</TableCell>
)}

<TableCell>
<Box
component={Link}
Expand Down
109 changes: 63 additions & 46 deletions frontend/src/components/entry/SearchResultsTableHead.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ interface Props {
searchAllEntities: boolean;
joinAttrs: AdvancedSearchJoinAttrInfo[];
refreshSearchResults: () => void;
isReadonly?: boolean;
}

export const SearchResultsTableHead: FC<Props> = ({
Expand All @@ -73,6 +74,7 @@ export const SearchResultsTableHead: FC<Props> = ({
searchAllEntities,
joinAttrs,
refreshSearchResults,
isReadonly = false,
}) => {
const location = useLocation();
const navigate = useNavigate();
Expand Down Expand Up @@ -187,33 +189,44 @@ export const SearchResultsTableHead: FC<Props> = ({
return (
<TableHead>
<TableRow sx={{ backgroundColor: "primary.dark" }}>
<TableCell sx={{ witdh: "80px" }} />
{/* Bulk operation checkbox would be invisible when Readonly mode is true */}
{!isReadonly && <TableCell sx={{ witdh: "80px" }} />}
<StyledTableCell sx={{ outline: "1px solid #FFFFFF" }}>
<HeaderBox>
<Typography>アイテム名</Typography>
<StyledIconButton
onClick={(e) => {
setEntryMenuEls(e.currentTarget);
}}
>
{defaultEntryFilter ? <FilterAltIcon /> : <FilterListIcon />}
</StyledIconButton>
<SearchResultControlMenuForEntry
entryFilter={entryFilter}
anchorElem={entryMenuEls}
handleClose={() => setEntryMenuEls(null)}
entryFilterDispatcher={entryFilterDispatcher}
handleSelectFilterConditions={handleSelectFilterConditions()}
handleClear={() => handleSelectFilterConditions()(undefined, "")}
/>

{/* SearchControlMenu would be invisible when Readonly Mode is True */}
{!isReadonly && (
<>
<StyledIconButton
onClick={(e) => {
setEntryMenuEls(e.currentTarget);
}}
>
{defaultEntryFilter ? <FilterAltIcon /> : <FilterListIcon />}
</StyledIconButton>
<SearchResultControlMenuForEntry
entryFilter={entryFilter}
anchorElem={entryMenuEls}
handleClose={() => setEntryMenuEls(null)}
entryFilterDispatcher={entryFilterDispatcher}
handleSelectFilterConditions={handleSelectFilterConditions()}
handleClear={() =>
handleSelectFilterConditions()(undefined, "")
}
/>
</>
)}
</HeaderBox>
</StyledTableCell>
{attrNames.map((attrName) => (
<StyledTableCell key={attrName}>
<HeaderBox>
<Typography>{attrName}</Typography>

{/* Bulk operation checkbox would be invisible when Readonly mode is true */}
{(attrTypes[attrName] & EntryAttributeTypeTypeEnum.OBJECT) > 0 &&
!isReadonly &&
attrsFilter[attrName]?.joinedAttrname === undefined && (
<StyledIconButton onClick={() => setJoinAttrname(attrName)}>
<AddIcon />
Expand All @@ -229,36 +242,40 @@ export const SearchResultsTableHead: FC<Props> = ({
refreshSearchResults={refreshSearchResults}
/>
)}
<StyledIconButton
onClick={(e) => {
setAttributeMenuEls({
...attributeMenuEls,
[attrName]: e.currentTarget,
});
}}
sx={{ marginLeft: "auto" }}
>
{isFiltered[attrName] ?? false ? (
<FilterAltIcon />
) : (
<FilterListIcon />
)}
</StyledIconButton>
<SearchResultControlMenu
attrFilter={attrsFilter[attrName]}
anchorElem={attributeMenuEls[attrName]}
handleClose={() =>
setAttributeMenuEls({
...attributeMenuEls,
[attrName]: null,
})
}
handleSelectFilterConditions={handleSelectFilterConditions(
attrName
)}
handleUpdateAttrFilter={handleUpdateAttrFilter(attrName)}
attrType={attrTypes[attrName]}
/>
{!isReadonly && (
<>
<StyledIconButton
onClick={(e) => {
setAttributeMenuEls({
...attributeMenuEls,
[attrName]: e.currentTarget,
});
}}
sx={{ marginLeft: "auto" }}
>
{isFiltered[attrName] ?? false ? (
<FilterAltIcon />
) : (
<FilterListIcon />
)}
</StyledIconButton>
<SearchResultControlMenu
attrFilter={attrsFilter[attrName]}
anchorElem={attributeMenuEls[attrName]}
handleClose={() =>
setAttributeMenuEls({
...attributeMenuEls,
[attrName]: null,
})
}
handleSelectFilterConditions={handleSelectFilterConditions(
attrName
)}
handleUpdateAttrFilter={handleUpdateAttrFilter(attrName)}
attrType={attrTypes[attrName]}
/>
</>
)}
</HeaderBox>
</StyledTableCell>
))}
Expand Down
Loading