mirror of
https://github.com/inventree/InvenTree.git
synced 2025-05-02 13:28:49 +00:00
Platform URL fixes (#5705)
* Fix API endpoints for attachment tables * Fix API URLs for notifications * Valid PK required for attachment table
This commit is contained in:
parent
59efae0bfc
commit
65e9ba0633
@ -18,11 +18,7 @@ import { api } from '../../App';
|
|||||||
import { constructFormUrl } from '../../functions/forms';
|
import { constructFormUrl } from '../../functions/forms';
|
||||||
import { invalidResponse } from '../../functions/notifications';
|
import { invalidResponse } from '../../functions/notifications';
|
||||||
import { ApiPaths } from '../../states/ApiState';
|
import { ApiPaths } from '../../states/ApiState';
|
||||||
import {
|
import { ApiFormField, ApiFormFieldSet } from './fields/ApiFormField';
|
||||||
ApiFormField,
|
|
||||||
ApiFormFieldSet,
|
|
||||||
ApiFormFieldType
|
|
||||||
} from './fields/ApiFormField';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Properties for the ApiForm component
|
* Properties for the ApiForm component
|
||||||
|
@ -97,8 +97,9 @@ export function NotificationDrawer({
|
|||||||
color="gray"
|
color="gray"
|
||||||
variant="hover"
|
variant="hover"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
|
let url = apiUrl(ApiPaths.notifications_list, notification.pk);
|
||||||
api
|
api
|
||||||
.patch(`/notifications/${notification.pk}/`, {
|
.patch(url, {
|
||||||
read: true
|
read: true
|
||||||
})
|
})
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
|
@ -13,7 +13,7 @@ import {
|
|||||||
editAttachment
|
editAttachment
|
||||||
} from '../../functions/forms/AttachmentForms';
|
} from '../../functions/forms/AttachmentForms';
|
||||||
import { useTableRefresh } from '../../hooks/TableRefresh';
|
import { useTableRefresh } from '../../hooks/TableRefresh';
|
||||||
import { ApiPaths } from '../../states/ApiState';
|
import { ApiPaths, apiUrl } from '../../states/ApiState';
|
||||||
import { AttachmentLink } from '../items/AttachmentLink';
|
import { AttachmentLink } from '../items/AttachmentLink';
|
||||||
import { TableColumn } from './Column';
|
import { TableColumn } from './Column';
|
||||||
import { InvenTreeTable } from './InvenTreeTable';
|
import { InvenTreeTable } from './InvenTreeTable';
|
||||||
@ -73,11 +73,11 @@ function attachmentTableColumns(): TableColumn[] {
|
|||||||
* Construct a table for displaying uploaded attachments
|
* Construct a table for displaying uploaded attachments
|
||||||
*/
|
*/
|
||||||
export function AttachmentTable({
|
export function AttachmentTable({
|
||||||
url,
|
endpoint,
|
||||||
model,
|
model,
|
||||||
pk
|
pk
|
||||||
}: {
|
}: {
|
||||||
url: ApiPaths;
|
endpoint: ApiPaths;
|
||||||
pk: number;
|
pk: number;
|
||||||
model: string;
|
model: string;
|
||||||
}): ReactNode {
|
}): ReactNode {
|
||||||
@ -88,6 +88,10 @@ export function AttachmentTable({
|
|||||||
const [allowEdit, setAllowEdit] = useState<boolean>(false);
|
const [allowEdit, setAllowEdit] = useState<boolean>(false);
|
||||||
const [allowDelete, setAllowDelete] = useState<boolean>(false);
|
const [allowDelete, setAllowDelete] = useState<boolean>(false);
|
||||||
|
|
||||||
|
const url = useMemo(() => apiUrl(endpoint), [endpoint]);
|
||||||
|
|
||||||
|
const validPk = useMemo(() => pk > 0, [pk]);
|
||||||
|
|
||||||
// Determine which permissions are available for this URL
|
// Determine which permissions are available for this URL
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
api
|
api
|
||||||
@ -113,7 +117,7 @@ export function AttachmentTable({
|
|||||||
title: t`Edit`,
|
title: t`Edit`,
|
||||||
onClick: () => {
|
onClick: () => {
|
||||||
editAttachment({
|
editAttachment({
|
||||||
url: url,
|
endpoint: endpoint,
|
||||||
model: model,
|
model: model,
|
||||||
pk: record.pk,
|
pk: record.pk,
|
||||||
attachmentType: record.attachment ? 'file' : 'link',
|
attachmentType: record.attachment ? 'file' : 'link',
|
||||||
@ -129,7 +133,7 @@ export function AttachmentTable({
|
|||||||
color: 'red',
|
color: 'red',
|
||||||
onClick: () => {
|
onClick: () => {
|
||||||
deleteAttachment({
|
deleteAttachment({
|
||||||
url: url,
|
endpoint: endpoint,
|
||||||
pk: record.pk,
|
pk: record.pk,
|
||||||
callback: refreshTable
|
callback: refreshTable
|
||||||
});
|
});
|
||||||
@ -182,7 +186,7 @@ export function AttachmentTable({
|
|||||||
radius="sm"
|
radius="sm"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
addAttachment({
|
addAttachment({
|
||||||
url: url,
|
endpoint: endpoint,
|
||||||
model: model,
|
model: model,
|
||||||
pk: pk,
|
pk: pk,
|
||||||
attachmentType: 'file',
|
attachmentType: 'file',
|
||||||
@ -201,7 +205,7 @@ export function AttachmentTable({
|
|||||||
radius="sm"
|
radius="sm"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
addAttachment({
|
addAttachment({
|
||||||
url: url,
|
endpoint: endpoint,
|
||||||
model: model,
|
model: model,
|
||||||
pk: pk,
|
pk: pk,
|
||||||
attachmentType: 'link',
|
attachmentType: 'link',
|
||||||
@ -234,7 +238,7 @@ export function AttachmentTable({
|
|||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
{allowEdit && (
|
{allowEdit && validPk && (
|
||||||
<Dropzone onDrop={uploadFiles}>
|
<Dropzone onDrop={uploadFiles}>
|
||||||
<Dropzone.Idle>
|
<Dropzone.Idle>
|
||||||
<Group position="center">
|
<Group position="center">
|
||||||
|
@ -26,13 +26,13 @@ export function attachmentFields(editing: boolean): ApiFormFieldSet {
|
|||||||
* Add a new attachment (either a file or a link)
|
* Add a new attachment (either a file or a link)
|
||||||
*/
|
*/
|
||||||
export function addAttachment({
|
export function addAttachment({
|
||||||
url,
|
endpoint,
|
||||||
model,
|
model,
|
||||||
pk,
|
pk,
|
||||||
attachmentType,
|
attachmentType,
|
||||||
callback
|
callback
|
||||||
}: {
|
}: {
|
||||||
url: ApiPaths;
|
endpoint: ApiPaths;
|
||||||
model: string;
|
model: string;
|
||||||
pk: number;
|
pk: number;
|
||||||
attachmentType: 'file' | 'link';
|
attachmentType: 'file' | 'link';
|
||||||
@ -61,7 +61,7 @@ export function addAttachment({
|
|||||||
openCreateApiForm({
|
openCreateApiForm({
|
||||||
name: 'attachment-add',
|
name: 'attachment-add',
|
||||||
title: title,
|
title: title,
|
||||||
url: url,
|
url: endpoint,
|
||||||
successMessage: message,
|
successMessage: message,
|
||||||
fields: formFields,
|
fields: formFields,
|
||||||
onFormSuccess: callback
|
onFormSuccess: callback
|
||||||
@ -72,13 +72,13 @@ export function addAttachment({
|
|||||||
* Edit an existing attachment (either a file or a link)
|
* Edit an existing attachment (either a file or a link)
|
||||||
*/
|
*/
|
||||||
export function editAttachment({
|
export function editAttachment({
|
||||||
url,
|
endpoint,
|
||||||
model,
|
model,
|
||||||
pk,
|
pk,
|
||||||
attachmentType,
|
attachmentType,
|
||||||
callback
|
callback
|
||||||
}: {
|
}: {
|
||||||
url: ApiPaths;
|
endpoint: ApiPaths;
|
||||||
model: string;
|
model: string;
|
||||||
pk: number;
|
pk: number;
|
||||||
attachmentType: 'file' | 'link';
|
attachmentType: 'file' | 'link';
|
||||||
@ -104,7 +104,7 @@ export function editAttachment({
|
|||||||
openEditApiForm({
|
openEditApiForm({
|
||||||
name: 'attachment-edit',
|
name: 'attachment-edit',
|
||||||
title: title,
|
title: title,
|
||||||
url: url,
|
url: endpoint,
|
||||||
pk: pk,
|
pk: pk,
|
||||||
successMessage: message,
|
successMessage: message,
|
||||||
fields: formFields,
|
fields: formFields,
|
||||||
@ -113,16 +113,16 @@ export function editAttachment({
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function deleteAttachment({
|
export function deleteAttachment({
|
||||||
url,
|
endpoint,
|
||||||
pk,
|
pk,
|
||||||
callback
|
callback
|
||||||
}: {
|
}: {
|
||||||
url: ApiPaths;
|
endpoint: ApiPaths;
|
||||||
pk: number;
|
pk: number;
|
||||||
callback: () => void;
|
callback: () => void;
|
||||||
}) {
|
}) {
|
||||||
openDeleteApiForm({
|
openDeleteApiForm({
|
||||||
url: url,
|
url: endpoint,
|
||||||
pk: pk,
|
pk: pk,
|
||||||
name: 'attachment-edit',
|
name: 'attachment-edit',
|
||||||
title: t`Delete Attachment`,
|
title: t`Delete Attachment`,
|
||||||
|
@ -9,6 +9,7 @@ import { PageDetail } from '../components/nav/PageDetail';
|
|||||||
import { PanelGroup } from '../components/nav/PanelGroup';
|
import { PanelGroup } from '../components/nav/PanelGroup';
|
||||||
import { NotificationTable } from '../components/tables/notifications/NotificationsTable';
|
import { NotificationTable } from '../components/tables/notifications/NotificationsTable';
|
||||||
import { useTableRefresh } from '../hooks/TableRefresh';
|
import { useTableRefresh } from '../hooks/TableRefresh';
|
||||||
|
import { ApiPaths, apiUrl } from '../states/ApiState';
|
||||||
|
|
||||||
export default function NotificationsPage() {
|
export default function NotificationsPage() {
|
||||||
const unreadRefresh = useTableRefresh('unreadnotifications');
|
const unreadRefresh = useTableRefresh('unreadnotifications');
|
||||||
@ -28,8 +29,9 @@ export default function NotificationsPage() {
|
|||||||
{
|
{
|
||||||
title: t`Mark as read`,
|
title: t`Mark as read`,
|
||||||
onClick: () => {
|
onClick: () => {
|
||||||
|
let url = apiUrl(ApiPaths.notifications_list, record.pk);
|
||||||
api
|
api
|
||||||
.patch(`/notifications/${record.pk}/`, {
|
.patch(url, {
|
||||||
read: true
|
read: true
|
||||||
})
|
})
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
@ -53,8 +55,10 @@ export default function NotificationsPage() {
|
|||||||
{
|
{
|
||||||
title: t`Mark as unread`,
|
title: t`Mark as unread`,
|
||||||
onClick: () => {
|
onClick: () => {
|
||||||
|
let url = apiUrl(ApiPaths.notifications_list, record.pk);
|
||||||
|
|
||||||
api
|
api
|
||||||
.patch(`/notifications/${record.pk}/`, {
|
.patch(url, {
|
||||||
read: false
|
read: false
|
||||||
})
|
})
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
|
@ -109,7 +109,7 @@ export default function BuildDetail() {
|
|||||||
icon: <IconPaperclip size="18" />,
|
icon: <IconPaperclip size="18" />,
|
||||||
content: (
|
content: (
|
||||||
<AttachmentTable
|
<AttachmentTable
|
||||||
url={ApiPaths.build_order_attachment_list}
|
endpoint={ApiPaths.build_order_attachment_list}
|
||||||
model="build"
|
model="build"
|
||||||
pk={build.pk ?? -1}
|
pk={build.pk ?? -1}
|
||||||
/>
|
/>
|
||||||
|
@ -138,7 +138,7 @@ export default function PartDetail() {
|
|||||||
icon: <IconPaperclip size="18" />,
|
icon: <IconPaperclip size="18" />,
|
||||||
content: (
|
content: (
|
||||||
<AttachmentTable
|
<AttachmentTable
|
||||||
url={ApiPaths.part_attachment_list}
|
endpoint={ApiPaths.part_attachment_list}
|
||||||
model="part"
|
model="part"
|
||||||
pk={part.pk ?? -1}
|
pk={part.pk ?? -1}
|
||||||
/>
|
/>
|
||||||
|
@ -75,7 +75,7 @@ export default function StockDetail() {
|
|||||||
icon: <IconPaperclip size="18" />,
|
icon: <IconPaperclip size="18" />,
|
||||||
content: (
|
content: (
|
||||||
<AttachmentTable
|
<AttachmentTable
|
||||||
url={ApiPaths.stock_attachment_list}
|
endpoint={ApiPaths.stock_attachment_list}
|
||||||
model="stock_item"
|
model="stock_item"
|
||||||
pk={stockitem.pk ?? -1}
|
pk={stockitem.pk ?? -1}
|
||||||
/>
|
/>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user