Skip to content

Commit

Permalink
Merge branch 'master' into FIO-7488
Browse files Browse the repository at this point in the history
  • Loading branch information
brendanbond authored Mar 25, 2024
2 parents f56bd69 + 1fa1a17 commit f62b4a5
Show file tree
Hide file tree
Showing 41 changed files with 877 additions and 216 deletions.
75 changes: 75 additions & 0 deletions .github/workflows/repo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Build & Test

on: push

env:
NODE_VERSION: 18.x

jobs:
setup:
runs-on: ubuntu-latest
steps:
- run: echo "Triggered by ${{ github.event_name }} event."

- name: Check out repository code ${{ github.repository }} on ${{ github.ref }}
uses: actions/checkout@v3

- name: Set up Node.js ${{ env.NODE_VERSION }}
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'

- name: Cache node modules
uses: actions/cache@v3
with:
path: node_modules
key: ${{ runner.os }}-node-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-node-
- name: Installing dependencies
if: steps.cache.outputs.cache-hit != 'true'
uses: borales/actions-yarn@v4
with:
cmd: install --frozen-lockfile

build:
needs: setup
runs-on: ubuntu-latest
steps:
- name: Check out repository code ${{ github.repository }} on ${{ github.ref }}
uses: actions/checkout@v3

- name: Restore node modules from cache
uses: actions/cache@v3
with:
path: node_modules
key: ${{ runner.os }}-node-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-node-
- name: Build
uses: borales/actions-yarn@v4
with:
cmd: build

test:
needs: setup
runs-on: ubuntu-latest
steps:
- name: Check out repository code ${{ github.repository }} on ${{ github.ref }}
uses: actions/checkout@v3

- name: Restore node modules from cache
uses: actions/cache@v3
with:
path: node_modules
key: ${{ runner.os }}-node-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-node-
- name: Test
uses: borales/actions-yarn@v4
with:
cmd: test
13 changes: 13 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
## 2.0.0-rc.21
### Changed
- FIO-8092: update isEmpty to isComponentDataEmpty and account for differing component data types

## 2.0.0-rc.20
### Changed
- FIO-8086: don't multiple validate select components
- FIO-8079: add stricter time validation

## 2.0.0-rc.19
### Changed
- FIO-8047: add dereferencing processor for datatable comp

## 2.0.0-rc.18
### Changed
- FIO-8055: validate components that include custom validations, even when their data is empty
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@formio/core",
"version": "2.0.0-rc.18",
"version": "2.0.0-rc.21",
"description": "The core Form.io renderering framework.",
"main": "lib/index.js",
"exports": {
Expand Down
12 changes: 12 additions & 0 deletions src/process/__tests__/fixtures/util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import get from 'lodash/get';
import { ProcessorContext, ProcessorScope, Component } from 'types';
export const generateProcessorContext = (component: Component, data: any): ProcessorContext<ProcessorScope> => {
return {
component,
path: component.key,
data,
row: data,
scope: {} as ProcessorScope,
value: get(data, component.key),
}
}
20 changes: 20 additions & 0 deletions src/process/normalize/__tests__/normalize.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { expect } from 'chai';

import { TimeComponent } from 'types';
import { normalizeProcessSync } from '../';
import { generateProcessorContext } from '../../__tests__/fixtures/util';

const timeField: TimeComponent = {
type: 'time',
key: 'time',
label: 'Time',
input: true,
dataFormat: 'HH:mm:ss'
};

it('Should normalize a time component with a valid time value that doees not match dataFormat', async () => {
const data = { time: '12:00' };
const context = generateProcessorContext(timeField, data);
normalizeProcessSync(context);
expect(context.data).to.deep.equal({time: '12:00:00'});
});
21 changes: 20 additions & 1 deletion src/process/normalize/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import isString from 'lodash/isString';
import toString from 'lodash/toString';
import isNil from 'lodash/isNil';
import isObject from 'lodash/isObject';
import dayjs from 'dayjs';
import customParseFormat from 'dayjs/plugin/customParseFormat';
import {
AddressComponent,
DayComponent,
Expand All @@ -18,11 +20,14 @@ import {
TextFieldComponent,
DefaultValueScope,
ProcessorInfo,
ProcessorContext
ProcessorContext,
TimeComponent
} from "types";

type NormalizeScope = DefaultValueScope;

dayjs.extend(customParseFormat)

const isAddressComponent = (component: any): component is AddressComponent => component.type === "address";
const isDayComponent = (component: any): component is DayComponent => component.type === "day";
const isEmailComponent = (component:any): component is EmailComponent => component.type === "email";
Expand All @@ -32,6 +37,7 @@ const isSelectComponent = (component: any): component is SelectComponent => comp
const isSelectBoxesComponent = (component: any): component is SelectBoxesComponent => component.type === "selectboxes";
const isTagsComponent = (component: any): component is TagsComponent => component.type === "tags";
const isTextFieldComponent = (component: any): component is TextFieldComponent => component.type === "textfield";
const isTimeComponent = (component: any): component is TimeComponent => component.type === "time";

const normalizeAddressComponentValue = (component: AddressComponent, value: any) => {
if (!component.multiple && Boolean(component.enableManualMode) && value && !value.mode) {
Expand Down Expand Up @@ -249,6 +255,17 @@ const normalizeTextFieldComponentValue = (
return value;
}

// Allow submissions of time components in their visual "format" property by coercing them to the "dataFormat" property
// i.e. "HH:mm" -> "HH:mm:ss"
const normalizeTimeComponentValue = (component: TimeComponent, value: string) => {
const defaultDataFormat = 'HH:mm:ss';
const defaultFormat = 'HH:mm';
if (dayjs(value, component.format || defaultFormat, true).isValid()) {
return dayjs(value, component.format || defaultFormat, true).format(component.dataFormat || defaultDataFormat);
}
return value;
};

export const normalizeProcess: ProcessorFn<NormalizeScope> = async (context) => {
return normalizeProcessSync(context);
}
Expand All @@ -275,6 +292,8 @@ export const normalizeProcessSync: ProcessorFnSync<NormalizeScope> = (context) =
set(data, path, normalizeTagsComponentValue(component, value));
} else if (isTextFieldComponent(component)) {
set(data, path, normalizeTextFieldComponentValue(component, defaultValues, value, path));
} else if (isTimeComponent(component)) {
set(data, path, normalizeTimeComponentValue(component, value));
}

// Next perform component-type-agnostic transformations (i.e. super())
Expand Down
3 changes: 2 additions & 1 deletion src/process/validation/i18n/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@ export const EN_ERRORS = {
valueIsNotAvailable: '{{ field }} is an invalid value.',
captchaTokenValidation: 'ReCAPTCHA: Token validation error',
captchaTokenNotSpecified: 'ReCAPTCHA: Token is not specified in submission',
captchaFailure: 'ReCaptcha: Response token not found'
captchaFailure: 'ReCaptcha: Response token not found',
time: '{{field}} is not a valid time.',
};
4 changes: 2 additions & 2 deletions src/process/validation/rules/__tests__/fixtures/util.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { get } from "lodash";
import { Component, DataObject, ProcessorType, ValidationContext } from "types";

export const generateProcessContext = (component: Component, data: DataObject): ValidationContext => {
export const generateProcessorContext = (component: Component, data: DataObject): ValidationContext => {
const path = component.key;
const value = get(data, path);
return {
return {
component,
data,
scope: {errors: []},
Expand Down
Loading

0 comments on commit f62b4a5

Please sign in to comment.