Skip to content

Commit

Permalink
WIP - New trigger model
Browse files Browse the repository at this point in the history
  • Loading branch information
tlawrie committed Oct 25, 2023
1 parent 0625e40 commit e9fc4d7
Show file tree
Hide file tree
Showing 4 changed files with 158 additions and 169 deletions.
43 changes: 21 additions & 22 deletions src/ApiServer/fixtures/revisions.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,28 +163,27 @@ export default [
},
icon: "bot",
upgradesAvailable: false,
triggers: {
manual: {
enable: true,
},
scheduler: {
enable: false,
},
webhook: {
enable: false,
},
event: {
enable: false,
type: null,
subject: null,
},
},
tokens: [
{
token: "7AFBE8B30B2958B2B1879AAAF59B68EC31BF7C581F6D1C0833F64F623A667102",
label: "default",
},
],
triggers: [{
type: "manual",
enabled: true,
conditions: null,
},{
type: "webhook",
enabled: false,
conditions: null,
},{
type: "scheduler",
enabled: false,
conditions: null,
},{
type: "event",
enabled: true,
conditions: [{operation: "matches", field: "type", value: "io.boomerang.test"}, {operation: "matches", field: "subject", value: "australia"}],
},{
type: "github",
enabled: true,
conditions: [{operation: "in", field: "event", values: ["create", "delete"]}, {operation: "in", field: "repository", values: ["australia","img","test"]}],
}],
config: [
{
key: "token",
Expand Down
138 changes: 84 additions & 54 deletions src/ApiServer/fixtures/summaries.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,27 @@ const summaries = [
name: "ML Train – Bot Efficiency",
shortDescription: "Train and store ML model for Bot Efficiency.",
status: "active",
triggers: {
scheduler: { enable: false },
webhook: { enable: false },
event: {
enable: false,
type: null,
subject: null,
},
},
triggers: [{
type: "manual",
enabled: true,
conditions: null,
},{
type: "webhook",
enabled: false,
conditions: null,
},{
type: "scheduler",
enabled: false,
conditions: null,
},{
type: "event",
enabled: true,
conditions: [{operation: "matches", field: "type", value: "io.boomerang.test"}, {operation: "matches", field: "subject", value: "australia"}],
},{
type: "github",
enabled: true,
conditions: [{operation: "in", field: "event", values: ["create", "delete"]}, {operation: "in", field: "repository", values: ["australia","img","test"]}],
}],
labels: [
{
key: "testing",
Expand All @@ -163,7 +175,6 @@ const summaries = [
},
],
scope: "team",
tokens: [],
storage: {
activity: {
enabled: true,
Expand Down Expand Up @@ -317,23 +328,34 @@ const summaries = [
name: "ML Train – Bot Efficiency",
shortDescription: "Train and store ML model for Bot Efficiency.",
status: "active",
triggers: {
scheduler: { enable: false },
webhook: { enable: false},
event: {
enable: false,
type: null,
subject: null,
},
},
triggers: [{
type: "manual",
enabled: true,
conditions: null,
},{
type: "webhook",
enabled: false,
conditions: null,
},{
type: "scheduler",
enabled: false,
conditions: null,
},{
type: "event",
enabled: true,
conditions: [{operation: "matches", field: "type", value: "io.boomerang.test"}, {operation: "matches", field: "subject", value: "australia"}],
},{
type: "github",
enabled: true,
conditions: [{operation: "in", field: "event", values: ["create", "delete"]}, {operation: "in", field: "repository", values: ["australia","img","test"]}],
}],
labels: [
{
key: "purpose",
value: "test",
},
],
scope: "system",
tokens: [],
storage: {
activity: {
enabled: true,
Expand Down Expand Up @@ -379,23 +401,27 @@ const summaries = [
name: "Java - Deploy",
shortDescription: "",
status: "active",
triggers: {
manual: {
enable: true,
},
scheduler: {
enable: false,
},
webhook: {
enable: true,
},
event: {
enable: false,
type: null,
subject: null,
},
},
tokens: [],
triggers: [{
type: "manual",
enabled: true,
conditions: null,
},{
type: "webhook",
enabled: false,
conditions: null,
},{
type: "scheduler",
enabled: false,
conditions: null,
},{
type: "event",
enabled: true,
conditions: [{operation: "matches", field: "type", value: "io.boomerang.test"}, {operation: "matches", field: "subject", value: "australia"}],
},{
type: "github",
enabled: true,
conditions: [{operation: "in", field: "event", values: ["create", "delete"]}, {operation: "in", field: "repository", values: ["australia","img","test"]}],
}],
storage: {
activity: {
enabled: true,
Expand Down Expand Up @@ -441,23 +467,27 @@ const summaries = [
name: "Java - Build",
shortDescription: "Java - Build",
status: "active",
triggers: {
manual: {
enable: true,
},
scheduler: {
enable: false,
},
webhook: {
enable: true,
},
event: {
enable: false,
type: null,
subject: null,
},
},
tokens: [],
triggers: [{
type: "manual",
enabled: true,
conditions: null,
},{
type: "webhook",
enabled: false,
conditions: null,
},{
type: "scheduler",
enabled: false,
conditions: null,
},{
type: "event",
enabled: true,
conditions: [{operation: "matches", field: "type", value: "io.boomerang.test"}, {operation: "matches", field: "subject", value: "australia"}],
},{
type: "github",
enabled: true,
conditions: [{operation: "in", field: "event", values: ["create", "delete"]}, {operation: "in", field: "repository", values: ["australia","img","test"]}],
}],
storage: {
activity: {
enabled: true,
Expand Down
75 changes: 24 additions & 51 deletions src/Features/Editor/Configure/Configure.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,27 +94,7 @@ function ConfigureContainer({ quotas, workflow, settingsRef }: ConfigureContaine
timeout: workflow.timeout ?? null,
retries: workflow.retries ?? null,
labels: workflow.labels ? Object.entries(workflow.labels).map(([key, value]) => ({ key, value })) : [],
triggers: {
manual: {
enable: workflow.triggers?.manual?.enable ?? true,
},
event: {
enable: workflow.triggers?.event?.enable ?? false,
subject: workflow.triggers?.event?.subject ?? "",
type: workflow.triggers?.event?.type ?? "",
},
scheduler: {
enable: workflow.triggers?.scheduler?.enable ?? false,
},
webhook: {
enable: workflow.triggers?.webhook?.enable ?? false,
},
github: {
enable: workflow.triggers?.github?.enable ?? false,
events: workflow.triggers?.github?.events ?? [],
repositories: workflow.triggers?.github?.repositories ?? [],
},
},
triggers: workflow.triggers ?? [],
config: workflow.config ?? [],
}}
validationSchema={Yup.object().shape({
Expand All @@ -136,27 +116,20 @@ function ConfigureContainer({ quotas, workflow, settingsRef }: ConfigureContaine
name: Yup.string().required("Name is required").max(64, "Name must not be greater than 64 characters"),
retries: Yup.number(),
timeout: Yup.number(),
triggers: Yup.object().shape({
manual: Yup.object().shape({
enable: Yup.boolean(),
}),
event: Yup.object().shape({
enable: Yup.boolean(),
triggers: Yup.array().of(
Yup.object().shape({
type: Yup.string(),
subject: Yup.string(),
}),
scheduler: Yup.object().shape({
enable: Yup.boolean(),
}),
webhook: Yup.object().shape({
enable: Yup.boolean(),
}),
github: Yup.object().shape({
enable: Yup.boolean(),
events: Yup.array().of(Yup.string()),
repositories: Yup.array().of(Yup.string()),
}),
}),
enabled: Yup.boolean(),
conditions: Yup.array().of(
Yup.object().shape({
operation: Yup.string(),
field: Yup.string(),
value: Yup.string().optional(),
values: Yup.array().of(Yup.string()).optional(),
})
),
})
),
})}
>
{(formikProps) =>
Expand Down Expand Up @@ -331,8 +304,8 @@ function Configure(props: ConfigureProps) {
id="triggers.manual.enable"
data-testid="triggers.manual.enable"
label="Enable"
onToggle={(checked: boolean) => handleOnToggleChange(checked, "triggers.manual.enable")}
toggled={values.triggers.manual.enable}
onToggle={(checked: boolean) => handleOnToggleChange(checked, "triggers.manual.enabled")}
toggled={values.triggers.some((trigger) => trigger.type === "manual" && trigger.enabled)}
/>
</div>
</Section>
Expand All @@ -343,11 +316,11 @@ function Configure(props: ConfigureProps) {
id="triggers.scheduler.enable"
data-testid="triggers.scheduler.enable"
label="Enable"
onToggle={(checked: boolean) => handleOnToggleChange(checked, "triggers.scheduler.enable")}
toggled={values.triggers.scheduler.enable}
onToggle={(checked: boolean) => handleOnToggleChange(checked, "triggers.scheduler.enabled")}
toggled={values.triggers.some((trigger) => trigger.type === "scheduler" && trigger.enabled)}
/>
</div>
{values.triggers.scheduler.enable ? (
{values.triggers.some((trigger) => trigger.type === "scheduler" && trigger.enabled) ? (
<InlineNotification
lowContrast
kind="info"
Expand All @@ -373,14 +346,14 @@ function Configure(props: ConfigureProps) {
<Toggle
id="triggers.webhook.enable"
label="Enable"
toggled={values.triggers.webhook.enable}
toggled={values.triggers.some((trigger) => trigger.type === "webhook" && trigger.enabled)}
onToggle={(checked: boolean) => handleOnToggleChange(checked, "triggers.webhook.enable")}
tooltipContent="Enable workflow to be executed by a webhook"
tooltipProps={{ direction: "top" }}
reversed
/>
</div>
{values.triggers.webhook.enable && (
{values.triggers.some((trigger) => trigger.type === "webhook" && trigger.enabled) && (
<ComposedModal
modalHeaderProps={{
title: "Webhook Usage",
Expand Down Expand Up @@ -423,14 +396,14 @@ function Configure(props: ConfigureProps) {
<Toggle
id="triggers.event.enable"
label="Enable"
toggled={values.triggers.event.enable}
onToggle={(checked: boolean) => handleOnToggleChange(checked, "triggers.event.enable")}
toggled={values.triggers.some((trigger) => trigger.type === "event" && trigger.enabled)}
onToggle={(checked: boolean) => handleOnToggleChange(checked, "triggers.event.enabled")}
tooltipContent="Enable workflow to be triggered by received events."
tooltipProps={{ direction: "top" }}
reversed
/>
</div>
{values.triggers.event.enable && (
{values.triggers.some((trigger) => trigger.type === "event" && trigger.enabled) && (
<>
<p className={styles.sectionDescription}>
The following filters will be applied to any incoming event based on the{" "}
Expand Down
Loading

0 comments on commit e9fc4d7

Please sign in to comment.