Merge branch 'master' into preview-panel

This commit is contained in:
Oliver 2026-06-30 00:37:08 +10:00 committed by GitHub
commit 9e2383de39
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 11 deletions

View File

@ -455,6 +455,12 @@ export function ApiForm({
}
})
.then((response) => {
const followPk = Array.isArray(response.data)
? response.data.length === 1
? response.data[0]?.pk
: undefined
: response.data?.pk;
switch (response.status) {
case 200:
case 201:
@ -469,12 +475,12 @@ export function ApiForm({
if (
props.follow &&
props.modelType &&
response.data?.pk &&
followPk &&
!keepOpenRef.current
) {
// If we want to automatically follow the returned data
if (!!navigate && !keepOpenRef.current) {
navigate(getDetailUrl(props.modelType, response.data?.pk));
navigate(getDetailUrl(props.modelType, followPk));
}
} else if (props.table) {
// If we want to automatically update or reload a linked table

View File

@ -1,6 +1,5 @@
import { t } from '@lingui/core/macro';
import { useMemo, useState } from 'react';
import { useNavigate } from 'react-router-dom';
import { ActionButton } from '@lib/components/ActionButton';
import { AddItemButton } from '@lib/components/AddItemButton';
@ -8,7 +7,6 @@ import { ApiEndpoints } from '@lib/enums/ApiEndpoints';
import { ModelType } from '@lib/enums/ModelType';
import { UserRoles } from '@lib/enums/Roles';
import { apiUrl } from '@lib/functions/Api';
import { getDetailUrl } from '@lib/functions/Navigation';
import useTable from '@lib/hooks/UseTable';
import type { TableFilter } from '@lib/types/Filters';
import type { StockOperationProps } from '@lib/types/Forms';
@ -381,8 +379,6 @@ export function StockItemTable({
[settings]
);
const navigate = useNavigate();
const tableColumns = useMemo(
() =>
stockItemTableColumns({
@ -433,11 +429,7 @@ export function StockItemTable({
},
follow: params.openNewStockItem ?? true,
table: table,
onFormSuccess: (response: any) => {
// Returns a list that may contain multiple serialized stock items
// Navigate to the first result
navigate(getDetailUrl(ModelType.stockitem, response[0].pk));
},
modelType: ModelType.stockitem,
successMessage: t`Stock item created`,
keepOpenOption: true
});