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

Feature/display adhooc or scheduled #731

Merged
merged 3 commits into from
Aug 4, 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
4 changes: 3 additions & 1 deletion packages/react-components/lib/tasks/create-task.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -884,8 +884,10 @@ export function CreateTaskForm({
return;
}

const requester = scheduling ? `${user}__scheduled` : user;

for (const t of taskRequests) {
t.requester = user;
t.requester = requester;
t.unix_millis_request_time = Date.now();
}

Expand Down
41 changes: 36 additions & 5 deletions packages/react-components/lib/tasks/task-table-datagrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import {
GridFilterModel,
GridSortModel,
} from '@mui/x-data-grid';
import { styled, TextField } from '@mui/material';
import { styled, TextField, Stack, Typography, Tooltip } from '@mui/material';
import * as React from 'react';
import { TaskState, Status } from 'api-client';
import { InsertInvitation as ScheduleIcon, Person as UserIcon } from '@mui/icons-material/';

const classes = {
taskActiveCell: 'MuiDataGrid-cell-active-cell',
Expand Down Expand Up @@ -79,6 +80,37 @@ export interface TableDataGridState {
setSortFields: React.Dispatch<React.SetStateAction<SortFields>>;
}

const TaskRequester = (requester: string | null): JSX.Element => {
if (!requester) {
return <Typography variant="body1">unknown</Typography>;
}

/** When a task is created as scheduled,
we save the requester as USERNAME__scheduled.
Therefore, we remove the __schedule because the different icon is enough indicator to know
if the task was adhoc or scheduled.
*/
return (
<Stack direction="row" alignItems="center" gap={1}>
{requester.includes('scheduled') ? (
<>
<Tooltip title="User scheduled">
<ScheduleIcon />
</Tooltip>
<Typography variant="body1">{requester.split('__')[0]}</Typography>
</>
) : (
<>
<Tooltip title="User submitted">
<UserIcon />
</Tooltip>
<Typography variant="body1">{requester}</Typography>
</>
)}
</Stack>
);
};

export function TaskDataGridTable({
tasks,
onTaskClick,
Expand Down Expand Up @@ -134,11 +166,10 @@ export function TaskDataGridTable({
{
field: 'requester',
headerName: 'Requester',
width: 150,
minWidth: 160,
editable: false,
valueGetter: (params: GridValueGetterParams) =>
params.row.booking.requester ? params.row.booking.requester : 'unknown',
flex: 1,
renderCell: (cellValues) => TaskRequester(cellValues.row.booking.requester),
flex: 2,
filterOperators: getMinimalStringFilterOperators,
filterable: true,
},
Expand Down
Loading