From 0bdabceb014a939893a1955e63bc9064ded60f99 Mon Sep 17 00:00:00 2001 From: Devesh Tiwari <70621864+dtiwarATS@users.noreply.github.com> Date: Tue, 19 Nov 2024 20:13:10 +0530 Subject: [PATCH] [BUG FIX] [MER-3918] Simple Author and Advanced Author - Slider component - Setting intervals (#5240) * MER-3918 * Simple Authoring * Update SliderAuthor.tsx * Update SliderAuthor.tsx * Update SliderAuthor.tsx --- .../parts/janus-slider/SliderAuthor.tsx | 15 ++++++++++++++- .../parts/janus-slider/authoring-entry.ts | 2 +- .../src/components/parts/janus-slider/schema.ts | 4 +++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/assets/src/components/parts/janus-slider/SliderAuthor.tsx b/assets/src/components/parts/janus-slider/SliderAuthor.tsx index 51f56f4acb8..382d90e032e 100644 --- a/assets/src/components/parts/janus-slider/SliderAuthor.tsx +++ b/assets/src/components/parts/janus-slider/SliderAuthor.tsx @@ -1,10 +1,11 @@ import React, { CSSProperties, useEffect, useRef, useState } from 'react'; import { AuthorPartComponentProps } from 'components/parts/types/parts'; +import { clone } from 'utils/common'; import './Slider.scss'; import { SliderModel } from './schema'; const SliderAuthor: React.FC> = (props) => { - const { id, model } = props; + const { id, model, onSaveConfigure } = props; const { z, @@ -71,6 +72,18 @@ const SliderAuthor: React.FC> = (props) => if (snapInterval) { const options = []; const numberOfTicks = (maximum - minimum) / snapInterval; + const numberOfTicksThreshold = 100; + if (numberOfTicks > numberOfTicksThreshold) { + const modelClone = clone(model); + const snapIntervalThreshold = (maximum - minimum) / numberOfTicksThreshold; + // As per the requirement, Users cannot enter a value that divides the slider into more than 100 equal sections. + // if it goes beyond that, we need to calculate the snapIntervalThreshold between the min and max values + // and set the interval + modelClone.snapInterval = +snapIntervalThreshold.toFixed(2); + //we need to save the snapInterval so that the custom property is updated with adjusted values + onSaveConfigure({ id, snapshot: modelClone }); + return; + } for (let i = 0; i <= numberOfTicks; i++) { options.push(); } diff --git a/assets/src/components/parts/janus-slider/authoring-entry.ts b/assets/src/components/parts/janus-slider/authoring-entry.ts index 756a8248e3d..90dbe21f142 100644 --- a/assets/src/components/parts/janus-slider/authoring-entry.ts +++ b/assets/src/components/parts/janus-slider/authoring-entry.ts @@ -18,7 +18,7 @@ import { const manifest = require('./manifest.json'); const observedAttributes: string[] = [...apiObservedAttributes]; -const customEvents: any = { ...apiCustomEvents }; +const customEvents: any = { ...apiCustomEvents, onSaveConfigure: 'saveconfigure' }; register(SliderAuthor, manifest.authoring.element, observedAttributes, { customEvents, diff --git a/assets/src/components/parts/janus-slider/schema.ts b/assets/src/components/parts/janus-slider/schema.ts index 9b872740e8a..f5d998c25ae 100644 --- a/assets/src/components/parts/janus-slider/schema.ts +++ b/assets/src/components/parts/janus-slider/schema.ts @@ -44,6 +44,7 @@ export const simpleSchema: JSONSchema7Object = { snapInterval: { title: 'Interval', type: 'number', + description: 'Value cannot be smaller than 1/100 of the range between the min and max values', }, answer: correctOrRange.schema, @@ -71,7 +72,7 @@ export const simpleUISchema = { classNames: 'col-span-6', }, snapInterval: { - classNames: 'col-span-6', + classNames: 'col-span-12', }, advancedFeedback: numericAdvancedFeedback.uiSchema, }; @@ -118,6 +119,7 @@ export const schema: JSONSchema7Object = { }, snapInterval: { title: 'Interval', + description: 'Value cannot be smaller than 1/100 of the range between the min and max values', type: 'number', }, enabled: {