Skip to content

Commit

Permalink
#1275 Jenkins job property
Browse files Browse the repository at this point in the history
  • Loading branch information
dcoraboeuf committed Jul 27, 2024
1 parent e9e28fe commit f3f2079
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 5 deletions.
15 changes: 15 additions & 0 deletions ontrack-web-core/__tests__/components/form/formUtils.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import {prefixedFormName} from "@components/form/formUtils";

describe('prefixedFormName', () => {

it('renders an array for a simple name', () => {
const result = prefixedFormName('data', 'address')
expect(result).toEqual(['data', 'address'])
})

it('renders an array for a name array', () => {
const result = prefixedFormName('data', ['person', 'name'])
expect(result).toEqual(['data', 'person', 'name'])
})

})
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import PropertyComponent from "@components/framework/properties/PropertyComponen
import PropertyForm from "@components/framework/properties/PropertyForm";
import {gql} from "graphql-request";
import {EventsContext} from "@components/common/EventsContext";
import {callDynamicFunction} from "@components/common/DynamicFunction";
import {getExtensionShortName} from "@components/common/ExtensionUtils";

export const usePropertyDialog = () => {

Expand All @@ -17,6 +19,15 @@ export const usePropertyDialog = () => {

const [entity, setEntity] = useState({})

const customPreparation = async (type, values) => {
const shortName = getExtensionShortName(type)
const newValues = await callDynamicFunction(
`framework/properties/${shortName}/FormPrepare`,
values,
)
return newValues ?? values
}

return useFormDialog({
init: (form, {entityType, entityId, propertyList, initialProperty}) => {
form.setFieldValue("propertyType", initialProperty?.type?.typeName)
Expand Down Expand Up @@ -67,12 +78,17 @@ export const usePropertyDialog = () => {
}
`,
userNode: 'setGenericProperty',
prepareValues: (values, {entityType, entityId}) => {
prepareValues: async (values, {entityType, entityId}) => {

const type = selectedProperty?.type?.typeName

const preparedValues = await customPreparation(type, values.value)

return {
entityType,
entityId,
type: selectedProperty?.type?.typeName,
value: values.value,
type: type,
value: preparedValues,
}
},
onSuccess: () => {
Expand Down
10 changes: 8 additions & 2 deletions ontrack-web-core/components/form/formUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@ export const formFieldArraySwap = (form, fieldName, oldIndex, newIndex) => {
}

export const prefixedFormName = (prefix, name) => {
let values
if (typeof name === 'string') {
values = [name]
} else {
values = [...name]
}
if (typeof prefix === 'string') {
return [prefix, name]
return [prefix, ...values]
} else {
return [...prefix, name]
return [...prefix, ...values]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {Form, Input} from "antd";
import {prefixedFormName} from "@components/form/formUtils";

export default function PropertyForm({prefix}) {
return (
<>
<Form.Item
label="Configuration"
extra="Name of the Jenkins configuration in Ontrack"
name={prefixedFormName(prefix, ['configuration', 'name'])}
>
<Input/>
</Form.Item>
<Form.Item
label="Job"
extra="Path to the job in Jenkins"
name={prefixedFormName(prefix, 'job')}
>
<Input/>
</Form.Item>
</>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default function JenkinsJobPropertyTypeFormPrepare(value) {
return {
...value,
configuration: value?.configuration?.name,
}
}

0 comments on commit f3f2079

Please sign in to comment.