Skip to content

Commit 5912104

Browse files
Nil20Nil20
andauthored
Ocrvs 11215 (#11237)
* chore: amend custom validation for flags * fix: add unit test case for flags * fix: amend flags refine function * fix: amend if conditional * chore: allow configurable scope for draft * clean up * fix: amend action modal order * fix: include custom action as update action * chore: add stamp icon --------- Co-authored-by: Nil20 <[email protected]>
1 parent 295c3da commit 5912104

File tree

9 files changed

+46
-16
lines changed

9 files changed

+46
-16
lines changed

packages/client/src/v2-events/features/events/actions/quick-actions/useQuickActionModal.tsx

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
TertiaryButton
2020
} from '@opencrvs/components/lib/buttons'
2121
import { Icon, IconProps } from '@opencrvs/components/src/Icon'
22+
import { Stack } from '@opencrvs/components/lib/Stack'
2223
import {
2324
ActionType,
2425
CustomActionConfig,
@@ -157,15 +158,17 @@ function QuickActionModal({
157158
width={898}
158159
onClose={() => close({ result: false })}
159160
>
160-
<FormFieldGenerator
161-
fields={config.fields ?? []}
162-
id={'quick-action-modal-form'}
163-
validatorContext={validatorContext}
164-
onChange={handleChange}
165-
/>
166-
<Text color="grey500" element="p" variant="reg16">
167-
{config.description ? intl.formatMessage(config.description) : null}
168-
</Text>
161+
<Stack alignItems="left" direction="column" gap={16}>
162+
<Text color="grey500" element="p" variant="reg16">
163+
{config.description ? intl.formatMessage(config.description) : null}
164+
</Text>
165+
<FormFieldGenerator
166+
fields={config.fields ?? []}
167+
id={'quick-action-modal-form'}
168+
validatorContext={validatorContext}
169+
onChange={handleChange}
170+
/>
171+
</Stack>
169172
</Dialog>
170173
)
171174
}

packages/client/src/v2-events/utils.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import {
2323
SystemVariables,
2424
Scope,
2525
ActionScopes,
26+
ConfigurableActionScopes,
27+
parseConfigurableScope,
2628
WorkqueueConfigWithoutQuery,
2729
joinValues,
2830
UUID,
@@ -232,7 +234,14 @@ export enum CoreWorkqueues {
232234
}
233235

234236
export function hasOutboxWorkqueue(scopes: Scope[]) {
235-
return scopes.some((scope) => ActionScopes.safeParse(scope).success)
237+
const hasLiteralActionScopes = scopes.some(
238+
(scope) => ActionScopes.safeParse(scope).success
239+
)
240+
const parsedScopes = scopes.map(parseConfigurableScope)
241+
const hasConfigurableActionScopes = parsedScopes.some(
242+
(scope) => ConfigurableActionScopes.safeParse(scope).success
243+
)
244+
return hasLiteralActionScopes || hasConfigurableActionScopes
236245
}
237246

238247
export function hasDraftWorkqueue(scopes: Scope[]) {

packages/commons/src/conditionals/conditionals.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,6 +1048,9 @@ describe('"flag" conditionals', () => {
10481048
expect(validate(flag(InherentFlags.CORRECTION_REQUESTED), params)).toBe(
10491049
false
10501050
)
1051+
expect(
1052+
validate(not(flag(InherentFlags.CORRECTION_REQUESTED)), params)
1053+
).toBe(true)
10511054
})
10521055

10531056
it('validation fails if params dont include flags', () => {

packages/commons/src/events/EventConfig.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { DeclarationFormConfig } from './FormConfig'
1818

1919
import { FieldType } from './FieldType'
2020
import { FieldReference } from './FieldConfig'
21-
import { FlagConfig } from './Flag'
21+
import { FlagConfig, InherentFlags } from './Flag'
2222

2323
/**
2424
* Description of event features defined by the country. Includes configuration for process steps and forms involved.
@@ -134,17 +134,23 @@ export const EventConfig = z
134134
}
135135
}
136136

137+
const isInherentFlag = (value: unknown): value is InherentFlags =>
138+
Object.values(InherentFlags).includes(value as InherentFlags)
139+
137140
// Validate that all referenced action flags are configured in the event flags array.
138141
const configuredFlagIds = event.flags.map((flag) => flag.id)
139142
const actionFlagIds = event.actions.flatMap((action) =>
140143
action.flags.map((flag) => flag.id)
141144
)
142145

143146
for (const actionFlagId of actionFlagIds) {
144-
if (!configuredFlagIds.includes(actionFlagId)) {
147+
const isConfigured = configuredFlagIds.includes(actionFlagId)
148+
const isInherent = isInherentFlag(actionFlagId)
149+
150+
if (!isConfigured && !isInherent) {
145151
ctx.addIssue({
146152
code: 'custom',
147-
message: `Action flag id must match a configured flag in the flags array. Invalid action flag ID for event '${event.id}': '${actionFlagId}'`,
153+
message: `Action flag id must match an inherent flag or a configured flag in the flags array. Invalid action flag ID for event '${event.id}': '${actionFlagId}'`,
148154
path: ['actions']
149155
})
150156
}

packages/commons/src/events/Flag.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export type FlagConfig = z.infer<typeof FlagConfig>
7979
* Configuration for a flag action, which is executed when the action is performed.
8080
*/
8181
export const ActionFlagConfig = z.object({
82-
id: CustomFlag,
82+
id: Flag,
8383
operation: z
8484
.enum(['add', 'remove'])
8585
.describe('Operation to perform on the flag.'),

packages/commons/src/events/state/utils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ const updateActions = ActionTypes.extract([
9393
ActionType.REJECT,
9494
ActionType.ARCHIVE,
9595
ActionType.PRINT_CERTIFICATE,
96-
ActionType.REQUEST_CORRECTION
96+
ActionType.REQUEST_CORRECTION,
97+
ActionType.CUSTOM
9798
])
9899

99100
/**

packages/commons/src/icons.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ export const AvailableIcons = z.enum([
8383
'Plus',
8484
'Printer',
8585
'SignOut',
86+
'Stamp',
8687
'Star',
8788
'Target',
8889
'TextT',

packages/commons/src/scopes.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,12 @@ const ConfigurableRawScopes = z.discriminatedUnion('type', [
327327
CustomActionScope
328328
])
329329

330+
export const ConfigurableActionScopes = z.discriminatedUnion('type', [
331+
// @TODO - Record scope holds non-action scopes as well e.g., `record.read`
332+
RecordScope,
333+
CustomActionScope
334+
])
335+
330336
type ConfigurableRawScopes = z.infer<typeof ConfigurableRawScopes>
331337
export type ConfigurableScopeType = ConfigurableRawScopes['type']
332338

packages/components/src/Icon/all-icons.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ export {
9191
Users,
9292
WarningCircle,
9393
Webcam,
94-
X
94+
X,
95+
Stamp
9596
} from 'phosphor-react'
9697
export * from './custom-icons'

0 commit comments

Comments
 (0)