Skip to content

Commit

Permalink
Feature/display adhooc or scheduled (#731)
Browse files Browse the repository at this point in the history
* Add scheduled sufix to the requester name

Signed-off-by: Angatupyry <fierrofenix@gmail.com>

* Include icon in the requester column

Signed-off-by: Angatupyry <fierrofenix@gmail.com>

* Remove __shceduled and display only the username from schedule task and add Tooltip to the icons

Signed-off-by: Angatupyry <fierrofenix@gmail.com>

---------

Signed-off-by: Angatupyry <fierrofenix@gmail.com>
  • Loading branch information
Angatupyry authored Aug 4, 2023
1 parent 87bcb6f commit 0aa093d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
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

0 comments on commit 0aa093d

Please sign in to comment.