Fix save-and-stay on new items (#474)

This commit is contained in:
Rijk van Zanten
2020-04-24 17:23:11 -04:00
committed by GitHub
parent 9138e7ab5b
commit 0d01265e9e
4 changed files with 30 additions and 4 deletions

View File

@@ -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({

View File

@@ -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() {

View File

@@ -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() {

View File

@@ -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() {