Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-48923: Provide Times Square support for date and date-time parameters #183

Merged
merged 5 commits into from
Mar 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/seven-buckets-brake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'squareone': patch
---

Times Square now supports date and date-time parameter types.
1 change: 1 addition & 0 deletions apps/squareone/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"@microsoft/fetch-event-source": "^2.0.1",
"@sentry/nextjs": "^8",
"ajv": "^8.11.0",
"ajv-formats": "^3.0.1",
"date-fns": "^3.6.0",
"formik": "^2.2.9",
"js-yaml": "^4.1.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ export default function ParameterInput({
touched,
errors,
}) {
const errorMessage = computeErrorMessage(errors, paramSchema);
return (
<>
<label htmlFor={`${paramName}`}>
<ParameterName>{paramName}</ParameterName>
{children}
{errors && touched && (
{errorMessage && (
<ErrorMessage id={`tsparam-${paramName}-error`} type="polite">
{errors}
{errorMessage}
</ErrorMessage>
)}
<Description id={`tsparam-${paramName}-description`}>
Expand All @@ -25,6 +26,21 @@ export default function ParameterInput({
);
}

function computeErrorMessage(errors, paramSchema) {
if (errors) {
if (paramSchema.type === 'string' && paramSchema.format === 'date') {
return 'Expecting YYYY-MM-DD';
} else if (
paramSchema.type === 'string' &&
paramSchema.format === 'date-time'
) {
return 'Expecting YYYY-MM-DDTHH:MM:SS-HH:MM';
}
return errors;
}
return null;
}

const ParameterName = styled.p`
margin-bottom: 0.2em;
font-weight: regular;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useRouter } from 'next/router';
import styled from 'styled-components';
import { Formik, Field } from 'formik';
import Ajv from 'ajv';
import addFormats from 'ajv-formats';

import Button, { RedGhostButton } from '../Button';
import StringInput from './StringInput';
Expand Down Expand Up @@ -40,6 +41,7 @@ export default function TimesSquareParameters({}) {
const { parameters } = useTimesSquarePage();

const ajv = new Ajv({ coerceTypes: true });
addFormats(ajv);

// Merge userParameters with defaults
const initialValues = {};
Expand Down
20 changes: 17 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading