Skip to content

Commit

Permalink
Merge pull request #357 from TykTechnologies/string-builder-revert
Browse files Browse the repository at this point in the history
String builder revert
  • Loading branch information
ifrim authored Mar 12, 2024
2 parents 5e926ec + 7707169 commit b470a9a
Show file tree
Hide file tree
Showing 19 changed files with 128 additions and 129 deletions.
2 changes: 1 addition & 1 deletion lib/index.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/index.css.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/index.js.map

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
font: inherit;
display: block;
z-index: 1;
width: 100%;
padding: 0px;
width: calc(100% - 35px);

&:focus,
&:active {
border: none;
Expand All @@ -34,7 +34,7 @@
border: none;
word-wrap: break-word;
word-break: break-all;

}

.string-builder__disabled{
Expand Down
2 changes: 1 addition & 1 deletion lib/tyk-ui.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/tyk-ui.css.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/tyk-ui.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/tyk-ui.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tyk-technologies/tyk-ui",
"version": "3.0.16",
"version": "3.0.17",
"description": "Tyk UI - ui reusable components",
"main": "lib/index.js",
"scripts": {
Expand Down
8 changes: 4 additions & 4 deletions src/form/components/StringBuilder/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function StringBuilder(props) {
const [stringBuilderHeight, setStringBuilderHeight] = useState();
const [showOptions, setShowOptions] = useState(false);
const [tokenString, setTokenString] = useState(stringToTokenString(value, options));
const [contentMaxLength, setContentMaxLength] = useState(
const [contextMaxLength, setContentMaxLength] = useState(
tokenValue.length + 5,
);
const [tokens, setTokens] = useState([]);
Expand Down Expand Up @@ -82,10 +82,10 @@ function StringBuilder(props) {

useEffect(() => {
// Auto Grow Input
if (contentMaxLength - 3 < tokenValue.length) {
if (contextMaxLength - 3 < tokenValue.length) {
const newHeight = inputRef.current.scrollHeight + 3;
setStringBuilderHeight(() => newHeight);
setContentMaxLength(() => contentMaxLength + 25);
setContentMaxLength(() => contextMaxLength + 25);
}
}, [tokenString, tokenValue]);

Expand Down Expand Up @@ -183,7 +183,7 @@ function StringBuilder(props) {
inputRef={inputRef}
invalidTokenRegex={invalidTokenRegex}
name={name}
contentMaxLength={contentMaxLength}
contextMaxLength={contextMaxLength}
setContentMaxLength={setContentMaxLength}
/>
<TokenizedString
Expand Down
5 changes: 3 additions & 2 deletions src/form/components/StringBuilder/js/invalid-token.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import PropTypes from 'prop-types';
import Tooltip from '../../../../components/Tooltip';
import Icon from '../../../../components/Icon';

function InvalidToken(props) {

const InvalidToken = (props) => {
const { token, findInvalidTokenSubstitute } = props;
return (
<span
Expand All @@ -19,7 +20,7 @@ function InvalidToken(props) {
</Tooltip>
</span>
);
}
};

InvalidToken.propTypes = {
token: PropTypes.string,
Expand Down
104 changes: 53 additions & 51 deletions src/form/components/StringBuilder/js/options-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import PropTypes from 'prop-types';

import FloatingContainer from '../../../../components/FloatingContainer';

export function OptionsList({
export const OptionsList = ({
options,
showOptions,
handleOptionSelection,
Expand All @@ -12,7 +12,7 @@ export function OptionsList({
setShowOptions,
allowSearch,
initialSearchValue,
}) {
}) => {
const [filterValue, setFilterValue] = useState(initialSearchValue);
const [filteredOptions, setFilteredOptions] = useState(options);

Expand All @@ -26,7 +26,7 @@ export function OptionsList({
return;
}
const newFilteredOptions = options.filter(
(option) => option.name.toLowerCase().includes(filterValue.toLowerCase()),
option => option.name.toLowerCase().includes(filterValue.toLowerCase()),
);
setFilteredOptions(newFilteredOptions);
}, [filterValue]);
Expand All @@ -40,56 +40,58 @@ export function OptionsList({
}

return (
<FloatingContainer
className={`string-builder-dropdown tyk-form-group ${getThemeClasses().join(' ')}`}
element={containerRef}
size="matchElement"
displayAxis="vertical"
>
{allowSearch && (
<div className="string-builder-search">
<input
autoFocus
className="tyk-form-control"
value={filterValue}
placeholder="Search parameter"
onChange={(e) => {
setFilterValue(e.target.value);
}}
onKeyDown={(e) => {
if (
e.key === 'Escape'
|| e.key === 'ArrowUp'
// || e.key === 'ArrowDown'
|| e.key === 'Enter'
) {
setShowOptions(false);
}
}}
/>
</div>
)}
<ul className="string-builder-list">
{filteredOptions.map((option) => (
<li
key={`${option.id}-${option.name}`}
onMouseDown={() => handleOptionSelection(option)}
>
<span className={`url-builder__options_name ${option.className || 'default-option-name'}`}>
{option.name}
</span>
{option.desc && (
<span className="url-builder__options_description">
&nbsp; : &nbsp;
{option.desc}
<>
<FloatingContainer
className={`string-builder-dropdown tyk-form-group ${getThemeClasses().join(' ')}`}
element={containerRef}
size="matchElement"
displayAxis="vertical"
>
{allowSearch && (
<div className="string-builder-search">
<input
autoFocus
className="tyk-form-control"
value={filterValue}
placeholder="Search parameter"
onChange={(e) => {
setFilterValue(e.target.value);
}}
onKeyDown={(e) => {
if (
e.key === 'Escape'
|| e.key === 'ArrowUp'
// || e.key === 'ArrowDown'
|| e.key === 'Enter'
) {
setShowOptions(false);
}
}}
/>
</div>
)}
<ul className="string-builder-list">
{filteredOptions.map(option => (
<li
key={`${option.id}${Math.random()}`}
onMouseDown={() => handleOptionSelection(option)}
>
<span className={`url-builder__options_name ${option.className || 'default-option-name'}`}>
{option.name}
</span>
)}
</li>
))}
</ul>
</FloatingContainer>
{option.desc && (
<span className="url-builder__options_description">
&nbsp; : &nbsp;
{option.desc}
</span>
)}
</li>
))}
</ul>
</FloatingContainer>
</>
);
}
};

OptionsList.propTypes = {
options: PropTypes.arrayOf(Object),
Expand Down
1 change: 1 addition & 0 deletions src/form/components/StringBuilder/js/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const stringToTokenString = (value, options) => {
return tempStr;
};


export const setCursorPos = (ref, pos) => {
setTimeout(() => {
ref.current.setSelectionRange(pos, pos);
Expand Down
6 changes: 2 additions & 4 deletions src/form/components/StringBuilder/js/string-builder-footer.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';

export function StringBuilderFooter(props) {
export const StringBuilderFooter = (props) => {
const {
note, error, inputInFocus, stringBuilderHeight, dropdownTriggerKey,
} = props;
Expand All @@ -18,9 +18,7 @@ export function StringBuilderFooter(props) {
<p className="tyk-form-control__help-block">
<span>
Enter
{' '}
<span className="string_builder_trigger">{dropdownTriggerKey}</span>
{' '}
to add any parameter
</span>
</p>
Expand All @@ -31,7 +29,7 @@ export function StringBuilderFooter(props) {
)}
</div>
);
}
};

StringBuilderFooter.propTypes = {
note: PropTypes.string,
Expand Down
10 changes: 5 additions & 5 deletions src/form/components/StringBuilder/js/string-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function StringInput({
setInputInFocus,
invalidTokenRegex,
name,
contentMaxLength,
contextMaxLength,
}) {
const [isPasteEvent, setIsPasteEvent] = useState(false);

Expand Down Expand Up @@ -82,8 +82,8 @@ function StringInput({

// -- START :: Handle backspacing when cursor is at the end of the string
if (selectionEnd === tokenValue.length) {
const lastToken = tokens[tokens.length - 2];
const lastCharsInString = tokenValue.slice(-(lastToken?.length ?? 0));
const lastToken = tokens[tokens?.length - 2];
const lastCharsInString = tokenValue.slice(-lastToken?.length);
if (lastToken === lastCharsInString) {
e.preventDefault();
setTokenString(
Expand Down Expand Up @@ -257,7 +257,7 @@ function StringInput({
name={name}
ref={inputRef}
style={{ height: `${stringBuilderHeight}px` }}
maxLength={contentMaxLength}
maxLength={contextMaxLength}
onPaste={handlePasteEvent}
onFocus={handleOnFocus}
onBlur={() => setInputInFocus(false)}
Expand Down Expand Up @@ -290,7 +290,7 @@ StringInput.propTypes = {
inputRef: PropTypes.instanceOf(Object),
invalidTokenRegex: PropTypes.instanceOf(RegExp),
name: PropTypes.string,
contentMaxLength: PropTypes.number,
contextMaxLength: PropTypes.number,
};

export { StringInput };
Loading

0 comments on commit b470a9a

Please sign in to comment.