From 3d9b6eacf078be876e5b284464bbdc42e6113929 Mon Sep 17 00:00:00 2001 From: Luiz Motta Date: Fri, 13 Sep 2024 18:21:07 -0300 Subject: [PATCH 01/10] Upgrade to ajv 8.17.1 --- examples/uniforms-patternfly/package.json | 3 +- .../package.json | 3 +- .../src/Uniforms.tsx | 4 +- packages/dmn-runner/package.json | 3 +- packages/dmn-runner/src/ajv.ts | 159 ++++++++---------- packages/form/package.json | 3 +- packages/form/src/Validator.ts | 4 +- .../runtime-tools-components/package.json | 2 +- packages/unitables/package.json | 3 +- packages/unitables/src/UnitablesValidator.ts | 4 +- pnpm-lock.yaml | 129 +++++++------- 11 files changed, 156 insertions(+), 161 deletions(-) diff --git a/examples/uniforms-patternfly/package.json b/examples/uniforms-patternfly/package.json index 77f4acef161..a4be92f79df 100644 --- a/examples/uniforms-patternfly/package.json +++ b/examples/uniforms-patternfly/package.json @@ -14,7 +14,8 @@ "@kie-tools/uniforms-patternfly": "workspace:*", "@patternfly/react-core": "^4.276.6", "@patternfly/react-icons": "^4.93.6", - "ajv": "^6.12.6", + "ajv": "^8.17.1", + "ajv-draft-04": "^1.0.0", "react": "^17.0.2", "react-dom": "^17.0.2", "simpl-schema": "^1.12.0", diff --git a/packages/dashbuilder-component-uniforms/package.json b/packages/dashbuilder-component-uniforms/package.json index 526996a3bfb..dd0b2fcddf3 100644 --- a/packages/dashbuilder-component-uniforms/package.json +++ b/packages/dashbuilder-component-uniforms/package.json @@ -26,7 +26,8 @@ "@kie-tools/uniforms-patternfly": "workspace:*", "@patternfly/react-core": "^4.276.6", "@patternfly/react-table": "^4.112.39", - "ajv": "^6.12.6", + "ajv": "^8.17.1", + "ajv-draft-04": "^1.0.0", "lodash": "^4.17.21", "uniforms": "^3.10.2", "uniforms-bridge-json-schema": "^3.10.2" diff --git a/packages/dashbuilder-component-uniforms/src/Uniforms.tsx b/packages/dashbuilder-component-uniforms/src/Uniforms.tsx index 311ccfb730f..7af1905d2fa 100644 --- a/packages/dashbuilder-component-uniforms/src/Uniforms.tsx +++ b/packages/dashbuilder-component-uniforms/src/Uniforms.tsx @@ -18,11 +18,11 @@ */ import { JSONSchemaBridge } from "uniforms-bridge-json-schema"; import { AutoForm } from "@kie-tools/uniforms-patternfly/dist/esm"; -import * as Ajv from "ajv"; +import AjvDraft04 from "ajv-draft-04"; import * as React from "react"; import { useCallback } from "react"; -const ajv = new Ajv({ allErrors: true, useDefaults: true }); +const ajv = new AjvDraft04({ allErrors: true, useDefaults: true }); const createValidator = (schema: any) => { const validator = ajv.compile(schema); return (model: any) => { diff --git a/packages/dmn-runner/package.json b/packages/dmn-runner/package.json index a6a48868501..9033ee8ec1d 100644 --- a/packages/dmn-runner/package.json +++ b/packages/dmn-runner/package.json @@ -29,7 +29,8 @@ "@kie-tools/uniforms-patternfly": "workspace:*", "@patternfly/react-core": "^4.276.6", "@patternfly/react-icons": "^4.93.6", - "ajv": "^6.12.6", + "ajv": "^8.17.1", + "ajv-draft-04": "^1.0.0", "deep-object-diff": "^1.1.9", "json-refs": "^3.0.15", "lodash": "^4.17.21", diff --git a/packages/dmn-runner/src/ajv.ts b/packages/dmn-runner/src/ajv.ts index 2ba7cecc2d3..9d3817acbb3 100644 --- a/packages/dmn-runner/src/ajv.ts +++ b/packages/dmn-runner/src/ajv.ts @@ -17,8 +17,7 @@ * under the License. */ -import Ajv from "ajv"; -import * as metaSchemaDraft04 from "ajv/lib/refs/json-schema-draft-04.json"; +import AjvDraft04, { KeywordCxt } from "ajv-draft-04"; export { ValidateFunction } from "ajv"; import { duration } from "moment"; import { @@ -139,102 +138,92 @@ export class DmnRunnerAjv { return []; }; - private constraintCompiler() { - return (schema: any, parentSchema: { format?: DmnAjvSchemaFormat }, it: any) => { - if (!parentSchema.format) { - return (data: string) => true; - } - const { minAllowed, minAllowedIncluded, maxAllowed, maxAllowedIncluded } = this.parseRangeFromConstraints( - schema ?? "", - parentSchema.format - ); - const enumeratedValues = this.parseEnumerationFromConstraints(schema ?? "", parentSchema.format); - const isUnderTheMinBoundary: (value: Date | String | number, minBoundary: Date | String | number) => boolean = - minAllowedIncluded ? (value, minBoundary) => value < minBoundary : (value, minBoundary) => value <= minBoundary; - const isOverTheMaxBoundary: (value: Date | String | number, maxBoundary: Date | String | number) => boolean = - maxAllowedIncluded ? (value, maxBoundary) => value > maxBoundary : (value, maxBoundary) => value >= maxBoundary; + private constraintCompiler(ctx: KeywordCxt) { + const { schema, parentSchema } = ctx; + if (!parentSchema.format) { + return (data: string) => true; + } + const { minAllowed, minAllowedIncluded, maxAllowed, maxAllowedIncluded } = this.parseRangeFromConstraints( + schema ?? "", + parentSchema.format + ); + const enumeratedValues = this.parseEnumerationFromConstraints(schema ?? "", parentSchema.format); + const isUnderTheMinBoundary: (value: Date | String | number, minBoundary: Date | String | number) => boolean = + minAllowedIncluded ? (value, minBoundary) => value < minBoundary : (value, minBoundary) => value <= minBoundary; + const isOverTheMaxBoundary: (value: Date | String | number, maxBoundary: Date | String | number) => boolean = + maxAllowedIncluded ? (value, maxBoundary) => value > maxBoundary : (value, maxBoundary) => value >= maxBoundary; - return (rawData: string | Date) => { - let data = rawData instanceof Date ? rawData.toISOString() : rawData; - if (data.includes(".") && data.endsWith("Z")) { - // adjusting from "2023-06-01T10:42:00.000Z" to "2023-06-01T10:42:00" - data = data.substring(0, data.lastIndexOf(".")); - } - if (minAllowed && maxAllowed) { - // It is a Range constraint - if (parentSchema.format === "time") { - if (isUnderTheMinBoundary(data, minAllowed) || isOverTheMaxBoundary(data, maxAllowed)) { - return false; - } - } else if (parentSchema.format?.includes("duration")) { - const actualDuration = duration(data).asMilliseconds(); - const minDuration = duration(minAllowed).asMilliseconds(); - const maxDuration = duration(maxAllowed).asMilliseconds(); - if ( - isUnderTheMinBoundary(actualDuration, minDuration) || - isOverTheMaxBoundary(actualDuration, maxDuration) - ) { - return false; - } - } else if (parentSchema.format?.includes("date")) { - const actualDate = new Date(data); - if (actualDate.toString() === "Invalid Date") { - return false; - } - const minAllowedDate = new Date(minAllowed); - if (minAllowedDate && isUnderTheMinBoundary(actualDate, minAllowedDate)) { - return false; - } - const maxAllowedDate = new Date(maxAllowed); - if (maxAllowedDate && isOverTheMaxBoundary(actualDate, maxAllowedDate)) { - return false; - } + return (rawData: string | Date) => { + let data = rawData instanceof Date ? rawData.toISOString() : rawData; + if (data.includes(".") && data.endsWith("Z")) { + // adjusting from "2023-06-01T10:42:00.000Z" to "2023-06-01T10:42:00" + data = data.substring(0, data.lastIndexOf(".")); + } + if (minAllowed && maxAllowed) { + // It is a Range constraint + if (parentSchema.format === "time") { + if (isUnderTheMinBoundary(data, minAllowed) || isOverTheMaxBoundary(data, maxAllowed)) { + return false; + } + } else if (parentSchema.format?.includes("duration")) { + const actualDuration = duration(data).asMilliseconds(); + const minDuration = duration(minAllowed).asMilliseconds(); + const maxDuration = duration(maxAllowed).asMilliseconds(); + if (isUnderTheMinBoundary(actualDuration, minDuration) || isOverTheMaxBoundary(actualDuration, maxDuration)) { + return false; + } + } else if (parentSchema.format?.includes("date")) { + const actualDate = new Date(data); + if (actualDate.toString() === "Invalid Date") { + return false; } - } else if (enumeratedValues) { - if (parentSchema.format === "time") { - return enumeratedValues.includes(data); - } else if (parentSchema.format?.includes("duration")) { - const actualDuration = duration(data).asMilliseconds(); - return enumeratedValues.some((value) => { - const enumeratedDurationValue = duration(value).asMilliseconds(); - return enumeratedDurationValue === actualDuration; - }); - } else if (parentSchema.format?.includes("date")) { - const actualDate = new Date(data); - if (actualDate.toString() === "Invalid Date") { - return false; - } - return enumeratedValues.some((value) => { - const enumeratedDateValue = new Date(value); - return !(enumeratedDateValue < actualDate) && !(enumeratedDateValue > actualDate); - }); + const minAllowedDate = new Date(minAllowed); + if (minAllowedDate && isUnderTheMinBoundary(actualDate, minAllowedDate)) { + return false; } + const maxAllowedDate = new Date(maxAllowed); + if (maxAllowedDate && isOverTheMaxBoundary(actualDate, maxAllowedDate)) { + return false; + } + } + } else if (enumeratedValues) { + if (parentSchema.format === "time") { + return enumeratedValues.includes(data); + } else if (parentSchema.format?.includes("duration")) { + const actualDuration = duration(data).asMilliseconds(); + return enumeratedValues.some((value) => { + const enumeratedDurationValue = duration(value).asMilliseconds(); + return enumeratedDurationValue === actualDuration; + }); + } else if (parentSchema.format?.includes("date")) { + const actualDate = new Date(data); + if (actualDate.toString() === "Invalid Date") { + return false; + } + return enumeratedValues.some((value) => { + const enumeratedDateValue = new Date(value); + return !(enumeratedDateValue < actualDate) && !(enumeratedDateValue > actualDate); + }); } + } - return true; - }; + return true; }; } constructor() { - this.ajv = new Ajv({ + this.ajv = new AjvDraft04({ allErrors: true, - schemaId: "auto", useDefaults: true, removeAdditional: "all", verbose: true, }); - this.ajv.addMetaSchema(metaSchemaDraft04); - this.ajv.addKeyword(X_DMN_TYPE_KEYWORD, {}); - this.ajv.addKeyword(X_DMN_ALLOWED_VALUES_KEYWORD, { - compile: this.constraintCompiler(), - }); - this.ajv.addKeyword(X_DMN_TYPE_CONSTRAINTS_KEYWORD, { - compile: this.constraintCompiler(), - }); - this.ajv.addKeyword(X_DMN_DESCRIPTIONS_KEYWORD, {}); - this.ajv.addKeyword(RECURSION_KEYWORD, {}); - this.ajv.addKeyword(RECURSION_REF_KEYWORD, {}); + this.ajv.addKeyword(X_DMN_TYPE_KEYWORD); + this.ajv.addKeyword({ keyword: X_DMN_ALLOWED_VALUES_KEYWORD, code: (ctx) => this.constraintCompiler(ctx) }); + this.ajv.addKeyword({ keyword: X_DMN_TYPE_CONSTRAINTS_KEYWORD, code: (ctx) => this.constraintCompiler(ctx) }); + this.ajv.addKeyword(X_DMN_DESCRIPTIONS_KEYWORD); + this.ajv.addKeyword(RECURSION_KEYWORD); + this.ajv.addKeyword(RECURSION_REF_KEYWORD); this.ajv.addFormat(DAYS_AND_TIME_DURATION_FORMAT, { type: "string", validate: (data: string) => !!data.match(DAYS_AND_TIME_DURATION_REGEXP), @@ -246,7 +235,7 @@ export class DmnRunnerAjv { }); } - public getAjv(): Ajv.Ajv { + public getAjv(): AjvDraft04 { return this.ajv; } } diff --git a/packages/form/package.json b/packages/form/package.json index fa85168c3ba..bc6e40e1655 100644 --- a/packages/form/package.json +++ b/packages/form/package.json @@ -31,7 +31,8 @@ "@kie-tools/uniforms-patternfly": "workspace:*", "@patternfly/react-core": "^4.276.6", "@patternfly/react-icons": "^4.93.6", - "ajv": "^6.12.6", + "ajv": "^8.17.1", + "ajv-draft-04": "^1.0.0", "ajv-errors": "^1.0.1", "deep-object-diff": "^1.1.9", "lodash": "^4.17.21", diff --git a/packages/form/src/Validator.ts b/packages/form/src/Validator.ts index 752d1100d62..1ead2ddc7e6 100644 --- a/packages/form/src/Validator.ts +++ b/packages/form/src/Validator.ts @@ -17,14 +17,14 @@ * under the License. */ -import Ajv from "ajv"; +import AjvDraft04 from "ajv-draft-04"; import { FormJsonSchemaBridge } from "./uniforms/FormJsonSchemaBridge"; import { FormI18n } from "./i18n"; export class Validator { constructor(public i18n: FormI18n) {} - protected readonly ajv = new Ajv({ allErrors: true, schemaId: "auto", useDefaults: true }); + protected readonly ajv = new AjvDraft04({ allErrors: true, useDefaults: true }); public createValidator(formSchema: object) { const validator = this.ajv.compile(formSchema); diff --git a/packages/runtime-tools-components/package.json b/packages/runtime-tools-components/package.json index 359515151f0..2e572fff0fd 100644 --- a/packages/runtime-tools-components/package.json +++ b/packages/runtime-tools-components/package.json @@ -34,7 +34,7 @@ "@patternfly/react-icons": "^4.93.6", "@patternfly/react-styles": "^4.92.6", "@patternfly/react-table": "^4.112.39", - "ajv": "^6.12.6", + "ajv": "^8.17.1", "axios": "^1.7.4", "copyfiles": "^2.4.1", "history": "^4.9.0", diff --git a/packages/unitables/package.json b/packages/unitables/package.json index 37a8dec047f..26ea2ca267c 100644 --- a/packages/unitables/package.json +++ b/packages/unitables/package.json @@ -37,7 +37,8 @@ "@patternfly/react-icons": "^4.93.6", "@types/lodash": "^4.14.168", "@types/react-table": "^7.0.25", - "ajv": "^6.12.6", + "ajv": "^8.17.1", + "ajv-draft-04": "^1.0.0", "ajv-errors": "^1.0.1", "deep-object-diff": "^1.1.9", "lodash": "^4.17.21", diff --git a/packages/unitables/src/UnitablesValidator.ts b/packages/unitables/src/UnitablesValidator.ts index d36a4e5d259..2f8567dc757 100644 --- a/packages/unitables/src/UnitablesValidator.ts +++ b/packages/unitables/src/UnitablesValidator.ts @@ -17,14 +17,14 @@ * under the License. */ -import Ajv from "ajv"; +import AjvDraft04 from "ajv-draft-04"; import { UnitablesJsonSchemaBridge } from "./uniforms"; import { UnitablesI18n } from "./i18n"; export class UnitablesValidator { constructor(public i18n: UnitablesI18n) {} - protected readonly ajv = new Ajv({ allErrors: true, schemaId: "auto", useDefaults: true }); + protected readonly ajv = new AjvDraft04({ allErrors: true, useDefaults: true }); public createValidator(formSchema: object) { const validator = this.ajv.compile(formSchema); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 17ce344b215..30cf3cacca0 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -599,8 +599,11 @@ importers: specifier: ^4.93.6 version: 4.93.6(react-dom@17.0.2(react@17.0.2))(react@17.0.2) ajv: - specifier: ^6.12.6 - version: 6.12.6 + specifier: ^8.17.1 + version: 8.17.1 + ajv-draft-04: + specifier: ^1.0.0 + version: 1.0.0(ajv@8.17.1) react: specifier: ^17.0.2 version: 17.0.2 @@ -2337,8 +2340,11 @@ importers: specifier: ^4.112.39 version: 4.112.39(react-dom@17.0.2(react@17.0.2))(react@17.0.2) ajv: - specifier: ^6.12.6 - version: 6.12.6 + specifier: ^8.17.1 + version: 8.17.1 + ajv-draft-04: + specifier: ^1.0.0 + version: 1.0.0(ajv@8.17.1) lodash: specifier: ^4.17.21 version: 4.17.21 @@ -3886,8 +3892,11 @@ importers: specifier: ^4.93.6 version: 4.93.6(react-dom@17.0.2(react@17.0.2))(react@17.0.2) ajv: - specifier: ^6.12.6 - version: 6.12.6 + specifier: ^8.17.1 + version: 8.17.1 + ajv-draft-04: + specifier: ^1.0.0 + version: 1.0.0(ajv@8.17.1) deep-object-diff: specifier: ^1.1.9 version: 1.1.9 @@ -4559,11 +4568,14 @@ importers: specifier: ^4.93.6 version: 4.93.6(react-dom@17.0.2(react@17.0.2))(react@17.0.2) ajv: - specifier: ^6.12.6 - version: 6.12.6 + specifier: ^8.17.1 + version: 8.17.1 + ajv-draft-04: + specifier: ^1.0.0 + version: 1.0.0(ajv@8.17.1) ajv-errors: specifier: ^1.0.1 - version: 1.0.1(ajv@6.12.6) + version: 1.0.1(ajv@8.17.1) deep-object-diff: specifier: ^1.1.9 version: 1.1.9 @@ -6990,8 +7002,8 @@ importers: specifier: ^4.112.39 version: 4.112.39(react-dom@17.0.2(react@17.0.2))(react@17.0.2) ajv: - specifier: ^6.12.6 - version: 6.12.6 + specifier: ^8.17.1 + version: 8.17.1 axios: specifier: ^1.7.4 version: 1.7.4 @@ -11880,11 +11892,14 @@ importers: specifier: ^7.0.25 version: 7.7.7 ajv: - specifier: ^6.12.6 - version: 6.12.6 + specifier: ^8.17.1 + version: 8.17.1 + ajv-draft-04: + specifier: ^1.0.0 + version: 1.0.0(ajv@8.17.1) ajv-errors: specifier: ^1.0.1 - version: 1.0.1(ajv@6.12.6) + version: 1.0.1(ajv@8.17.1) deep-object-diff: specifier: ^1.1.9 version: 1.1.9 @@ -19927,15 +19942,12 @@ packages: ajv@6.12.6: resolution: {integrity: sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==} - ajv@8.11.0: - resolution: {integrity: sha512-wGgprdCvMalC0BztXvitD2hC04YffAvtsUn93JbGXYLAtCUO4xd17mCCZQxUOItiBwZvJScWo8NIvQMQ71rdpg==} - - ajv@8.12.0: - resolution: {integrity: sha512-sRu1kpcO9yLtYxBKvqfTeh9KzZEwO3STyX1HT+4CaDzC6HpTGYhIhPIzj9XuKU7KYDwnaeh5hcOwjy1QuJzBPA==} - ajv@8.16.0: resolution: {integrity: sha512-F0twR8U1ZU67JIEtekUcLkXkoO5mMMmgGD8sK/xUFzJ805jxHQl92hImFAqqXMyMYjSPOyUPAwHYhB72g5sTXw==} + ajv@8.17.1: + resolution: {integrity: sha512-B/gBuNg5SiMTrPkC+A2+cW0RszwxYmn6VYxB/inlBStS5nx6xHIt/ehKRhIMhqusl7a8LjQoZnjCs5vhwxOQ1g==} + ansi-align@2.0.0: resolution: {integrity: sha512-TdlOggdA/zURfMYa7ABC66j+oqfMew58KpJMbUlH3bcZP1b+cBHIHDDn5uH9INsxrHBPjsqM0tDB4jPTF/vgJA==} @@ -22878,6 +22890,9 @@ packages: fast-text-encoding@1.0.3: resolution: {integrity: sha512-dtm4QZH9nZtcDt8qJiOH9fcQd1NAgi+K1O2DbE6GG1PPCK/BWfOH3idCTRQ4ImXRUOyopDEgDEnVEE7Y/2Wrig==} + fast-uri@3.0.1: + resolution: {integrity: sha512-MWipKbbYiYI0UC7cl8m/i/IWTqfC8YXsqjzybjddLsFjStroQzsHXkc73JutMvBiXmOvapk+axIl79ig5t55Bw==} + fast-url-parser@1.1.3: resolution: {integrity: sha512-5jOCVXADYNuRkKFzNJ0dCCewsZiYo0dz8QNYljkOpFC6r2U4OBmKtvm/Tsuh4w1YYdDqDb31a8TVhBJ2OJKdqQ==} @@ -30441,8 +30456,8 @@ snapshots: '@apidevtools/openapi-schemas': 2.1.0 '@apidevtools/swagger-methods': 3.0.2 '@jsdevtools/ono': 7.1.3 - ajv: 8.12.0 - ajv-draft-04: 1.0.0(ajv@8.12.0) + ajv: 8.17.1 + ajv-draft-04: 1.0.0(ajv@8.17.1) call-me-maybe: 1.0.2 openapi-types: 7.2.3 @@ -38269,8 +38284,8 @@ snapshots: '@kubernetes-models/validate@3.0.0': dependencies: - ajv: 8.12.0 - ajv-formats: 2.1.1(ajv@8.12.0) + ajv: 8.17.1 + ajv-formats: 2.1.1(ajv@8.17.1) tslib: 2.6.2 '@leichtgewicht/ip-codec@2.0.4': {} @@ -39924,12 +39939,12 @@ snapshots: - '@types/react' - immer - '@readme/better-ajv-errors@1.6.0(ajv@8.12.0)': + '@readme/better-ajv-errors@1.6.0(ajv@8.17.1)': dependencies: '@babel/code-frame': 7.23.5 '@babel/runtime': 7.23.6 '@humanwhocodes/momoa': 2.0.4 - ajv: 8.12.0 + ajv: 8.17.1 chalk: 4.1.2 json-to-ast: 2.1.0 jsonpointer: 5.0.1 @@ -39947,10 +39962,10 @@ snapshots: '@apidevtools/openapi-schemas': 2.1.0 '@apidevtools/swagger-methods': 3.0.2 '@jsdevtools/ono': 7.1.3 - '@readme/better-ajv-errors': 1.6.0(ajv@8.12.0) + '@readme/better-ajv-errors': 1.6.0(ajv@8.17.1) '@readme/json-schema-ref-parser': 1.2.0 - ajv: 8.12.0 - ajv-draft-04: 1.0.0(ajv@8.12.0) + ajv: 8.17.1 + ajv-draft-04: 1.0.0(ajv@8.17.1) call-me-maybe: 1.0.2 openapi-types: 7.2.3 @@ -40082,7 +40097,7 @@ snapshots: '@severlessworkflow/sdk-typescript@3.0.3': dependencies: - ajv: 8.12.0 + ajv: 8.17.1 js-yaml: 4.1.0 '@sideway/address@4.1.4': @@ -43772,21 +43787,17 @@ snapshots: clean-stack: 2.2.0 indent-string: 4.0.0 - ajv-draft-04@1.0.0(ajv@8.12.0): + ajv-draft-04@1.0.0(ajv@8.17.1): optionalDependencies: - ajv: 8.12.0 + ajv: 8.17.1 - ajv-errors@1.0.1(ajv@6.12.6): + ajv-errors@1.0.1(ajv@8.17.1): dependencies: - ajv: 6.12.6 + ajv: 8.17.1 - ajv-formats@2.1.1(ajv@8.12.0): + ajv-formats@2.1.1(ajv@8.17.1): optionalDependencies: - ajv: 8.12.0 - - ajv-formats@2.1.1(ajv@8.16.0): - optionalDependencies: - ajv: 8.16.0 + ajv: 8.17.1 ajv-formats@3.0.1(ajv@8.16.0): optionalDependencies: @@ -43796,14 +43807,9 @@ snapshots: dependencies: ajv: 6.12.6 - ajv-keywords@5.1.0(ajv@8.12.0): - dependencies: - ajv: 8.12.0 - fast-deep-equal: 3.1.3 - - ajv-keywords@5.1.0(ajv@8.16.0): + ajv-keywords@5.1.0(ajv@8.17.1): dependencies: - ajv: 8.16.0 + ajv: 8.17.1 fast-deep-equal: 3.1.3 ajv@6.12.6: @@ -43813,26 +43819,19 @@ snapshots: json-schema-traverse: 0.4.1 uri-js: 4.4.1 - ajv@8.11.0: - dependencies: - fast-deep-equal: 3.1.3 - json-schema-traverse: 1.0.0 - require-from-string: 2.0.2 - uri-js: 4.4.1 - - ajv@8.12.0: + ajv@8.16.0: dependencies: fast-deep-equal: 3.1.3 json-schema-traverse: 1.0.0 require-from-string: 2.0.2 uri-js: 4.4.1 - ajv@8.16.0: + ajv@8.17.1: dependencies: fast-deep-equal: 3.1.3 + fast-uri: 3.0.1 json-schema-traverse: 1.0.0 require-from-string: 2.0.2 - uri-js: 4.4.1 ansi-align@2.0.0: dependencies: @@ -48282,6 +48281,8 @@ snapshots: fast-text-encoding@1.0.3: {} + fast-uri@3.0.1: {} + fast-url-parser@1.1.3: dependencies: punycode: 1.4.1 @@ -54998,16 +54999,16 @@ snapshots: schema-utils@4.0.0: dependencies: '@types/json-schema': 7.0.15 - ajv: 8.12.0 - ajv-formats: 2.1.1(ajv@8.12.0) - ajv-keywords: 5.1.0(ajv@8.12.0) + ajv: 8.17.1 + ajv-formats: 2.1.1(ajv@8.17.1) + ajv-keywords: 5.1.0(ajv@8.17.1) schema-utils@4.2.0: dependencies: '@types/json-schema': 7.0.15 - ajv: 8.16.0 - ajv-formats: 2.1.1(ajv@8.16.0) - ajv-keywords: 5.1.0(ajv@8.16.0) + ajv: 8.17.1 + ajv-formats: 2.1.1(ajv@8.17.1) + ajv-keywords: 5.1.0(ajv@8.17.1) scuid@1.1.0: {} @@ -58390,7 +58391,7 @@ snapshots: yaml-language-server@1.10.0: dependencies: - ajv: 8.11.0 + ajv: 8.17.1 request-light: 0.5.8 vscode-json-languageservice: 4.1.8 vscode-languageserver: 7.0.0 From 2a1f73ea111e0ddb3ff5f914ecf071c993fea07f Mon Sep 17 00:00:00 2001 From: Luiz Motta Date: Fri, 13 Sep 2024 18:40:19 -0300 Subject: [PATCH 02/10] Simplify DataField logic and update tests --- .../src/schemas/json-schema.ts | 6 +- .../uniforms-patternfly/src/DateField.tsx | 23 ++-- .../tests/DateField.test.tsx | 105 ++++++++++-------- 3 files changed, 73 insertions(+), 61 deletions(-) diff --git a/examples/uniforms-patternfly/src/schemas/json-schema.ts b/examples/uniforms-patternfly/src/schemas/json-schema.ts index d2e99e55434..c177023ccc7 100644 --- a/examples/uniforms-patternfly/src/schemas/json-schema.ts +++ b/examples/uniforms-patternfly/src/schemas/json-schema.ts @@ -17,10 +17,10 @@ * under the License. */ -import * as Ajv from "ajv"; +import AjvDraft04 from "ajv-draft-04"; import { JSONSchemaBridge } from "uniforms-bridge-json-schema"; -const ajv = new Ajv({ allErrors: true, useDefaults: true }); +const ajv = new AjvDraft04({ strict: false, allErrors: true, useDefaults: true }); function createValidator(schema: any) { const validator = ajv.compile(schema); @@ -56,7 +56,7 @@ const schema = { type: "string", format: "date-time", max: "2000-04-04T10:30:00.000Z", - description: "this is date and time field", + description: "this is the date and time field", }, }, disabled: false, diff --git a/packages/uniforms-patternfly/src/DateField.tsx b/packages/uniforms-patternfly/src/DateField.tsx index 709a6989eb1..795e3bf6046 100644 --- a/packages/uniforms-patternfly/src/DateField.tsx +++ b/packages/uniforms-patternfly/src/DateField.tsx @@ -24,13 +24,13 @@ import { TextInput, TextInputProps } from "@patternfly/react-core/dist/js/compon import wrapField from "./wrapField"; export type DateFieldProps = FieldProps< - Date, + string, TextInputProps, { inputRef?: React.RefObject; labelProps?: object; - max?: Date; - min?: Date; + max?: string; + min?: string; type?: "date" | "datetime-local"; } >; @@ -54,39 +54,40 @@ const dateParse = (value: string, onChange: DateFieldProps["onChange"]) => { if (splitedValue.length > 1) { // A year can't be bigger than 9999; splitedValue[0] = parseInt(splitedValue[0]) > 9999 ? "9999" : splitedValue[0]; - onChange(new DateConstructor(`${splitedValue.join("-")}Z`)); + onChange(new DateConstructor(`${splitedValue.join("-")}Z`).toISOString()); return; } onChange(undefined); } else { const date = new DateConstructor(`${value}Z`); if (date.getFullYear() < 10000) { - onChange(date); + onChange(date.toISOString()); } else { - onChange(date); + onChange(date.toISOString()); } } }; function DateField({ onChange, ...props }: DateFieldProps) { const isInvalid = useMemo(() => { - if (!props.value) { + if (props.value === undefined) { return false; } + const dateValue = new DateConstructor(props.value); if (props.min) { - const minDate = new Date(props.min); + const minDate = new DateConstructor(props.min); if (minDate.toString() === "Invalid Date") { return false; - } else if (props.value < minDate) { + } else if (dateValue < minDate) { return `Should be after ${minDate.toISOString()}`; } } if (props.max) { - const maxDate = new Date(props.max); + const maxDate = new DateConstructor(props.max); if (maxDate.toString() === "Invalid Date") { return false; - } else if (props.value > maxDate) { + } else if (dateValue > maxDate) { return `Should be before ${maxDate.toISOString()}`; } } diff --git a/packages/uniforms-patternfly/tests/DateField.test.tsx b/packages/uniforms-patternfly/tests/DateField.test.tsx index a3b455b5b04..ab6a5c2fd99 100644 --- a/packages/uniforms-patternfly/tests/DateField.test.tsx +++ b/packages/uniforms-patternfly/tests/DateField.test.tsx @@ -23,47 +23,51 @@ import { render, screen, fireEvent } from "@testing-library/react"; import { usingUniformsContext } from "./test-utils"; test(" - renders an input", () => { - render(usingUniformsContext(, { x: { type: Date } })); + render(usingUniformsContext(, { x: { type: "string" } })); expect(screen.getByTestId("date-field")).toBeInTheDocument(); }); test(" - renders a input with correct id (inherited)", () => { - render(usingUniformsContext(, { x: { type: Date } })); + render(usingUniformsContext(, { x: { type: "string" } })); expect(screen.getByTestId("date-field")).toBeInTheDocument(); }); test(" - renders a input with correct id (specified)", () => { - render(usingUniformsContext(, { x: { type: Date } })); + render(usingUniformsContext(, { x: { type: "string" } })); expect(screen.getByTestId("date-field")).toBeInTheDocument(); expect(screen.getByTestId("date-field").getAttribute("id")).toBe("y"); }); test(" - renders a input with correct name", () => { - render(usingUniformsContext(, { x: { type: Date } })); + render(usingUniformsContext(, { x: { type: "string" } })); expect(screen.getByTestId("date-field")).toBeInTheDocument(); expect(screen.getByTestId("date-field").getAttribute("name")).toBe("x"); }); test(" - renders an input with correct disabled state", () => { - render(usingUniformsContext(, { x: { type: Date } })); + render(usingUniformsContext(, { x: { type: "string" } })); expect(screen.getByTestId("date-field")).toBeInTheDocument(); expect(screen.getByTestId("date-field") as HTMLInputElement).toBeDisabled(); }); test(" - renders a input with correct label (specified)", () => { - render(usingUniformsContext(, { x: { type: Date } })); + render( + usingUniformsContext(, { x: { type: "string" } }) + ); expect(screen.getByTestId("date-field")).toBeInTheDocument(); expect(screen.getByText("DateFieldLabel")).toBeInTheDocument(); }); test(" - renders a input with correct label (specified)", () => { - render(usingUniformsContext(, { x: { type: Date } })); + render( + usingUniformsContext(, { x: { type: "string" } }) + ); expect(screen.getByTestId("date-field")).toBeInTheDocument(); expect(screen.getByText("DateFieldLabel")).toBeInTheDocument(); @@ -71,7 +75,7 @@ test(" - renders a input with correct label (specified)", () => { }); test(" - renders a input with correct value (default)", () => { - render(usingUniformsContext(, { x: { type: Date } })); + render(usingUniformsContext(, { x: { type: "string" } })); expect(screen.getByTestId("date-field")).toBeInTheDocument(); expect((screen.getByTestId("date-field") as HTMLInputElement).value).toBe(""); @@ -79,7 +83,7 @@ test(" - renders a input with correct value (default)", () => { test(" - renders a input with correct value (model)", () => { const now = new Date(); - render(usingUniformsContext(, { x: { type: Date } }, { model: { x: now } })); + render(usingUniformsContext(, { x: { type: "string" } }, { model: { x: now } })); const stringfyDate = now.toISOString().split(":").slice(0, 2).join(":"); expect(screen.getByTestId("date-field")).toBeInTheDocument(); @@ -89,20 +93,24 @@ test(" - renders a input with correct value (model)", () => { test(" - renders a input which correctly reacts on change", () => { const onChange = jest.fn(); - const now = "2000-04-04"; - render(usingUniformsContext(, { x: { type: Date } }, { onChange })); + render(usingUniformsContext(, { x: { type: "string" } }, { onChange })); const input = screen.getByTestId("date-field") as HTMLInputElement; fireEvent.change(input, { target: { value: "2000-04-04T10:20" } }); - expect(onChange).toHaveBeenLastCalledWith("x", new Date("2000-04-04T10:20:00.000Z")); + expect(onChange).toHaveBeenLastCalledWith("x", "2000-04-04T10:20:00.000Z"); }); test(" - renders a input which correctly reacts on change (empty value)", () => { const onChange = jest.fn(); - const dateValue = new Date("2000-04-04"); - render(usingUniformsContext(, { x: { type: Date } }, { onChange })); + render( + usingUniformsContext( + , + { x: { type: "string" } }, + { onChange } + ) + ); const input = screen.getByTestId("date-field") as HTMLInputElement; fireEvent.change(input, { target: { value: "" } }); @@ -113,7 +121,7 @@ test(" - renders a input which correctly reacts on change (empty valu test(" - renders a input which correctly reacts on change (empty)", () => { const onChange = jest.fn(); - render(usingUniformsContext(, { x: { type: Date } })); + render(usingUniformsContext(, { x: { type: "string" } })); const input = screen.getByTestId("date-field") as HTMLInputElement; fireEvent.change(input, { target: { value: "" } }); @@ -124,11 +132,10 @@ test(" - renders a input which correctly reacts on change (empty)", ( test(" - renders a input which correctly reacts on change (invalid)", () => { const onChange = jest.fn(); - const now = "10:00"; - render(usingUniformsContext(, { x: { type: Date } }, { onChange })); + render(usingUniformsContext(, { x: { type: "string" } }, { onChange })); const input = screen.getByTestId("date-field") as HTMLInputElement; - fireEvent.change(input, { target: { value: now } }); + fireEvent.change(input, { target: { value: "10:00" } }); expect(onChange).not.toHaveBeenCalled(); }); @@ -136,63 +143,67 @@ test(" - renders a input which correctly reacts on change (invalid)", test(" - renders a input which correctly reacts on change (valid)", () => { const onChange = jest.fn(); - const date = "2000-04-04"; - const time = "10:30"; - - const dateValue = new Date(`${date}T00:00:00Z`); - render(usingUniformsContext(, { x: { type: Date } }, { onChange })); + render( + usingUniformsContext( + , + { x: { type: "string" } }, + { onChange } + ) + ); const input = screen.getByTestId("date-field") as HTMLInputElement; - fireEvent.change(input, { target: { value: `${date}T${time}` } }); + fireEvent.change(input, { target: { value: `2000-04-04T10:30` } }); - expect(onChange).toHaveBeenLastCalledWith("x", new Date(`${date}T${time}:00.000Z`)); + expect(onChange).toHaveBeenLastCalledWith("x", `2000-04-04T10:30:00.000Z`); }); test(" - renders a input which correctly reacts on change (year bigger than 9999)", () => { const onChange = jest.fn(); - render(usingUniformsContext(, { x: { type: Date } }, { onChange })); + render(usingUniformsContext(, { x: { type: "string" } }, { onChange })); const input = screen.getByTestId("date-field") as HTMLInputElement; fireEvent.change(input, { target: { value: "121212-12-12T12:12" } }); - expect(onChange).toHaveBeenLastCalledWith("x", new Date("9999-12-12T12:12:00.000Z")); + expect(onChange).toHaveBeenLastCalledWith("x", "9999-12-12T12:12:00.000Z"); }); test(" - test max property - valid", () => { - const dateValue = new Date("1998-12-31"); - const maxValue = new Date("1999-01-01T00:00:00Z"); - render(usingUniformsContext(, { x: { type: Date } })); + render( + usingUniformsContext(, { + x: { type: "string" }, + }) + ); expect(screen.queryByTestId("Should be before")).toBeNull(); }); test(" - test max property - invalid", () => { - const date = "1999-01-02"; - const max = "1999-01-01T00:00:00.000Z"; - - const dateValue = new Date(date); - const maxValue = new Date(max); - render(usingUniformsContext(, { x: { type: Date } })); + render( + usingUniformsContext(, { + x: { type: "string" }, + }) + ); - expect(screen.getByText(`Should be before ${max}`)).toBeInTheDocument(); + expect(screen.getByText(`Should be before 1999-01-01T00:00:00.000Z`)).toBeInTheDocument(); }); test(" - test min property - valid", () => { - const dateValue = new Date("1999-01-02"); - const minValue = new Date("1999-01-01T00:00:00Z"); - render(usingUniformsContext(, { x: { type: Date } })); + render( + usingUniformsContext(, { + x: { type: "string" }, + }) + ); expect(screen.queryByTestId("Should be after")).toBeNull(); }); test(" - test min property - invalid", () => { - const date = "1998-12-31"; - const min = "1999-01-01T00:00:00.000Z"; - - const dateValue = new Date(date); - const minValue = new Date(min); - render(usingUniformsContext(, { x: { type: Date } })); + render( + usingUniformsContext(, { + x: { type: "string" }, + }) + ); - expect(screen.getByText(`Should be after ${min}`)).toBeInTheDocument(); + expect(screen.getByText(`Should be after 1999-01-01T00:00:00.000Z`)).toBeInTheDocument(); }); From ef153844ab9cc2ec90a6724332a6b07529e1907d Mon Sep 17 00:00:00 2001 From: Luiz Motta Date: Mon, 16 Sep 2024 18:15:01 -0300 Subject: [PATCH 03/10] Fix dev-ui dev webapp --- .../resources/index.html | 2 + .../server/MockData/controllers.js | 7 +- .../MockData/forms/examples/hiring.config | 7 + .../server/MockData/forms/examples/hiring.tsx | 154 ++++++++++++++++++ .../server/MockData/forms/formData.js | 5 + .../server/MockData/graphql.js | 136 +++++++++++++++- .../server/MockData/types.js | 29 ++++ .../server/server.js | 20 ++- .../src/gatewayApi/apis.tsx | 2 +- .../src/formDisplayer/utils/utils.tsx | 2 +- 10 files changed, 354 insertions(+), 10 deletions(-) create mode 100644 packages/runtime-tools-process-dev-ui-webapp/server/MockData/forms/examples/hiring.config create mode 100644 packages/runtime-tools-process-dev-ui-webapp/server/MockData/forms/examples/hiring.tsx diff --git a/packages/runtime-tools-process-dev-ui-webapp/resources/index.html b/packages/runtime-tools-process-dev-ui-webapp/resources/index.html index 3758c0ab286..2abfee455ce 100644 --- a/packages/runtime-tools-process-dev-ui-webapp/resources/index.html +++ b/packages/runtime-tools-process-dev-ui-webapp/resources/index.html @@ -49,6 +49,8 @@ { id: "saravana", groups: [] }, { id: "john", groups: [] }, ], + quarkusAppOrigin: "http://localhost:9027", + quarkusAppRootPath: "", page: "Processes", devUIUrl: "http://localhost:9027", customLabels: { diff --git a/packages/runtime-tools-process-dev-ui-webapp/server/MockData/controllers.js b/packages/runtime-tools-process-dev-ui-webapp/server/MockData/controllers.js index f83124f4564..d80ae87ff40 100644 --- a/packages/runtime-tools-process-dev-ui-webapp/server/MockData/controllers.js +++ b/packages/runtime-tools-process-dev-ui-webapp/server/MockData/controllers.js @@ -29,7 +29,7 @@ const emptyForm = require("./forms/EmptyForm"); const formData = require("../MockData/forms/formData"); const customDashboardData = require("../MockData/customDashboard/data"); const hiringSchema = require("./process-forms-schema/hiring"); -const uuidv4 = require("uuid"); +const uuid = require("uuid"); const tasksUnableToTransition = [ "047ec38d-5d57-4330-8c8d-9bd67b53a529", "841b9dba-3d91-4725-9de3-f9f4853b417e", @@ -399,8 +399,11 @@ module.exports = controller = { }, startProcessInstance: (req, res) => { + console.log( + `......Starting Process Instance:: id: ${req.headers["ce-id"]} type: ${req.headers["ce-type"]} source: ${req.headers["ce-source"]}` + ); const businessKey = req.query.businessKey ? req.query.businessKey : null; - const processId = uuidv4(); + const processId = uuid.v4(); const processInstance = { id: processId, processId: "hiring", diff --git a/packages/runtime-tools-process-dev-ui-webapp/server/MockData/forms/examples/hiring.config b/packages/runtime-tools-process-dev-ui-webapp/server/MockData/forms/examples/hiring.config new file mode 100644 index 00000000000..562befafd9a --- /dev/null +++ b/packages/runtime-tools-process-dev-ui-webapp/server/MockData/forms/examples/hiring.config @@ -0,0 +1,7 @@ +{ + "resources": { + "styles": {}, + "scripts": {} + }, + "schema": "{\"$schema\":\"https://json-schema.org/draft/2019-09/schema\",\"$defs\":{\"CandidateData\":{\"type\":\"object\",\"properties\":{\"email\":{\"type\":\"string\"},\"experience\":{\"type\":\"integer\"},\"lastName\":{\"type\":\"string\"},\"name\":{\"type\":\"string\"},\"skills\":{\"type\":\"array\",\"items\":{\"type\":\"string\"}}}}},\"type\":\"object\",\"properties\":{\"candidateData\":{\"$ref\":\"#/$defs/CandidateData\"}}}" +} \ No newline at end of file diff --git a/packages/runtime-tools-process-dev-ui-webapp/server/MockData/forms/examples/hiring.tsx b/packages/runtime-tools-process-dev-ui-webapp/server/MockData/forms/examples/hiring.tsx new file mode 100644 index 00000000000..8d7504ec37a --- /dev/null +++ b/packages/runtime-tools-process-dev-ui-webapp/server/MockData/forms/examples/hiring.tsx @@ -0,0 +1,154 @@ +import React, { useCallback, useEffect, useState } from "react"; +import { Card, CardBody, TextInput, FormGroup, Alert } from "@patternfly/react-core"; +const Form__hiring: React.FC = (props: any) => { + const [formApi, setFormApi] = useState(); + const [candidateData__email, set__candidateData__email] = useState(""); + const [candidateData__experience, set__candidateData__experience] = useState(); + const [candidateData__lastName, set__candidateData__lastName] = useState(""); + const [candidateData__name, set__candidateData__name] = useState(""); + const [candidateData__skills, set__candidateData__skills] = useState(); + + const [candidateData__email__validation, setCandidateData__email__validation] = useState(""); + /* Utility function that fills the form with the data received from the kogito runtime */ + const setFormData = (data) => { + if (!data) { + return; + } + set__candidateData__email(data?.candidateData?.email ?? ""); + set__candidateData__experience(data?.candidateData?.experience); + set__candidateData__lastName(data?.candidateData?.lastName ?? ""); + set__candidateData__name(data?.candidateData?.name ?? ""); + set__candidateData__skills(data?.candidateData?.skills); + }; + /* Utility function to generate the expected form output as a json object */ + const getFormData = useCallback(() => { + const formData: any = {}; + formData.candidateData = {}; + formData.candidateData.email = candidateData__email; + formData.candidateData.experience = candidateData__experience; + formData.candidateData.lastName = candidateData__lastName; + formData.candidateData.name = candidateData__name; + formData.candidateData.skills = candidateData__skills; + return formData; + }, [ + candidateData__email, + candidateData__experience, + candidateData__lastName, + candidateData__name, + candidateData__skills, + ]); + /* Utility function to validate the form on the 'beforeSubmit' Lifecycle Hook */ + const validateForm = useCallback(() => { + if (candidateData__email.includes("@") === false) { + setCandidateData__email__validation("It's not an email!"); + throw new Error("It's not an email!"); + } + }, [candidateData__email]); + /* Utility function to perform actions on the on the 'afterSubmit' Lifecycle Hook */ + const afterSubmit = useCallback((result) => {}, []); + useEffect(() => { + if (formApi) { + /* + Form Lifecycle Hook that will be executed before the form is submitted. + Throwing an error will stop the form submit. Usually should be used to validate the form. + */ + formApi.beforeSubmit = () => validateForm(); + /* + Form Lifecycle Hook that will be executed after the form is submitted. + It will receive a response object containing the `type` flag indicating if the submit has been successful and `info` with extra information about the submit result. + */ + formApi.afterSubmit = (result) => afterSubmit(result); + /* Generates the expected form output object to be posted */ + formApi.getFormData = () => getFormData(); + } + }, [getFormData, validateForm, afterSubmit]); + useEffect(() => { + /* + Call to the Kogito console form engine. It will establish the connection with the console embeding the form + and return an instance of FormAPI that will allow hook custom code into the form lifecycle. + The `window.Form.openForm` call expects an object with the following entries: + - onOpen: Callback that will be called after the connection with the console is established. The callback + will receive the following arguments: + - data: the data to be bound into the form + - ctx: info about the context where the form is being displayed. This will contain information such as the form JSON Schema, process/task, user... + */ + const api = window.Form.openForm({ + onOpen: (data, context) => { + setFormData(data); + }, + }); + setFormApi(api); + }, []); + return ( +
+ + + + + + + + set__candidateData__experience(Number(newValue))} + /> + + + + + + + + + + Cannot find form control for property candidateData.skills with type Array: +
+ Some complex property types, such as Array<object> aren't yet supported, however, you + can still write your own component into the form and use the already existing states{" "} + const [ candidateData__skills, set__candidateData__skills ]. +
+
+
+
+
+ ); +}; +export default Form__hiring; diff --git a/packages/runtime-tools-process-dev-ui-webapp/server/MockData/forms/formData.js b/packages/runtime-tools-process-dev-ui-webapp/server/MockData/forms/formData.js index 5fd2704b123..7420e713ea3 100644 --- a/packages/runtime-tools-process-dev-ui-webapp/server/MockData/forms/formData.js +++ b/packages/runtime-tools-process-dev-ui-webapp/server/MockData/forms/formData.js @@ -37,4 +37,9 @@ module.exports = [ type: "TSX", lastModified: new Date("2021-08-23T13:26:02.13Z"), }, + { + name: "hiring", + type: "TSX", + lastModified: new Date("2021-08-23T13:26:02.13Z"), + }, ]; diff --git a/packages/runtime-tools-process-dev-ui-webapp/server/MockData/graphql.js b/packages/runtime-tools-process-dev-ui-webapp/server/MockData/graphql.js index e7464d30bb4..06e3250b86d 100644 --- a/packages/runtime-tools-process-dev-ui-webapp/server/MockData/graphql.js +++ b/packages/runtime-tools-process-dev-ui-webapp/server/MockData/graphql.js @@ -1731,7 +1731,6 @@ module.exports = { state: "ACTIVE", serviceUrl: "http://localhost:4000", rootProcessInstanceId: null, - serviceUrl: "http://localhost:4000", endpoint: "http://localhost:4000/", addons: ["process-management"], error: { @@ -3150,6 +3149,141 @@ module.exports = { ], }, ], + ProcessDefinitionData: [ + { + id: "hiring", + endpoint: "http://localhost:4000/hiring", + serviceUrl: "http://localhost:4000", + __typename: "ProcessDefinition", + nodes: [ + { + nodeId: "1", + name: "End Event 1", + definitionId: "EndEvent_1", + id: "870bdda0-be04-4e59-bb0b-f9b665eaacc9", + enter: "2019-10-22T03:37:38.586Z", + exit: "2019-10-22T03:37:38.586Z", + type: "EndNode", + }, + { + nodeId: "2", + name: "Confirm travel", + definitionId: "UserTask_2", + id: "6b4a4fe9-4aab-4e8c-bb79-27b8b6b88d1f", + enter: "2019-10-22T03:37:30.807Z", + exit: "2019-10-22T03:37:38.586Z", + type: "HumanTaskNode", + }, + { + nodeId: "3", + name: "Book Hotel", + definitionId: "CallActivity_1", + id: "dd33de7c-c39c-484a-83a8-3e1b007fce95", + enter: "2019-10-22T03:37:30.793Z", + exit: "2019-10-22T03:37:30.803Z", + type: "SubProcessNode", + }, + { + nodeId: "4", + name: "Join", + definitionId: "_2140F05A-364F-40B3-BB7B-B12927065DF8", + id: "08c153e8-2766-4675-81f7-29943efdf411", + enter: "2019-10-22T03:37:30.806Z", + exit: "2019-10-22T03:37:30.807Z", + type: "Join", + }, + { + nodeId: "4", + name: "Book Flight", + definitionId: "CallActivity_2", + id: "683cf307-f082-4a8e-9c85-d5a11b13903a", + enter: "2019-10-22T03:37:30.803Z", + exit: "2019-10-22T03:37:30.806Z", + type: "SubProcessNode", + }, + { + nodeId: "5", + name: "Book", + definitionId: "ParallelGateway_1", + id: "cf057e58-4113-46c0-be13-6de42ea8377e", + enter: "2019-10-22T03:37:30.792Z", + exit: "2019-10-22T03:37:30.803Z", + type: "Split", + }, + { + nodeId: "6", + name: "Join", + definitionId: "ExclusiveGateway_2", + id: "415a52c0-dc1f-4a93-9238-862dc8072262", + enter: "2019-10-22T03:37:30.792Z", + exit: "2019-10-22T03:37:30.792Z", + type: "Join", + }, + { + nodeId: "7", + name: "is visa required", + definitionId: "ExclusiveGateway_1", + id: "52d64298-3f28-4aba-a812-dba4077c9665", + enter: "2019-10-22T03:37:30.79Z", + exit: "2019-10-22T03:37:30.792Z", + type: "Split", + }, + { + nodeId: "8", + name: "Visa check", + definitionId: "BusinessRuleTask_1", + id: "6fdee287-08f6-49c2-af2d-2d125ba76ab7", + enter: "2019-10-22T03:37:30.755Z", + exit: "2019-10-22T03:37:30.79Z", + type: "RuleSetNode", + }, + { + nodeId: "9", + name: "StartProcess", + definitionId: "StartEvent_1", + id: "d98c1762-9d3c-4228-9ffc-bc3f423079c0", + enter: "2019-10-22T03:37:30.753Z", + exit: "2019-10-22T03:37:30.754Z", + type: "StartNode", + }, + ], + }, + { + id: "travels", + endpoint: "http://localhost:4000/travels", + serviceUrl: "http://localhost:4000", + __typename: "ProcessDefinition", + nodes: [ + { + nodeId: "1", + name: "End Event 1", + definitionId: "EndEvent_1", + id: "ed36cd72-5e52-4a53-9d0d-865c98781282", + enter: "2019-10-22T03:40:44.088Z", + exit: "2019-10-22T03:40:44.088Z", + type: "EndNode", + }, + { + nodeId: "2", + name: "Book hotel", + definitionId: "ServiceTask_1", + id: "040cd02a-7f4c-4d41-bda5-4889f82e921f", + enter: "2019-10-22T03:40:44.088Z", + exit: "2019-10-22T03:40:44.088Z", + type: "WorkItemNode", + }, + { + nodeId: "3", + name: "StartProcess", + definitionId: "StartEvent_1", + id: "8528c7bf-8ac8-401f-b7e5-6f3e69b9f9f2", + enter: "2019-10-22T03:40:44.088Z", + exit: "2019-10-22T03:40:44.088Z", + type: "StartNode", + }, + ], + }, + ], JobsData: [ { id: "6e74a570-31c8-4020-bd70-19be2cb625f3_0", diff --git a/packages/runtime-tools-process-dev-ui-webapp/server/MockData/types.js b/packages/runtime-tools-process-dev-ui-webapp/server/MockData/types.js index fe8ab99df53..164fd8a3eed 100644 --- a/packages/runtime-tools-process-dev-ui-webapp/server/MockData/types.js +++ b/packages/runtime-tools-process-dev-ui-webapp/server/MockData/types.js @@ -43,6 +43,7 @@ module.exports = typeDefs = gql` orderBy: ProcessInstanceOrderBy pagination: Pagination ): [ProcessInstance] + ProcessDefinitions(where: ProcessDefinitionArgument): [ProcessDefinition] UserTaskInstances( where: UserTaskInstanceArgument orderBy: UserTaskInstanceOrderBy @@ -84,6 +85,34 @@ module.exports = typeDefs = gql` diagram: String } + type ProcessDefinition { + id: String! + endpoint: String! + serviceUrl: String + nodes: [NodeInstance!] + } + + input ProcessDefinitionArgument { + and: [ProcessDefinitionArgument!] + or: [ProcessDefinitionArgument!] + id: IdArgument + processId: StringArgument + processName: StringArgument + parentProcessInstanceId: IdArgument + rootProcessInstanceId: IdArgument + rootProcessId: StringArgument + state: ProcessInstanceStateArgument + error: ProcessInstanceErrorArgument + nodes: NodeInstanceArgument + endpoint: StringArgument + roles: StringArrayArgument + start: DateArgument + end: DateArgument + addons: StringArrayArgument + lastUpdate: DateArgument + businessKey: StringArgument + } + type KogitoMetadata { lastUpdate: DateTime! processInstances: [ProcessInstanceMeta] diff --git a/packages/runtime-tools-process-dev-ui-webapp/server/server.js b/packages/runtime-tools-process-dev-ui-webapp/server/server.js index e7eb6301723..8d0540868bf 100644 --- a/packages/runtime-tools-process-dev-ui-webapp/server/server.js +++ b/packages/runtime-tools-process-dev-ui-webapp/server/server.js @@ -22,7 +22,7 @@ const swaggerUi = require("swagger-ui-express"); const swaggerApiDoc = require("./MockData/openAPI/openapi.json"); var cors = require("cors"); const app = express(); -const { ApolloServer, gql } = require("apollo-server-express"); +const { ApolloServer } = require("apollo-server-express"); var bodyParser = require("body-parser"); // GraphQL - Apollo const { GraphQLScalarType } = require("graphql"); @@ -360,7 +360,7 @@ const resolvers = { Query: { ProcessInstances: async (parent, args) => { let result = data.ProcessInstanceData.filter((datum) => { - console.log("args", args["where"]); + // console.log("args", args["where"]); if (args["where"].id && args["where"].id.equal) { return datum.id == args["where"].id.equal; } else if (args["where"].rootProcessInstanceId && args["where"].rootProcessInstanceId.equal) { @@ -392,7 +392,7 @@ const resolvers = { } }); if (args["orderBy"]) { - console.log("orderBy args: ", args["orderBy"]); + // console.log("orderBy args: ", args["orderBy"]); result = _.orderBy( result, _.keys(args["orderBy"]).map((key) => key), @@ -403,9 +403,19 @@ const resolvers = { if (args["pagination"]) { result = paginatedResult(result, args["pagination"].offset, args["pagination"].limit); } - console.log("result length: " + result.length); + // console.log("result length: " + result.length); return result; }, + ProcessDefinitions: async (parent, args) => { + await timeout(); + return data.ProcessDefinitionData.filter((proccessDefinition) => { + if (args["where"] !== undefined) { + return proccessDefinition.id === args["where"].id.equal; + } else { + return proccessDefinition; + } + }); + }, Jobs: async (parent, args) => { if (Object.keys(args).length > 0) { const result = data.JobsData.filter((jobData) => { @@ -515,7 +525,7 @@ const resolvers = { serialize(value) { return value; }, - parseLiteral(ast) { + parseLiteral() { return null; }, }), diff --git a/packages/runtime-tools-process-gateway-api/src/gatewayApi/apis.tsx b/packages/runtime-tools-process-gateway-api/src/gatewayApi/apis.tsx index c68ce8d3778..cd01d939ad1 100644 --- a/packages/runtime-tools-process-gateway-api/src/gatewayApi/apis.tsx +++ b/packages/runtime-tools-process-gateway-api/src/gatewayApi/apis.tsx @@ -521,7 +521,7 @@ export const getProcessDefinitions = (client: ApolloClient): Promise { resolve( - value.data.ProcessDefinitions.map((item: { id: string; endpoint: string }) => { + (value.data.ProcessDefinitions ?? []).map((item: { id: string; endpoint: string }) => { return { processName: item.id, endpoint: item.endpoint, diff --git a/packages/runtime-tools-shared-enveloped-components/src/formDisplayer/utils/utils.tsx b/packages/runtime-tools-shared-enveloped-components/src/formDisplayer/utils/utils.tsx index 6b4141fe7a6..f3e63b9c148 100644 --- a/packages/runtime-tools-shared-enveloped-components/src/formDisplayer/utils/utils.tsx +++ b/packages/runtime-tools-shared-enveloped-components/src/formDisplayer/utils/utils.tsx @@ -37,7 +37,7 @@ export const sourceHandler = ( const patternflyElements = reg.exec(patternflyImport[0])?.[1]; const trimmedSource = source.split(reactReg).join("").trim().split(patternflyReg).join("").trim(); - const formName = trimmedSource.split(":")[0].split("const ")[1]; + const formName = trimmedSource.split(": React.FC")[0].split("const ")[1]; return { reactElements: reactElements!, patternflyElements: patternflyElements!, formName, trimmedSource }; }; From e006f3bbf1019da36e79ed11566afdec5f8a13f7 Mon Sep 17 00:00:00 2001 From: Luiz Motta Date: Wed, 18 Sep 2024 13:14:04 -0300 Subject: [PATCH 04/10] Add ajv-formats --- examples/uniforms-patternfly/package.json | 1 + .../src/schemas/json-schema.ts | 2 ++ .../package.json | 1 + .../src/Uniforms.tsx | 11 +++++--- packages/dmn-runner/package.json | 1 + packages/dmn-runner/src/ajv.ts | 18 ++++++++----- packages/dmn-runner/src/jsonSchema.ts | 2 +- packages/form/package.json | 1 + packages/form/src/Validator.ts | 8 ++++-- .../runtime-tools-components/package.json | 1 + .../src/common/utils/FormValidator.ts | 7 ++++-- .../package.json | 1 + packages/unitables/package.json | 1 + packages/unitables/src/UnitablesValidator.ts | 8 ++++-- pnpm-lock.yaml | 25 +++++++++++++++++++ 15 files changed, 71 insertions(+), 17 deletions(-) diff --git a/examples/uniforms-patternfly/package.json b/examples/uniforms-patternfly/package.json index a4be92f79df..afc29cf9288 100644 --- a/examples/uniforms-patternfly/package.json +++ b/examples/uniforms-patternfly/package.json @@ -16,6 +16,7 @@ "@patternfly/react-icons": "^4.93.6", "ajv": "^8.17.1", "ajv-draft-04": "^1.0.0", + "ajv-formats": "^3.0.1", "react": "^17.0.2", "react-dom": "^17.0.2", "simpl-schema": "^1.12.0", diff --git a/examples/uniforms-patternfly/src/schemas/json-schema.ts b/examples/uniforms-patternfly/src/schemas/json-schema.ts index c177023ccc7..ca8a30c0506 100644 --- a/examples/uniforms-patternfly/src/schemas/json-schema.ts +++ b/examples/uniforms-patternfly/src/schemas/json-schema.ts @@ -18,9 +18,11 @@ */ import AjvDraft04 from "ajv-draft-04"; +import addFormats from "ajv-formats"; import { JSONSchemaBridge } from "uniforms-bridge-json-schema"; const ajv = new AjvDraft04({ strict: false, allErrors: true, useDefaults: true }); +addFormats(ajv); function createValidator(schema: any) { const validator = ajv.compile(schema); diff --git a/packages/dashbuilder-component-uniforms/package.json b/packages/dashbuilder-component-uniforms/package.json index dd0b2fcddf3..14ebad675aa 100644 --- a/packages/dashbuilder-component-uniforms/package.json +++ b/packages/dashbuilder-component-uniforms/package.json @@ -28,6 +28,7 @@ "@patternfly/react-table": "^4.112.39", "ajv": "^8.17.1", "ajv-draft-04": "^1.0.0", + "ajv-formats": "^3.0.1", "lodash": "^4.17.21", "uniforms": "^3.10.2", "uniforms-bridge-json-schema": "^3.10.2" diff --git a/packages/dashbuilder-component-uniforms/src/Uniforms.tsx b/packages/dashbuilder-component-uniforms/src/Uniforms.tsx index 7af1905d2fa..ad9a2979985 100644 --- a/packages/dashbuilder-component-uniforms/src/Uniforms.tsx +++ b/packages/dashbuilder-component-uniforms/src/Uniforms.tsx @@ -16,13 +16,16 @@ * specific language governing permissions and limitations * under the License. */ -import { JSONSchemaBridge } from "uniforms-bridge-json-schema"; -import { AutoForm } from "@kie-tools/uniforms-patternfly/dist/esm"; -import AjvDraft04 from "ajv-draft-04"; import * as React from "react"; import { useCallback } from "react"; +import { AutoForm } from "@kie-tools/uniforms-patternfly/dist/esm"; +import AjvDraft04 from "ajv-draft-04"; +import addFormats from "ajv-formats"; +import { JSONSchemaBridge } from "uniforms-bridge-json-schema"; + +const ajv = new AjvDraft04({ strict: false, allErrors: true, useDefaults: true }); +addFormats(ajv); -const ajv = new AjvDraft04({ allErrors: true, useDefaults: true }); const createValidator = (schema: any) => { const validator = ajv.compile(schema); return (model: any) => { diff --git a/packages/dmn-runner/package.json b/packages/dmn-runner/package.json index 9033ee8ec1d..44b7fdc785a 100644 --- a/packages/dmn-runner/package.json +++ b/packages/dmn-runner/package.json @@ -31,6 +31,7 @@ "@patternfly/react-icons": "^4.93.6", "ajv": "^8.17.1", "ajv-draft-04": "^1.0.0", + "ajv-formats": "^3.0.1", "deep-object-diff": "^1.1.9", "json-refs": "^3.0.15", "lodash": "^4.17.21", diff --git a/packages/dmn-runner/src/ajv.ts b/packages/dmn-runner/src/ajv.ts index 9d3817acbb3..82d220240e1 100644 --- a/packages/dmn-runner/src/ajv.ts +++ b/packages/dmn-runner/src/ajv.ts @@ -17,8 +17,8 @@ * under the License. */ -import AjvDraft04, { KeywordCxt } from "ajv-draft-04"; -export { ValidateFunction } from "ajv"; +import AjvDraft04, { AnySchemaObject } from "ajv-draft-04"; +import addFormats from "ajv-formats"; import { duration } from "moment"; import { DATE_AND_TIME_ENUM_REGEXP, @@ -138,8 +138,7 @@ export class DmnRunnerAjv { return []; }; - private constraintCompiler(ctx: KeywordCxt) { - const { schema, parentSchema } = ctx; + private constraintCompiler(schema: any, parentSchema: AnySchemaObject) { if (!parentSchema.format) { return (data: string) => true; } @@ -218,9 +217,16 @@ export class DmnRunnerAjv { removeAdditional: "all", verbose: true, }); + addFormats(this.ajv); this.ajv.addKeyword(X_DMN_TYPE_KEYWORD); - this.ajv.addKeyword({ keyword: X_DMN_ALLOWED_VALUES_KEYWORD, code: (ctx) => this.constraintCompiler(ctx) }); - this.ajv.addKeyword({ keyword: X_DMN_TYPE_CONSTRAINTS_KEYWORD, code: (ctx) => this.constraintCompiler(ctx) }); + this.ajv.addKeyword({ + keyword: X_DMN_ALLOWED_VALUES_KEYWORD, + compile: (schema, parentSchema) => this.constraintCompiler(schema, parentSchema), + }); + this.ajv.addKeyword({ + keyword: X_DMN_TYPE_CONSTRAINTS_KEYWORD, + compile: (schema, parentSchema) => this.constraintCompiler(schema, parentSchema), + }); this.ajv.addKeyword(X_DMN_DESCRIPTIONS_KEYWORD); this.ajv.addKeyword(RECURSION_KEYWORD); this.ajv.addKeyword(RECURSION_REF_KEYWORD); diff --git a/packages/dmn-runner/src/jsonSchema.ts b/packages/dmn-runner/src/jsonSchema.ts index be94d9f62be..ab44a745587 100644 --- a/packages/dmn-runner/src/jsonSchema.ts +++ b/packages/dmn-runner/src/jsonSchema.ts @@ -87,7 +87,7 @@ export function removeChangedPropertiesAndAdditionalProperties Date: Wed, 18 Sep 2024 13:27:57 -0300 Subject: [PATCH 05/10] Clean up --- packages/dmn-runner/src/ajv.ts | 137 +++++++++--------- .../server/MockData/controllers.js | 4 +- .../server/server.js | 6 +- 3 files changed, 76 insertions(+), 71 deletions(-) diff --git a/packages/dmn-runner/src/ajv.ts b/packages/dmn-runner/src/ajv.ts index 82d220240e1..0a192b87e9c 100644 --- a/packages/dmn-runner/src/ajv.ts +++ b/packages/dmn-runner/src/ajv.ts @@ -138,75 +138,80 @@ export class DmnRunnerAjv { return []; }; - private constraintCompiler(schema: any, parentSchema: AnySchemaObject) { - if (!parentSchema.format) { - return (data: string) => true; - } - const { minAllowed, minAllowedIncluded, maxAllowed, maxAllowedIncluded } = this.parseRangeFromConstraints( - schema ?? "", - parentSchema.format - ); - const enumeratedValues = this.parseEnumerationFromConstraints(schema ?? "", parentSchema.format); - const isUnderTheMinBoundary: (value: Date | String | number, minBoundary: Date | String | number) => boolean = - minAllowedIncluded ? (value, minBoundary) => value < minBoundary : (value, minBoundary) => value <= minBoundary; - const isOverTheMaxBoundary: (value: Date | String | number, maxBoundary: Date | String | number) => boolean = - maxAllowedIncluded ? (value, maxBoundary) => value > maxBoundary : (value, maxBoundary) => value >= maxBoundary; - - return (rawData: string | Date) => { - let data = rawData instanceof Date ? rawData.toISOString() : rawData; - if (data.includes(".") && data.endsWith("Z")) { - // adjusting from "2023-06-01T10:42:00.000Z" to "2023-06-01T10:42:00" - data = data.substring(0, data.lastIndexOf(".")); + private constraintCompiler() { + return (schema: any, parentSchema: AnySchemaObject) => { + if (!parentSchema.format) { + return (data: string) => true; } - if (minAllowed && maxAllowed) { - // It is a Range constraint - if (parentSchema.format === "time") { - if (isUnderTheMinBoundary(data, minAllowed) || isOverTheMaxBoundary(data, maxAllowed)) { - return false; - } - } else if (parentSchema.format?.includes("duration")) { - const actualDuration = duration(data).asMilliseconds(); - const minDuration = duration(minAllowed).asMilliseconds(); - const maxDuration = duration(maxAllowed).asMilliseconds(); - if (isUnderTheMinBoundary(actualDuration, minDuration) || isOverTheMaxBoundary(actualDuration, maxDuration)) { - return false; - } - } else if (parentSchema.format?.includes("date")) { - const actualDate = new Date(data); - if (actualDate.toString() === "Invalid Date") { - return false; - } - const minAllowedDate = new Date(minAllowed); - if (minAllowedDate && isUnderTheMinBoundary(actualDate, minAllowedDate)) { - return false; - } - const maxAllowedDate = new Date(maxAllowed); - if (maxAllowedDate && isOverTheMaxBoundary(actualDate, maxAllowedDate)) { - return false; - } + const { minAllowed, minAllowedIncluded, maxAllowed, maxAllowedIncluded } = this.parseRangeFromConstraints( + schema ?? "", + parentSchema.format + ); + const enumeratedValues = this.parseEnumerationFromConstraints(schema ?? "", parentSchema.format); + const isUnderTheMinBoundary: (value: Date | String | number, minBoundary: Date | String | number) => boolean = + minAllowedIncluded ? (value, minBoundary) => value < minBoundary : (value, minBoundary) => value <= minBoundary; + const isOverTheMaxBoundary: (value: Date | String | number, maxBoundary: Date | String | number) => boolean = + maxAllowedIncluded ? (value, maxBoundary) => value > maxBoundary : (value, maxBoundary) => value >= maxBoundary; + + return (rawData: string | Date) => { + let data = rawData instanceof Date ? rawData.toISOString() : rawData; + if (data.includes(".") && data.endsWith("Z")) { + // adjusting from "2023-06-01T10:42:00.000Z" to "2023-06-01T10:42:00" + data = data.substring(0, data.lastIndexOf(".")); } - } else if (enumeratedValues) { - if (parentSchema.format === "time") { - return enumeratedValues.includes(data); - } else if (parentSchema.format?.includes("duration")) { - const actualDuration = duration(data).asMilliseconds(); - return enumeratedValues.some((value) => { - const enumeratedDurationValue = duration(value).asMilliseconds(); - return enumeratedDurationValue === actualDuration; - }); - } else if (parentSchema.format?.includes("date")) { - const actualDate = new Date(data); - if (actualDate.toString() === "Invalid Date") { - return false; + if (minAllowed && maxAllowed) { + // It is a Range constraint + if (parentSchema.format === "time") { + if (isUnderTheMinBoundary(data, minAllowed) || isOverTheMaxBoundary(data, maxAllowed)) { + return false; + } + } else if (parentSchema.format?.includes("duration")) { + const actualDuration = duration(data).asMilliseconds(); + const minDuration = duration(minAllowed).asMilliseconds(); + const maxDuration = duration(maxAllowed).asMilliseconds(); + if ( + isUnderTheMinBoundary(actualDuration, minDuration) || + isOverTheMaxBoundary(actualDuration, maxDuration) + ) { + return false; + } + } else if (parentSchema.format?.includes("date")) { + const actualDate = new Date(data); + if (actualDate.toString() === "Invalid Date") { + return false; + } + const minAllowedDate = new Date(minAllowed); + if (minAllowedDate && isUnderTheMinBoundary(actualDate, minAllowedDate)) { + return false; + } + const maxAllowedDate = new Date(maxAllowed); + if (maxAllowedDate && isOverTheMaxBoundary(actualDate, maxAllowedDate)) { + return false; + } + } + } else if (enumeratedValues) { + if (parentSchema.format === "time") { + return enumeratedValues.includes(data); + } else if (parentSchema.format?.includes("duration")) { + const actualDuration = duration(data).asMilliseconds(); + return enumeratedValues.some((value) => { + const enumeratedDurationValue = duration(value).asMilliseconds(); + return enumeratedDurationValue === actualDuration; + }); + } else if (parentSchema.format?.includes("date")) { + const actualDate = new Date(data); + if (actualDate.toString() === "Invalid Date") { + return false; + } + return enumeratedValues.some((value) => { + const enumeratedDateValue = new Date(value); + return !(enumeratedDateValue < actualDate) && !(enumeratedDateValue > actualDate); + }); } - return enumeratedValues.some((value) => { - const enumeratedDateValue = new Date(value); - return !(enumeratedDateValue < actualDate) && !(enumeratedDateValue > actualDate); - }); } - } - return true; + return true; + }; }; } @@ -221,11 +226,11 @@ export class DmnRunnerAjv { this.ajv.addKeyword(X_DMN_TYPE_KEYWORD); this.ajv.addKeyword({ keyword: X_DMN_ALLOWED_VALUES_KEYWORD, - compile: (schema, parentSchema) => this.constraintCompiler(schema, parentSchema), + compile: this.constraintCompiler(), }); this.ajv.addKeyword({ keyword: X_DMN_TYPE_CONSTRAINTS_KEYWORD, - compile: (schema, parentSchema) => this.constraintCompiler(schema, parentSchema), + compile: this.constraintCompiler(), }); this.ajv.addKeyword(X_DMN_DESCRIPTIONS_KEYWORD); this.ajv.addKeyword(RECURSION_KEYWORD); diff --git a/packages/runtime-tools-process-dev-ui-webapp/server/MockData/controllers.js b/packages/runtime-tools-process-dev-ui-webapp/server/MockData/controllers.js index d80ae87ff40..5df1d04cb90 100644 --- a/packages/runtime-tools-process-dev-ui-webapp/server/MockData/controllers.js +++ b/packages/runtime-tools-process-dev-ui-webapp/server/MockData/controllers.js @@ -29,7 +29,7 @@ const emptyForm = require("./forms/EmptyForm"); const formData = require("../MockData/forms/formData"); const customDashboardData = require("../MockData/customDashboard/data"); const hiringSchema = require("./process-forms-schema/hiring"); -const uuid = require("uuid"); +const { v4: uuid } = require("uuid"); const tasksUnableToTransition = [ "047ec38d-5d57-4330-8c8d-9bd67b53a529", "841b9dba-3d91-4725-9de3-f9f4853b417e", @@ -403,7 +403,7 @@ module.exports = controller = { `......Starting Process Instance:: id: ${req.headers["ce-id"]} type: ${req.headers["ce-type"]} source: ${req.headers["ce-source"]}` ); const businessKey = req.query.businessKey ? req.query.businessKey : null; - const processId = uuid.v4(); + const processId = uuid(); const processInstance = { id: processId, processId: "hiring", diff --git a/packages/runtime-tools-process-dev-ui-webapp/server/server.js b/packages/runtime-tools-process-dev-ui-webapp/server/server.js index 8d0540868bf..acdf370be6a 100644 --- a/packages/runtime-tools-process-dev-ui-webapp/server/server.js +++ b/packages/runtime-tools-process-dev-ui-webapp/server/server.js @@ -360,7 +360,7 @@ const resolvers = { Query: { ProcessInstances: async (parent, args) => { let result = data.ProcessInstanceData.filter((datum) => { - // console.log("args", args["where"]); + console.log("args", args["where"]); if (args["where"].id && args["where"].id.equal) { return datum.id == args["where"].id.equal; } else if (args["where"].rootProcessInstanceId && args["where"].rootProcessInstanceId.equal) { @@ -392,7 +392,7 @@ const resolvers = { } }); if (args["orderBy"]) { - // console.log("orderBy args: ", args["orderBy"]); + console.log("orderBy args: ", args["orderBy"]); result = _.orderBy( result, _.keys(args["orderBy"]).map((key) => key), @@ -403,7 +403,7 @@ const resolvers = { if (args["pagination"]) { result = paginatedResult(result, args["pagination"].offset, args["pagination"].limit); } - // console.log("result length: " + result.length); + console.log("result length: " + result.length); return result; }, ProcessDefinitions: async (parent, args) => { From 7296cacc2cb3b274e8c29b2352dc3cfcf4ad849a Mon Sep 17 00:00:00 2001 From: Luiz Motta Date: Wed, 18 Sep 2024 15:24:03 -0300 Subject: [PATCH 06/10] Oops --- packages/dmn-runner/src/jsonSchema.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/dmn-runner/src/jsonSchema.ts b/packages/dmn-runner/src/jsonSchema.ts index ab44a745587..b895edb9f8b 100644 --- a/packages/dmn-runner/src/jsonSchema.ts +++ b/packages/dmn-runner/src/jsonSchema.ts @@ -18,7 +18,8 @@ */ import { JSON_SCHEMA_INPUT_SET_PATH, RECURSION_KEYWORD, RECURSION_REF_KEYWORD } from "./jsonSchemaConstants"; -import { DmnAjvSchemaFormat, ValidateFunction } from "./ajv"; +import { DmnAjvSchemaFormat } from "./ajv"; +import { ValidateFunction } from "ajv-draft-04"; import { ExtendedServicesFormSchema, DmnInputFieldProperties } from "@kie-tools/extended-services-api/dist/formSchema"; import { Holder } from "@kie-tools-core/react-hooks/dist/Holder"; import { resolveRefs, pathFromPtr } from "json-refs"; From 9cb4f22c8b1e8395937bc71c9b89dd0521accf49 Mon Sep 17 00:00:00 2001 From: Luiz Motta Date: Wed, 18 Sep 2024 16:29:23 -0300 Subject: [PATCH 07/10] Update tests to be aligned with ajv v8 --- packages/form/tests/Validator.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/form/tests/Validator.test.ts b/packages/form/tests/Validator.test.ts index c65eee0b022..46700da84fd 100644 --- a/packages/form/tests/Validator.test.ts +++ b/packages/form/tests/Validator.test.ts @@ -67,7 +67,7 @@ describe("Validator Tests", () => { const validate = validator.createValidator(schema); const errors = validate(model); expect(errors?.details[0].keyword).toEqual("minimum"); - expect(errors?.details[0].message).toEqual("should be >= 1"); + expect(errors?.details[0].message).toEqual("must be >= 1"); }); it("invalid model - format", () => { @@ -82,7 +82,7 @@ describe("Validator Tests", () => { const validate = validator.createValidator(schema); const errors = validate(model); expect(errors?.details[0].keyword).toEqual("format"); - expect(errors?.details[0].message).toEqual(`should match format "date-time"`); + expect(errors?.details[0].message).toEqual(`must match format "date-time"`); }); }); From 64616408dc3dedfd2573b1ec3293dce67e67eb43 Mon Sep 17 00:00:00 2001 From: Luiz Motta Date: Thu, 19 Sep 2024 12:26:52 -0300 Subject: [PATCH 08/10] Rollback DateField to Date type --- .../uniforms-patternfly/src/DateField.tsx | 12 ++--- .../tests/DateField.test.tsx | 48 ++++++++++++------- 2 files changed, 36 insertions(+), 24 deletions(-) diff --git a/packages/uniforms-patternfly/src/DateField.tsx b/packages/uniforms-patternfly/src/DateField.tsx index 795e3bf6046..c7dfd6c86ee 100644 --- a/packages/uniforms-patternfly/src/DateField.tsx +++ b/packages/uniforms-patternfly/src/DateField.tsx @@ -24,13 +24,13 @@ import { TextInput, TextInputProps } from "@patternfly/react-core/dist/js/compon import wrapField from "./wrapField"; export type DateFieldProps = FieldProps< - string, + Date, TextInputProps, { inputRef?: React.RefObject; labelProps?: object; - max?: string; - min?: string; + max?: Date; + min?: Date; type?: "date" | "datetime-local"; } >; @@ -54,16 +54,16 @@ const dateParse = (value: string, onChange: DateFieldProps["onChange"]) => { if (splitedValue.length > 1) { // A year can't be bigger than 9999; splitedValue[0] = parseInt(splitedValue[0]) > 9999 ? "9999" : splitedValue[0]; - onChange(new DateConstructor(`${splitedValue.join("-")}Z`).toISOString()); + onChange(new DateConstructor(`${splitedValue.join("-")}Z`)); return; } onChange(undefined); } else { const date = new DateConstructor(`${value}Z`); if (date.getFullYear() < 10000) { - onChange(date.toISOString()); + onChange(date); } else { - onChange(date.toISOString()); + onChange(date); } } }; diff --git a/packages/uniforms-patternfly/tests/DateField.test.tsx b/packages/uniforms-patternfly/tests/DateField.test.tsx index ab6a5c2fd99..3655f390c01 100644 --- a/packages/uniforms-patternfly/tests/DateField.test.tsx +++ b/packages/uniforms-patternfly/tests/DateField.test.tsx @@ -98,7 +98,7 @@ test(" - renders a input which correctly reacts on change", () => { const input = screen.getByTestId("date-field") as HTMLInputElement; fireEvent.change(input, { target: { value: "2000-04-04T10:20" } }); - expect(onChange).toHaveBeenLastCalledWith("x", "2000-04-04T10:20:00.000Z"); + expect(onChange).toHaveBeenLastCalledWith("x", new Date("2000-04-04T10:20:00.000Z")); }); test(" - renders a input which correctly reacts on change (empty value)", () => { @@ -106,7 +106,7 @@ test(" - renders a input which correctly reacts on change (empty valu render( usingUniformsContext( - , + , { x: { type: "string" } }, { onChange } ) @@ -145,16 +145,16 @@ test(" - renders a input which correctly reacts on change (valid)", ( render( usingUniformsContext( - , + , { x: { type: "string" } }, { onChange } ) ); const input = screen.getByTestId("date-field") as HTMLInputElement; - fireEvent.change(input, { target: { value: `2000-04-04T10:30` } }); + fireEvent.change(input, { target: { value: "2000-04-04T10:30" } }); - expect(onChange).toHaveBeenLastCalledWith("x", `2000-04-04T10:30:00.000Z`); + expect(onChange).toHaveBeenLastCalledWith("x", new Date("2000-04-04T10:30:00.000Z")); }); test(" - renders a input which correctly reacts on change (year bigger than 9999)", () => { @@ -165,14 +165,17 @@ test(" - renders a input which correctly reacts on change (year bigge const input = screen.getByTestId("date-field") as HTMLInputElement; fireEvent.change(input, { target: { value: "121212-12-12T12:12" } }); - expect(onChange).toHaveBeenLastCalledWith("x", "9999-12-12T12:12:00.000Z"); + expect(onChange).toHaveBeenLastCalledWith("x", new Date("9999-12-12T12:12:00.000Z")); }); test(" - test max property - valid", () => { render( - usingUniformsContext(, { - x: { type: "string" }, - }) + usingUniformsContext( + , + { + x: { type: "string" }, + } + ) ); expect(screen.queryByTestId("Should be before")).toBeNull(); @@ -180,9 +183,12 @@ test(" - test max property - valid", () => { test(" - test max property - invalid", () => { render( - usingUniformsContext(, { - x: { type: "string" }, - }) + usingUniformsContext( + , + { + x: { type: "string" }, + } + ) ); expect(screen.getByText(`Should be before 1999-01-01T00:00:00.000Z`)).toBeInTheDocument(); @@ -190,9 +196,12 @@ test(" - test max property - invalid", () => { test(" - test min property - valid", () => { render( - usingUniformsContext(, { - x: { type: "string" }, - }) + usingUniformsContext( + , + { + x: { type: "string" }, + } + ) ); expect(screen.queryByTestId("Should be after")).toBeNull(); @@ -200,9 +209,12 @@ test(" - test min property - valid", () => { test(" - test min property - invalid", () => { render( - usingUniformsContext(, { - x: { type: "string" }, - }) + usingUniformsContext( + , + { + x: { type: "string" }, + } + ) ); expect(screen.getByText(`Should be after 1999-01-01T00:00:00.000Z`)).toBeInTheDocument(); From 52c105de118543c8dbb6ff3fabe7fb18abc9cd8d Mon Sep 17 00:00:00 2001 From: Luiz Motta Date: Thu, 19 Sep 2024 12:27:50 -0300 Subject: [PATCH 09/10] Use webpack to set the host and port of Dev UI parameters --- .../package.json | 1 + .../resources/index.html | 4 +- .../webpack.config.js | 12 +++ pnpm-lock.yaml | 84 ++++++++++++++----- 4 files changed, 79 insertions(+), 22 deletions(-) diff --git a/packages/runtime-tools-process-dev-ui-webapp/package.json b/packages/runtime-tools-process-dev-ui-webapp/package.json index 88bb5429365..2ea9b30646f 100644 --- a/packages/runtime-tools-process-dev-ui-webapp/package.json +++ b/packages/runtime-tools-process-dev-ui-webapp/package.json @@ -90,6 +90,7 @@ "file-loader": "^6.2.0", "filemanager-webpack-plugin": "^7.0.0", "graphql": "14.3.1", + "html-replace-webpack-plugin": "^2.6.0", "html-webpack-plugin": "^5.3.2", "https-browserify": "^1.0.0", "identity-obj-proxy": "^3.0.0", diff --git a/packages/runtime-tools-process-dev-ui-webapp/resources/index.html b/packages/runtime-tools-process-dev-ui-webapp/resources/index.html index 2abfee455ce..362db9c6605 100644 --- a/packages/runtime-tools-process-dev-ui-webapp/resources/index.html +++ b/packages/runtime-tools-process-dev-ui-webapp/resources/index.html @@ -49,10 +49,10 @@ { id: "saravana", groups: [] }, { id: "john", groups: [] }, ], - quarkusAppOrigin: "http://localhost:9027", + quarkusAppOrigin: "http://${WEBPACK_REPLACEMENT_WEBAPP_HOST}:${WEBPACK_REPLACEMENT_WEBAPP_PORT}", quarkusAppRootPath: "", page: "Processes", - devUIUrl: "http://localhost:9027", + devUIUrl: "http://${WEBPACK_REPLACEMENT_WEBAPP_HOST}:${WEBPACK_REPLACEMENT_WEBAPP_PORT}", customLabels: { singularProcessLabel: "Process", pluralProcessLabel: "Process", diff --git a/packages/runtime-tools-process-dev-ui-webapp/webpack.config.js b/packages/runtime-tools-process-dev-ui-webapp/webpack.config.js index 63b8e84bf8d..62e07c79c02 100644 --- a/packages/runtime-tools-process-dev-ui-webapp/webpack.config.js +++ b/packages/runtime-tools-process-dev-ui-webapp/webpack.config.js @@ -27,6 +27,8 @@ const MonacoWebpackPlugin = require("monaco-editor-webpack-plugin"); const NodePolyfillPlugin = require("node-polyfill-webpack-plugin"); const { merge } = require("webpack-merge"); const common = require("@kie-tools-core/webpack-base/webpack.common.config"); +const HtmlReplaceWebpackPlugin = require("html-replace-webpack-plugin"); + const { env: buildEnv } = require("./env"); module.exports = async (env) => { @@ -94,6 +96,16 @@ module.exports = async (env) => { favicon: "src/favicon.ico", chunks: ["app"], }), + new HtmlReplaceWebpackPlugin([ + { + pattern: /\${WEBPACK_REPLACEMENT_WEBAPP_HOST}/g, + replacement: () => buildEnv.runtimeToolsProcessDevUIWebapp.host ?? "", + }, + { + pattern: /\${WEBPACK_REPLACEMENT_WEBAPP_PORT}/g, + replacement: () => buildEnv.runtimeToolsProcessDevUIWebapp.port ?? "", + }, + ]), ], module: { rules: [ diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 97d5df8511a..b28ce996939 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -861,13 +861,13 @@ importers: version: 1.67.0 jest: specifier: ^29.7.0 - version: 29.7.0(@types/node@20.14.2)(node-notifier@8.0.2)(ts-node@10.9.2(@types/node@20.14.2)(typescript@5.5.3)) + version: 29.7.0(@types/node@22.5.2)(node-notifier@8.0.2)(ts-node@10.9.2(@types/node@22.5.2)(typescript@5.5.3)) jest-junit: specifier: ^16.0.0 version: 16.0.0 jest-when: specifier: ^3.6.0 - version: 3.6.0(jest@29.7.0(@types/node@20.14.2)(node-notifier@8.0.2)(ts-node@10.9.2(@types/node@20.14.2)(typescript@5.5.3))) + version: 3.6.0(jest@29.7.0(@types/node@22.5.2)(node-notifier@8.0.2)(ts-node@10.9.2(@types/node@22.5.2)(typescript@5.5.3))) rimraf: specifier: ^3.0.2 version: 3.0.2 @@ -876,7 +876,7 @@ importers: version: 0.0.2 ts-jest: specifier: ^29.1.5 - version: 29.1.5(@babel/core@7.16.12)(@jest/transform@29.7.0)(@jest/types@29.6.3)(babel-jest@29.7.0(@babel/core@7.16.12))(jest@29.7.0(@types/node@20.14.2)(node-notifier@8.0.2)(ts-node@10.9.2(@types/node@20.14.2)(typescript@5.5.3)))(typescript@5.5.3) + version: 29.1.5(@babel/core@7.16.12)(@jest/transform@29.7.0)(@jest/types@29.6.3)(babel-jest@29.7.0(@babel/core@7.16.12))(jest@29.7.0(@types/node@22.5.2)(node-notifier@8.0.2)(ts-node@10.9.2(@types/node@22.5.2)(typescript@5.5.3)))(typescript@5.5.3) typescript: specifier: ^5.5.3 version: 5.5.3 @@ -4140,7 +4140,7 @@ importers: version: link:../tsconfig '@testing-library/jest-dom': specifier: ^6.4.6 - version: 6.4.6(@jest/globals@29.7.0)(@types/jest@29.5.12)(jest@29.7.0(@types/node@22.5.2)(node-notifier@8.0.2)(ts-node@10.9.2(@types/node@22.5.2)(typescript@5.5.3))) + version: 6.4.6(@jest/globals@29.7.0)(@types/jest@29.5.12)(jest@29.7.0(@types/node@20.14.2)(node-notifier@8.0.2)(ts-node@10.9.2(@types/node@20.14.2)(typescript@5.5.3))) '@testing-library/react': specifier: ^12.1.5 version: 12.1.5(react-dom@17.0.2(react@17.0.2))(react@17.0.2) @@ -4167,7 +4167,7 @@ importers: version: 2.4.1 jest: specifier: ^29.7.0 - version: 29.7.0(@types/node@22.5.2)(node-notifier@8.0.2)(ts-node@10.9.2(@types/node@22.5.2)(typescript@5.5.3)) + version: 29.7.0(@types/node@20.14.2)(node-notifier@8.0.2)(ts-node@10.9.2(@types/node@20.14.2)(typescript@5.5.3)) jest-environment-jsdom: specifier: ^29.7.0 version: 29.7.0 @@ -4176,13 +4176,13 @@ importers: version: 16.0.0 jest-when: specifier: ^3.6.0 - version: 3.6.0(jest@29.7.0(@types/node@22.5.2)(node-notifier@8.0.2)(ts-node@10.9.2(@types/node@22.5.2)(typescript@5.5.3))) + version: 3.6.0(jest@29.7.0(@types/node@20.14.2)(node-notifier@8.0.2)(ts-node@10.9.2(@types/node@20.14.2)(typescript@5.5.3))) rimraf: specifier: ^3.0.2 version: 3.0.2 ts-jest: specifier: ^29.1.5 - version: 29.1.5(@babel/core@7.16.12)(@jest/transform@29.7.0)(@jest/types@29.6.3)(babel-jest@29.7.0(@babel/core@7.16.12))(jest@29.7.0(@types/node@22.5.2)(node-notifier@8.0.2)(ts-node@10.9.2(@types/node@22.5.2)(typescript@5.5.3)))(typescript@5.5.3) + version: 29.1.5(@babel/core@7.16.12)(@jest/transform@29.7.0)(@jest/types@29.6.3)(babel-jest@29.7.0(@babel/core@7.16.12))(jest@29.7.0(@types/node@20.14.2)(node-notifier@8.0.2)(ts-node@10.9.2(@types/node@20.14.2)(typescript@5.5.3)))(typescript@5.5.3) typescript: specifier: ^5.5.3 version: 5.5.3 @@ -7551,6 +7551,9 @@ importers: graphql: specifier: 14.3.1 version: 14.3.1 + html-replace-webpack-plugin: + specifier: ^2.6.0 + version: 2.6.0 html-webpack-plugin: specifier: ^5.3.2 version: 5.5.3(webpack@5.94.0(@swc/core@1.3.92)(webpack-cli@4.10.0)) @@ -7718,7 +7721,7 @@ importers: version: 2.3.0(react@17.0.2) react-json-view: specifier: ^1.21.3 - version: 1.21.3(@types/react@17.0.21)(react-dom@17.0.2(react@17.0.2))(react@17.0.2) + version: 1.21.3(@types/react@17.0.21)(encoding@0.1.13)(react-dom@17.0.2(react@17.0.2))(react@17.0.2) react-moment: specifier: 0.9.7 version: 0.9.7(moment@2.29.4)(prop-types@15.8.1)(react@17.0.2) @@ -8033,7 +8036,7 @@ importers: version: 2.3.0(react@17.0.2) react-json-view: specifier: ^1.21.3 - version: 1.21.3(@types/react@17.0.21)(react-dom@17.0.2(react@17.0.2))(react@17.0.2) + version: 1.21.3(@types/react@17.0.21)(encoding@0.1.13)(react-dom@17.0.2(react@17.0.2))(react@17.0.2) react-moment: specifier: 0.9.7 version: 0.9.7(moment@2.29.4)(prop-types@15.8.1)(react@17.0.2) @@ -30954,7 +30957,7 @@ snapshots: '@babel/core@7.24.9': dependencies: - '@ampproject/remapping': 2.2.0 + '@ampproject/remapping': 2.3.0 '@babel/code-frame': 7.24.7 '@babel/generator': 7.25.0 '@babel/helper-compilation-targets': 7.25.2 @@ -30965,7 +30968,7 @@ snapshots: '@babel/traverse': 7.25.3 '@babel/types': 7.25.2 convert-source-map: 2.0.0 - debug: 4.3.5 + debug: 4.3.6 gensync: 1.0.0-beta.2 json5: 2.2.3 semver: 6.3.1 @@ -42242,6 +42245,21 @@ snapshots: lz-string: 1.5.0 pretty-format: 27.5.1 + '@testing-library/jest-dom@6.4.6(@jest/globals@29.7.0)(@types/jest@29.5.12)(jest@29.7.0(@types/node@20.14.2)(node-notifier@8.0.2)(ts-node@10.9.2(@types/node@20.14.2)(typescript@5.5.3)))': + dependencies: + '@adobe/css-tools': 4.4.0 + '@babel/runtime': 7.23.6 + aria-query: 5.1.3 + chalk: 3.0.0 + css.escape: 1.5.1 + dom-accessibility-api: 0.6.3 + lodash: 4.17.21 + redent: 3.0.0 + optionalDependencies: + '@jest/globals': 29.7.0 + '@types/jest': 29.5.12 + jest: 29.7.0(@types/node@20.14.2)(node-notifier@8.0.2)(ts-node@10.9.2(@types/node@20.14.2)(typescript@5.5.3)) + '@testing-library/jest-dom@6.4.6(@jest/globals@29.7.0)(@types/jest@29.5.12)(jest@29.7.0(@types/node@22.5.2)(node-notifier@8.0.2)(ts-node@10.9.2(@swc/core@1.3.92)(@types/node@22.5.2)(typescript@5.5.3)))': dependencies: '@adobe/css-tools': 4.4.0 @@ -43366,9 +43384,9 @@ snapshots: webpack: 5.94.0(webpack-cli@4.10.0) webpack-cli: 4.10.0(webpack-bundle-analyzer@4.10.2)(webpack-dev-server@4.15.1)(webpack@5.94.0) - '@webpack-cli/configtest@1.2.0(webpack-cli@4.10.0(webpack-dev-server@4.15.1)(webpack@5.94.0))(webpack@5.94.0(webpack-cli@4.10.0))': + '@webpack-cli/configtest@1.2.0(webpack-cli@4.10.0(webpack-dev-server@4.15.1)(webpack@5.94.0))(webpack@5.94.0(@swc/core@1.3.92)(webpack-cli@4.10.0))': dependencies: - webpack: 5.94.0(webpack-cli@4.10.0) + webpack: 5.94.0(@swc/core@1.3.92)(webpack-cli@4.10.0) webpack-cli: 4.10.0(webpack-dev-server@4.15.1)(webpack@5.94.0) '@webpack-cli/configtest@1.2.0(webpack-cli@4.10.0(webpack@5.94.0))(webpack@5.94.0(webpack-cli@4.10.0))': @@ -48336,6 +48354,12 @@ snapshots: transitivePeerDependencies: - encoding + fbemitter@3.0.0(encoding@0.1.13): + dependencies: + fbjs: 3.0.2(encoding@0.1.13) + transitivePeerDependencies: + - encoding + fbjs-css-vars@1.0.2: {} fbjs@3.0.2: @@ -48581,6 +48605,14 @@ snapshots: flow-parser@0.218.0: {} + flux@4.0.3(encoding@0.1.13)(react@17.0.2): + dependencies: + fbemitter: 3.0.0(encoding@0.1.13) + fbjs: 3.0.2(encoding@0.1.13) + react: 17.0.2 + transitivePeerDependencies: + - encoding + flux@4.0.3(react@17.0.2): dependencies: fbemitter: 3.0.0 @@ -54163,6 +54195,18 @@ snapshots: react-is@18.1.0: {} + react-json-view@1.21.3(@types/react@17.0.21)(encoding@0.1.13)(react-dom@17.0.2(react@17.0.2))(react@17.0.2): + dependencies: + flux: 4.0.3(encoding@0.1.13)(react@17.0.2) + react: 17.0.2 + react-base16-styling: 0.6.0 + react-dom: 17.0.2(react@17.0.2) + react-lifecycles-compat: 3.0.4 + react-textarea-autosize: 8.3.3(@types/react@17.0.21)(react@17.0.2) + transitivePeerDependencies: + - '@types/react' + - encoding + react-json-view@1.21.3(@types/react@17.0.21)(react-dom@17.0.2(react@17.0.2))(react@17.0.2): dependencies: flux: 4.0.3(react@17.0.2) @@ -54272,7 +54316,7 @@ snapshots: dependencies: object-assign: 4.1.1 react: 17.0.2 - react-is: 17.0.2 + react-is: 18.1.0 react-side-effect@2.1.2(react@17.0.2): dependencies: @@ -57668,7 +57712,7 @@ snapshots: webpack-cli@4.10.0(webpack-dev-server@4.15.1)(webpack@5.94.0): dependencies: '@discoveryjs/json-ext': 0.5.7 - '@webpack-cli/configtest': 1.2.0(webpack-cli@4.10.0(webpack-dev-server@4.15.1)(webpack@5.94.0))(webpack@5.94.0(webpack-cli@4.10.0)) + '@webpack-cli/configtest': 1.2.0(webpack-cli@4.10.0(webpack-dev-server@4.15.1)(webpack@5.94.0))(webpack@5.94.0(@swc/core@1.3.92)(webpack-cli@4.10.0)) '@webpack-cli/info': 1.5.0(webpack-cli@4.10.0(webpack-dev-server@4.15.1)(webpack@5.94.0)) '@webpack-cli/serve': 1.7.0(webpack-cli@4.10.0(webpack-dev-server@4.15.1)(webpack@5.94.0))(webpack-dev-server@4.15.1(webpack-cli@4.10.0)(webpack@5.94.0)) colorette: 2.0.16 @@ -57678,7 +57722,7 @@ snapshots: import-local: 3.0.2 interpret: 2.2.0 rechoir: 0.7.0 - webpack: 5.94.0(webpack-cli@4.10.0) + webpack: 5.94.0(@swc/core@1.3.92)(webpack-cli@4.10.0) webpack-merge: 5.9.0 optionalDependencies: webpack-dev-server: 4.15.1(webpack-cli@4.10.0)(webpack@5.94.0) @@ -57699,14 +57743,14 @@ snapshots: webpack: 5.94.0(webpack-cli@4.10.0) webpack-merge: 5.9.0 - webpack-dev-middleware@5.3.3(webpack@5.94.0(webpack-cli@4.10.0)): + webpack-dev-middleware@5.3.3(webpack@5.94.0(@swc/core@1.3.92)(webpack-cli@4.10.0)): dependencies: colorette: 2.0.20 memfs: 3.5.1 mime-types: 2.1.34 range-parser: 1.2.1 schema-utils: 4.2.0 - webpack: 5.94.0(webpack-cli@4.10.0) + webpack: 5.94.0(@swc/core@1.3.92)(webpack-cli@4.10.0) webpack-dev-middleware@5.3.3(webpack@5.94.0): dependencies: @@ -57798,10 +57842,10 @@ snapshots: serve-index: 1.9.1 sockjs: 0.3.24 spdy: 4.0.2 - webpack-dev-middleware: 5.3.3(webpack@5.94.0(webpack-cli@4.10.0)) + webpack-dev-middleware: 5.3.3(webpack@5.94.0(@swc/core@1.3.92)(webpack-cli@4.10.0)) ws: 8.18.0 optionalDependencies: - webpack: 5.94.0(webpack-cli@4.10.0) + webpack: 5.94.0(@swc/core@1.3.92)(webpack-cli@4.10.0) webpack-cli: 4.10.0(webpack-dev-server@4.15.1)(webpack@5.94.0) transitivePeerDependencies: - bufferutil From e1199c3e2d426c9fde6fb9afa95edc65a68458e0 Mon Sep 17 00:00:00 2001 From: Luiz Motta Date: Thu, 19 Sep 2024 12:38:57 -0300 Subject: [PATCH 10/10] Rollback DateField to Date type --- .../uniforms-patternfly/src/DateField.tsx | 5 +-- .../tests/DateField.test.tsx | 42 +++++++++---------- 2 files changed, 21 insertions(+), 26 deletions(-) diff --git a/packages/uniforms-patternfly/src/DateField.tsx b/packages/uniforms-patternfly/src/DateField.tsx index c7dfd6c86ee..7de8ffdabdd 100644 --- a/packages/uniforms-patternfly/src/DateField.tsx +++ b/packages/uniforms-patternfly/src/DateField.tsx @@ -74,12 +74,11 @@ function DateField({ onChange, ...props }: DateFieldProps) { return false; } - const dateValue = new DateConstructor(props.value); if (props.min) { const minDate = new DateConstructor(props.min); if (minDate.toString() === "Invalid Date") { return false; - } else if (dateValue < minDate) { + } else if (props.value < minDate) { return `Should be after ${minDate.toISOString()}`; } } @@ -87,7 +86,7 @@ function DateField({ onChange, ...props }: DateFieldProps) { const maxDate = new DateConstructor(props.max); if (maxDate.toString() === "Invalid Date") { return false; - } else if (dateValue > maxDate) { + } else if (props.value > maxDate) { return `Should be before ${maxDate.toISOString()}`; } } diff --git a/packages/uniforms-patternfly/tests/DateField.test.tsx b/packages/uniforms-patternfly/tests/DateField.test.tsx index 3655f390c01..8743c955cad 100644 --- a/packages/uniforms-patternfly/tests/DateField.test.tsx +++ b/packages/uniforms-patternfly/tests/DateField.test.tsx @@ -23,51 +23,47 @@ import { render, screen, fireEvent } from "@testing-library/react"; import { usingUniformsContext } from "./test-utils"; test(" - renders an input", () => { - render(usingUniformsContext(, { x: { type: "string" } })); + render(usingUniformsContext(, { x: { type: Date } })); expect(screen.getByTestId("date-field")).toBeInTheDocument(); }); test(" - renders a input with correct id (inherited)", () => { - render(usingUniformsContext(, { x: { type: "string" } })); + render(usingUniformsContext(, { x: { type: Date } })); expect(screen.getByTestId("date-field")).toBeInTheDocument(); }); test(" - renders a input with correct id (specified)", () => { - render(usingUniformsContext(, { x: { type: "string" } })); + render(usingUniformsContext(, { x: { type: Date } })); expect(screen.getByTestId("date-field")).toBeInTheDocument(); expect(screen.getByTestId("date-field").getAttribute("id")).toBe("y"); }); test(" - renders a input with correct name", () => { - render(usingUniformsContext(, { x: { type: "string" } })); + render(usingUniformsContext(, { x: { type: Date } })); expect(screen.getByTestId("date-field")).toBeInTheDocument(); expect(screen.getByTestId("date-field").getAttribute("name")).toBe("x"); }); test(" - renders an input with correct disabled state", () => { - render(usingUniformsContext(, { x: { type: "string" } })); + render(usingUniformsContext(, { x: { type: Date } })); expect(screen.getByTestId("date-field")).toBeInTheDocument(); expect(screen.getByTestId("date-field") as HTMLInputElement).toBeDisabled(); }); test(" - renders a input with correct label (specified)", () => { - render( - usingUniformsContext(, { x: { type: "string" } }) - ); + render(usingUniformsContext(, { x: { type: Date } })); expect(screen.getByTestId("date-field")).toBeInTheDocument(); expect(screen.getByText("DateFieldLabel")).toBeInTheDocument(); }); test(" - renders a input with correct label (specified)", () => { - render( - usingUniformsContext(, { x: { type: "string" } }) - ); + render(usingUniformsContext(, { x: { type: Date } })); expect(screen.getByTestId("date-field")).toBeInTheDocument(); expect(screen.getByText("DateFieldLabel")).toBeInTheDocument(); @@ -75,7 +71,7 @@ test(" - renders a input with correct label (specified)", () => { }); test(" - renders a input with correct value (default)", () => { - render(usingUniformsContext(, { x: { type: "string" } })); + render(usingUniformsContext(, { x: { type: Date } })); expect(screen.getByTestId("date-field")).toBeInTheDocument(); expect((screen.getByTestId("date-field") as HTMLInputElement).value).toBe(""); @@ -83,7 +79,7 @@ test(" - renders a input with correct value (default)", () => { test(" - renders a input with correct value (model)", () => { const now = new Date(); - render(usingUniformsContext(, { x: { type: "string" } }, { model: { x: now } })); + render(usingUniformsContext(, { x: { type: Date } }, { model: { x: now } })); const stringfyDate = now.toISOString().split(":").slice(0, 2).join(":"); expect(screen.getByTestId("date-field")).toBeInTheDocument(); @@ -93,7 +89,7 @@ test(" - renders a input with correct value (model)", () => { test(" - renders a input which correctly reacts on change", () => { const onChange = jest.fn(); - render(usingUniformsContext(, { x: { type: "string" } }, { onChange })); + render(usingUniformsContext(, { x: { type: Date } }, { onChange })); const input = screen.getByTestId("date-field") as HTMLInputElement; fireEvent.change(input, { target: { value: "2000-04-04T10:20" } }); @@ -107,7 +103,7 @@ test(" - renders a input which correctly reacts on change (empty valu render( usingUniformsContext( , - { x: { type: "string" } }, + { x: { type: Date } }, { onChange } ) ); @@ -121,7 +117,7 @@ test(" - renders a input which correctly reacts on change (empty valu test(" - renders a input which correctly reacts on change (empty)", () => { const onChange = jest.fn(); - render(usingUniformsContext(, { x: { type: "string" } })); + render(usingUniformsContext(, { x: { type: Date } })); const input = screen.getByTestId("date-field") as HTMLInputElement; fireEvent.change(input, { target: { value: "" } }); @@ -132,7 +128,7 @@ test(" - renders a input which correctly reacts on change (empty)", ( test(" - renders a input which correctly reacts on change (invalid)", () => { const onChange = jest.fn(); - render(usingUniformsContext(, { x: { type: "string" } }, { onChange })); + render(usingUniformsContext(, { x: { type: Date } }, { onChange })); const input = screen.getByTestId("date-field") as HTMLInputElement; fireEvent.change(input, { target: { value: "10:00" } }); @@ -146,7 +142,7 @@ test(" - renders a input which correctly reacts on change (valid)", ( render( usingUniformsContext( , - { x: { type: "string" } }, + { x: { type: Date } }, { onChange } ) ); @@ -160,7 +156,7 @@ test(" - renders a input which correctly reacts on change (valid)", ( test(" - renders a input which correctly reacts on change (year bigger than 9999)", () => { const onChange = jest.fn(); - render(usingUniformsContext(, { x: { type: "string" } }, { onChange })); + render(usingUniformsContext(, { x: { type: Date } }, { onChange })); const input = screen.getByTestId("date-field") as HTMLInputElement; fireEvent.change(input, { target: { value: "121212-12-12T12:12" } }); @@ -173,7 +169,7 @@ test(" - test max property - valid", () => { usingUniformsContext( , { - x: { type: "string" }, + x: { type: Date }, } ) ); @@ -186,7 +182,7 @@ test(" - test max property - invalid", () => { usingUniformsContext( , { - x: { type: "string" }, + x: { type: Date }, } ) ); @@ -199,7 +195,7 @@ test(" - test min property - valid", () => { usingUniformsContext( , { - x: { type: "string" }, + x: { type: Date }, } ) ); @@ -212,7 +208,7 @@ test(" - test min property - invalid", () => { usingUniformsContext( , { - x: { type: "string" }, + x: { type: Date }, } ) );