Skip to content

Commit

Permalink
Show driver name
Browse files Browse the repository at this point in the history
  • Loading branch information
tananaev committed Nov 19, 2023
1 parent 00eb494 commit 1b21fad
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 11 deletions.
2 changes: 1 addition & 1 deletion modern/src/common/attributes/usePositionAttributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ export default (t) => useMemo(() => ({
type: 'string',
},
driverUniqueId: {
name: t('positionDriverUniqueId'),
name: t('sharedDriver'),
type: 'string',
},
card: {
Expand Down
9 changes: 9 additions & 0 deletions modern/src/common/components/DriverValue.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { useSelector } from 'react-redux';

const DriverValue = ({ driverUniqueId }) => {
const driver = useSelector((state) => state.drivers.items[driverUniqueId]);

return driver.name;
};

export default DriverValue;
16 changes: 11 additions & 5 deletions modern/src/common/components/PositionValue.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { useTranslation } from './LocalizationProvider';
import { useAdministrator } from '../util/permissions';
import AddressValue from './AddressValue';
import GeofencesValue from './GeofencesValue';
import DriverValue from './DriverValue';

const PositionValue = ({ position, property, attribute }) => {
const t = useTranslation();
Expand Down Expand Up @@ -97,26 +98,31 @@ const PositionValue = ({ position, property, attribute }) => {
case 'image':
case 'video':
case 'audio':
return (<Link href={`/api/media/${device.uniqueId}/${value}`} target="_blank">{value}</Link>);
return <Link href={`/api/media/${device.uniqueId}/${value}`} target="_blank">{value}</Link>;
case 'totalDistance':
case 'hours':
return (
<>
{formatValue(value)}
&nbsp;&nbsp;
{admin && (<Link component={RouterLink} underline="none" to={`/settings/accumulators/${position.deviceId}`}>&#9881;</Link>)}
{admin && <Link component={RouterLink} underline="none" to={`/settings/accumulators/${position.deviceId}`}>&#9881;</Link>}
</>
);
case 'address':
return (<AddressValue latitude={position.latitude} longitude={position.longitude} originalAddress={value} />);
return <AddressValue latitude={position.latitude} longitude={position.longitude} originalAddress={value} />;
case 'network':
if (value) {
return (<Link component={RouterLink} underline="none" to={`/network/${position.id}`}>{t('sharedInfoTitle')}</Link>);
return <Link component={RouterLink} underline="none" to={`/network/${position.id}`}>{t('sharedInfoTitle')}</Link>;
}
return '';
case 'geofenceIds':
if (value) {
return (<GeofencesValue geofenceIds={value} />);
return <GeofencesValue geofenceIds={value} />;
}
return '';
case 'driverUniqueId':
if (value) {
return <DriverValue driverUniqueId={value} />;
}
return '';
default:
Expand Down
2 changes: 1 addition & 1 deletion modern/src/common/components/StatusCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ const StatusCard = ({ deviceId, position, onClose, disableActions, desktopPaddin
{positionItems.split(',').filter((key) => position.hasOwnProperty(key) || position.attributes.hasOwnProperty(key)).map((key) => (
<StatusRow
key={key}
name={positionAttributes.hasOwnProperty(key) ? positionAttributes[key].name : key}
name={positionAttributes[key]?.name || key}
content={(
<PositionValue
position={position}
Expand Down
7 changes: 5 additions & 2 deletions modern/src/other/PositionPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { useEffectAsync } from '../reactHelper';
import { prefixString } from '../common/util/stringUtils';
import { useTranslation } from '../common/components/LocalizationProvider';
import PositionValue from '../common/components/PositionValue';
import usePositionAttributes from '../common/attributes/usePositionAttributes';

const useStyles = makeStyles((theme) => ({
root: {
Expand All @@ -30,6 +31,8 @@ const PositionPage = () => {
const navigate = useNavigate();
const t = useTranslation();

const positionAttributes = usePositionAttributes(t);

const { id } = useParams();

const [item, setItem] = useState();
Expand Down Expand Up @@ -85,14 +88,14 @@ const PositionPage = () => {
{item && Object.getOwnPropertyNames(item).filter((it) => it !== 'attributes').map((property) => (
<TableRow key={property}>
<TableCell>{property}</TableCell>
<TableCell><strong>{t(prefixString('position', property))}</strong></TableCell>
<TableCell><strong>{positionAttributes[property]?.name || property}</strong></TableCell>
<TableCell><PositionValue position={item} property={property} /></TableCell>
</TableRow>
))}
{item && Object.getOwnPropertyNames(item.attributes).map((attribute) => (
<TableRow key={attribute}>
<TableCell>{attribute}</TableCell>
<TableCell><strong>{t(prefixString('position', attribute)) || t(prefixString('device', attribute))}</strong></TableCell>
<TableCell><strong>{positionAttributes[attribute]?.name || attribute}</strong></TableCell>
<TableCell><PositionValue position={item} attribute={attribute} /></TableCell>
</TableRow>
))}
Expand Down
2 changes: 1 addition & 1 deletion modern/src/settings/PreferencesPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ const PreferencesPage = () => {
multiple
freeSolo
options={Object.keys(positionAttributes)}
getOptionLabel={(option) => (positionAttributes.hasOwnProperty(option) ? positionAttributes[option].name : option)}
getOptionLabel={(option) => (positionAttributes[option]?.name || option)}
value={attributes.positionItems?.split(',') || ['speed', 'address', 'totalDistance', 'course']}
onChange={(_, option) => {
setAttributes({ ...attributes, positionItems: option.join(',') });
Expand Down
2 changes: 1 addition & 1 deletion modern/src/store/drivers.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const { reducer, actions } = createSlice({
},
reducers: {
update(state, action) {
action.payload.forEach((item) => state.items[item.id] = item);
action.payload.forEach((item) => state.items[item.uniqueId] = item);
},
},
});
Expand Down

0 comments on commit 1b21fad

Please sign in to comment.