mirror of
https://github.com/directus/directus.git
synced 2026-04-03 03:00:39 -04:00
Fix save-and-stay on new items (#474)
This commit is contained in:
@@ -96,6 +96,7 @@ export function useItem(collection: Ref<string>, primaryKey: Ref<string | number
|
||||
|
||||
setItemValueToResponse(response);
|
||||
edits.value = {};
|
||||
return response.data.data;
|
||||
} catch (err) {
|
||||
if (isNew.value) {
|
||||
notify({
|
||||
|
||||
@@ -162,7 +162,9 @@ export default defineComponent({
|
||||
const { currentProjectKey } = toRefs(projectsStore.state);
|
||||
const { collection, primaryKey } = toRefs(props);
|
||||
|
||||
const { info: collectionInfo, softDeleteStatus } = useCollection(collection);
|
||||
const { info: collectionInfo, softDeleteStatus, primaryKeyField } = useCollection(
|
||||
collection
|
||||
);
|
||||
|
||||
const {
|
||||
isNew,
|
||||
@@ -217,7 +219,16 @@ export default defineComponent({
|
||||
}
|
||||
|
||||
async function saveAndStay() {
|
||||
await save();
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const savedItem: Record<string, any> = await save();
|
||||
|
||||
if (props.primaryKey === '+') {
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
const newPrimaryKey = savedItem[primaryKeyField.value!.field];
|
||||
router.replace(
|
||||
`/${currentProjectKey.value}/collections/${props.collection}/${newPrimaryKey}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async function saveAndAddNew() {
|
||||
|
||||
@@ -164,7 +164,14 @@ export default defineComponent({
|
||||
}
|
||||
|
||||
async function saveAndStay() {
|
||||
await save();
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const savedItem: Record<string, any> = await save();
|
||||
|
||||
if (props.primaryKey === '+') {
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
const newPrimaryKey = savedItem.id;
|
||||
router.replace(`/${currentProjectKey.value}/collections/files/${newPrimaryKey}`);
|
||||
}
|
||||
}
|
||||
|
||||
async function saveAndAddNew() {
|
||||
|
||||
@@ -164,7 +164,14 @@ export default defineComponent({
|
||||
}
|
||||
|
||||
async function saveAndStay() {
|
||||
await save();
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const savedItem: Record<string, any> = await save();
|
||||
|
||||
if (props.primaryKey === '+') {
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
const newPrimaryKey = savedItem.id;
|
||||
router.replace(`/${currentProjectKey.value}/collections/users/${newPrimaryKey}`);
|
||||
}
|
||||
}
|
||||
|
||||
async function saveAndAddNew() {
|
||||
|
||||
Reference in New Issue
Block a user