@squiz/generic-browser-lib 1.59.1-alpha.0 → 1.60.1-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/ResourceItem/ResourceItem.js +3 -3
- package/lib/Skeleton/List/SkeletonList.js +2 -2
- package/lib/Utils/utils.d.ts +2 -0
- package/lib/Utils/{uuid.js → utils.js} +5 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/package.json +2 -2
- package/src/ResourceItem/ResourceItem.spec.tsx +24 -0
- package/src/ResourceItem/ResourceItem.tsx +2 -2
- package/src/Skeleton/List/SkeletonList.tsx +1 -1
- package/src/Utils/utils.spec.ts +45 -0
- package/src/Utils/{uuid.ts → utils.ts} +4 -2
- package/src/index.ts +1 -1
- package/lib/Utils/uuid.d.ts +0 -2
@@ -8,12 +8,12 @@ const react_1 = __importDefault(require("react"));
|
|
8
8
|
const react_aria_1 = require("react-aria");
|
9
9
|
const ModalOpeningButton_1 = require("../Modal/ModalOpeningButton");
|
10
10
|
const Icon_1 = require("../Icons/Icon");
|
11
|
-
const
|
11
|
+
const utils_1 = require("../Utils/utils");
|
12
12
|
const ResourceItem = ({ item, selected, label, type, childCount, previewModalState, onSelect, onDrillDown, className, allowedTypes, componentIcon, iconSource = 'matrix', showChevron = false, }) => {
|
13
13
|
const { triggerProps, overlayProps } = (0, react_aria_1.useOverlayTrigger)({ type: 'dialog' }, previewModalState);
|
14
|
-
const isDisabled = allowedTypes !== undefined && !allowedTypes.includes(type);
|
14
|
+
const isDisabled = allowedTypes !== undefined && !allowedTypes.includes((0, utils_1.transformSnakeCase)(type));
|
15
15
|
const title = isDisabled ? "You can't select this item" : label;
|
16
|
-
return (react_1.default.createElement("li", { className: `squiz-gb-scope flex items-stretch p-1 bg-white border-1 border-grey-200 min-h-[64px] ${className}`, key: (0,
|
16
|
+
return (react_1.default.createElement("li", { className: `squiz-gb-scope flex items-stretch p-1 bg-white border-1 border-grey-200 min-h-[64px] ${className}`, key: (0, utils_1.uuid)() },
|
17
17
|
react_1.default.createElement(ModalOpeningButton_1.ModalOpeningButton, { type: "button", ...triggerProps, isDisabled: isDisabled, onPress: () => onSelect(item, overlayProps), "aria-label": childCount === undefined ? `Drill down to ${label} children` : '', className: `
|
18
18
|
relative grow flex items-center px-4 py-2 rounded outline-0 ${selected ? 'bg-blue-100 text-blue-400' : ''} ${childCount !== undefined && childCount > 0 ? 'mr-2' : ''} ${isDisabled ? 'font-normal text-gray-600 cursor-not-allowed' : 'hover:bg-gray-50 focus:bg-gray-50'}
|
19
19
|
`, title: title },
|
@@ -6,9 +6,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.SkeletonList = void 0;
|
7
7
|
const react_1 = __importDefault(require("react"));
|
8
8
|
const SkeletonListItem_1 = require("../ListItem/SkeletonListItem");
|
9
|
-
const
|
9
|
+
const utils_1 = require("../../Utils/utils");
|
10
10
|
const clsx_1 = __importDefault(require("clsx"));
|
11
11
|
const SkeletonList = ({ itemCount = 8, className, ariaLabel }) => (react_1.default.createElement("ul", { className: (0, clsx_1.default)(`flex flex-col px-7 my-4 focus-visible:outline-0`, className), "aria-label": `${ariaLabel || 'Skeleton loader list'}` }, [...Array(itemCount)].map((_item) => {
|
12
|
-
return react_1.default.createElement(SkeletonListItem_1.SkeletonListItem, { key: (0,
|
12
|
+
return react_1.default.createElement(SkeletonListItem_1.SkeletonListItem, { key: (0, utils_1.uuid)() });
|
13
13
|
})));
|
14
14
|
exports.SkeletonList = SkeletonList;
|
@@ -1,7 +1,11 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.uuid = void 0;
|
3
|
+
exports.transformSnakeCase = exports.uuid = void 0;
|
4
4
|
function uuid() {
|
5
5
|
return '10000000-1000-4000-8000-100000000000'.replace(/[018]/g, (c) => (Number(c) ^ (window.crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (Number(c) / 4)))).toString(16));
|
6
6
|
}
|
7
7
|
exports.uuid = uuid;
|
8
|
+
function transformSnakeCase(str) {
|
9
|
+
return str.replace(/(_\w)/g, (m) => m[1].toUpperCase());
|
10
|
+
}
|
11
|
+
exports.transformSnakeCase = transformSnakeCase;
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
@@ -27,4 +27,4 @@ __exportStar(require("./PreviewPanel/PreviewPanel"), exports);
|
|
27
27
|
__exportStar(require("./PreviewPanel/PreviewPanelHOC"), exports);
|
28
28
|
__exportStar(require("./Hooks/useAsync"), exports);
|
29
29
|
__exportStar(require("./ResetButton/ResetButton"), exports);
|
30
|
-
__exportStar(require("./Utils/
|
30
|
+
__exportStar(require("./Utils/utils"), exports);
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@squiz/generic-browser-lib",
|
3
|
-
"version": "1.
|
3
|
+
"version": "1.60.1-alpha.1",
|
4
4
|
"description": "Package with reusable components used by resource/component browsers",
|
5
5
|
"main": "lib/index.js",
|
6
6
|
"types": "lib/index.d.ts",
|
@@ -72,5 +72,5 @@
|
|
72
72
|
"volta": {
|
73
73
|
"node": "18.15.0"
|
74
74
|
},
|
75
|
-
"gitHead": "
|
75
|
+
"gitHead": "936bac195e49fd181b83d6441e747ca7738780c9"
|
76
76
|
}
|
@@ -62,4 +62,28 @@ describe('ResourceItem', () => {
|
|
62
62
|
|
63
63
|
expect(buttonElement).not.toBeDisabled();
|
64
64
|
});
|
65
|
+
|
66
|
+
it('should handle converting snake_case types to camelCase', () => {
|
67
|
+
const props = {
|
68
|
+
...defaultProps,
|
69
|
+
type: 'page_standard',
|
70
|
+
};
|
71
|
+
|
72
|
+
const { getByRole } = render(<ResourceItem {...props} allowedTypes={['pageStandard']} />);
|
73
|
+
const buttonElement = getByRole('button');
|
74
|
+
|
75
|
+
expect(buttonElement).not.toBeDisabled();
|
76
|
+
});
|
77
|
+
|
78
|
+
it('should still handle camelCase types', () => {
|
79
|
+
const props = {
|
80
|
+
...defaultProps,
|
81
|
+
type: 'pageStandard',
|
82
|
+
};
|
83
|
+
|
84
|
+
const { getByRole } = render(<ResourceItem {...props} allowedTypes={['pageStandard']} />);
|
85
|
+
const buttonElement = getByRole('button');
|
86
|
+
|
87
|
+
expect(buttonElement).not.toBeDisabled();
|
88
|
+
});
|
65
89
|
});
|
@@ -5,7 +5,7 @@ import { OverlayTriggerState } from 'react-stately';
|
|
5
5
|
|
6
6
|
import { ModalOpeningButton } from '../Modal/ModalOpeningButton';
|
7
7
|
import { Icon, IconOptions, ResourceSources } from '../Icons/Icon';
|
8
|
-
import { uuid } from '../Utils/
|
8
|
+
import { uuid, transformSnakeCase } from '../Utils/utils';
|
9
9
|
|
10
10
|
interface ResourceItem<T> {
|
11
11
|
item: T;
|
@@ -39,7 +39,7 @@ const ResourceItem = <T,>({
|
|
39
39
|
showChevron = false,
|
40
40
|
}: ResourceItem<T>) => {
|
41
41
|
const { triggerProps, overlayProps } = useOverlayTrigger({ type: 'dialog' }, previewModalState);
|
42
|
-
const isDisabled = allowedTypes !== undefined && !allowedTypes.includes(type);
|
42
|
+
const isDisabled = allowedTypes !== undefined && !allowedTypes.includes(transformSnakeCase(type));
|
43
43
|
const title = isDisabled ? "You can't select this item" : label;
|
44
44
|
|
45
45
|
return (
|
@@ -0,0 +1,45 @@
|
|
1
|
+
import { transformSnakeCase, uuid } from './utils';
|
2
|
+
|
3
|
+
describe('uuid', () => {
|
4
|
+
it('should generate a random uuid each time', () => {
|
5
|
+
const uniqueId = uuid();
|
6
|
+
|
7
|
+
expect(typeof uniqueId).toBe('string');
|
8
|
+
expect(uniqueId).toMatch(/[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}/);
|
9
|
+
|
10
|
+
const uniqueId2 = uuid();
|
11
|
+
expect(uniqueId).not.toBe(uniqueId2);
|
12
|
+
});
|
13
|
+
});
|
14
|
+
|
15
|
+
describe('transformSnakeCase', () => {
|
16
|
+
it.each([
|
17
|
+
['data_entry', 'dataEntry'],
|
18
|
+
['user_input', 'userInput'],
|
19
|
+
['file_path', 'filePath'],
|
20
|
+
['image_size', 'imageSize'],
|
21
|
+
['color_code', 'colorCode'],
|
22
|
+
['table_row', 'tableRow'],
|
23
|
+
['page_number', 'pageNumber'],
|
24
|
+
['search_query', 'searchQuery'],
|
25
|
+
['last_update', 'lastUpdate'],
|
26
|
+
['item_list', 'itemList'],
|
27
|
+
])('should convert %s to camelCase "%s"', (input, expected) => {
|
28
|
+
expect(transformSnakeCase(input)).toBe(expected);
|
29
|
+
});
|
30
|
+
|
31
|
+
it.each([
|
32
|
+
'dataEntry',
|
33
|
+
'userInput',
|
34
|
+
'filePath',
|
35
|
+
'imageSize',
|
36
|
+
'colorCode',
|
37
|
+
'tableRow',
|
38
|
+
'pageNumber',
|
39
|
+
'searchQuery',
|
40
|
+
'lastUpdate',
|
41
|
+
'itemList',
|
42
|
+
])('should maintain camelCase formatting for camelCase strings passed in', (input) => {
|
43
|
+
expect(transformSnakeCase(input)).toBe(input);
|
44
|
+
});
|
45
|
+
});
|
@@ -1,7 +1,9 @@
|
|
1
|
-
function uuid(): string {
|
1
|
+
export function uuid(): string {
|
2
2
|
return '10000000-1000-4000-8000-100000000000'.replace(/[018]/g, (c) =>
|
3
3
|
(Number(c) ^ (window.crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (Number(c) / 4)))).toString(16),
|
4
4
|
);
|
5
5
|
}
|
6
6
|
|
7
|
-
export
|
7
|
+
export function transformSnakeCase(str: string) {
|
8
|
+
return str.replace(/(_\w)/g, (m) => m[1].toUpperCase());
|
9
|
+
}
|
package/src/index.ts
CHANGED
package/lib/Utils/uuid.d.ts
DELETED