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

Show projectobject operative names instead of ids #720

Merged
merged 1 commit into from
Sep 19, 2023
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
28 changes: 18 additions & 10 deletions frontend/src/views/WorkTable/ProjectObjectUsers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,23 @@ interface Props {
onChange: (value: Value) => void;
}

export function ProjectObjectUsers({ value }: { value: Value }) {
const users = trpc.user.getAll.useQuery();

return (
<Box
css={(theme) => css`
display: flex;
flex-direction: column;
padding: ${theme.spacing(1)};
`}
>
<span>{users.data?.find(({ id }) => id === value.rakennuttajaUser)?.name}</span>
<span>{users.data?.find(({ id }) => id === value.suunnitteluttajaUser)?.name}</span>
</Box>
);
}

export function ProjectObjectUserEdit({ value, onChange }: Props) {
const tr = useTranslations();
const anchorElRef = useRef<HTMLDivElement>(null);
Expand All @@ -39,16 +56,7 @@ export function ProjectObjectUserEdit({ value, onChange }: Props) {

return (
<Box ref={anchorElRef} position={'absolute'}>
<Box
css={(theme) => css`
display: flex;
flex-direction: column;
padding: ${theme.spacing(1)};
`}
>
<i>{value.rakennuttajaUser}</i>
<i>{value.suunnitteluttajaUser}</i>
</Box>
<ProjectObjectUsers value={value} />
<Popper open={open} anchorEl={anchorElRef.current?.parentElement} placement={'bottom-end'}>
{open && users.isLoading && (
<Paper sx={{ p: 1 }}>
Expand Down
18 changes: 5 additions & 13 deletions frontend/src/views/WorkTable/columns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ import { TableCodeSelect } from '@frontend/views/WorkTable/CodeSelect';
import { CodeSpanMulti } from '@frontend/views/WorkTable/CodeSpanMulti';
import { CurrencyEdit } from '@frontend/views/WorkTable/CurrencyEdit';
import { DateRangeEdit, DateRangeView } from '@frontend/views/WorkTable/DateRangePicker';
import { ProjectObjectUserEdit } from '@frontend/views/WorkTable/ProjectObjectUsers';
import {
ProjectObjectUserEdit,
ProjectObjectUsers,
} from '@frontend/views/WorkTable/ProjectObjectUsers';

import { CodeSpan } from './CodeSpan';
import { ProjectObjectNameEdit } from './ProjectObjectNameEdit';
Expand Down Expand Up @@ -236,18 +239,7 @@ export function getColumns({ modifiedFields }: GetColumnsParams): GridColDef<Wor
field: 'operatives',
headerName: 'Rakennuttaja / Suunnitteluttaja',
width: 144,
renderCell: ({ value }: GridRenderCellParams) => (
<div
css={css`
display: flex;
flex-direction: column;
align-items: flex-start;
`}
>
<div>{value.rakennuttajaUser}</div>
<div>{value.suunnitteluttajaUser}</div>
</div>
),
renderCell: ({ value }: GridRenderCellParams) => <ProjectObjectUsers value={value} />,
renderEditCell: (params: GridRenderEditCellParams) => {
const { id, field, value } = params;
return (
Expand Down