diff --git a/change/design-to-code-react-f6b2d907-f657-4704-ba4b-31b5e72cf16e.json b/change/design-to-code-react-f6b2d907-f657-4704-ba4b-31b5e72cf16e.json new file mode 100644 index 0000000..3932b09 --- /dev/null +++ b/change/design-to-code-react-f6b2d907-f657-4704-ba4b-31b5e72cf16e.json @@ -0,0 +1,7 @@ +{ + "type": "none", + "comment": "Removal of unused utilities", + "packageName": "design-to-code-react", + "email": "7559015+janechu@users.noreply.github.com", + "dependentChangeType": "none" +} diff --git a/packages/design-to-code-react/src/form/controls/utilities/form.tsx b/packages/design-to-code-react/src/form/controls/utilities/form.tsx index 5fe783d..675043f 100644 --- a/packages/design-to-code-react/src/form/controls/utilities/form.tsx +++ b/packages/design-to-code-react/src/form/controls/utilities/form.tsx @@ -1,9 +1,5 @@ import React from "react"; import { FormCategoryDictionary, FormState } from "../../form.props"; -import { - AttributeSettingsMappingToPropertyNames, - FormChildOptionItem, -} from "../../types"; import { CategoryState, SectionControlProps, @@ -48,80 +44,6 @@ export function getArrayLinks(data: any, displayTextDataLocation?: string): stri } } -/** - * Get the string value of a number - */ -function getStringFromData(data: string | number): string { - if (typeof data === "number") { - return data.toString(); - } - - return data || ""; -} - -export function getStringValue( - data: string | number, - defaultData: string | number -): string { - return typeof data === "string" || typeof data === "number" - ? getStringFromData(data) - : getStringFromData(defaultData); -} - -/** - * Determine if an item is required - */ -export function getIsRequired(item: any, required: string[]): boolean { - let isRequired: boolean = false; - - if (Array.isArray(required)) { - required.forEach((requiredItem: string): void => { - if (requiredItem === item) { - isRequired = true; - } - }); - } - - return isRequired; -} - -/** - * Determine if an item is not required - */ -export function getIsNotRequired(item: any, not?: string[]): boolean { - let notRequired: boolean = false; - - if (Array.isArray(not)) { - not.forEach((notRequiredItem: any) => { - if (notRequiredItem === item) { - notRequired = true; - } - }); - } - - return notRequired; -} - -/** - * Normalizes a location for getting and setting values - */ -export function getNormalizedLocation( - location: string, - property: string, - schema: any -): string { - let normalizedProperty: string = ""; - let normalizedLocation: string = - location === "" || property === "" ? location : `${location}.`; - normalizedProperty = property.split(".").join(`.${PropertyKeyword.properties}.`); - normalizedLocation = - typeof property !== "undefined" - ? `${normalizedLocation}${normalizedProperty}` - : normalizedLocation; - - return normalizedLocation; -} - function getArrayExample(baseSchema: any, schemaSection: any): any[] { const example: any = getDataFromSchema(baseSchema, schemaSection.items); @@ -177,73 +99,10 @@ export function generateExampleData( return getDataFromSchema(baseSchema, schemaSection); } -/** - * Get the array location - */ -export function getArraySchemaLocation( - schemaLocation: string, - propertyName: string, - schema: any, - oneOfAnyOf: any -): string { - let arraySchemaLocation: string = ""; - - if (oneOfAnyOf) { - arraySchemaLocation += `${oneOfAnyOf.type}[${oneOfAnyOf.activeIndex}]`; - } - - if (propertyName !== "") { - arraySchemaLocation += `${arraySchemaLocation === "" ? "" : "."}${ - PropertyKeyword.properties - }.${propertyName}`; - } - - return arraySchemaLocation; -} - -/** - * Assigns an attribute value based on property names - */ -export function formControlAttributeMapping( - config: AttributeSettingsMappingToPropertyNames, - propertyName: string -): number | null { - let itemAttributeValue: any = null; - - Object.keys(config).forEach((attributeName: string): void => { - for (const attributeConfig of config[attributeName]) { - for (const property of attributeConfig.propertyNames) { - if (property === propertyName) { - itemAttributeValue = attributeConfig.value; - } - } - } - }); - - return itemAttributeValue; -} - -export function checkHasOneOfAnyOf(oneOf: any, anyOf: any): boolean { - return oneOf || anyOf; -} - export function checkIsDifferentSchema(currentSchema: any, nextSchema: any): boolean { return JSON.stringify(nextSchema) !== JSON.stringify(currentSchema); } -export function checkIsDifferentData(currentData: any, nextData: any): boolean { - return currentData !== nextData; -} - -export function getDataLocationRelativeToRoot( - location: string, - dataLocation: string -): string { - return isRootLocation(dataLocation) || isRootLocation(location) - ? `${dataLocation}${location}` - : `${dataLocation}.${location}`; -} - export function getData(location: string, data: any): any { return isRootLocation(location) ? data : get(data, location); } @@ -256,18 +115,6 @@ export function isConst(property: any): boolean { return typeof property.const !== "undefined"; } -export function checkIsObject(property: any, schema: any): boolean { - return (property.properties || property.type === "object") && property === schema; -} - -export function handleToggleClick(value: any, id: string, updateRequested: any): any { - return (e: React.MouseEvent): void => { - e.preventDefault(); - - updateRequested(value, id); - }; -} - export function getLabel(label: string, title: string): string { return label === "" && title !== void 0 ? title : label; } @@ -286,43 +133,6 @@ export interface NavigationItemConfig { default: any; } -/** - * Determines the navigation from - * - section links - * - child components - * - array items - * - breadcrumb links - */ -export function getActiveComponentAndSection(dataLocation: string): Partial { - const state: Partial = {}; - - state.activeNavigationConfigId = dataLocation; - - return state; -} - -/** - * Gets locations from individual location segments - * Example: - * getLocationsFromSegments(["children[0].props.object"]) - * output: ["children[0]", "children[0].props", "children[0].props.object"] - */ -export function getLocationsFromSegments(segments: string[]): string[] { - return segments.map((location: string, index: number) => { - return segments.slice(0, index + 1).join("."); - }); -} - -/** - * Gets the data location from the current component - */ -export function getCurrentComponentDataLocation( - dataLocation: string, - lastComponentDataLocation: string -): string { - return dataLocation.replace(lastComponentDataLocation, "").replace(/^\./, ""); -} - /** * Check to see if we are on the root location */ @@ -330,46 +140,6 @@ export function isRootLocation(location: string): boolean { return location === ""; } -/** - * Check to see if this schema is the same as another schema - */ -export function isDifferentSchema(oldSchema: any, newSchema: any): boolean { - return stringify(oldSchema) !== stringify(newSchema); -} - -/** - * Check to see if this schema has been modified - */ -export function isModifiedSchema(oldSchema: any, newSchema: any): boolean { - return stringify(oldSchema) !== stringify(newSchema); -} - -/** - * Finds the schema using the data location - */ -export function getSchemaByDataLocation( - currentSchema: any, - data: any, - dataLocation: string, - childOptions: FormChildOptionItem[] -): any { - if (dataLocation === "") { - return currentSchema; - } - - const subData: any = get(data, dataLocation); - const id: string | undefined = subData ? subData.id : void 0; - const childOptionWithMatchingSchemaId: any = childOptions.find( - (childOption: FormChildOptionItem) => { - return childOption.schema.$id === id; - } - ); - - return childOptionWithMatchingSchemaId - ? childOptionWithMatchingSchemaId.schema - : currentSchema; -} - /** * Gets the validation error message using a data location */