Skip to content

Commit

Permalink
Edit workflow definition
Browse files Browse the repository at this point in the history
  • Loading branch information
FyreByrd committed Oct 31, 2024
1 parent 600518a commit 876f1fd
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@ import { superValidate } from 'sveltekit-superforms';
import { valibot } from 'sveltekit-superforms/adapters';
import * as v from 'valibot';
import type { Actions, PageServerLoad } from './$types';
import { ProductType, WorkflowAdminRequirements } from 'sil.appbuilder.portal.common/workflow';

const editSchema = v.object({
id: idSchema,
name: v.nullable(v.string()),
storeType: idSchema,
productType: v.pipe(idSchema, v.enum(ProductType)),
workflowType: idSchema,
workflowScheme: v.nullable(v.string()),
workflowBusinessFlow: v.nullable(v.string()),
description: v.nullable(v.string()),
properties: v.nullable(v.string()),
adminRequirements: v.array(v.pipe(idSchema, v.enum(WorkflowAdminRequirements))),
enabled: v.boolean()
});
export const load = (async ({ url }) => {
Expand All @@ -29,22 +32,27 @@ export const load = (async ({ url }) => {
}
});
if (!data) return redirect(302, base + '/admin/settings/workflow-definitions');
const options = await prisma.storeTypes.findMany();
const storeTypes = await prisma.storeTypes.findMany();
const form = await superValidate(
{
id: data.Id,
name: data.Name,
storeType: data.StoreTypeId!,
productType: data.ProductType,
workflowType: data.Type,
workflowScheme: data.WorkflowScheme,
workflowBusinessFlow: data.WorkflowBusinessFlow,
description: data.Description,
properties: data.Properties,
adminRequirements:
data.AdminRequirements.length > 1 || data.AdminRequirements[0]
? data.AdminRequirements
: [],
enabled: data.Enabled
},
valibot(editSchema)
);
return { form, options };
return { form, storeTypes };
}) satisfies PageServerLoad;

export const actions = {
Expand All @@ -63,7 +71,9 @@ export const actions = {
storeType,
workflowBusinessFlow,
workflowScheme,
workflowType
workflowType,
adminRequirements,
productType
} = form.data;
await DatabaseWrites.workflowDefinitions.update({
where: {
Expand All @@ -77,7 +87,9 @@ export const actions = {
StoreTypeId: storeType,
Description: description,
Properties: properties,
Enabled: enabled
Enabled: enabled,
ProductType: productType,
AdminRequirements: adminRequirements.length ? adminRequirements : [0]
}
});
return { ok: true, form };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,17 @@
import * as m from '$lib/paraglide/messages';
import { superForm } from 'sveltekit-superforms';
import type { ActionData, PageData } from './$types';
import { ProductType, WorkflowAdminRequirements } from 'sil.appbuilder.portal.common/workflow';
export let data: PageData;
export let form: ActionData;
const { form: superFormData, enhance, allErrors } = superForm(data.form);
const {
form: superFormData,
enhance,
allErrors
} = superForm(data.form, {
dataType: 'json'
});
$: if (form?.ok) goto('/admin/settings/workflow-definitions');
</script>
Expand All @@ -25,11 +32,29 @@
</LabeledFormInput>
<LabeledFormInput name="admin_settings_workflowDefinitions_storeType">
<select class="select select-bordered" name="storeType" bind:value={$superFormData.storeType}>
{#each data.options as option}
<option value={option.Id}>{option.Name}</option>
{#each data.storeTypes as storeType}
<option value={storeType.Id}>{storeType.Name}</option>
{/each}
</select>
</LabeledFormInput>
<div>
<label>
<!-- TODO: i18n (add to JSON) -->
<div class="label">
<span class="label-text">Product Type</span>
</div>
<select
class="select select-bordered"
name="productType"
bind:value={$superFormData.productType}
>
<option value={ProductType.Android_GooglePlay}>Android GooglePlay</option>
<option value={ProductType.Android_S3}>Android S3</option>
<option value={ProductType.AssetPackage}>Asset Package</option>
<option value={ProductType.Web}>Web</option>
</select>
</label>
</div>
<LabeledFormInput name="admin_settings_workflowDefinitions_workflowType">
<select
class="select select-bordered"
Expand Down Expand Up @@ -71,6 +96,40 @@
bind:value={$superFormData.properties}
/>
</LabeledFormInput>
<div>
<label>
<!-- TODO: i18n (add to JSON) -->
<div class="label">
<span class="">Administrative Requirements</span>
</div>
<div class="label flex flex-row">
<div class="label">
<span class="label-text">
Require an organization admin to access the GooglePlay developer console.
</span>
</div>
<input
class="checkbox checkbox-info"
type="checkbox"
bind:group={$superFormData.adminRequirements}
value={WorkflowAdminRequirements.StoreAccess}
/>
</div>
<div class="label flex flex-row">
<div class="label">
<span class="label-text">
Require approval by an organization admin before product is created.
</span>
</div>
<input
class="checkbox checkbox-info"
type="checkbox"
bind:group={$superFormData.adminRequirements}
value={WorkflowAdminRequirements.ApprovalProcess}
/>
</div>
</label>
</div>
<div>
<label>
<div class="label flex flex-row">
Expand Down

0 comments on commit 876f1fd

Please sign in to comment.