mirror of
https://github.com/inventree/InvenTree.git
synced 2025-10-29 20:30:39 +00:00
[UI] User column (#10661)
* Refactor user display columns * More refactoring
This commit is contained in:
@@ -2,7 +2,15 @@
|
|||||||
* Common rendering functions for table column data.
|
* Common rendering functions for table column data.
|
||||||
*/
|
*/
|
||||||
import { t } from '@lingui/core/macro';
|
import { t } from '@lingui/core/macro';
|
||||||
import { Anchor, Center, Group, Skeleton, Text, Tooltip } from '@mantine/core';
|
import {
|
||||||
|
Anchor,
|
||||||
|
Badge,
|
||||||
|
Center,
|
||||||
|
Group,
|
||||||
|
Skeleton,
|
||||||
|
Text,
|
||||||
|
Tooltip
|
||||||
|
} from '@mantine/core';
|
||||||
import {
|
import {
|
||||||
IconBell,
|
IconBell,
|
||||||
IconExclamationCircle,
|
IconExclamationCircle,
|
||||||
@@ -16,9 +24,10 @@ import type { ModelType } from '@lib/enums/ModelType';
|
|||||||
import { resolveItem } from '@lib/functions/Conversion';
|
import { resolveItem } from '@lib/functions/Conversion';
|
||||||
import { cancelEvent } from '@lib/functions/Events';
|
import { cancelEvent } from '@lib/functions/Events';
|
||||||
import type { TableColumn, TableColumnProps } from '@lib/types/Tables';
|
import type { TableColumn, TableColumnProps } from '@lib/types/Tables';
|
||||||
|
import type { ReactNode } from 'react';
|
||||||
import { Thumbnail } from '../components/images/Thumbnail';
|
import { Thumbnail } from '../components/images/Thumbnail';
|
||||||
import { TableStatusRenderer } from '../components/render/StatusRenderer';
|
import { TableStatusRenderer } from '../components/render/StatusRenderer';
|
||||||
import { RenderOwner, RenderUser } from '../components/render/User';
|
import { RenderOwner } from '../components/render/User';
|
||||||
import {
|
import {
|
||||||
formatCurrency,
|
formatCurrency,
|
||||||
formatDate,
|
formatDate,
|
||||||
@@ -380,28 +389,81 @@ export function StatusColumn(props: StatusColumnProps): TableColumn {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function CreatedByColumn(props: TableColumnProps): TableColumn {
|
export function UserColumn(props: TableColumnProps): TableColumn {
|
||||||
return {
|
return {
|
||||||
accessor: 'created_by',
|
accessor: 'user',
|
||||||
title: t`Created By`,
|
title: t`User`,
|
||||||
sortable: true,
|
sortable: true,
|
||||||
switchable: true,
|
switchable: true,
|
||||||
render: (record: any) =>
|
render: (record: any) => {
|
||||||
record.created_by && RenderUser({ instance: record.created_by }),
|
const instance = resolveItem(record, props.accessor ?? 'user_detail');
|
||||||
|
if (instance) {
|
||||||
|
const extra: ReactNode[] = [
|
||||||
|
<Text size='sm'>
|
||||||
|
{instance.first_name} {instance.last_name}
|
||||||
|
</Text>
|
||||||
|
];
|
||||||
|
|
||||||
|
if (instance.is_active === false) {
|
||||||
|
extra.push(
|
||||||
|
<Badge autoContrast color='red' size='xs'>
|
||||||
|
{t`Inactive`}
|
||||||
|
</Badge>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<TableHoverCard
|
||||||
|
value={instance.username}
|
||||||
|
title={t`User Information`}
|
||||||
|
icon='user'
|
||||||
|
extra={extra}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return '-';
|
||||||
|
}
|
||||||
|
},
|
||||||
|
...props
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function CreatedByColumn(props: TableColumnProps): TableColumn {
|
||||||
|
return UserColumn({
|
||||||
|
accessor: 'created_by',
|
||||||
|
ordering: 'created_by',
|
||||||
|
title: t`Created By`,
|
||||||
|
...props
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function OwnerColumn(props: TableColumnProps): TableColumn {
|
||||||
|
return {
|
||||||
|
accessor: 'owner_detail',
|
||||||
|
ordering: 'owner',
|
||||||
|
title: t`Owner`,
|
||||||
|
sortable: true,
|
||||||
|
switchable: true,
|
||||||
|
render: (record: any) => {
|
||||||
|
const instance = resolveItem(record, props.accessor ?? 'owner_detail');
|
||||||
|
|
||||||
|
if (instance) {
|
||||||
|
return <RenderOwner instance={instance} />;
|
||||||
|
} else {
|
||||||
|
return '-';
|
||||||
|
}
|
||||||
|
},
|
||||||
...props
|
...props
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ResponsibleColumn(props: TableColumnProps): TableColumn {
|
export function ResponsibleColumn(props: TableColumnProps): TableColumn {
|
||||||
return {
|
return OwnerColumn({
|
||||||
accessor: 'responsible',
|
accessor: 'responsible_detail',
|
||||||
sortable: true,
|
ordering: 'responsible',
|
||||||
switchable: true,
|
title: t`Responsible`,
|
||||||
render: (record: any) =>
|
|
||||||
record.responsible &&
|
|
||||||
RenderOwner({ instance: record.responsible_detail }),
|
|
||||||
...props
|
...props
|
||||||
};
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function DateColumn(props: TableColumnProps): TableColumn {
|
export function DateColumn(props: TableColumnProps): TableColumn {
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import { ModelType } from '@lib/enums/ModelType';
|
|||||||
import { UserRoles } from '@lib/enums/Roles';
|
import { UserRoles } from '@lib/enums/Roles';
|
||||||
import { apiUrl } from '@lib/functions/Api';
|
import { apiUrl } from '@lib/functions/Api';
|
||||||
import type { TableFilter } from '@lib/types/Filters';
|
import type { TableFilter } from '@lib/types/Filters';
|
||||||
import { RenderUser } from '../../components/render/User';
|
|
||||||
import { useBuildOrderFields } from '../../forms/BuildForms';
|
import { useBuildOrderFields } from '../../forms/BuildForms';
|
||||||
import { useCreateApiFormModal } from '../../hooks/UseForm';
|
import { useCreateApiFormModal } from '../../hooks/UseForm';
|
||||||
import { useTable } from '../../hooks/UseTable';
|
import { useTable } from '../../hooks/UseTable';
|
||||||
@@ -25,7 +24,8 @@ import {
|
|||||||
ResponsibleColumn,
|
ResponsibleColumn,
|
||||||
StartDateColumn,
|
StartDateColumn,
|
||||||
StatusColumn,
|
StatusColumn,
|
||||||
TargetDateColumn
|
TargetDateColumn,
|
||||||
|
UserColumn
|
||||||
} from '../ColumnRenderers';
|
} from '../ColumnRenderers';
|
||||||
import {
|
import {
|
||||||
AssignedToMeFilter,
|
AssignedToMeFilter,
|
||||||
@@ -137,13 +137,11 @@ export function BuildOrderTable({
|
|||||||
title: t`Completion Date`,
|
title: t`Completion Date`,
|
||||||
sortable: true
|
sortable: true
|
||||||
}),
|
}),
|
||||||
{
|
UserColumn({
|
||||||
accessor: 'issued_by',
|
accessor: 'issued_by_detail',
|
||||||
sortable: true,
|
ordering: 'issued_by',
|
||||||
render: (record: any) => (
|
title: t`Issued By`
|
||||||
<RenderUser instance={record?.issued_by_detail} />
|
}),
|
||||||
)
|
|
||||||
},
|
|
||||||
ResponsibleColumn({})
|
ResponsibleColumn({})
|
||||||
];
|
];
|
||||||
}, [parentBuildId, globalSettings]);
|
}, [parentBuildId, globalSettings]);
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ import { apiUrl } from '@lib/functions/Api';
|
|||||||
import type { TableFilter } from '@lib/types/Filters';
|
import type { TableFilter } from '@lib/types/Filters';
|
||||||
import type { ApiFormFieldSet } from '@lib/types/Forms';
|
import type { ApiFormFieldSet } from '@lib/types/Forms';
|
||||||
import type { TableColumn } from '@lib/types/Tables';
|
import type { TableColumn } from '@lib/types/Tables';
|
||||||
import { RenderUser } from '../../components/render/User';
|
|
||||||
import { formatDecimal } from '../../defaults/formatters';
|
import { formatDecimal } from '../../defaults/formatters';
|
||||||
import { usePartParameterFields } from '../../forms/PartForms';
|
import { usePartParameterFields } from '../../forms/PartForms';
|
||||||
import {
|
import {
|
||||||
@@ -30,7 +29,8 @@ import {
|
|||||||
DateColumn,
|
DateColumn,
|
||||||
DescriptionColumn,
|
DescriptionColumn,
|
||||||
NoteColumn,
|
NoteColumn,
|
||||||
PartColumn
|
PartColumn,
|
||||||
|
UserColumn
|
||||||
} from '../ColumnRenderers';
|
} from '../ColumnRenderers';
|
||||||
import { IncludeVariantsFilter, UserFilter } from '../Filter';
|
import { IncludeVariantsFilter, UserFilter } from '../Filter';
|
||||||
import { InvenTreeTable } from '../InvenTreeTable';
|
import { InvenTreeTable } from '../InvenTreeTable';
|
||||||
@@ -122,19 +122,11 @@ export function PartParameterTable({
|
|||||||
sortable: true,
|
sortable: true,
|
||||||
switchable: true
|
switchable: true
|
||||||
}),
|
}),
|
||||||
{
|
UserColumn({
|
||||||
accessor: 'updated_by',
|
accessor: 'updated_by_detail',
|
||||||
title: t`Updated By`,
|
ordering: 'updated_by',
|
||||||
sortable: true,
|
title: t`Updated By`
|
||||||
switchable: true,
|
})
|
||||||
render: (record: any) => {
|
|
||||||
return record.updated_by_detail ? (
|
|
||||||
<RenderUser instance={record.updated_by_detail} />
|
|
||||||
) : (
|
|
||||||
'-'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
];
|
];
|
||||||
}, [partId]);
|
}, [partId]);
|
||||||
|
|
||||||
|
|||||||
@@ -12,11 +12,10 @@ import { useCallback, useMemo, useState } from 'react';
|
|||||||
import { api } from '../../App';
|
import { api } from '../../App';
|
||||||
import { CopyButton } from '../../components/buttons/CopyButton';
|
import { CopyButton } from '../../components/buttons/CopyButton';
|
||||||
import { StylishText } from '../../components/items/StylishText';
|
import { StylishText } from '../../components/items/StylishText';
|
||||||
import { RenderUser } from '../../components/render/User';
|
|
||||||
import { showApiErrorMessage } from '../../functions/notifications';
|
import { showApiErrorMessage } from '../../functions/notifications';
|
||||||
import { useCreateApiFormModal } from '../../hooks/UseForm';
|
import { useCreateApiFormModal } from '../../hooks/UseForm';
|
||||||
import { useTable } from '../../hooks/UseTable';
|
import { useTable } from '../../hooks/UseTable';
|
||||||
import { BooleanColumn } from '../ColumnRenderers';
|
import { BooleanColumn, UserColumn } from '../ColumnRenderers';
|
||||||
import { UserFilter } from '../Filter';
|
import { UserFilter } from '../Filter';
|
||||||
import { InvenTreeTable } from '../InvenTreeTable';
|
import { InvenTreeTable } from '../InvenTreeTable';
|
||||||
|
|
||||||
@@ -100,18 +99,13 @@ export function ApiTokenTable({
|
|||||||
}
|
}
|
||||||
];
|
];
|
||||||
if (!only_myself) {
|
if (!only_myself) {
|
||||||
cols.push({
|
cols.push(
|
||||||
accessor: 'user',
|
UserColumn({
|
||||||
title: t`User`,
|
accessor: 'user_detail',
|
||||||
sortable: true,
|
ordering: 'user',
|
||||||
render: (record: any) => {
|
title: t`User`
|
||||||
if (record.user_detail) {
|
})
|
||||||
return <RenderUser instance={record.user_detail} />;
|
);
|
||||||
} else {
|
|
||||||
return record.user;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
return cols;
|
return cols;
|
||||||
}, [only_myself]);
|
}, [only_myself]);
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ import type { TableFilter } from '@lib/types/Filters';
|
|||||||
import type { ApiFormFieldSet } from '@lib/types/Forms';
|
import type { ApiFormFieldSet } from '@lib/types/Forms';
|
||||||
import type { TableColumn } from '@lib/types/Tables';
|
import type { TableColumn } from '@lib/types/Tables';
|
||||||
import { AttachmentLink } from '../../components/items/AttachmentLink';
|
import { AttachmentLink } from '../../components/items/AttachmentLink';
|
||||||
import { RenderUser } from '../../components/render/User';
|
|
||||||
import { useApi } from '../../contexts/ApiContext';
|
import { useApi } from '../../contexts/ApiContext';
|
||||||
import { formatDate } from '../../defaults/formatters';
|
import { formatDate } from '../../defaults/formatters';
|
||||||
import { useTestResultFields } from '../../forms/StockForms';
|
import { useTestResultFields } from '../../forms/StockForms';
|
||||||
@@ -37,7 +36,12 @@ import {
|
|||||||
import { useTable } from '../../hooks/UseTable';
|
import { useTable } from '../../hooks/UseTable';
|
||||||
import { useGlobalSettingsState } from '../../states/SettingsStates';
|
import { useGlobalSettingsState } from '../../states/SettingsStates';
|
||||||
import { useUserState } from '../../states/UserState';
|
import { useUserState } from '../../states/UserState';
|
||||||
import { DateColumn, DescriptionColumn, NoteColumn } from '../ColumnRenderers';
|
import {
|
||||||
|
DateColumn,
|
||||||
|
DescriptionColumn,
|
||||||
|
NoteColumn,
|
||||||
|
UserColumn
|
||||||
|
} from '../ColumnRenderers';
|
||||||
import { InvenTreeTable } from '../InvenTreeTable';
|
import { InvenTreeTable } from '../InvenTreeTable';
|
||||||
import RowExpansionIcon from '../RowExpansionIcon';
|
import RowExpansionIcon from '../RowExpansionIcon';
|
||||||
|
|
||||||
@@ -211,13 +215,10 @@ export default function StockItemTestResultTable({
|
|||||||
},
|
},
|
||||||
NoteColumn({}),
|
NoteColumn({}),
|
||||||
DateColumn({}),
|
DateColumn({}),
|
||||||
{
|
UserColumn({
|
||||||
accessor: 'user',
|
accessor: 'user_detail',
|
||||||
title: t`User`,
|
ordering: 'user'
|
||||||
sortable: false,
|
}),
|
||||||
render: (record: any) =>
|
|
||||||
record.user_detail && <RenderUser instance={record.user_detail} />
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
accessor: 'test_station',
|
accessor: 'test_station',
|
||||||
sortable: true,
|
sortable: true,
|
||||||
|
|||||||
Reference in New Issue
Block a user