Skip to content

Commit

Permalink
Fixed records list edit/view selected button style (#3542)
Browse files Browse the repository at this point in the history
* Fixed records list edit/view selected record button style

* code cleanup

---------

Co-authored-by: Stefano Ricci <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Aug 30, 2024
1 parent 10e1137 commit 3cc513b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
1 change: 1 addition & 0 deletions core/i18n/resources/en/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,7 @@ Merge cannot be performed.`,
noSelection:
'Please make your selection using the left side panel or select an existing query from "Manage queries"',
},
viewSelectedRecord: 'View selected record',
},

mapView: {
Expand Down
2 changes: 1 addition & 1 deletion webapp/store/user/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const useAuthCanEditRecords = (records) => {
const user = useUser()
return records.length > 0 && records.every((record) => _canEditRecord({ user, surveyInfo, record }))
}
export const useAuthCanEditRecord = (record) => useAuthCanEditRecords([record])
export const useAuthCanEditRecord = (record) => useAuthCanEditRecords(record ? [record] : [])
export const useAuthCanDeleteRecords = (records) => useAuthCanEditRecords(records)
export const useAuthCanDeleteRecord = (record) => useAuthCanDeleteRecords([record])
export const useAuthCanCleanseRecords = () => Authorizer.canCleanseRecords(useUser(), useSurveyInfo())
Expand Down
8 changes: 0 additions & 8 deletions webapp/style/formBase.scss
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,6 @@ button,
background-color: white;
transition: 0.2s all;

&:hover {
background-color: $blueLightFocus;

&:not([aria-disabled='true']) {
cursor: pointer;
}
}

&.active {
background-color: $blueLightActive;

Expand Down
23 changes: 18 additions & 5 deletions webapp/views/App/views/Data/Records/HeaderLeft/HeaderLeft.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ import { RecordActions, useRecord } from '@webapp/store/ui/record'

import { TestId } from '@webapp/utils/testId'

import { Button, ButtonDelete, ButtonDownload, ButtonIconEdit } from '@webapp/components'
import { Button, ButtonDelete, ButtonDownload, ButtonIconEdit, ButtonIconView } from '@webapp/components'
import { useConfirmAsync } from '@webapp/components/hooks'
import {
useAuthCanDeleteRecords,
useAuthCanEditRecord,
useAuthCanExportRecords,
useAuthCanExportRecordsList,
useAuthCanUpdateRecordsStep,
Expand Down Expand Up @@ -69,6 +70,7 @@ const HeaderLeft = ({ handleSearch, navigateToRecord, onRecordsUpdate, search, s

const selectedItemsCount = selectedItems.length
const selectedRecordsUuids = selectedItems.map((selectedItem) => selectedItem.uuid)
const canEditSelectedItem = useAuthCanEditRecord(selectedItems[0]) && selectedItems.length === 1

const [state, setState] = useState({
recordsCloneModalOpen: false,
Expand Down Expand Up @@ -206,10 +208,21 @@ const HeaderLeft = ({ handleSearch, navigateToRecord, onRecordsUpdate, search, s
/>
)}
{
// Edit selected record
selectedItemsCount === 1 && (
<ButtonIconEdit onClick={onSelectedRecordClick} title="dataView.editSelectedRecord" />
)
// View/Edit selected record
selectedItemsCount === 1 &&
(canEditSelectedItem ? (
<ButtonIconEdit
onClick={onSelectedRecordClick}
title="dataView.editSelectedRecord"
variant="contained"
/>
) : (
<ButtonIconView
onClick={onSelectedRecordClick}
title="dataView.viewSelectedRecord"
variant="contained"
/>
))
}
{canCloneRecords && (
<Button
Expand Down

0 comments on commit 3cc513b

Please sign in to comment.