mirror of
https://github.com/hcengineering/platform.git
synced 2026-09-28 04:25:03 +02:00
Add array manipulation functions and editors for process (#9594)
Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
@@ -75,6 +75,7 @@ import {
|
||||
FirstValue,
|
||||
FirstWorkingDayAfter,
|
||||
Floor,
|
||||
Insert,
|
||||
LastValue,
|
||||
LowerCase,
|
||||
Modulo,
|
||||
@@ -83,11 +84,14 @@ import {
|
||||
Power,
|
||||
Prepend,
|
||||
Random,
|
||||
Remove,
|
||||
Replace,
|
||||
ReplaceAll,
|
||||
Round,
|
||||
Split,
|
||||
Subtract,
|
||||
RemoveFirst,
|
||||
RemoveLast,
|
||||
Trim,
|
||||
UpperCase
|
||||
} from './transform'
|
||||
@@ -1046,7 +1050,11 @@ export default async () => ({
|
||||
Floor,
|
||||
Offset,
|
||||
FirstWorkingDayAfter,
|
||||
RoleContext
|
||||
RoleContext,
|
||||
Insert,
|
||||
Remove,
|
||||
RemoveFirst,
|
||||
RemoveLast
|
||||
},
|
||||
trigger: {
|
||||
OnProcessRemove,
|
||||
|
||||
@@ -41,6 +41,60 @@ export function All (value: Doc[]): Doc[] {
|
||||
|
||||
// #endregion
|
||||
|
||||
// #region Array
|
||||
|
||||
export async function Insert (
|
||||
value: Doc[],
|
||||
props: Record<string, any>,
|
||||
control: TriggerControl,
|
||||
execution: Execution
|
||||
): Promise<Doc[]> {
|
||||
if (!Array.isArray(value)) return value
|
||||
if (props.value == null) return value
|
||||
const context = parseContext(props.value)
|
||||
if (context !== undefined) {
|
||||
if (context.type === 'attribute') {
|
||||
const addition = await getAttributeValue(control, execution, context)
|
||||
value.push(addition)
|
||||
}
|
||||
} else {
|
||||
value.push(props.value)
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
export async function Remove (
|
||||
value: Doc[],
|
||||
props: Record<string, any>,
|
||||
control: TriggerControl,
|
||||
execution: Execution
|
||||
): Promise<Doc[]> {
|
||||
if (!Array.isArray(value)) return value
|
||||
if (props.value == null) return value
|
||||
const context = parseContext(props.value)
|
||||
if (context !== undefined) {
|
||||
if (context.type === 'attribute') {
|
||||
const addition = await getAttributeValue(control, execution, context)
|
||||
return value.filter((item) => item !== addition)
|
||||
}
|
||||
} else {
|
||||
return value.filter((item) => item !== props.value)
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
export function RemoveFirst (value: Doc[], props: Record<string, any>): Doc[] {
|
||||
if (!Array.isArray(value)) return value
|
||||
return value.slice(1)
|
||||
}
|
||||
|
||||
export function RemoveLast (value: Doc[], props: Record<string, any>): Doc[] {
|
||||
if (!Array.isArray(value)) return value
|
||||
return value.slice(0, -1)
|
||||
}
|
||||
|
||||
// #endregion
|
||||
|
||||
// #region String
|
||||
|
||||
export function UpperCase (value: string): string {
|
||||
|
||||
Reference in New Issue
Block a user