Skip to content

Commit

Permalink
fix(entities-plugins): keep dynamic ordering in edit payload [KM-148] (
Browse files Browse the repository at this point in the history
  • Loading branch information
Leopoldthecoder authored May 16, 2024
1 parent 7fb9c44 commit c6eedee
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
10 changes: 7 additions & 3 deletions packages/entities/entities-plugins/src/components/PluginForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ import {
type PluginEntityInfo,
type PluginFormFields,
type PluginFormState,
type PluginOrdering,
} from '../types'
import PluginEntityForm from './PluginEntityForm.vue'
Expand Down Expand Up @@ -885,10 +886,12 @@ const changesExist = computed(() => {
const canSubmit = computed((): boolean => !schemaLoading.value && !formLoading.value && (formType.value === EntityBaseFormType.Create || changesExist.value))
const initialized = ref(false)
const dynamicOrdering = ref<PluginOrdering>()
// The whole purpose of this function is to wait for the existing record to be loaded if editing
// We need to wait for this before we start attempting to build the schema
const initForm = (data: Record<string, any>): void => {
form.fields.id = data?.id || undefined
dynamicOrdering.value = data?.ordering
// Set initial state of `formFieldsOriginal` to these values in order to detect changes
Object.assign(formFieldsOriginal, form.fields)
Expand Down Expand Up @@ -1043,9 +1046,10 @@ const saveFormData = async (): Promise<void> => {
response = await axiosInstance.post(submitUrl.value, getRequestBody.value)
} else if (formType.value === 'edit') {
response = props.config.app === 'konnect'
// Note: Konnect currently uses PUT because PATCH is not fully supported in Koko
// If this changes, the `edit` form methods should be re-evaluated/updated accordingly
? await axiosInstance.put(submitUrl.value, getRequestBody.value)
// Note 1: Konnect currently uses PUT because PATCH is not fully supported in Koko
// If this changes, the `edit` form methods should be re-evaluated/updated accordingly
// Note 2: Because Konnect uses PUT, we need to include dynamic ordering in the request body
? await axiosInstance.put(submitUrl.value, Object.assign({ ordering: dynamicOrdering.value }, getRequestBody.value))
: await axiosInstance.patch(submitUrl.value, getRequestBody.value)
}
Expand Down
9 changes: 9 additions & 0 deletions packages/entities/entities-plugins/src/types/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,12 @@ export type PluginCardList = {
export type TriggerLabels = {
[key in PluginGroup]?: string // [plugin.group]: label
}

export type PluginOrdering = {
before: {
access: string[]
}
after: {
access: string[]
}
}

0 comments on commit c6eedee

Please sign in to comment.