add an underscorize helper and use it for form fields where they need to be python identifiers
This commit is contained in:
parent
b0b5ccf74d
commit
f6c5c005d9
|
@ -1,4 +1,8 @@
|
|||
import { convertSecondsToFormattedDateString, slugifyString } from './helpers';
|
||||
import {
|
||||
convertSecondsToFormattedDateString,
|
||||
slugifyString,
|
||||
underscorizeString,
|
||||
} from './helpers';
|
||||
|
||||
test('it can slugify a string', () => {
|
||||
expect(slugifyString('hello---world_ and then Some such-')).toEqual(
|
||||
|
@ -6,6 +10,12 @@ test('it can slugify a string', () => {
|
|||
);
|
||||
});
|
||||
|
||||
test('it can underscorize a string', () => {
|
||||
expect(underscorizeString('hello---world_ and then Some such-')).toEqual(
|
||||
'hello_world_and_then_some_such'
|
||||
);
|
||||
});
|
||||
|
||||
test('it can keep the correct date when converting seconds to date', () => {
|
||||
const dateString = convertSecondsToFormattedDateString(1666325400);
|
||||
expect(dateString).toEqual('2022-10-21');
|
||||
|
|
|
@ -20,6 +20,10 @@ export const slugifyString = (str: any) => {
|
|||
.replace(/-+$/g, '');
|
||||
};
|
||||
|
||||
export const underscorizeString = (inputString: string) => {
|
||||
return slugifyString(inputString).replace(/-/g, '_');
|
||||
};
|
||||
|
||||
export const capitalizeFirstLetter = (string: any) => {
|
||||
return string.charAt(0).toUpperCase() + string.slice(1);
|
||||
};
|
||||
|
|
|
@ -3,7 +3,11 @@ import { useEffect, useState } from 'react';
|
|||
import { Button, Select, SelectItem, TextInput } from '@carbon/react';
|
||||
import { useParams } from 'react-router-dom';
|
||||
import { FormField } from '../interfaces';
|
||||
import { modifyProcessIdentifierForPathParam, slugifyString } from '../helpers';
|
||||
import {
|
||||
modifyProcessIdentifierForPathParam,
|
||||
slugifyString,
|
||||
underscorizeString,
|
||||
} from '../helpers';
|
||||
import HttpService from '../services/HttpService';
|
||||
|
||||
export default function JsonSchemaFormBuilder() {
|
||||
|
@ -75,7 +79,7 @@ export default function JsonSchemaFormBuilder() {
|
|||
formFieldIdHasBeenUpdatedByUser
|
||||
);
|
||||
if (!formFieldIdHasBeenUpdatedByUser) {
|
||||
setFormFieldId(slugifyString(newFormFieldTitle));
|
||||
setFormFieldId(underscorizeString(newFormFieldTitle));
|
||||
}
|
||||
setFormFieldTitle(newFormFieldTitle);
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue