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