Skip to content

Commit

Permalink
fix: Delete requests should use the correct params
Browse files Browse the repository at this point in the history
  • Loading branch information
staylorwr committed Dec 14, 2020
1 parent d072dcb commit 331b996
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 6 deletions.
1 change: 1 addition & 0 deletions assets/src/components/DeleteMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export default {
deleteSelectedResources () {
if (this.allMatchingSelected) {
this.$emit('deleteAllMatching');
return;
}
this.$emit('deleteSelected');
Expand Down
2 changes: 1 addition & 1 deletion assets/src/components/Index/ResourceTableRow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@
</template>

<script>
import { Deleteable } from 'ex-teal-js';
import Deleteable from '@/mixins/Deleteable';
export default {
mixins: [ Deleteable ],
props: {
Expand Down
97 changes: 97 additions & 0 deletions assets/src/mixins/Deleteable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
const Deleteable = {
computed: {
deleteParams () {
return {
search: this.currentSearch,
field_filters: this.encodedFieldFilters,
via_resource: this.viaResource,
via_resource_id: this.viaResourceId,
via_resource_relationship: this.viaResourceRelationship,
via_relationship: this.viaRelationship,
relationship_type: this.relationshipType
};
}
},

methods: {
/**
* Open the delete menu modal.
*/
openDeleteModal () {
this.deleteModalOpen = true;
},

/**
* Delete the given resources.
*/
deleteResources (resources, callback = null) {
if (this.viaManyToMany) {
return this.detachResources(resources, callback);
}

return ExTeal.request({
url: `api/${this.resourceName}`,
method: 'delete',
params: {
...this.deleteParams,
...{ resources: mapResources(resources) }
}
}).then(
callback
? callback
: () => {
this.deleteModalOpen = false;
this.getResources();
}
);
},

detachResources (resources, callback) {
return ExTeal.request({
url: `api/${this.viaResource}/${this.viaResourceId}/detach/${this.viaRelationship}`,
method: 'delete',
params: {
...this.deleteParams,
resources: mapResources(resources)
}
}).then(
callback
? callback
: () => {
this.deleteModalOpen = false;
this.getResources();
}
);
},

/**
* Delete the selected resources.
*/
deleteSelectedResources () {
this.deleteResources(this.selectedResources);
},

/**
* Delete all of the matching resources.
*/
deleteAllMatchingResources () {
return ExTeal.request({
url: `api/${this.resourceName}`,
method: 'delete',
params: {
...this.deleteParams,
...{ resources: 'all' }
}
}).then(() => {
this.deleteModalOpen = false;
this.getResources();
});
}
}
};

export default Deleteable;

function mapResources (resources) {
return resources.map(resource => resource.id).join(',');
}
3 changes: 2 additions & 1 deletion assets/src/views/Detail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@
</template>

<script>
import { Deleteable, HasCards, InteractsWithResourceInformation } from 'ex-teal-js';
import { HasCards, InteractsWithResourceInformation } from 'ex-teal-js';
import Deletable from '@/mixins/Deleteable';
import _ from 'lodash';
export default {
mixins: [ InteractsWithResourceInformation, Deleteable, HasCards ],
Expand Down
8 changes: 4 additions & 4 deletions assets/src/views/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,6 @@
import _ from 'lodash';
import {
Capitalize,
Deleteable,
HasCards,
InteractsWithQueryString,
InteractsWithResourceInformation,
Expand All @@ -290,6 +289,7 @@ import {
} from 'ex-teal-js';
import InteractsWithFieldFilters from '@/mixins/InteractsWithFieldFilters';
import Deleteable from '@/mixins/Deleteable';
export default {
mixins: [
Expand Down Expand Up @@ -859,9 +859,9 @@ export default {
const query = {
search: this.currentSearch,
field_filters: this.encodedFieldFilters,
viaResource: this.viaResource,
viaResourceId: this.viaResourceId,
viaRelationship: this.viaRelationship,
via_resource: this.viaResource,
via_resource_id: this.viaResourceId,
via_relationship: this.viaRelationship,
order_by: this.currentOrderBy,
order_by_direction: this.currentOrderByDirection,
resources: this.selectedResourcesForActionSelector,
Expand Down

0 comments on commit 331b996

Please sign in to comment.