Skip to content

Commit

Permalink
Only submit form differential
Browse files Browse the repository at this point in the history
  • Loading branch information
kamorel committed Apr 5, 2023
1 parent 5a61807 commit d8c5a18
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
22 changes: 2 additions & 20 deletions frontend/src/components/bucket/BucketConfigForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Password from '@/components/form/Password.vue';
import TextInput from '@/components/form/TextInput.vue';
import { Button, useToast } from '@/lib/primevue';
import { useAuthStore, useBucketStore } from '@/store';
import { differential } from '@/utils/utils';
import type { Bucket } from '@/types';
Expand Down Expand Up @@ -50,19 +51,6 @@ const schema = object({
const toast = useToast();
const onSubmit = async (values: any) => {
const differential = (left: any, right: any) => {
let diff: any = {};
for (const [key, value] of Object.entries(left)) {
if(!Object.prototype.hasOwnProperty.call(right, key) ||
(Object.prototype.hasOwnProperty.call(right, key) && right[key] !== value)) {
diff[key] = value;
}
}
return diff;
};
try {
const formBucket = {
bucketName: values.bucketName,
Expand All @@ -73,14 +61,8 @@ const onSubmit = async (values: any) => {
key: values.key ? values.key : '/',
} as Bucket;
const d = differential(formBucket, initialValues);
console.log(values);
console.log(d);
return;
props.bucket ?
await bucketStore.updateBucket(props.bucket?.bucketId, formBucket) :
await bucketStore.updateBucket(props.bucket?.bucketId, differential(formBucket, initialValues)) :
await bucketStore.createBucket(formBucket);
await bucketStore.fetchBuckets({ userId: getUserId.value, objectPerms: true });
Expand Down
19 changes: 19 additions & 0 deletions frontend/src/utils/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
/**
* @function differential
* Create a key/value differential from source against comparer
* @param {object} source Source object
* @param {object} comparer The object to be compared against
* @returns {object} Object containing the non-matching key/value pairs in the source object
*/
export function differential(source: any, comparer: any) {
const diff: any = {};
for (const [key, value] of Object.entries(source)) {
if (!Object.prototype.hasOwnProperty.call(comparer, key) ||
(Object.prototype.hasOwnProperty.call(comparer, key) && comparer[key] !== value)) {
diff[key] = value;
}
}

return diff;
}

/**
* @function isDebugMode
* Checks if the app is currently running in debug mode
Expand Down

0 comments on commit d8c5a18

Please sign in to comment.