@washingtonpost/subs-de-inputs 0.2.3-canary.0 → 0.3.0
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/CHANGELOG.md +34 -0
- package/dist/components/DESelect/Dropdown.d.ts +16 -0
- package/dist/subs-de-inputs.cjs.development.js +153 -30
- package/dist/subs-de-inputs.cjs.development.js.map +1 -1
- package/dist/subs-de-inputs.cjs.production.min.js +1 -1
- package/dist/subs-de-inputs.cjs.production.min.js.map +1 -1
- package/dist/subs-de-inputs.esm.js +155 -32
- package/dist/subs-de-inputs.esm.js.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# Change Log
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file. See
|
|
4
|
+
[Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
+
|
|
6
|
+
**[0.3.0 - 2024-05-06]**:
|
|
7
|
+
* Uses the native `<select />` element in smaller viewport sizes for better UX
|
|
8
|
+
|
|
9
|
+
**[0.2.2 - 2024-05-03]**:
|
|
10
|
+
* use `window.__twpdeu.push()` for submitting
|
|
11
|
+
* Better loading state when fetching config over the wire
|
|
12
|
+
* Prevent extra calls to `ingest` API if user changes value after clicking submit
|
|
13
|
+
* Fix `ingest()` function to send the right format (again)
|
|
14
|
+
|
|
15
|
+
**[0.2.1 - 2024-05-02]**:
|
|
16
|
+
* Revert "ESM build only"
|
|
17
|
+
* `ingest()` function throws error if `submitData.value` is not an array (required by BE)
|
|
18
|
+
|
|
19
|
+
**[0.2.0 - 2024-05-01]**:
|
|
20
|
+
* Adds `ingest()` function
|
|
21
|
+
* ESM build only
|
|
22
|
+
* Babel config to target recent browsers only
|
|
23
|
+
|
|
24
|
+
**[0.1.1 - 2024-04-30]**:
|
|
25
|
+
* Fix build by removing unused file
|
|
26
|
+
|
|
27
|
+
**[0.1.0 - 2024-04-25]**:
|
|
28
|
+
* Add initial `<DESelect />` component
|
|
29
|
+
|
|
30
|
+
**[0.0.2 - 2024-04-24]**:
|
|
31
|
+
* Fix build error
|
|
32
|
+
|
|
33
|
+
**[0.0.1 - 2024-04-09]**:
|
|
34
|
+
* Initial setup
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
interface IDropdownProps {
|
|
2
|
+
id: string;
|
|
3
|
+
label: string;
|
|
4
|
+
values: Array<string>;
|
|
5
|
+
required?: boolean;
|
|
6
|
+
defaultValue?: string;
|
|
7
|
+
onChange?: (value: string) => void;
|
|
8
|
+
disabled?: boolean;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Dropdown component. Uses wpds-ui-kit on desktop and native select on mobile.
|
|
12
|
+
* @param {IDropdownProps} props The props.
|
|
13
|
+
* @returns {React.ReactElement} The dropdown.
|
|
14
|
+
*/
|
|
15
|
+
export declare const Dropdown: ({ id, label, values, required, defaultValue, onChange, disabled, }: IDropdownProps) => JSX.Element;
|
|
16
|
+
export {};
|
|
@@ -9,6 +9,7 @@ var React = require('react');
|
|
|
9
9
|
var React__default = _interopDefault(React);
|
|
10
10
|
var wpdsUiKit = require('@washingtonpost/wpds-ui-kit');
|
|
11
11
|
var subsHooks = require('@washingtonpost/subs-hooks');
|
|
12
|
+
var wpdsAssets = require('@washingtonpost/wpds-assets');
|
|
12
13
|
|
|
13
14
|
const CollectionBehaviors = {
|
|
14
15
|
COLLECT: 'COLLECT',
|
|
@@ -45,26 +46,19 @@ const hasRequiredPrivacyCookies = () => {
|
|
|
45
46
|
return !!(wp_usp && countryCode === 'US');
|
|
46
47
|
};
|
|
47
48
|
|
|
48
|
-
const DEBUG_FLAG = 'f_de_debug';
|
|
49
49
|
const base = `${subsSdk.ENDPOINTS.base}/de/v1`;
|
|
50
50
|
const attributesCache = {};
|
|
51
51
|
const getAttributes = async _ref => {
|
|
52
52
|
let {
|
|
53
53
|
fieldName
|
|
54
54
|
} = _ref;
|
|
55
|
-
const debug = window.location.search.includes(DEBUG_FLAG);
|
|
56
|
-
if (debug) {
|
|
57
|
-
console.debug('getAttributes()');
|
|
58
|
-
}
|
|
59
55
|
if (attributesCache[fieldName]) {
|
|
60
|
-
if (debug) console.debug('getAttributes() > return cached info');
|
|
61
56
|
return attributesCache[fieldName];
|
|
62
57
|
}
|
|
63
58
|
const fieldNames = [fieldName];
|
|
64
59
|
try {
|
|
65
60
|
const url = new URL(`${base}/attributes`);
|
|
66
61
|
url.searchParams.set('attributes', fieldNames.join(','));
|
|
67
|
-
if (debug) console.debug(`getAttributes() > ${url.toString()}`);
|
|
68
62
|
const data = await fetch(url.toString(), {
|
|
69
63
|
credentials: 'include',
|
|
70
64
|
headers: subsSdk.JSON_HEADERS
|
|
@@ -91,27 +85,18 @@ const ingest = async _ref2 => {
|
|
|
91
85
|
type = IngestType.IMPLICIT,
|
|
92
86
|
source
|
|
93
87
|
} = _ref2;
|
|
94
|
-
const debug = window.location.search.includes(DEBUG_FLAG);
|
|
95
|
-
if (debug) {
|
|
96
|
-
console.debug('ingest()');
|
|
97
|
-
}
|
|
98
88
|
const url = `${base}/ingest`;
|
|
99
89
|
const wapo_login_id = subsSdk.getCookie('wapo_login_id');
|
|
100
90
|
if (!hasRequiredPrivacyCookies()) {
|
|
101
|
-
if (debug) console.debug('ingest() > hasRequiredPrivacyCookies falsy');
|
|
102
91
|
throw new Error('does not satisfy cookie check');
|
|
103
92
|
}
|
|
104
93
|
let attributeInfo = attributesCache[fieldName];
|
|
105
94
|
if (!attributeInfo) {
|
|
106
|
-
if (debug) console.debug('ingest() > fetch attribute info');
|
|
107
95
|
attributeInfo = await getAttributes({
|
|
108
96
|
fieldName
|
|
109
97
|
});
|
|
110
|
-
} else {
|
|
111
|
-
if (debug) console.debug('ingest() > use cached attribute info');
|
|
112
98
|
}
|
|
113
99
|
if (attributeInfo[0] && attributeInfo[0].name === fieldName && attributeInfo[0].collection_behavior === CollectionBehaviors.DO_NOT_COLLECT) {
|
|
114
|
-
if (debug) console.debug('ingest() > do not collect');
|
|
115
100
|
throw new Error('do not collect');
|
|
116
101
|
}
|
|
117
102
|
const jucid = localStorage.getItem('uuid');
|
|
@@ -143,6 +128,139 @@ const ingest = async _ref2 => {
|
|
|
143
128
|
}
|
|
144
129
|
};
|
|
145
130
|
|
|
131
|
+
const StyledMobileSelect = /*#__PURE__*/wpdsUiKit.styled('select', {
|
|
132
|
+
padding: '12px 16px 12px 6px',
|
|
133
|
+
display: 'flex',
|
|
134
|
+
justifyContent: 'space-between',
|
|
135
|
+
width: '100%',
|
|
136
|
+
backgroundColor: '$secondary',
|
|
137
|
+
color: '$primary',
|
|
138
|
+
fontFamily: '$meta',
|
|
139
|
+
fontSize: '$100',
|
|
140
|
+
fontWeight: '$light',
|
|
141
|
+
lineHeight: '$125',
|
|
142
|
+
paddingBlockRight: '$125',
|
|
143
|
+
textOverflow: 'ellipsis',
|
|
144
|
+
position: 'relative',
|
|
145
|
+
borderColor: 'transparent',
|
|
146
|
+
borderRightWidth: '10px',
|
|
147
|
+
borderRightColor: 'transparent',
|
|
148
|
+
appearance: 'none',
|
|
149
|
+
'-webkit-appearance': 'none',
|
|
150
|
+
'&:disabled': {
|
|
151
|
+
backgroundColor: wpdsUiKit.theme.colors.disabled,
|
|
152
|
+
borderColor: wpdsUiKit.theme.colors.disabled,
|
|
153
|
+
color: wpdsUiKit.theme.colors.onDisabled,
|
|
154
|
+
cursor: 'not-allowed'
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
const StyledSelectWrapper = /*#__PURE__*/wpdsUiKit.styled('div', {
|
|
158
|
+
width: '100%',
|
|
159
|
+
maxWidth: '380px',
|
|
160
|
+
borderRadius: '$012',
|
|
161
|
+
borderColor: '$subtle',
|
|
162
|
+
borderStyle: 'solid',
|
|
163
|
+
borderWidth: '1px',
|
|
164
|
+
backgroundColor: '$secondary',
|
|
165
|
+
position: 'relative'
|
|
166
|
+
});
|
|
167
|
+
const StyledMobileOption = /*#__PURE__*/wpdsUiKit.styled('option', {
|
|
168
|
+
fontFamily: 'inherit',
|
|
169
|
+
fontSize: 'inherit',
|
|
170
|
+
color: 'inherit'
|
|
171
|
+
});
|
|
172
|
+
/**
|
|
173
|
+
* Dropdown component. Uses wpds-ui-kit on desktop and native select on mobile.
|
|
174
|
+
* @param {IDropdownProps} props The props.
|
|
175
|
+
* @returns {React.ReactElement} The dropdown.
|
|
176
|
+
*/
|
|
177
|
+
const Dropdown = _ref => {
|
|
178
|
+
let {
|
|
179
|
+
id,
|
|
180
|
+
label,
|
|
181
|
+
values,
|
|
182
|
+
required = false,
|
|
183
|
+
defaultValue,
|
|
184
|
+
onChange = () => {},
|
|
185
|
+
disabled = false
|
|
186
|
+
} = _ref;
|
|
187
|
+
const [answer, setAnswer] = React.useState();
|
|
188
|
+
const {
|
|
189
|
+
isMobileSize
|
|
190
|
+
} = subsHooks.useWindowSize();
|
|
191
|
+
React.useEffect(() => {
|
|
192
|
+
if (answer) onChange(answer);
|
|
193
|
+
}, [answer]);
|
|
194
|
+
const disabledProp = disabled ? {
|
|
195
|
+
disabled: true
|
|
196
|
+
} : {};
|
|
197
|
+
// helps maintain state between WPDS and native dropdowns
|
|
198
|
+
const defaultValueProp = answer ? {
|
|
199
|
+
defaultValue: answer
|
|
200
|
+
} : defaultValue ? {
|
|
201
|
+
defaultValue
|
|
202
|
+
} : {};
|
|
203
|
+
const defaultValuePropMobile = value => {
|
|
204
|
+
if (answer) {
|
|
205
|
+
return value === answer ? {
|
|
206
|
+
selected: true
|
|
207
|
+
} : {};
|
|
208
|
+
}
|
|
209
|
+
return value === defaultValue ? {
|
|
210
|
+
selected: true
|
|
211
|
+
} : {};
|
|
212
|
+
};
|
|
213
|
+
return isMobileSize ? React__default.createElement(StyledSelectWrapper, null, React__default.createElement(StyledMobileSelect, {
|
|
214
|
+
id: "",
|
|
215
|
+
required: required,
|
|
216
|
+
onChange: e => setAnswer(e.target.value),
|
|
217
|
+
placeholder: label,
|
|
218
|
+
...disabledProp
|
|
219
|
+
}, React__default.createElement("label", null, label), React__default.createElement(StyledMobileOption, {
|
|
220
|
+
value: "",
|
|
221
|
+
disabled: true,
|
|
222
|
+
selected: true,
|
|
223
|
+
style: {
|
|
224
|
+
color: '#666666'
|
|
225
|
+
}
|
|
226
|
+
}, label), values.map(value => React__default.createElement(StyledMobileOption, {
|
|
227
|
+
value: value,
|
|
228
|
+
key: value,
|
|
229
|
+
...defaultValuePropMobile(value)
|
|
230
|
+
}, value))), React__default.createElement(wpdsUiKit.Icon, {
|
|
231
|
+
label: "",
|
|
232
|
+
size: "100",
|
|
233
|
+
fill: wpdsUiKit.theme.colors['gray80'],
|
|
234
|
+
style: {
|
|
235
|
+
pointerEvents: 'none',
|
|
236
|
+
position: 'absolute',
|
|
237
|
+
right: '10px',
|
|
238
|
+
top: '50%',
|
|
239
|
+
transform: 'translateY(-50%)'
|
|
240
|
+
}
|
|
241
|
+
}, React__default.createElement(wpdsAssets.ChevronDown, {
|
|
242
|
+
style: {
|
|
243
|
+
position: 'absolute',
|
|
244
|
+
right: '10px'
|
|
245
|
+
}
|
|
246
|
+
}))) : React__default.createElement(wpdsUiKit.Select.Root, {
|
|
247
|
+
onValueChange: e => setAnswer(e),
|
|
248
|
+
required: required,
|
|
249
|
+
...defaultValueProp,
|
|
250
|
+
...disabledProp
|
|
251
|
+
}, React__default.createElement(wpdsUiKit.Select.Trigger, {
|
|
252
|
+
"data-test-id": `${id}-select-trigger`
|
|
253
|
+
}, React__default.createElement(wpdsUiKit.Select.Label, null, label), React__default.createElement(wpdsUiKit.Select.Value, null)), React__default.createElement(wpdsUiKit.Select.Content, {
|
|
254
|
+
css: {
|
|
255
|
+
zIndex: wpdsUiKit.theme.zIndices.page
|
|
256
|
+
},
|
|
257
|
+
"data-test-id": `${id}-select-content`
|
|
258
|
+
}, values.map(value => React__default.createElement(wpdsUiKit.Select.Item, {
|
|
259
|
+
value: value,
|
|
260
|
+
key: value
|
|
261
|
+
}, value))));
|
|
262
|
+
};
|
|
263
|
+
|
|
146
264
|
const scriptSrc = `${subsSdk.ENDPOINTS.staticAssets === 'https://subscribe.washingtonpost.com/static' ? 'https://www.washingtonpost.com/subscribe/static/' : subsSdk.ENDPOINTS.staticAssets}/de-utils/twpdeu.min.js`;
|
|
147
265
|
const DESelect = _ref => {
|
|
148
266
|
let {
|
|
@@ -219,28 +337,33 @@ const DESelect = _ref => {
|
|
|
219
337
|
} : {};
|
|
220
338
|
// sort and filter out archived values
|
|
221
339
|
const values = config ? config.values.sort((a, b) => a.order - b.order).filter(value => value.archived !== true).filter(valuesFilter) : [];
|
|
222
|
-
return React__default.createElement(SelectWrapper, null, React__default.createElement(wpdsUiKit.Select.Root, {
|
|
340
|
+
return React__default.createElement(SelectWrapper, null, children && React__default.createElement(wpdsUiKit.Select.Root, {
|
|
223
341
|
onValueChange: e => {
|
|
342
|
+
setSelected(e);
|
|
224
343
|
onChange({
|
|
225
344
|
value: e
|
|
226
345
|
});
|
|
227
|
-
setSelected(e);
|
|
228
346
|
},
|
|
229
347
|
...defaultValueProp,
|
|
230
348
|
...disabledProp
|
|
231
|
-
}, children
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
349
|
+
}, children), !children && !config && React__default.createElement(Dropdown, {
|
|
350
|
+
id: 'loading',
|
|
351
|
+
label: 'Loading...',
|
|
352
|
+
values: [],
|
|
353
|
+
disabled: true
|
|
354
|
+
}), !children && config && React__default.createElement(Dropdown, {
|
|
355
|
+
id: config.name,
|
|
356
|
+
label: label || config.name,
|
|
357
|
+
onChange: e => {
|
|
358
|
+
setSelected(e);
|
|
359
|
+
onChange({
|
|
360
|
+
value: e
|
|
361
|
+
});
|
|
238
362
|
},
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
}, value.name))))));
|
|
363
|
+
values: values.map(value => value.name),
|
|
364
|
+
defaultValue: defaultValue,
|
|
365
|
+
disabled: disabled
|
|
366
|
+
}));
|
|
244
367
|
};
|
|
245
368
|
const SelectWrapper = /*#__PURE__*/wpdsUiKit.styled('div', {
|
|
246
369
|
boxSizing: 'border-box',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subs-de-inputs.cjs.development.js","sources":["../src/interfaces/index.ts","../src/utils/hasRequiredPrivacyCookies.ts","../src/services/dataEnrichment.ts","../src/components/DESelect/index.tsx"],"sourcesContent":["export type AttributeValue = {\n name: string;\n date_created: Number;\n last_modified_date: Number;\n archived: boolean;\n order: number;\n};\n\nexport const CollectionBehaviors = {\n COLLECT: 'COLLECT',\n DO_NOT_COLLECT: 'DO_NOT_COLLECT',\n} as const;\n\nexport type Attribute = {\n name: string;\n approved_for_use?: boolean;\n collection_behavior?: (typeof CollectionBehaviors)[keyof typeof CollectionBehaviors];\n datatype: 'string';\n explicit: boolean;\n multiple_value: boolean;\n last_modified_date: Number;\n date_created: Number;\n values: Array<AttributeValue>;\n};\n\nexport const AttributesState = {\n SUCCESS: '100',\n} as const;\n\nexport const IngestType = {\n EXPLICIT: 'explicit',\n IMPLICIT: 'implicit',\n} as const;\n\nexport const IngestResponseState = {\n SUCCESS: '100',\n SYSTEM_ERROR: '101',\n INVALID_TYPE: '102',\n INVALID_IDENTIFIER: '103',\n INVALID_DATA: '104',\n INVALID_ATTRIBUTE_DEFINITION: '105',\n INVALID_META_DEFINITION: '106',\n UNAUTHENTICATED: '107',\n MISMATCHED_IDENTIFIER: '108',\n DISABLED_ATTRIBUTE_DEFINITION: '109',\n DO_NOT_COLLECT: '110',\n} as const;\n","import { WPGeo, getCookie } from '@washingtonpost/subs-sdk';\n\nexport const hasRequiredPrivacyCookies = () => {\n if (typeof window === 'undefined') {\n return false;\n }\n\n const wp_usp = getCookie('wp_usp');\n\n const countryCode = WPGeo()?.country_code;\n\n return !!(wp_usp && countryCode === 'US');\n};\n","import {\n ENDPOINTS,\n ResponseStatus,\n JSON_HEADERS,\n getCookie,\n} from '@washingtonpost/subs-sdk';\nimport {\n Attribute,\n CollectionBehaviors,\n IngestResponseState,\n IngestType,\n} from '../interfaces';\nimport { hasRequiredPrivacyCookies } from '../utils/hasRequiredPrivacyCookies';\n\nconst DEBUG_FLAG = 'f_de_debug';\n\nconst base = `${ENDPOINTS.base}/de/v1`;\n\nconst attributesCache: Record<string, any> = {};\nexport const getAttributes: GetAttributesType = async ({\n fieldName,\n}: {\n fieldName: string;\n}) => {\n const debug = window.location.search.includes(DEBUG_FLAG);\n\n if (debug) {\n console.debug('getAttributes()');\n }\n\n if (attributesCache[fieldName]) {\n if (debug) console.debug('getAttributes() > return cached info');\n return attributesCache[fieldName];\n }\n\n const fieldNames = [fieldName];\n\n try {\n const url = new URL(`${base}/attributes`);\n url.searchParams.set('attributes', fieldNames.join(','));\n\n if (debug) console.debug(`getAttributes() > ${url.toString()}`);\n\n const data = await fetch(url.toString(), {\n credentials: 'include',\n headers: JSON_HEADERS,\n });\n const json = await data.json();\n\n if (data.ok && json.status === ResponseStatus.SUCCESS) {\n const attributes = json.attributes || [];\n attributesCache[fieldName] = attributes;\n return attributes;\n } else {\n return [];\n }\n } catch (e) {\n console.debug(e);\n return [];\n }\n};\n\ntype GetAttributesType = ({\n fieldName,\n}: {\n fieldName: string;\n}) => Promise<Attribute[]>;\n\nexport const ingest: IngestType = async ({\n submitData: { fieldName, value },\n type = IngestType.IMPLICIT,\n source,\n}) => {\n const debug = window.location.search.includes(DEBUG_FLAG);\n\n if (debug) {\n console.debug('ingest()');\n }\n\n const url = `${base}/ingest`;\n\n const wapo_login_id = getCookie('wapo_login_id');\n\n if (!hasRequiredPrivacyCookies()) {\n if (debug) console.debug('ingest() > hasRequiredPrivacyCookies falsy');\n throw new Error('does not satisfy cookie check');\n }\n\n let attributeInfo = attributesCache[fieldName];\n if (!attributeInfo) {\n if (debug) console.debug('ingest() > fetch attribute info');\n attributeInfo = await getAttributes({ fieldName });\n } else {\n if (debug) console.debug('ingest() > use cached attribute info');\n }\n\n if (\n attributeInfo[0] &&\n attributeInfo[0].name === fieldName &&\n attributeInfo[0].collection_behavior === CollectionBehaviors.DO_NOT_COLLECT\n ) {\n if (debug) console.debug('ingest() > do not collect');\n throw new Error('do not collect');\n }\n\n const jucid = localStorage.getItem('uuid');\n const ga = getCookie('_ga');\n\n const payload = {\n jucid,\n ga,\n type,\n wapo_login_id, // TODO: move this to BE to read from cookie headers\n data: {\n [fieldName]: [value],\n },\n metadata: { source },\n };\n\n try {\n const response = await fetch(url, {\n method: 'POST',\n credentials: 'include',\n headers: JSON_HEADERS,\n body: JSON.stringify(payload),\n });\n\n const json = await response.json();\n\n return json;\n } catch (e) {\n console.debug(e);\n return null;\n }\n};\n\ntype IngestType = ({\n submitData: { fieldName, value },\n source,\n}: {\n submitData: {\n fieldName: string;\n value: string;\n };\n type?: (typeof IngestType)[keyof typeof IngestType];\n source: string;\n}) => Promise<{\n status: ResponseStatus;\n state: (typeof IngestResponseState)[keyof typeof IngestResponseState];\n} | null>;\n","import React, { useState, useEffect } from 'react';\nimport { Select, styled, theme } from '@washingtonpost/wpds-ui-kit';\nimport { Attribute, AttributeValue, IngestType } from '../../interfaces';\nimport { ENDPOINTS, ResponseStatus } from '@washingtonpost/subs-sdk';\nimport { useScript, ScriptStatus } from '@washingtonpost/subs-hooks';\n\ninterface DESelectProps {\n source: string;\n fieldName: string;\n label?: string;\n dataDictionaryConfig?: Attribute;\n defaultValue?: string;\n disabled?: boolean;\n submit: boolean;\n onChange?: ({ value }: { value: string }) => void;\n onFinished?: ({\n isFinished,\n isError,\n }: {\n isFinished: boolean;\n isError: boolean;\n }) => void;\n valuesFilter?: (value: AttributeValue) => boolean;\n selectProps?: {\n root?: any;\n trigger?: any;\n label?: any;\n value?: any;\n content?: any;\n item?: any;\n };\n children?: React.ReactNode;\n}\n\nconst scriptSrc = `${\n ENDPOINTS.staticAssets === 'https://subscribe.washingtonpost.com/static'\n ? 'https://www.washingtonpost.com/subscribe/static/'\n : ENDPOINTS.staticAssets\n}/de-utils/twpdeu.min.js`;\n\nexport const DESelect: React.FC<DESelectProps> = ({\n source,\n fieldName,\n label,\n dataDictionaryConfig,\n defaultValue,\n disabled,\n submit,\n onChange = () => {},\n onFinished = () => {},\n valuesFilter = () => true,\n children,\n}) => {\n const [config, setConfig] = useState(dataDictionaryConfig);\n\n const [selected, setSelected] = useState('');\n\n const scriptStatus = useScript(scriptSrc);\n\n useEffect(() => {\n const fetchConfig = async () => {\n try {\n const config = await window?.__twpdeu?.getFieldConfigs({ fieldName });\n if (config) {\n setConfig(config[0]);\n } else {\n console.error('unable to get config', fieldName);\n }\n } catch (e) {\n console.warn('unable to get config', fieldName, e);\n }\n };\n\n if (scriptStatus === ScriptStatus.READY && !(children || config)) {\n fetchConfig();\n }\n }, [scriptStatus]);\n\n useEffect(() => {\n const submitSelected = async () => {\n try {\n // TODO: Log to GA?\n\n const result = await window?.__twpdeu?.push({\n submitData: { fieldName, value: selected },\n type: config?.explicit ? IngestType.EXPLICIT : IngestType.IMPLICIT,\n source,\n });\n\n const isError = result\n ? result.status !== ResponseStatus.SUCCESS\n : true;\n\n onFinished({\n isFinished: true,\n isError,\n });\n } catch (e) {\n onFinished({\n isFinished: false,\n isError: true,\n });\n }\n };\n\n if (scriptStatus === ScriptStatus.READY && submit && selected) {\n submitSelected();\n }\n }, [scriptStatus, submit]);\n\n const defaultValueProp = defaultValue && config ? { defaultValue } : {};\n\n const isLoading = !(children || config);\n\n const disabledProp = disabled || isLoading ? { disabled: true } : {};\n\n // sort and filter out archived values\n const values = config\n ? config.values\n .sort((a, b) => a.order - b.order)\n .filter((value) => value.archived !== true)\n .filter(valuesFilter)\n : [];\n\n return (\n <SelectWrapper>\n <Select.Root\n onValueChange={(e: string) => {\n onChange({ value: e });\n setSelected(e);\n }}\n {...defaultValueProp}\n {...disabledProp}\n >\n {children ? children : null}\n {!children && !config && (\n <>\n <Select.Trigger data-test-id={`select-trigger-loading`}>\n <Select.Label>{label || 'loading...'}</Select.Label>\n <Select.Value />\n </Select.Trigger>\n </>\n )}\n {!children && config && (\n <>\n <Select.Trigger data-test-id={`${config.name}-select-trigger`}>\n <Select.Label>{label || config.name}</Select.Label>\n <Select.Value />\n </Select.Trigger>\n <Select.Content\n css={{ zIndex: theme.zIndices.page }}\n data-test-id={`${config.name}-select-content`}\n >\n {values.map((value) => (\n <Select.Item value={value.name} key={value.name}>\n {value.name}\n </Select.Item>\n ))}\n </Select.Content>\n </>\n )}\n </Select.Root>\n </SelectWrapper>\n );\n};\n\nconst SelectWrapper = styled('div', {\n boxSizing: 'border-box',\n display: 'flex',\n marginBottom: '$100',\n flexDirection: 'column',\n '& button': {\n padding: '1px 6px',\n },\n '& *': { boxSizing: 'border-box' },\n});\n"],"names":["CollectionBehaviors","COLLECT","DO_NOT_COLLECT","AttributesState","SUCCESS","IngestType","EXPLICIT","IMPLICIT","IngestResponseState","SYSTEM_ERROR","INVALID_TYPE","INVALID_IDENTIFIER","INVALID_DATA","INVALID_ATTRIBUTE_DEFINITION","INVALID_META_DEFINITION","UNAUTHENTICATED","MISMATCHED_IDENTIFIER","DISABLED_ATTRIBUTE_DEFINITION","hasRequiredPrivacyCookies","window","wp_usp","getCookie","countryCode","_WPGeo","WPGeo","country_code","DEBUG_FLAG","base","ENDPOINTS","attributesCache","getAttributes","_ref","fieldName","debug","location","search","includes","console","fieldNames","url","URL","searchParams","set","join","toString","data","fetch","credentials","headers","JSON_HEADERS","json","ok","status","ResponseStatus","attributes","e","ingest","_ref2","submitData","value","type","source","wapo_login_id","Error","attributeInfo","name","collection_behavior","jucid","localStorage","getItem","ga","payload","metadata","response","method","body","JSON","stringify","scriptSrc","staticAssets","DESelect","label","dataDictionaryConfig","defaultValue","disabled","submit","onChange","onFinished","valuesFilter","children","config","setConfig","useState","selected","setSelected","scriptStatus","useScript","useEffect","fetchConfig","_window","__twpdeu","getFieldConfigs","error","warn","ScriptStatus","READY","submitSelected","_window2","result","push","explicit","isError","isFinished","defaultValueProp","isLoading","disabledProp","values","sort","a","b","order","filter","archived","React","SelectWrapper","Select","Root","onValueChange","Trigger","Label","Value","Content","css","zIndex","theme","zIndices","page","map","Item","key","styled","boxSizing","display","marginBottom","flexDirection","padding"],"mappings":";;;;;;;;;;;;MAQaA,mBAAmB,GAAG;EACjCC,OAAO,EAAE,SAAS;EAClBC,cAAc,EAAE;;MAeLC,eAAe,GAAG;EAC7BC,OAAO,EAAE;;MAGEC,UAAU,GAAG;EACxBC,QAAQ,EAAE,UAAU;EACpBC,QAAQ,EAAE;;MAGCC,mBAAmB,GAAG;EACjCJ,OAAO,EAAE,KAAK;EACdK,YAAY,EAAE,KAAK;EACnBC,YAAY,EAAE,KAAK;EACnBC,kBAAkB,EAAE,KAAK;EACzBC,YAAY,EAAE,KAAK;EACnBC,4BAA4B,EAAE,KAAK;EACnCC,uBAAuB,EAAE,KAAK;EAC9BC,eAAe,EAAE,KAAK;EACtBC,qBAAqB,EAAE,KAAK;EAC5BC,6BAA6B,EAAE,KAAK;EACpCf,cAAc,EAAE;;;MC3CLgB,yBAAyB,GAAGA;;EACvC,IAAI,OAAOC,MAAM,KAAK,WAAW,EAAE;IACjC,OAAO,KAAK;;EAGd,MAAMC,MAAM,GAAGC,iBAAS,CAAC,QAAQ,CAAC;EAElC,MAAMC,WAAW,IAAAC,MAAA,GAAGC,aAAK,EAAE,cAAAD,MAAA,uBAAPA,MAAA,CAASE,YAAY;EAEzC,OAAO,CAAC,EAAEL,MAAM,IAAIE,WAAW,KAAK,IAAI,CAAC;AAC3C,CAAC;;ACED,MAAMI,UAAU,GAAG,YAAY;AAE/B,MAAMC,IAAI,MAAMC,iBAAS,CAACD,YAAY;AAEtC,MAAME,eAAe,GAAwB,EAAE;AAC/C,MAAaC,aAAa,GAAsB,MAAAC,IAAA;MAAO;IACrDC;GAGD,GAAAD,IAAA;EACC,MAAME,KAAK,GAAGd,MAAM,CAACe,QAAQ,CAACC,MAAM,CAACC,QAAQ,CAACV,UAAU,CAAC;EAEzD,IAAIO,KAAK,EAAE;IACTI,OAAO,CAACJ,KAAK,CAAC,i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,OAAG,CACD,EACjBP,6BAACE,gBAAM,CAACM,OAAO;IACbC,GAAG,EAAE;MAAEC,MAAM,EAAEC,eAAK,CAACC,QAAQ,CAACC;KAAM;uBACnB9C,MAAM,CAACzB;KAEvBmD,MAAM,CAACqB,GAAG,CAAE9E,KAAK,IAChBgE,6BAACE,gBAAM,CAACa,IAAI;IAAC/E,KAAK,EAAEA,KAAK,CAACM,IAAI;IAAE0E,GAAG,EAAEhF,KAAK,CAACM;KACxCN,KAAK,CAACM,IAAI,CAEd,CAAC,CACa,CAEpB,CACW,CACA;AAEpB,CAAC;AAED,MAAM2D,aAAa,gBAAGgB,gBAAM,CAAC,KAAK,EAAE;EAClCC,SAAS,EAAE,YAAY;EACvBC,OAAO,EAAE,MAAM;EACfC,YAAY,EAAE,MAAM;EACpBC,aAAa,EAAE,QAAQ;EACvB,UAAU,EAAE;IACVC,OAAO,EAAE;GACV;EACD,KAAK,EAAE;IAAEJ,SAAS,EAAE;;CACrB,CAAC;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"subs-de-inputs.cjs.development.js","sources":["../src/interfaces/index.ts","../src/utils/hasRequiredPrivacyCookies.ts","../src/services/dataEnrichment.ts","../src/components/DESelect/Dropdown.tsx","../src/components/DESelect/index.tsx"],"sourcesContent":["export type AttributeValue = {\n name: string;\n date_created: Number;\n last_modified_date: Number;\n archived: boolean;\n order: number;\n};\n\nexport const CollectionBehaviors = {\n COLLECT: 'COLLECT',\n DO_NOT_COLLECT: 'DO_NOT_COLLECT',\n} as const;\n\nexport type Attribute = {\n name: string;\n approved_for_use?: boolean;\n collection_behavior?: (typeof CollectionBehaviors)[keyof typeof CollectionBehaviors];\n datatype: 'string';\n explicit: boolean;\n multiple_value: boolean;\n last_modified_date: Number;\n date_created: Number;\n values: Array<AttributeValue>;\n};\n\nexport const AttributesState = {\n SUCCESS: '100',\n} as const;\n\nexport const IngestType = {\n EXPLICIT: 'explicit',\n IMPLICIT: 'implicit',\n} as const;\n\nexport const IngestResponseState = {\n SUCCESS: '100',\n SYSTEM_ERROR: '101',\n INVALID_TYPE: '102',\n INVALID_IDENTIFIER: '103',\n INVALID_DATA: '104',\n INVALID_ATTRIBUTE_DEFINITION: '105',\n INVALID_META_DEFINITION: '106',\n UNAUTHENTICATED: '107',\n MISMATCHED_IDENTIFIER: '108',\n DISABLED_ATTRIBUTE_DEFINITION: '109',\n DO_NOT_COLLECT: '110',\n} as const;\n","import { WPGeo, getCookie } from '@washingtonpost/subs-sdk';\n\nexport const hasRequiredPrivacyCookies = () => {\n if (typeof window === 'undefined') {\n return false;\n }\n\n const wp_usp = getCookie('wp_usp');\n\n const countryCode = WPGeo()?.country_code;\n\n return !!(wp_usp && countryCode === 'US');\n};\n","import {\n ENDPOINTS,\n ResponseStatus,\n JSON_HEADERS,\n getCookie,\n} from '@washingtonpost/subs-sdk';\nimport {\n Attribute,\n CollectionBehaviors,\n IngestResponseState,\n IngestType,\n} from '../interfaces';\nimport { hasRequiredPrivacyCookies } from '../utils/hasRequiredPrivacyCookies';\n\nconst base = `${ENDPOINTS.base}/de/v1`;\n\nconst attributesCache: Record<string, any> = {};\nexport const getAttributes: GetAttributesType = async ({\n fieldName,\n}: {\n fieldName: string;\n}) => {\n if (attributesCache[fieldName]) {\n return attributesCache[fieldName];\n }\n\n const fieldNames = [fieldName];\n\n try {\n const url = new URL(`${base}/attributes`);\n url.searchParams.set('attributes', fieldNames.join(','));\n\n const data = await fetch(url.toString(), {\n credentials: 'include',\n headers: JSON_HEADERS,\n });\n const json = await data.json();\n\n if (data.ok && json.status === ResponseStatus.SUCCESS) {\n const attributes = json.attributes || [];\n attributesCache[fieldName] = attributes;\n return attributes;\n } else {\n return [];\n }\n } catch (e) {\n console.debug(e);\n return [];\n }\n};\n\ntype GetAttributesType = ({\n fieldName,\n}: {\n fieldName: string;\n}) => Promise<Attribute[]>;\n\nexport const ingest: IngestType = async ({\n submitData: { fieldName, value },\n type = IngestType.IMPLICIT,\n source,\n}) => {\n const url = `${base}/ingest`;\n\n const wapo_login_id = getCookie('wapo_login_id');\n\n if (!hasRequiredPrivacyCookies()) {\n throw new Error('does not satisfy cookie check');\n }\n\n let attributeInfo = attributesCache[fieldName];\n if (!attributeInfo) {\n attributeInfo = await getAttributes({ fieldName });\n }\n\n if (\n attributeInfo[0] &&\n attributeInfo[0].name === fieldName &&\n attributeInfo[0].collection_behavior === CollectionBehaviors.DO_NOT_COLLECT\n ) {\n throw new Error('do not collect');\n }\n\n const jucid = localStorage.getItem('uuid');\n const ga = getCookie('_ga');\n\n const payload = {\n jucid,\n ga,\n type,\n wapo_login_id, // TODO: move this to BE to read from cookie headers\n data: {\n [fieldName]: [value],\n },\n metadata: { source },\n };\n\n try {\n const response = await fetch(url, {\n method: 'POST',\n credentials: 'include',\n headers: JSON_HEADERS,\n body: JSON.stringify(payload),\n });\n\n const json = await response.json();\n\n return json;\n } catch (e) {\n console.debug(e);\n return null;\n }\n};\n\ntype IngestType = ({\n submitData: { fieldName, value },\n source,\n}: {\n submitData: {\n fieldName: string;\n value: string;\n };\n type?: (typeof IngestType)[keyof typeof IngestType];\n source: string;\n}) => Promise<{\n status: ResponseStatus;\n state: (typeof IngestResponseState)[keyof typeof IngestResponseState];\n} | null>;\n","import React, { useEffect, useState } from 'react';\nimport { Icon, Select, styled, theme } from '@washingtonpost/wpds-ui-kit';\nimport { useWindowSize } from '@washingtonpost/subs-hooks';\nimport { ChevronDown } from '@washingtonpost/wpds-assets';\n\ninterface IDropdownProps {\n id: string;\n label: string;\n values: Array<string>;\n required?: boolean;\n defaultValue?: string;\n onChange?: (value: string) => void;\n disabled?: boolean;\n}\n\nconst StyledMobileSelect = styled('select', {\n padding: '12px 16px 12px 6px',\n display: 'flex',\n justifyContent: 'space-between',\n width: '100%',\n backgroundColor: '$secondary',\n color: '$primary',\n fontFamily: '$meta',\n fontSize: '$100',\n fontWeight: '$light',\n lineHeight: '$125',\n paddingBlockRight: '$125',\n textOverflow: 'ellipsis',\n position: 'relative',\n borderColor: 'transparent',\n borderRightWidth: '10px',\n borderRightColor: 'transparent',\n appearance: 'none',\n '-webkit-appearance': 'none',\n '&:disabled': {\n backgroundColor: theme.colors.disabled,\n borderColor: theme.colors.disabled,\n color: theme.colors.onDisabled,\n cursor: 'not-allowed',\n },\n});\n\nconst StyledSelectWrapper = styled('div', {\n width: '100%',\n maxWidth: '380px',\n borderRadius: '$012',\n borderColor: '$subtle',\n borderStyle: 'solid',\n borderWidth: '1px',\n backgroundColor: '$secondary',\n position: 'relative',\n});\n\nconst StyledMobileOption = styled('option', {\n fontFamily: 'inherit',\n fontSize: 'inherit',\n color: 'inherit',\n});\n\n/**\n * Dropdown component. Uses wpds-ui-kit on desktop and native select on mobile.\n * @param {IDropdownProps} props The props.\n * @returns {React.ReactElement} The dropdown.\n */\nexport const Dropdown = ({\n id,\n label,\n values,\n required = false,\n defaultValue,\n onChange = () => {},\n disabled = false,\n}: IDropdownProps) => {\n const [answer, setAnswer] = useState<string>();\n const { isMobileSize } = useWindowSize();\n\n useEffect(() => {\n if (answer) onChange(answer);\n }, [answer]);\n\n const disabledProp = disabled ? { disabled: true } : {};\n\n // helps maintain state between WPDS and native dropdowns\n const defaultValueProp = answer\n ? { defaultValue: answer }\n : defaultValue\n ? { defaultValue }\n : {};\n\n const defaultValuePropMobile = (value: string) => {\n if (answer) {\n return value === answer ? { selected: true } : {};\n }\n return value === defaultValue ? { selected: true } : {};\n };\n\n return isMobileSize ? (\n <StyledSelectWrapper>\n <StyledMobileSelect\n id=\"\"\n required={required}\n onChange={(e) => setAnswer(e.target.value)}\n placeholder={label}\n {...disabledProp}\n >\n <label>{label}</label>\n <StyledMobileOption\n value=\"\"\n disabled\n selected\n style={{ color: '#666666' }}\n >\n {label}\n </StyledMobileOption>\n {values.map((value) => (\n <StyledMobileOption\n value={value}\n key={value}\n {...defaultValuePropMobile(value)}\n >\n {value}\n </StyledMobileOption>\n ))}\n </StyledMobileSelect>\n <Icon\n label=\"\"\n size=\"100\"\n fill={theme.colors['gray80']}\n style={{\n pointerEvents: 'none',\n position: 'absolute',\n right: '10px',\n top: '50%',\n transform: 'translateY(-50%)',\n }}\n >\n <ChevronDown style={{ position: 'absolute', right: '10px' }} />\n </Icon>\n </StyledSelectWrapper>\n ) : (\n <Select.Root\n onValueChange={(e) => setAnswer(e)}\n required={required}\n {...defaultValueProp}\n {...disabledProp}\n >\n <Select.Trigger data-test-id={`${id}-select-trigger`}>\n <Select.Label>{label}</Select.Label>\n <Select.Value />\n </Select.Trigger>\n <Select.Content\n css={{ zIndex: theme.zIndices.page }}\n data-test-id={`${id}-select-content`}\n >\n {values.map((value) => (\n <Select.Item value={value} key={value}>\n {value}\n </Select.Item>\n ))}\n </Select.Content>\n </Select.Root>\n );\n};\n","import React, { useState, useEffect } from 'react';\nimport { Select, styled } from '@washingtonpost/wpds-ui-kit';\nimport { Attribute, AttributeValue, IngestType } from '../../interfaces';\nimport { ENDPOINTS, ResponseStatus } from '@washingtonpost/subs-sdk';\nimport { useScript, ScriptStatus } from '@washingtonpost/subs-hooks';\nimport { Dropdown } from './Dropdown';\n\ninterface DESelectProps {\n source: string;\n fieldName: string;\n label?: string;\n dataDictionaryConfig?: Attribute;\n defaultValue?: string;\n disabled?: boolean;\n submit: boolean;\n onChange?: ({ value }: { value: string }) => void;\n onFinished?: ({\n isFinished,\n isError,\n }: {\n isFinished: boolean;\n isError: boolean;\n }) => void;\n valuesFilter?: (value: AttributeValue) => boolean;\n selectProps?: {\n root?: any;\n trigger?: any;\n label?: any;\n value?: any;\n content?: any;\n item?: any;\n };\n children?: React.ReactNode;\n}\n\nconst scriptSrc = `${\n ENDPOINTS.staticAssets === 'https://subscribe.washingtonpost.com/static'\n ? 'https://www.washingtonpost.com/subscribe/static/'\n : ENDPOINTS.staticAssets\n}/de-utils/twpdeu.min.js`;\n\nexport const DESelect: React.FC<DESelectProps> = ({\n source,\n fieldName,\n label,\n dataDictionaryConfig,\n defaultValue,\n disabled,\n submit,\n onChange = () => {},\n onFinished = () => {},\n valuesFilter = () => true,\n children,\n}) => {\n const [config, setConfig] = useState(dataDictionaryConfig);\n\n const [selected, setSelected] = useState('');\n\n const scriptStatus = useScript(scriptSrc);\n\n useEffect(() => {\n const fetchConfig = async () => {\n try {\n const config = await window?.__twpdeu?.getFieldConfigs({ fieldName });\n if (config) {\n setConfig(config[0]);\n } else {\n console.error('unable to get config', fieldName);\n }\n } catch (e) {\n console.warn('unable to get config', fieldName, e);\n }\n };\n\n if (scriptStatus === ScriptStatus.READY && !(children || config)) {\n fetchConfig();\n }\n }, [scriptStatus]);\n\n useEffect(() => {\n const submitSelected = async () => {\n try {\n // TODO: Log to GA?\n\n const result = await window?.__twpdeu?.push({\n submitData: { fieldName, value: selected },\n type: config?.explicit ? IngestType.EXPLICIT : IngestType.IMPLICIT,\n source,\n });\n\n const isError = result\n ? result.status !== ResponseStatus.SUCCESS\n : true;\n\n onFinished({\n isFinished: true,\n isError,\n });\n } catch (e) {\n onFinished({\n isFinished: false,\n isError: true,\n });\n }\n };\n\n if (scriptStatus === ScriptStatus.READY && submit && selected) {\n submitSelected();\n }\n }, [scriptStatus, submit]);\n\n const defaultValueProp = defaultValue && config ? { defaultValue } : {};\n\n const isLoading = !(children || config);\n\n const disabledProp = disabled || isLoading ? { disabled: true } : {};\n\n // sort and filter out archived values\n const values = config\n ? config.values\n .sort((a, b) => a.order - b.order)\n .filter((value) => value.archived !== true)\n .filter(valuesFilter)\n : [];\n\n return (\n <SelectWrapper>\n {children && (\n <Select.Root\n onValueChange={(e) => {\n setSelected(e);\n onChange({ value: e });\n }}\n {...defaultValueProp}\n {...disabledProp}\n >\n {children}\n </Select.Root>\n )}\n {!children && !config && (\n <Dropdown\n id={'loading'}\n label={'Loading...'}\n values={[]}\n disabled={true}\n />\n )}\n {!children && config && (\n <Dropdown\n id={config.name}\n label={label || config.name}\n onChange={(e) => {\n setSelected(e);\n onChange({ value: e });\n }}\n values={values.map((value) => value.name)}\n defaultValue={defaultValue}\n disabled={disabled}\n />\n )}\n </SelectWrapper>\n );\n};\n\nconst SelectWrapper = styled('div', {\n boxSizing: 'border-box',\n display: 'flex',\n marginBottom: '$100',\n flexDirection: 'column',\n '& button': {\n padding: '1px 6px',\n },\n '& *': { boxSizing: 'border-box' },\n});\n"],"names":["CollectionBehaviors","COLLECT","DO_NOT_COLLECT","AttributesState","SUCCESS","IngestType","EXPLICIT","IMPLICIT","IngestResponseState","SYSTEM_ERROR","INVALID_TYPE","INVALID_IDENTIFIER","INVALID_DATA","INVALID_ATTRIBUTE_DEFINITION","INVALID_META_DEFINITION","UNAUTHENTICATED","MISMATCHED_IDENTIFIER","DISABLED_ATTRIBUTE_DEFINITION","hasRequiredPrivacyCookies","window","wp_usp","getCookie","countryCode","_WPGeo","WPGeo","country_code","base","ENDPOINTS","attributesCache","getAttributes","_ref","fieldName","fieldNames","url","URL","searchParams","set","join","data","fetch","toString","credentials","headers","JSON_HEADERS","json","ok","status","ResponseStatus","attributes","e","console","debug","ingest","_ref2","submitData","value","type","source","wapo_login_id","Error","attributeInfo","name","collection_behavior","jucid","localStorage","getItem","ga","payload","metadata","response","method","body","JSON","stringify","StyledMobileSelect","styled","padding","display","justifyContent","width","backgroundColor","color","fontFamily","fontSize","fontWeight","lineHeight","paddingBlockRight","textOverflow","position","borderColor","borderRightWidth","borderRightColor","appearance","theme","colors","disabled","onDisabled","cursor","StyledSelectWrapper","maxWidth","borderRadius","borderStyle","borderWidth","StyledMobileOption","Dropdown","id","label","values","required","defaultValue","onChange","answer","setAnswer","useState","isMobileSize","useWindowSize","useEffect","disabledProp","defaultValueProp","defaultValuePropMobile","selected","React","target","placeholder","style","map","key","Icon","size","fill","pointerEvents","right","top","transform","ChevronDown","Select","Root","onValueChange","Trigger","Label","Value","Content","css","zIndex","zIndices","page","Item","scriptSrc","staticAssets","DESelect","dataDictionaryConfig","submit","onFinished","valuesFilter","children","config","setConfig","setSelected","scriptStatus","useScript","fetchConfig","_window","__twpdeu","getFieldConfigs","error","warn","ScriptStatus","READY","submitSelected","_window2","result","push","explicit","isError","isFinished","isLoading","sort","a","b","order","filter","archived","SelectWrapper","boxSizing","marginBottom","flexDirection"],"mappings":";;;;;;;;;;;;;MAQaA,mBAAmB,GAAG;EACjCC,OAAO,EAAE,SAAS;EAClBC,cAAc,EAAE;;MAeLC,eAAe,GAAG;EAC7BC,OAAO,EAAE;;MAGEC,UAAU,GAAG;EACxBC,QAAQ,EAAE,UAAU;EACpBC,QAAQ,EAAE;;MAGCC,mBAAmB,GAAG;EACjCJ,OAAO,EAAE,KAAK;EACdK,YAAY,EAAE,KAAK;EACnBC,YAAY,EAAE,KAAK;EACnBC,kBAAkB,EAAE,KAAK;EACzBC,YAAY,EAAE,KAAK;EACnBC,4BAA4B,EAAE,KAAK;EACnCC,uBAAuB,EAAE,KAAK;EAC9BC,eAAe,EAAE,KAAK;EACtBC,qBAAqB,EAAE,KAAK;EAC5BC,6BAA6B,EAAE,KAAK;EACpCf,cAAc,EAAE;;;MC3CLgB,yBAAyB,GAAGA;;EACvC,IAAI,OAAOC,MAAM,KAAK,WAAW,EAAE;IACjC,OAAO,KAAK;;EAGd,MAAMC,MAAM,GAAGC,iBAAS,CAAC,QAAQ,CAAC;EAElC,MAAMC,WAAW,IAAAC,MAAA,GAAGC,aAAK,EAAE,cAAAD,MAAA,uBAAPA,MAAA,CAASE,YAAY;EAEzC,OAAO,CAAC,EAAEL,MAAM,IAAIE,WAAW,KAAK,IAAI,CAAC;AAC3C,CAAC;;ACED,MAAMI,IAAI,MAAMC,iBAAS,CAACD,YAAY;AAEtC,MAAME,eAAe,GAAwB,EAAE;AAC/C,MAAaC,aAAa,GAAsB,MAAAC,IAAA;MAAO;IACrDC;GAGD,GAAAD,IAAA;EACC,IAAIF,eAAe,CAACG,SAAS,CAAC,EAAE;IAC9B,OAAOH,eAAe,CAACG,SAAS,CAAC;;EAGnC,MAAMC,UAAU,GAAG,CAACD,SAAS,CAAC;EAE9B,IAAI;IACF,MAAME,GAAG,GAAG,IAAIC,GAAG,IAAI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,YAAY;IACnBC,MAAM,EAAE,EAAE;IACVZ,QAAQ,EAAE;IAEb,EACA,CAAC2D,QAAQ,IAAIC,MAAM,IAClBlC,6BAACjB,QAAQ;IACPC,EAAE,EAAEkD,MAAM,CAAC9F,IAAI;IACf6C,KAAK,EAAEA,KAAK,IAAIiD,MAAM,CAAC9F,IAAI;IAC3BiD,QAAQ,EAAG7D,CAAC;MACV4G,WAAW,CAAC5G,CAAC,CAAC;MACd6D,QAAQ,CAAC;QAAEvD,KAAK,EAAEN;OAAG,CAAC;KACvB;IACD0D,MAAM,EAAEA,MAAM,CAACkB,GAAG,CAAEtE,KAAK,IAAKA,KAAK,CAACM,IAAI,CAAC;IACzCgD,YAAY,EAAEA,YAAY;IAC1Bd,QAAQ,EAAEA;IAEb,CACa;AAEpB,CAAC;AAED,MAAMuF,aAAa,gBAAG3G,gBAAM,CAAC,KAAK,EAAE;EAClC4G,SAAS,EAAE,YAAY;EACvB1G,OAAO,EAAE,MAAM;EACf2G,YAAY,EAAE,MAAM;EACpBC,aAAa,EAAE,QAAQ;EACvB,UAAU,EAAE;IACV7G,OAAO,EAAE;GACV;EACD,KAAK,EAAE;IAAE2G,SAAS,EAAE;;CACrB,CAAC;;;;;;;;;;;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("@washingtonpost/subs-sdk"),o=require("react"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("@washingtonpost/subs-sdk"),o=require("react"),a=(e=o)&&"object"==typeof e&&"default"in e?e.default:e,i=require("@washingtonpost/wpds-ui-kit"),s=require("@washingtonpost/subs-hooks"),l=require("@washingtonpost/wpds-assets");const r={COLLECT:"COLLECT",DO_NOT_COLLECT:"DO_NOT_COLLECT"},n={EXPLICIT:"explicit",IMPLICIT:"implicit"},d=()=>{var e;if("undefined"==typeof window)return!1;const o=t.getCookie("wp_usp"),a=null===(e=t.WPGeo())||void 0===e?void 0:e.country_code;return!(!o||"US"!==a)},c=t.ENDPOINTS.base+"/de/v1",u={},p=async e=>{let{fieldName:o}=e;if(u[o])return u[o];const a=[o];try{const e=new URL(c+"/attributes");e.searchParams.set("attributes",a.join(","));const i=await fetch(e.toString(),{credentials:"include",headers:t.JSON_HEADERS}),s=await i.json();if(i.ok&&s.status===t.ResponseStatus.SUCCESS){const e=s.attributes||[];return u[o]=e,e}return[]}catch(e){return console.debug(e),[]}},b=i.styled("select",{padding:"12px 16px 12px 6px",display:"flex",justifyContent:"space-between",width:"100%",backgroundColor:"$secondary",color:"$primary",fontFamily:"$meta",fontSize:"$100",fontWeight:"$light",lineHeight:"$125",paddingBlockRight:"$125",textOverflow:"ellipsis",position:"relative",borderColor:"transparent",borderRightWidth:"10px",borderRightColor:"transparent",appearance:"none","-webkit-appearance":"none","&:disabled":{backgroundColor:i.theme.colors.disabled,borderColor:i.theme.colors.disabled,color:i.theme.colors.onDisabled,cursor:"not-allowed"}}),E=i.styled("div",{width:"100%",maxWidth:"380px",borderRadius:"$012",borderColor:"$subtle",borderStyle:"solid",borderWidth:"1px",backgroundColor:"$secondary",position:"relative"}),g=i.styled("option",{fontFamily:"inherit",fontSize:"inherit",color:"inherit"}),h=e=>{let{id:t,label:r,values:n,required:d=!1,defaultValue:c,onChange:u=(()=>{}),disabled:p=!1}=e;const[h,m]=o.useState(),{isMobileSize:S}=s.useWindowSize();o.useEffect(()=>{h&&u(h)},[h]);const I=p?{disabled:!0}:{},f=h?{defaultValue:h}:c?{defaultValue:c}:{},C=e=>h?e===h?{selected:!0}:{}:e===c?{selected:!0}:{};return S?a.createElement(E,null,a.createElement(b,{id:"",required:d,onChange:e=>m(e.target.value),placeholder:r,...I},a.createElement("label",null,r),a.createElement(g,{value:"",disabled:!0,selected:!0,style:{color:"#666666"}},r),n.map(e=>a.createElement(g,{value:e,key:e,...C(e)},e))),a.createElement(i.Icon,{label:"",size:"100",fill:i.theme.colors.gray80,style:{pointerEvents:"none",position:"absolute",right:"10px",top:"50%",transform:"translateY(-50%)"}},a.createElement(l.ChevronDown,{style:{position:"absolute",right:"10px"}}))):a.createElement(i.Select.Root,{onValueChange:e=>m(e),required:d,...f,...I},a.createElement(i.Select.Trigger,{"data-test-id":t+"-select-trigger"},a.createElement(i.Select.Label,null,r),a.createElement(i.Select.Value,null)),a.createElement(i.Select.Content,{css:{zIndex:i.theme.zIndices.page},"data-test-id":t+"-select-content"},n.map(e=>a.createElement(i.Select.Item,{value:e,key:e},e))))},m=("https://subscribe.washingtonpost.com/static"===t.ENDPOINTS.staticAssets?"https://www.washingtonpost.com/subscribe/static/":t.ENDPOINTS.staticAssets)+"/de-utils/twpdeu.min.js",S=i.styled("div",{boxSizing:"border-box",display:"flex",marginBottom:"$100",flexDirection:"column","& button":{padding:"1px 6px"},"& *":{boxSizing:"border-box"}});exports.AttributesState={SUCCESS:"100"},exports.CollectionBehaviors=r,exports.DESelect=e=>{let{source:l,fieldName:r,label:d,dataDictionaryConfig:c,defaultValue:u,disabled:p,submit:b,onChange:E=(()=>{}),onFinished:g=(()=>{}),valuesFilter:I=(()=>!0),children:f}=e;const[C,w]=o.useState(c),[y,T]=o.useState(""),v=s.useScript(m);o.useEffect(()=>{v!==s.ScriptStatus.READY||f||C||(async()=>{try{var e;const t=await(null===(e=window)||void 0===e||null===(e=e.__twpdeu)||void 0===e?void 0:e.getFieldConfigs({fieldName:r}));t?w(t[0]):console.error("unable to get config",r)}catch(e){console.warn("unable to get config",r,e)}})()},[v]),o.useEffect(()=>{v===s.ScriptStatus.READY&&b&&y&&(async()=>{try{var e;const o=await(null===(e=window)||void 0===e||null===(e=e.__twpdeu)||void 0===e?void 0:e.push({submitData:{fieldName:r,value:y},type:null!=C&&C.explicit?n.EXPLICIT:n.IMPLICIT,source:l}));g({isFinished:!0,isError:!o||o.status!==t.ResponseStatus.SUCCESS})}catch(e){g({isFinished:!1,isError:!0})}})()},[v,b]);const _=u&&C?{defaultValue:u}:{},N=p||!f&&!C?{disabled:!0}:{},D=C?C.values.sort((e,t)=>e.order-t.order).filter(e=>!0!==e.archived).filter(I):[];return a.createElement(S,null,f&&a.createElement(i.Select.Root,{onValueChange:e=>{T(e),E({value:e})},..._,...N},f),!f&&!C&&a.createElement(h,{id:"loading",label:"Loading...",values:[],disabled:!0}),!f&&C&&a.createElement(h,{id:C.name,label:d||C.name,onChange:e=>{T(e),E({value:e})},values:D.map(e=>e.name),defaultValue:u,disabled:p}))},exports.IngestResponseState={SUCCESS:"100",SYSTEM_ERROR:"101",INVALID_TYPE:"102",INVALID_IDENTIFIER:"103",INVALID_DATA:"104",INVALID_ATTRIBUTE_DEFINITION:"105",INVALID_META_DEFINITION:"106",UNAUTHENTICATED:"107",MISMATCHED_IDENTIFIER:"108",DISABLED_ATTRIBUTE_DEFINITION:"109",DO_NOT_COLLECT:"110"},exports.IngestType=n,exports.getAttributes=p,exports.hasRequiredPrivacyCookies=d,exports.ingest=async e=>{let{submitData:{fieldName:o,value:a},type:i=n.IMPLICIT,source:s}=e;const l=c+"/ingest",b=t.getCookie("wapo_login_id");if(!d())throw new Error("does not satisfy cookie check");let E=u[o];if(E||(E=await p({fieldName:o})),E[0]&&E[0].name===o&&E[0].collection_behavior===r.DO_NOT_COLLECT)throw new Error("do not collect");const g={jucid:localStorage.getItem("uuid"),ga:t.getCookie("_ga"),type:i,wapo_login_id:b,data:{[o]:[a]},metadata:{source:s}};try{const e=await fetch(l,{method:"POST",credentials:"include",headers:t.JSON_HEADERS,body:JSON.stringify(g)});return await e.json()}catch(e){return console.debug(e),null}};
|
|
2
2
|
//# sourceMappingURL=subs-de-inputs.cjs.production.min.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subs-de-inputs.cjs.production.min.js","sources":["../src/interfaces/index.ts","../src/utils/hasRequiredPrivacyCookies.ts","../src/services/dataEnrichment.ts","../src/components/DESelect/index.tsx"],"sourcesContent":["export type AttributeValue = {\n name: string;\n date_created: Number;\n last_modified_date: Number;\n archived: boolean;\n order: number;\n};\n\nexport const CollectionBehaviors = {\n COLLECT: 'COLLECT',\n DO_NOT_COLLECT: 'DO_NOT_COLLECT',\n} as const;\n\nexport type Attribute = {\n name: string;\n approved_for_use?: boolean;\n collection_behavior?: (typeof CollectionBehaviors)[keyof typeof CollectionBehaviors];\n datatype: 'string';\n explicit: boolean;\n multiple_value: boolean;\n last_modified_date: Number;\n date_created: Number;\n values: Array<AttributeValue>;\n};\n\nexport const AttributesState = {\n SUCCESS: '100',\n} as const;\n\nexport const IngestType = {\n EXPLICIT: 'explicit',\n IMPLICIT: 'implicit',\n} as const;\n\nexport const IngestResponseState = {\n SUCCESS: '100',\n SYSTEM_ERROR: '101',\n INVALID_TYPE: '102',\n INVALID_IDENTIFIER: '103',\n INVALID_DATA: '104',\n INVALID_ATTRIBUTE_DEFINITION: '105',\n INVALID_META_DEFINITION: '106',\n UNAUTHENTICATED: '107',\n MISMATCHED_IDENTIFIER: '108',\n DISABLED_ATTRIBUTE_DEFINITION: '109',\n DO_NOT_COLLECT: '110',\n} as const;\n","import { WPGeo, getCookie } from '@washingtonpost/subs-sdk';\n\nexport const hasRequiredPrivacyCookies = () => {\n if (typeof window === 'undefined') {\n return false;\n }\n\n const wp_usp = getCookie('wp_usp');\n\n const countryCode = WPGeo()?.country_code;\n\n return !!(wp_usp && countryCode === 'US');\n};\n","import {\n ENDPOINTS,\n ResponseStatus,\n JSON_HEADERS,\n getCookie,\n} from '@washingtonpost/subs-sdk';\nimport {\n Attribute,\n CollectionBehaviors,\n IngestResponseState,\n IngestType,\n} from '../interfaces';\nimport { hasRequiredPrivacyCookies } from '../utils/hasRequiredPrivacyCookies';\n\nconst DEBUG_FLAG = 'f_de_debug';\n\nconst base = `${ENDPOINTS.base}/de/v1`;\n\nconst attributesCache: Record<string, any> = {};\nexport const getAttributes: GetAttributesType = async ({\n fieldName,\n}: {\n fieldName: string;\n}) => {\n const debug = window.location.search.includes(DEBUG_FLAG);\n\n if (debug) {\n console.debug('getAttributes()');\n }\n\n if (attributesCache[fieldName]) {\n if (debug) console.debug('getAttributes() > return cached info');\n return attributesCache[fieldName];\n }\n\n const fieldNames = [fieldName];\n\n try {\n const url = new URL(`${base}/attributes`);\n url.searchParams.set('attributes', fieldNames.join(','));\n\n if (debug) console.debug(`getAttributes() > ${url.toString()}`);\n\n const data = await fetch(url.toString(), {\n credentials: 'include',\n headers: JSON_HEADERS,\n });\n const json = await data.json();\n\n if (data.ok && json.status === ResponseStatus.SUCCESS) {\n const attributes = json.attributes || [];\n attributesCache[fieldName] = attributes;\n return attributes;\n } else {\n return [];\n }\n } catch (e) {\n console.debug(e);\n return [];\n }\n};\n\ntype GetAttributesType = ({\n fieldName,\n}: {\n fieldName: string;\n}) => Promise<Attribute[]>;\n\nexport const ingest: IngestType = async ({\n submitData: { fieldName, value },\n type = IngestType.IMPLICIT,\n source,\n}) => {\n const debug = window.location.search.includes(DEBUG_FLAG);\n\n if (debug) {\n console.debug('ingest()');\n }\n\n const url = `${base}/ingest`;\n\n const wapo_login_id = getCookie('wapo_login_id');\n\n if (!hasRequiredPrivacyCookies()) {\n if (debug) console.debug('ingest() > hasRequiredPrivacyCookies falsy');\n throw new Error('does not satisfy cookie check');\n }\n\n let attributeInfo = attributesCache[fieldName];\n if (!attributeInfo) {\n if (debug) console.debug('ingest() > fetch attribute info');\n attributeInfo = await getAttributes({ fieldName });\n } else {\n if (debug) console.debug('ingest() > use cached attribute info');\n }\n\n if (\n attributeInfo[0] &&\n attributeInfo[0].name === fieldName &&\n attributeInfo[0].collection_behavior === CollectionBehaviors.DO_NOT_COLLECT\n ) {\n if (debug) console.debug('ingest() > do not collect');\n throw new Error('do not collect');\n }\n\n const jucid = localStorage.getItem('uuid');\n const ga = getCookie('_ga');\n\n const payload = {\n jucid,\n ga,\n type,\n wapo_login_id, // TODO: move this to BE to read from cookie headers\n data: {\n [fieldName]: [value],\n },\n metadata: { source },\n };\n\n try {\n const response = await fetch(url, {\n method: 'POST',\n credentials: 'include',\n headers: JSON_HEADERS,\n body: JSON.stringify(payload),\n });\n\n const json = await response.json();\n\n return json;\n } catch (e) {\n console.debug(e);\n return null;\n }\n};\n\ntype IngestType = ({\n submitData: { fieldName, value },\n source,\n}: {\n submitData: {\n fieldName: string;\n value: string;\n };\n type?: (typeof IngestType)[keyof typeof IngestType];\n source: string;\n}) => Promise<{\n status: ResponseStatus;\n state: (typeof IngestResponseState)[keyof typeof IngestResponseState];\n} | null>;\n","import React, { useState, useEffect } from 'react';\nimport { Select, styled, theme } from '@washingtonpost/wpds-ui-kit';\nimport { Attribute, AttributeValue, IngestType } from '../../interfaces';\nimport { ENDPOINTS, ResponseStatus } from '@washingtonpost/subs-sdk';\nimport { useScript, ScriptStatus } from '@washingtonpost/subs-hooks';\n\ninterface DESelectProps {\n source: string;\n fieldName: string;\n label?: string;\n dataDictionaryConfig?: Attribute;\n defaultValue?: string;\n disabled?: boolean;\n submit: boolean;\n onChange?: ({ value }: { value: string }) => void;\n onFinished?: ({\n isFinished,\n isError,\n }: {\n isFinished: boolean;\n isError: boolean;\n }) => void;\n valuesFilter?: (value: AttributeValue) => boolean;\n selectProps?: {\n root?: any;\n trigger?: any;\n label?: any;\n value?: any;\n content?: any;\n item?: any;\n };\n children?: React.ReactNode;\n}\n\nconst scriptSrc = `${\n ENDPOINTS.staticAssets === 'https://subscribe.washingtonpost.com/static'\n ? 'https://www.washingtonpost.com/subscribe/static/'\n : ENDPOINTS.staticAssets\n}/de-utils/twpdeu.min.js`;\n\nexport const DESelect: React.FC<DESelectProps> = ({\n source,\n fieldName,\n label,\n dataDictionaryConfig,\n defaultValue,\n disabled,\n submit,\n onChange = () => {},\n onFinished = () => {},\n valuesFilter = () => true,\n children,\n}) => {\n const [config, setConfig] = useState(dataDictionaryConfig);\n\n const [selected, setSelected] = useState('');\n\n const scriptStatus = useScript(scriptSrc);\n\n useEffect(() => {\n const fetchConfig = async () => {\n try {\n const config = await window?.__twpdeu?.getFieldConfigs({ fieldName });\n if (config) {\n setConfig(config[0]);\n } else {\n console.error('unable to get config', fieldName);\n }\n } catch (e) {\n console.warn('unable to get config', fieldName, e);\n }\n };\n\n if (scriptStatus === ScriptStatus.READY && !(children || config)) {\n fetchConfig();\n }\n }, [scriptStatus]);\n\n useEffect(() => {\n const submitSelected = async () => {\n try {\n // TODO: Log to GA?\n\n const result = await window?.__twpdeu?.push({\n submitData: { fieldName, value: selected },\n type: config?.explicit ? IngestType.EXPLICIT : IngestType.IMPLICIT,\n source,\n });\n\n const isError = result\n ? result.status !== ResponseStatus.SUCCESS\n : true;\n\n onFinished({\n isFinished: true,\n isError,\n });\n } catch (e) {\n onFinished({\n isFinished: false,\n isError: true,\n });\n }\n };\n\n if (scriptStatus === ScriptStatus.READY && submit && selected) {\n submitSelected();\n }\n }, [scriptStatus, submit]);\n\n const defaultValueProp = defaultValue && config ? { defaultValue } : {};\n\n const isLoading = !(children || config);\n\n const disabledProp = disabled || isLoading ? { disabled: true } : {};\n\n // sort and filter out archived values\n const values = config\n ? config.values\n .sort((a, b) => a.order - b.order)\n .filter((value) => value.archived !== true)\n .filter(valuesFilter)\n : [];\n\n return (\n <SelectWrapper>\n <Select.Root\n onValueChange={(e: string) => {\n onChange({ value: e });\n setSelected(e);\n }}\n {...defaultValueProp}\n {...disabledProp}\n >\n {children ? children : null}\n {!children && !config && (\n <>\n <Select.Trigger data-test-id={`select-trigger-loading`}>\n <Select.Label>{label || 'loading...'}</Select.Label>\n <Select.Value />\n </Select.Trigger>\n </>\n )}\n {!children && config && (\n <>\n <Select.Trigger data-test-id={`${config.name}-select-trigger`}>\n <Select.Label>{label || config.name}</Select.Label>\n <Select.Value />\n </Select.Trigger>\n <Select.Content\n css={{ zIndex: theme.zIndices.page }}\n data-test-id={`${config.name}-select-content`}\n >\n {values.map((value) => (\n <Select.Item value={value.name} key={value.name}>\n {value.name}\n </Select.Item>\n ))}\n </Select.Content>\n </>\n )}\n </Select.Root>\n </SelectWrapper>\n );\n};\n\nconst SelectWrapper = styled('div', {\n boxSizing: 'border-box',\n display: 'flex',\n marginBottom: '$100',\n flexDirection: 'column',\n '& button': {\n padding: '1px 6px',\n },\n '& *': { boxSizing: 'border-box' },\n});\n"],"names":["CollectionBehaviors","COLLECT","DO_NOT_COLLECT","IngestType","EXPLICIT","IMPLICIT","hasRequiredPrivacyCookies","window","wp_usp","getCookie","countryCode","_WPGeo","WPGeo","country_code","base","ENDPOINTS","attributesCache","getAttributes","async","fieldName","_ref","debug","location","search","includes","console","fieldNames","url","URL","searchParams","set","join","toString","data","fetch","credentials","headers","JSON_HEADERS","json","ok","status","ResponseStatus","SUCCESS","attributes","e","scriptSrc","staticAssets","SelectWrapper","styled","boxSizing","display","marginBottom","flexDirection","& button","padding","& *","source","label","dataDictionaryConfig","defaultValue","disabled","submit","onChange","onFinished","valuesFilter","children","config","setConfig","useState","selected","setSelected","scriptStatus","useScript","useEffect","ScriptStatus","READY","_window","__twpdeu","getFieldConfigs","error","warn","fetchConfig","_window2","result","push","submitData","value","type","explicit","isFinished","isError","submitSelected","defaultValueProp","disabledProp","values","sort","a","b","order","filter","archived","React","Select","Root","onValueChange","Trigger","Label","Value","name","Content","css","zIndex","theme","zIndices","page","map","Item","key","SYSTEM_ERROR","INVALID_TYPE","INVALID_IDENTIFIER","INVALID_DATA","INVALID_ATTRIBUTE_DEFINITION","INVALID_META_DEFINITION","UNAUTHENTICATED","MISMATCHED_IDENTIFIER","DISABLED_ATTRIBUTE_DEFINITION","_ref2","wapo_login_id","Error","attributeInfo","collection_behavior","payload","jucid","localStorage","getItem","ga","[object Object]","metadata","response","method","body","JSON","stringify"],"mappings":"iRAQaA,EAAsB,CACjCC,QAAS,UACTC,eAAgB,kBAmBLC,EAAa,CACxBC,SAAU,WACVC,SAAU,YC7BCC,EAA4BA,WACvC,GAAsB,oBAAXC,OACT,OAAO,EAGT,MAAMC,EAASC,YAAU,UAEnBC,UAAWC,EAAGC,qBAAOD,SAAPA,EAASE,aAE7B,SAAUL,GAA0B,OAAhBE,ICKhBI,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AAAA,IAGd,IACE,MAAMmF,QAAiBzG,MAAMP,EAAK,CAChCiH,OAAQ,OACRzG,YAAa,UACbC,QAASC,eACTwG,KAAMC,KAAKC,UAAUX,KAKvB,aAFmBO,EAASrG,OAG5B,MAAOM,GAEP,OADAnB,QAAQJ,MAAMuB,GACP"}
|
|
1
|
+
{"version":3,"file":"subs-de-inputs.cjs.production.min.js","sources":["../src/interfaces/index.ts","../src/utils/hasRequiredPrivacyCookies.ts","../src/services/dataEnrichment.ts","../src/components/DESelect/Dropdown.tsx","../src/components/DESelect/index.tsx"],"sourcesContent":["export type AttributeValue = {\n name: string;\n date_created: Number;\n last_modified_date: Number;\n archived: boolean;\n order: number;\n};\n\nexport const CollectionBehaviors = {\n COLLECT: 'COLLECT',\n DO_NOT_COLLECT: 'DO_NOT_COLLECT',\n} as const;\n\nexport type Attribute = {\n name: string;\n approved_for_use?: boolean;\n collection_behavior?: (typeof CollectionBehaviors)[keyof typeof CollectionBehaviors];\n datatype: 'string';\n explicit: boolean;\n multiple_value: boolean;\n last_modified_date: Number;\n date_created: Number;\n values: Array<AttributeValue>;\n};\n\nexport const AttributesState = {\n SUCCESS: '100',\n} as const;\n\nexport const IngestType = {\n EXPLICIT: 'explicit',\n IMPLICIT: 'implicit',\n} as const;\n\nexport const IngestResponseState = {\n SUCCESS: '100',\n SYSTEM_ERROR: '101',\n INVALID_TYPE: '102',\n INVALID_IDENTIFIER: '103',\n INVALID_DATA: '104',\n INVALID_ATTRIBUTE_DEFINITION: '105',\n INVALID_META_DEFINITION: '106',\n UNAUTHENTICATED: '107',\n MISMATCHED_IDENTIFIER: '108',\n DISABLED_ATTRIBUTE_DEFINITION: '109',\n DO_NOT_COLLECT: '110',\n} as const;\n","import { WPGeo, getCookie } from '@washingtonpost/subs-sdk';\n\nexport const hasRequiredPrivacyCookies = () => {\n if (typeof window === 'undefined') {\n return false;\n }\n\n const wp_usp = getCookie('wp_usp');\n\n const countryCode = WPGeo()?.country_code;\n\n return !!(wp_usp && countryCode === 'US');\n};\n","import {\n ENDPOINTS,\n ResponseStatus,\n JSON_HEADERS,\n getCookie,\n} from '@washingtonpost/subs-sdk';\nimport {\n Attribute,\n CollectionBehaviors,\n IngestResponseState,\n IngestType,\n} from '../interfaces';\nimport { hasRequiredPrivacyCookies } from '../utils/hasRequiredPrivacyCookies';\n\nconst base = `${ENDPOINTS.base}/de/v1`;\n\nconst attributesCache: Record<string, any> = {};\nexport const getAttributes: GetAttributesType = async ({\n fieldName,\n}: {\n fieldName: string;\n}) => {\n if (attributesCache[fieldName]) {\n return attributesCache[fieldName];\n }\n\n const fieldNames = [fieldName];\n\n try {\n const url = new URL(`${base}/attributes`);\n url.searchParams.set('attributes', fieldNames.join(','));\n\n const data = await fetch(url.toString(), {\n credentials: 'include',\n headers: JSON_HEADERS,\n });\n const json = await data.json();\n\n if (data.ok && json.status === ResponseStatus.SUCCESS) {\n const attributes = json.attributes || [];\n attributesCache[fieldName] = attributes;\n return attributes;\n } else {\n return [];\n }\n } catch (e) {\n console.debug(e);\n return [];\n }\n};\n\ntype GetAttributesType = ({\n fieldName,\n}: {\n fieldName: string;\n}) => Promise<Attribute[]>;\n\nexport const ingest: IngestType = async ({\n submitData: { fieldName, value },\n type = IngestType.IMPLICIT,\n source,\n}) => {\n const url = `${base}/ingest`;\n\n const wapo_login_id = getCookie('wapo_login_id');\n\n if (!hasRequiredPrivacyCookies()) {\n throw new Error('does not satisfy cookie check');\n }\n\n let attributeInfo = attributesCache[fieldName];\n if (!attributeInfo) {\n attributeInfo = await getAttributes({ fieldName });\n }\n\n if (\n attributeInfo[0] &&\n attributeInfo[0].name === fieldName &&\n attributeInfo[0].collection_behavior === CollectionBehaviors.DO_NOT_COLLECT\n ) {\n throw new Error('do not collect');\n }\n\n const jucid = localStorage.getItem('uuid');\n const ga = getCookie('_ga');\n\n const payload = {\n jucid,\n ga,\n type,\n wapo_login_id, // TODO: move this to BE to read from cookie headers\n data: {\n [fieldName]: [value],\n },\n metadata: { source },\n };\n\n try {\n const response = await fetch(url, {\n method: 'POST',\n credentials: 'include',\n headers: JSON_HEADERS,\n body: JSON.stringify(payload),\n });\n\n const json = await response.json();\n\n return json;\n } catch (e) {\n console.debug(e);\n return null;\n }\n};\n\ntype IngestType = ({\n submitData: { fieldName, value },\n source,\n}: {\n submitData: {\n fieldName: string;\n value: string;\n };\n type?: (typeof IngestType)[keyof typeof IngestType];\n source: string;\n}) => Promise<{\n status: ResponseStatus;\n state: (typeof IngestResponseState)[keyof typeof IngestResponseState];\n} | null>;\n","import React, { useEffect, useState } from 'react';\nimport { Icon, Select, styled, theme } from '@washingtonpost/wpds-ui-kit';\nimport { useWindowSize } from '@washingtonpost/subs-hooks';\nimport { ChevronDown } from '@washingtonpost/wpds-assets';\n\ninterface IDropdownProps {\n id: string;\n label: string;\n values: Array<string>;\n required?: boolean;\n defaultValue?: string;\n onChange?: (value: string) => void;\n disabled?: boolean;\n}\n\nconst StyledMobileSelect = styled('select', {\n padding: '12px 16px 12px 6px',\n display: 'flex',\n justifyContent: 'space-between',\n width: '100%',\n backgroundColor: '$secondary',\n color: '$primary',\n fontFamily: '$meta',\n fontSize: '$100',\n fontWeight: '$light',\n lineHeight: '$125',\n paddingBlockRight: '$125',\n textOverflow: 'ellipsis',\n position: 'relative',\n borderColor: 'transparent',\n borderRightWidth: '10px',\n borderRightColor: 'transparent',\n appearance: 'none',\n '-webkit-appearance': 'none',\n '&:disabled': {\n backgroundColor: theme.colors.disabled,\n borderColor: theme.colors.disabled,\n color: theme.colors.onDisabled,\n cursor: 'not-allowed',\n },\n});\n\nconst StyledSelectWrapper = styled('div', {\n width: '100%',\n maxWidth: '380px',\n borderRadius: '$012',\n borderColor: '$subtle',\n borderStyle: 'solid',\n borderWidth: '1px',\n backgroundColor: '$secondary',\n position: 'relative',\n});\n\nconst StyledMobileOption = styled('option', {\n fontFamily: 'inherit',\n fontSize: 'inherit',\n color: 'inherit',\n});\n\n/**\n * Dropdown component. Uses wpds-ui-kit on desktop and native select on mobile.\n * @param {IDropdownProps} props The props.\n * @returns {React.ReactElement} The dropdown.\n */\nexport const Dropdown = ({\n id,\n label,\n values,\n required = false,\n defaultValue,\n onChange = () => {},\n disabled = false,\n}: IDropdownProps) => {\n const [answer, setAnswer] = useState<string>();\n const { isMobileSize } = useWindowSize();\n\n useEffect(() => {\n if (answer) onChange(answer);\n }, [answer]);\n\n const disabledProp = disabled ? { disabled: true } : {};\n\n // helps maintain state between WPDS and native dropdowns\n const defaultValueProp = answer\n ? { defaultValue: answer }\n : defaultValue\n ? { defaultValue }\n : {};\n\n const defaultValuePropMobile = (value: string) => {\n if (answer) {\n return value === answer ? { selected: true } : {};\n }\n return value === defaultValue ? { selected: true } : {};\n };\n\n return isMobileSize ? (\n <StyledSelectWrapper>\n <StyledMobileSelect\n id=\"\"\n required={required}\n onChange={(e) => setAnswer(e.target.value)}\n placeholder={label}\n {...disabledProp}\n >\n <label>{label}</label>\n <StyledMobileOption\n value=\"\"\n disabled\n selected\n style={{ color: '#666666' }}\n >\n {label}\n </StyledMobileOption>\n {values.map((value) => (\n <StyledMobileOption\n value={value}\n key={value}\n {...defaultValuePropMobile(value)}\n >\n {value}\n </StyledMobileOption>\n ))}\n </StyledMobileSelect>\n <Icon\n label=\"\"\n size=\"100\"\n fill={theme.colors['gray80']}\n style={{\n pointerEvents: 'none',\n position: 'absolute',\n right: '10px',\n top: '50%',\n transform: 'translateY(-50%)',\n }}\n >\n <ChevronDown style={{ position: 'absolute', right: '10px' }} />\n </Icon>\n </StyledSelectWrapper>\n ) : (\n <Select.Root\n onValueChange={(e) => setAnswer(e)}\n required={required}\n {...defaultValueProp}\n {...disabledProp}\n >\n <Select.Trigger data-test-id={`${id}-select-trigger`}>\n <Select.Label>{label}</Select.Label>\n <Select.Value />\n </Select.Trigger>\n <Select.Content\n css={{ zIndex: theme.zIndices.page }}\n data-test-id={`${id}-select-content`}\n >\n {values.map((value) => (\n <Select.Item value={value} key={value}>\n {value}\n </Select.Item>\n ))}\n </Select.Content>\n </Select.Root>\n );\n};\n","import React, { useState, useEffect } from 'react';\nimport { Select, styled } from '@washingtonpost/wpds-ui-kit';\nimport { Attribute, AttributeValue, IngestType } from '../../interfaces';\nimport { ENDPOINTS, ResponseStatus } from '@washingtonpost/subs-sdk';\nimport { useScript, ScriptStatus } from '@washingtonpost/subs-hooks';\nimport { Dropdown } from './Dropdown';\n\ninterface DESelectProps {\n source: string;\n fieldName: string;\n label?: string;\n dataDictionaryConfig?: Attribute;\n defaultValue?: string;\n disabled?: boolean;\n submit: boolean;\n onChange?: ({ value }: { value: string }) => void;\n onFinished?: ({\n isFinished,\n isError,\n }: {\n isFinished: boolean;\n isError: boolean;\n }) => void;\n valuesFilter?: (value: AttributeValue) => boolean;\n selectProps?: {\n root?: any;\n trigger?: any;\n label?: any;\n value?: any;\n content?: any;\n item?: any;\n };\n children?: React.ReactNode;\n}\n\nconst scriptSrc = `${\n ENDPOINTS.staticAssets === 'https://subscribe.washingtonpost.com/static'\n ? 'https://www.washingtonpost.com/subscribe/static/'\n : ENDPOINTS.staticAssets\n}/de-utils/twpdeu.min.js`;\n\nexport const DESelect: React.FC<DESelectProps> = ({\n source,\n fieldName,\n label,\n dataDictionaryConfig,\n defaultValue,\n disabled,\n submit,\n onChange = () => {},\n onFinished = () => {},\n valuesFilter = () => true,\n children,\n}) => {\n const [config, setConfig] = useState(dataDictionaryConfig);\n\n const [selected, setSelected] = useState('');\n\n const scriptStatus = useScript(scriptSrc);\n\n useEffect(() => {\n const fetchConfig = async () => {\n try {\n const config = await window?.__twpdeu?.getFieldConfigs({ fieldName });\n if (config) {\n setConfig(config[0]);\n } else {\n console.error('unable to get config', fieldName);\n }\n } catch (e) {\n console.warn('unable to get config', fieldName, e);\n }\n };\n\n if (scriptStatus === ScriptStatus.READY && !(children || config)) {\n fetchConfig();\n }\n }, [scriptStatus]);\n\n useEffect(() => {\n const submitSelected = async () => {\n try {\n // TODO: Log to GA?\n\n const result = await window?.__twpdeu?.push({\n submitData: { fieldName, value: selected },\n type: config?.explicit ? IngestType.EXPLICIT : IngestType.IMPLICIT,\n source,\n });\n\n const isError = result\n ? result.status !== ResponseStatus.SUCCESS\n : true;\n\n onFinished({\n isFinished: true,\n isError,\n });\n } catch (e) {\n onFinished({\n isFinished: false,\n isError: true,\n });\n }\n };\n\n if (scriptStatus === ScriptStatus.READY && submit && selected) {\n submitSelected();\n }\n }, [scriptStatus, submit]);\n\n const defaultValueProp = defaultValue && config ? { defaultValue } : {};\n\n const isLoading = !(children || config);\n\n const disabledProp = disabled || isLoading ? { disabled: true } : {};\n\n // sort and filter out archived values\n const values = config\n ? config.values\n .sort((a, b) => a.order - b.order)\n .filter((value) => value.archived !== true)\n .filter(valuesFilter)\n : [];\n\n return (\n <SelectWrapper>\n {children && (\n <Select.Root\n onValueChange={(e) => {\n setSelected(e);\n onChange({ value: e });\n }}\n {...defaultValueProp}\n {...disabledProp}\n >\n {children}\n </Select.Root>\n )}\n {!children && !config && (\n <Dropdown\n id={'loading'}\n label={'Loading...'}\n values={[]}\n disabled={true}\n />\n )}\n {!children && config && (\n <Dropdown\n id={config.name}\n label={label || config.name}\n onChange={(e) => {\n setSelected(e);\n onChange({ value: e });\n }}\n values={values.map((value) => value.name)}\n defaultValue={defaultValue}\n disabled={disabled}\n />\n )}\n </SelectWrapper>\n );\n};\n\nconst SelectWrapper = styled('div', {\n boxSizing: 'border-box',\n display: 'flex',\n marginBottom: '$100',\n flexDirection: 'column',\n '& button': {\n padding: '1px 6px',\n },\n '& *': { boxSizing: 'border-box' },\n});\n"],"names":["CollectionBehaviors","COLLECT","DO_NOT_COLLECT","IngestType","EXPLICIT","IMPLICIT","hasRequiredPrivacyCookies","window","wp_usp","getCookie","countryCode","_WPGeo","WPGeo","country_code","base","ENDPOINTS","attributesCache","getAttributes","async","fieldName","_ref","fieldNames","url","URL","searchParams","set","join","data","fetch","toString","credentials","headers","JSON_HEADERS","json","ok","status","ResponseStatus","SUCCESS","attributes","e","console","debug","StyledMobileSelect","styled","padding","display","justifyContent","width","backgroundColor","color","fontFamily","fontSize","fontWeight","lineHeight","paddingBlockRight","textOverflow","position","borderColor","borderRightWidth","borderRightColor","appearance","-webkit-appearance","&:disabled","theme","colors","disabled","onDisabled","cursor","StyledSelectWrapper","maxWidth","borderRadius","borderStyle","borderWidth","StyledMobileOption","Dropdown","id","label","values","required","defaultValue","onChange","answer","setAnswer","useState","isMobileSize","useWindowSize","useEffect","disabledProp","defaultValueProp","defaultValuePropMobile","value","selected","React","target","placeholder","style","map","key","Icon","size","fill","pointerEvents","right","top","transform","ChevronDown","Select","Root","onValueChange","Trigger","Label","Value","Content","css","zIndex","zIndices","page","Item","scriptSrc","staticAssets","SelectWrapper","boxSizing","marginBottom","flexDirection","& button","& *","source","dataDictionaryConfig","submit","onFinished","valuesFilter","children","config","setConfig","setSelected","scriptStatus","useScript","ScriptStatus","READY","_window","__twpdeu","getFieldConfigs","error","warn","fetchConfig","_window2","result","push","submitData","type","explicit","isFinished","isError","submitSelected","sort","a","b","order","filter","archived","name","SYSTEM_ERROR","INVALID_TYPE","INVALID_IDENTIFIER","INVALID_DATA","INVALID_ATTRIBUTE_DEFINITION","INVALID_META_DEFINITION","UNAUTHENTICATED","MISMATCHED_IDENTIFIER","DISABLED_ATTRIBUTE_DEFINITION","_ref2","wapo_login_id","Error","attributeInfo","collection_behavior","payload","jucid","localStorage","getItem","ga","[object Object]","metadata","response","method","body","JSON","stringify"],"mappings":"0TAQaA,EAAsB,CACjCC,QAAS,UACTC,eAAgB,kBAmBLC,EAAa,CACxBC,SAAU,WACVC,SAAU,YC7BCC,EAA4BA,WACvC,GAAsB,oBAAXC,OACT,OAAO,EAGT,MAAMC,EAASC,YAAU,UAEnBC,UAAWC,EAAGC,qBAAOD,SAAPA,EAASE,aAE7B,SAAUL,GAA0B,OAAhBE,ICGhBI,EAAUC,YAAUD,cAEpBE,EAAuC,GAChCC,EAAmCC,MAAAA,QAAOC,UACrDA,GAGDC,EACC,GAAIJ,EAAgBG,GACl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QAAQ,QAKjCC,GAJS1K,YAAU,OAKnB4I,KAAAA,EACAsB,cAAAA,EACAhJ,KAAM,CACJyJ,CAACjK,GAAY,CAACuE,IAEhB2F,SAAU,CAAEvD,OAAAA,IAGd,IACE,MAAMwD,QAAiB1J,MAAMN,EAAK,CAChCiK,OAAQ,OACRzJ,YAAa,UACbC,QAASC,eACTwJ,KAAMC,KAAKC,UAAUX,KAKvB,aAFmBO,EAASrJ,OAG5B,MAAOM,GAEP,OADAC,QAAQC,MAAMF,GACP"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { getCookie, WPGeo, JSON_HEADERS, ResponseStatus, ENDPOINTS } from '@washingtonpost/subs-sdk';
|
|
2
2
|
import React, { useState, useEffect } from 'react';
|
|
3
|
-
import {
|
|
4
|
-
import { useScript, ScriptStatus } from '@washingtonpost/subs-hooks';
|
|
3
|
+
import { Icon, theme, Select, styled } from '@washingtonpost/wpds-ui-kit';
|
|
4
|
+
import { useWindowSize, useScript, ScriptStatus } from '@washingtonpost/subs-hooks';
|
|
5
|
+
import { ChevronDown } from '@washingtonpost/wpds-assets';
|
|
5
6
|
|
|
6
7
|
const CollectionBehaviors = {
|
|
7
8
|
COLLECT: 'COLLECT',
|
|
@@ -38,26 +39,19 @@ const hasRequiredPrivacyCookies = () => {
|
|
|
38
39
|
return !!(wp_usp && countryCode === 'US');
|
|
39
40
|
};
|
|
40
41
|
|
|
41
|
-
const DEBUG_FLAG = 'f_de_debug';
|
|
42
42
|
const base = `${ENDPOINTS.base}/de/v1`;
|
|
43
43
|
const attributesCache = {};
|
|
44
44
|
const getAttributes = async _ref => {
|
|
45
45
|
let {
|
|
46
46
|
fieldName
|
|
47
47
|
} = _ref;
|
|
48
|
-
const debug = window.location.search.includes(DEBUG_FLAG);
|
|
49
|
-
if (debug) {
|
|
50
|
-
console.debug('getAttributes()');
|
|
51
|
-
}
|
|
52
48
|
if (attributesCache[fieldName]) {
|
|
53
|
-
if (debug) console.debug('getAttributes() > return cached info');
|
|
54
49
|
return attributesCache[fieldName];
|
|
55
50
|
}
|
|
56
51
|
const fieldNames = [fieldName];
|
|
57
52
|
try {
|
|
58
53
|
const url = new URL(`${base}/attributes`);
|
|
59
54
|
url.searchParams.set('attributes', fieldNames.join(','));
|
|
60
|
-
if (debug) console.debug(`getAttributes() > ${url.toString()}`);
|
|
61
55
|
const data = await fetch(url.toString(), {
|
|
62
56
|
credentials: 'include',
|
|
63
57
|
headers: JSON_HEADERS
|
|
@@ -84,27 +78,18 @@ const ingest = async _ref2 => {
|
|
|
84
78
|
type = IngestType.IMPLICIT,
|
|
85
79
|
source
|
|
86
80
|
} = _ref2;
|
|
87
|
-
const debug = window.location.search.includes(DEBUG_FLAG);
|
|
88
|
-
if (debug) {
|
|
89
|
-
console.debug('ingest()');
|
|
90
|
-
}
|
|
91
81
|
const url = `${base}/ingest`;
|
|
92
82
|
const wapo_login_id = getCookie('wapo_login_id');
|
|
93
83
|
if (!hasRequiredPrivacyCookies()) {
|
|
94
|
-
if (debug) console.debug('ingest() > hasRequiredPrivacyCookies falsy');
|
|
95
84
|
throw new Error('does not satisfy cookie check');
|
|
96
85
|
}
|
|
97
86
|
let attributeInfo = attributesCache[fieldName];
|
|
98
87
|
if (!attributeInfo) {
|
|
99
|
-
if (debug) console.debug('ingest() > fetch attribute info');
|
|
100
88
|
attributeInfo = await getAttributes({
|
|
101
89
|
fieldName
|
|
102
90
|
});
|
|
103
|
-
} else {
|
|
104
|
-
if (debug) console.debug('ingest() > use cached attribute info');
|
|
105
91
|
}
|
|
106
92
|
if (attributeInfo[0] && attributeInfo[0].name === fieldName && attributeInfo[0].collection_behavior === CollectionBehaviors.DO_NOT_COLLECT) {
|
|
107
|
-
if (debug) console.debug('ingest() > do not collect');
|
|
108
93
|
throw new Error('do not collect');
|
|
109
94
|
}
|
|
110
95
|
const jucid = localStorage.getItem('uuid');
|
|
@@ -136,6 +121,139 @@ const ingest = async _ref2 => {
|
|
|
136
121
|
}
|
|
137
122
|
};
|
|
138
123
|
|
|
124
|
+
const StyledMobileSelect = /*#__PURE__*/styled('select', {
|
|
125
|
+
padding: '12px 16px 12px 6px',
|
|
126
|
+
display: 'flex',
|
|
127
|
+
justifyContent: 'space-between',
|
|
128
|
+
width: '100%',
|
|
129
|
+
backgroundColor: '$secondary',
|
|
130
|
+
color: '$primary',
|
|
131
|
+
fontFamily: '$meta',
|
|
132
|
+
fontSize: '$100',
|
|
133
|
+
fontWeight: '$light',
|
|
134
|
+
lineHeight: '$125',
|
|
135
|
+
paddingBlockRight: '$125',
|
|
136
|
+
textOverflow: 'ellipsis',
|
|
137
|
+
position: 'relative',
|
|
138
|
+
borderColor: 'transparent',
|
|
139
|
+
borderRightWidth: '10px',
|
|
140
|
+
borderRightColor: 'transparent',
|
|
141
|
+
appearance: 'none',
|
|
142
|
+
'-webkit-appearance': 'none',
|
|
143
|
+
'&:disabled': {
|
|
144
|
+
backgroundColor: theme.colors.disabled,
|
|
145
|
+
borderColor: theme.colors.disabled,
|
|
146
|
+
color: theme.colors.onDisabled,
|
|
147
|
+
cursor: 'not-allowed'
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
const StyledSelectWrapper = /*#__PURE__*/styled('div', {
|
|
151
|
+
width: '100%',
|
|
152
|
+
maxWidth: '380px',
|
|
153
|
+
borderRadius: '$012',
|
|
154
|
+
borderColor: '$subtle',
|
|
155
|
+
borderStyle: 'solid',
|
|
156
|
+
borderWidth: '1px',
|
|
157
|
+
backgroundColor: '$secondary',
|
|
158
|
+
position: 'relative'
|
|
159
|
+
});
|
|
160
|
+
const StyledMobileOption = /*#__PURE__*/styled('option', {
|
|
161
|
+
fontFamily: 'inherit',
|
|
162
|
+
fontSize: 'inherit',
|
|
163
|
+
color: 'inherit'
|
|
164
|
+
});
|
|
165
|
+
/**
|
|
166
|
+
* Dropdown component. Uses wpds-ui-kit on desktop and native select on mobile.
|
|
167
|
+
* @param {IDropdownProps} props The props.
|
|
168
|
+
* @returns {React.ReactElement} The dropdown.
|
|
169
|
+
*/
|
|
170
|
+
const Dropdown = _ref => {
|
|
171
|
+
let {
|
|
172
|
+
id,
|
|
173
|
+
label,
|
|
174
|
+
values,
|
|
175
|
+
required = false,
|
|
176
|
+
defaultValue,
|
|
177
|
+
onChange = () => {},
|
|
178
|
+
disabled = false
|
|
179
|
+
} = _ref;
|
|
180
|
+
const [answer, setAnswer] = useState();
|
|
181
|
+
const {
|
|
182
|
+
isMobileSize
|
|
183
|
+
} = useWindowSize();
|
|
184
|
+
useEffect(() => {
|
|
185
|
+
if (answer) onChange(answer);
|
|
186
|
+
}, [answer]);
|
|
187
|
+
const disabledProp = disabled ? {
|
|
188
|
+
disabled: true
|
|
189
|
+
} : {};
|
|
190
|
+
// helps maintain state between WPDS and native dropdowns
|
|
191
|
+
const defaultValueProp = answer ? {
|
|
192
|
+
defaultValue: answer
|
|
193
|
+
} : defaultValue ? {
|
|
194
|
+
defaultValue
|
|
195
|
+
} : {};
|
|
196
|
+
const defaultValuePropMobile = value => {
|
|
197
|
+
if (answer) {
|
|
198
|
+
return value === answer ? {
|
|
199
|
+
selected: true
|
|
200
|
+
} : {};
|
|
201
|
+
}
|
|
202
|
+
return value === defaultValue ? {
|
|
203
|
+
selected: true
|
|
204
|
+
} : {};
|
|
205
|
+
};
|
|
206
|
+
return isMobileSize ? React.createElement(StyledSelectWrapper, null, React.createElement(StyledMobileSelect, {
|
|
207
|
+
id: "",
|
|
208
|
+
required: required,
|
|
209
|
+
onChange: e => setAnswer(e.target.value),
|
|
210
|
+
placeholder: label,
|
|
211
|
+
...disabledProp
|
|
212
|
+
}, React.createElement("label", null, label), React.createElement(StyledMobileOption, {
|
|
213
|
+
value: "",
|
|
214
|
+
disabled: true,
|
|
215
|
+
selected: true,
|
|
216
|
+
style: {
|
|
217
|
+
color: '#666666'
|
|
218
|
+
}
|
|
219
|
+
}, label), values.map(value => React.createElement(StyledMobileOption, {
|
|
220
|
+
value: value,
|
|
221
|
+
key: value,
|
|
222
|
+
...defaultValuePropMobile(value)
|
|
223
|
+
}, value))), React.createElement(Icon, {
|
|
224
|
+
label: "",
|
|
225
|
+
size: "100",
|
|
226
|
+
fill: theme.colors['gray80'],
|
|
227
|
+
style: {
|
|
228
|
+
pointerEvents: 'none',
|
|
229
|
+
position: 'absolute',
|
|
230
|
+
right: '10px',
|
|
231
|
+
top: '50%',
|
|
232
|
+
transform: 'translateY(-50%)'
|
|
233
|
+
}
|
|
234
|
+
}, React.createElement(ChevronDown, {
|
|
235
|
+
style: {
|
|
236
|
+
position: 'absolute',
|
|
237
|
+
right: '10px'
|
|
238
|
+
}
|
|
239
|
+
}))) : React.createElement(Select.Root, {
|
|
240
|
+
onValueChange: e => setAnswer(e),
|
|
241
|
+
required: required,
|
|
242
|
+
...defaultValueProp,
|
|
243
|
+
...disabledProp
|
|
244
|
+
}, React.createElement(Select.Trigger, {
|
|
245
|
+
"data-test-id": `${id}-select-trigger`
|
|
246
|
+
}, React.createElement(Select.Label, null, label), React.createElement(Select.Value, null)), React.createElement(Select.Content, {
|
|
247
|
+
css: {
|
|
248
|
+
zIndex: theme.zIndices.page
|
|
249
|
+
},
|
|
250
|
+
"data-test-id": `${id}-select-content`
|
|
251
|
+
}, values.map(value => React.createElement(Select.Item, {
|
|
252
|
+
value: value,
|
|
253
|
+
key: value
|
|
254
|
+
}, value))));
|
|
255
|
+
};
|
|
256
|
+
|
|
139
257
|
const scriptSrc = `${ENDPOINTS.staticAssets === 'https://subscribe.washingtonpost.com/static' ? 'https://www.washingtonpost.com/subscribe/static/' : ENDPOINTS.staticAssets}/de-utils/twpdeu.min.js`;
|
|
140
258
|
const DESelect = _ref => {
|
|
141
259
|
let {
|
|
@@ -212,28 +330,33 @@ const DESelect = _ref => {
|
|
|
212
330
|
} : {};
|
|
213
331
|
// sort and filter out archived values
|
|
214
332
|
const values = config ? config.values.sort((a, b) => a.order - b.order).filter(value => value.archived !== true).filter(valuesFilter) : [];
|
|
215
|
-
return React.createElement(SelectWrapper, null, React.createElement(Select.Root, {
|
|
333
|
+
return React.createElement(SelectWrapper, null, children && React.createElement(Select.Root, {
|
|
216
334
|
onValueChange: e => {
|
|
335
|
+
setSelected(e);
|
|
217
336
|
onChange({
|
|
218
337
|
value: e
|
|
219
338
|
});
|
|
220
|
-
setSelected(e);
|
|
221
339
|
},
|
|
222
340
|
...defaultValueProp,
|
|
223
341
|
...disabledProp
|
|
224
|
-
}, children
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
342
|
+
}, children), !children && !config && React.createElement(Dropdown, {
|
|
343
|
+
id: 'loading',
|
|
344
|
+
label: 'Loading...',
|
|
345
|
+
values: [],
|
|
346
|
+
disabled: true
|
|
347
|
+
}), !children && config && React.createElement(Dropdown, {
|
|
348
|
+
id: config.name,
|
|
349
|
+
label: label || config.name,
|
|
350
|
+
onChange: e => {
|
|
351
|
+
setSelected(e);
|
|
352
|
+
onChange({
|
|
353
|
+
value: e
|
|
354
|
+
});
|
|
231
355
|
},
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
}, value.name))))));
|
|
356
|
+
values: values.map(value => value.name),
|
|
357
|
+
defaultValue: defaultValue,
|
|
358
|
+
disabled: disabled
|
|
359
|
+
}));
|
|
237
360
|
};
|
|
238
361
|
const SelectWrapper = /*#__PURE__*/styled('div', {
|
|
239
362
|
boxSizing: 'border-box',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subs-de-inputs.esm.js","sources":["../src/interfaces/index.ts","../src/utils/hasRequiredPrivacyCookies.ts","../src/services/dataEnrichment.ts","../src/components/DESelect/index.tsx"],"sourcesContent":["export type AttributeValue = {\n name: string;\n date_created: Number;\n last_modified_date: Number;\n archived: boolean;\n order: number;\n};\n\nexport const CollectionBehaviors = {\n COLLECT: 'COLLECT',\n DO_NOT_COLLECT: 'DO_NOT_COLLECT',\n} as const;\n\nexport type Attribute = {\n name: string;\n approved_for_use?: boolean;\n collection_behavior?: (typeof CollectionBehaviors)[keyof typeof CollectionBehaviors];\n datatype: 'string';\n explicit: boolean;\n multiple_value: boolean;\n last_modified_date: Number;\n date_created: Number;\n values: Array<AttributeValue>;\n};\n\nexport const AttributesState = {\n SUCCESS: '100',\n} as const;\n\nexport const IngestType = {\n EXPLICIT: 'explicit',\n IMPLICIT: 'implicit',\n} as const;\n\nexport const IngestResponseState = {\n SUCCESS: '100',\n SYSTEM_ERROR: '101',\n INVALID_TYPE: '102',\n INVALID_IDENTIFIER: '103',\n INVALID_DATA: '104',\n INVALID_ATTRIBUTE_DEFINITION: '105',\n INVALID_META_DEFINITION: '106',\n UNAUTHENTICATED: '107',\n MISMATCHED_IDENTIFIER: '108',\n DISABLED_ATTRIBUTE_DEFINITION: '109',\n DO_NOT_COLLECT: '110',\n} as const;\n","import { WPGeo, getCookie } from '@washingtonpost/subs-sdk';\n\nexport const hasRequiredPrivacyCookies = () => {\n if (typeof window === 'undefined') {\n return false;\n }\n\n const wp_usp = getCookie('wp_usp');\n\n const countryCode = WPGeo()?.country_code;\n\n return !!(wp_usp && countryCode === 'US');\n};\n","import {\n ENDPOINTS,\n ResponseStatus,\n JSON_HEADERS,\n getCookie,\n} from '@washingtonpost/subs-sdk';\nimport {\n Attribute,\n CollectionBehaviors,\n IngestResponseState,\n IngestType,\n} from '../interfaces';\nimport { hasRequiredPrivacyCookies } from '../utils/hasRequiredPrivacyCookies';\n\nconst DEBUG_FLAG = 'f_de_debug';\n\nconst base = `${ENDPOINTS.base}/de/v1`;\n\nconst attributesCache: Record<string, any> = {};\nexport const getAttributes: GetAttributesType = async ({\n fieldName,\n}: {\n fieldName: string;\n}) => {\n const debug = window.location.search.includes(DEBUG_FLAG);\n\n if (debug) {\n console.debug('getAttributes()');\n }\n\n if (attributesCache[fieldName]) {\n if (debug) console.debug('getAttributes() > return cached info');\n return attributesCache[fieldName];\n }\n\n const fieldNames = [fieldName];\n\n try {\n const url = new URL(`${base}/attributes`);\n url.searchParams.set('attributes', fieldNames.join(','));\n\n if (debug) console.debug(`getAttributes() > ${url.toString()}`);\n\n const data = await fetch(url.toString(), {\n credentials: 'include',\n headers: JSON_HEADERS,\n });\n const json = await data.json();\n\n if (data.ok && json.status === ResponseStatus.SUCCESS) {\n const attributes = json.attributes || [];\n attributesCache[fieldName] = attributes;\n return attributes;\n } else {\n return [];\n }\n } catch (e) {\n console.debug(e);\n return [];\n }\n};\n\ntype GetAttributesType = ({\n fieldName,\n}: {\n fieldName: string;\n}) => Promise<Attribute[]>;\n\nexport const ingest: IngestType = async ({\n submitData: { fieldName, value },\n type = IngestType.IMPLICIT,\n source,\n}) => {\n const debug = window.location.search.includes(DEBUG_FLAG);\n\n if (debug) {\n console.debug('ingest()');\n }\n\n const url = `${base}/ingest`;\n\n const wapo_login_id = getCookie('wapo_login_id');\n\n if (!hasRequiredPrivacyCookies()) {\n if (debug) console.debug('ingest() > hasRequiredPrivacyCookies falsy');\n throw new Error('does not satisfy cookie check');\n }\n\n let attributeInfo = attributesCache[fieldName];\n if (!attributeInfo) {\n if (debug) console.debug('ingest() > fetch attribute info');\n attributeInfo = await getAttributes({ fieldName });\n } else {\n if (debug) console.debug('ingest() > use cached attribute info');\n }\n\n if (\n attributeInfo[0] &&\n attributeInfo[0].name === fieldName &&\n attributeInfo[0].collection_behavior === CollectionBehaviors.DO_NOT_COLLECT\n ) {\n if (debug) console.debug('ingest() > do not collect');\n throw new Error('do not collect');\n }\n\n const jucid = localStorage.getItem('uuid');\n const ga = getCookie('_ga');\n\n const payload = {\n jucid,\n ga,\n type,\n wapo_login_id, // TODO: move this to BE to read from cookie headers\n data: {\n [fieldName]: [value],\n },\n metadata: { source },\n };\n\n try {\n const response = await fetch(url, {\n method: 'POST',\n credentials: 'include',\n headers: JSON_HEADERS,\n body: JSON.stringify(payload),\n });\n\n const json = await response.json();\n\n return json;\n } catch (e) {\n console.debug(e);\n return null;\n }\n};\n\ntype IngestType = ({\n submitData: { fieldName, value },\n source,\n}: {\n submitData: {\n fieldName: string;\n value: string;\n };\n type?: (typeof IngestType)[keyof typeof IngestType];\n source: string;\n}) => Promise<{\n status: ResponseStatus;\n state: (typeof IngestResponseState)[keyof typeof IngestResponseState];\n} | null>;\n","import React, { useState, useEffect } from 'react';\nimport { Select, styled, theme } from '@washingtonpost/wpds-ui-kit';\nimport { Attribute, AttributeValue, IngestType } from '../../interfaces';\nimport { ENDPOINTS, ResponseStatus } from '@washingtonpost/subs-sdk';\nimport { useScript, ScriptStatus } from '@washingtonpost/subs-hooks';\n\ninterface DESelectProps {\n source: string;\n fieldName: string;\n label?: string;\n dataDictionaryConfig?: Attribute;\n defaultValue?: string;\n disabled?: boolean;\n submit: boolean;\n onChange?: ({ value }: { value: string }) => void;\n onFinished?: ({\n isFinished,\n isError,\n }: {\n isFinished: boolean;\n isError: boolean;\n }) => void;\n valuesFilter?: (value: AttributeValue) => boolean;\n selectProps?: {\n root?: any;\n trigger?: any;\n label?: any;\n value?: any;\n content?: any;\n item?: any;\n };\n children?: React.ReactNode;\n}\n\nconst scriptSrc = `${\n ENDPOINTS.staticAssets === 'https://subscribe.washingtonpost.com/static'\n ? 'https://www.washingtonpost.com/subscribe/static/'\n : ENDPOINTS.staticAssets\n}/de-utils/twpdeu.min.js`;\n\nexport const DESelect: React.FC<DESelectProps> = ({\n source,\n fieldName,\n label,\n dataDictionaryConfig,\n defaultValue,\n disabled,\n submit,\n onChange = () => {},\n onFinished = () => {},\n valuesFilter = () => true,\n children,\n}) => {\n const [config, setConfig] = useState(dataDictionaryConfig);\n\n const [selected, setSelected] = useState('');\n\n const scriptStatus = useScript(scriptSrc);\n\n useEffect(() => {\n const fetchConfig = async () => {\n try {\n const config = await window?.__twpdeu?.getFieldConfigs({ fieldName });\n if (config) {\n setConfig(config[0]);\n } else {\n console.error('unable to get config', fieldName);\n }\n } catch (e) {\n console.warn('unable to get config', fieldName, e);\n }\n };\n\n if (scriptStatus === ScriptStatus.READY && !(children || config)) {\n fetchConfig();\n }\n }, [scriptStatus]);\n\n useEffect(() => {\n const submitSelected = async () => {\n try {\n // TODO: Log to GA?\n\n const result = await window?.__twpdeu?.push({\n submitData: { fieldName, value: selected },\n type: config?.explicit ? IngestType.EXPLICIT : IngestType.IMPLICIT,\n source,\n });\n\n const isError = result\n ? result.status !== ResponseStatus.SUCCESS\n : true;\n\n onFinished({\n isFinished: true,\n isError,\n });\n } catch (e) {\n onFinished({\n isFinished: false,\n isError: true,\n });\n }\n };\n\n if (scriptStatus === ScriptStatus.READY && submit && selected) {\n submitSelected();\n }\n }, [scriptStatus, submit]);\n\n const defaultValueProp = defaultValue && config ? { defaultValue } : {};\n\n const isLoading = !(children || config);\n\n const disabledProp = disabled || isLoading ? { disabled: true } : {};\n\n // sort and filter out archived values\n const values = config\n ? config.values\n .sort((a, b) => a.order - b.order)\n .filter((value) => value.archived !== true)\n .filter(valuesFilter)\n : [];\n\n return (\n <SelectWrapper>\n <Select.Root\n onValueChange={(e: string) => {\n onChange({ value: e });\n setSelected(e);\n }}\n {...defaultValueProp}\n {...disabledProp}\n >\n {children ? children : null}\n {!children && !config && (\n <>\n <Select.Trigger data-test-id={`select-trigger-loading`}>\n <Select.Label>{label || 'loading...'}</Select.Label>\n <Select.Value />\n </Select.Trigger>\n </>\n )}\n {!children && config && (\n <>\n <Select.Trigger data-test-id={`${config.name}-select-trigger`}>\n <Select.Label>{label || config.name}</Select.Label>\n <Select.Value />\n </Select.Trigger>\n <Select.Content\n css={{ zIndex: theme.zIndices.page }}\n data-test-id={`${config.name}-select-content`}\n >\n {values.map((value) => (\n <Select.Item value={value.name} key={value.name}>\n {value.name}\n </Select.Item>\n ))}\n </Select.Content>\n </>\n )}\n </Select.Root>\n </SelectWrapper>\n );\n};\n\nconst SelectWrapper = styled('div', {\n boxSizing: 'border-box',\n display: 'flex',\n marginBottom: '$100',\n flexDirection: 'column',\n '& button': {\n padding: '1px 6px',\n },\n '& *': { boxSizing: 'border-box' },\n});\n"],"names":["CollectionBehaviors","COLLECT","DO_NOT_COLLECT","AttributesState","SUCCESS","IngestType","EXPLICIT","IMPLICIT","IngestResponseState","SYSTEM_ERROR","INVALID_TYPE","INVALID_IDENTIFIER","INVALID_DATA","INVALID_ATTRIBUTE_DEFINITION","INVALID_META_DEFINITION","UNAUTHENTICATED","MISMATCHED_IDENTIFIER","DISABLED_ATTRIBUTE_DEFINITION","hasRequiredPrivacyCookies","window","wp_usp","getCookie","countryCode","_WPGeo","WPGeo","country_code","DEBUG_FLAG","base","ENDPOINTS","attributesCache","getAttributes","_ref","fieldName","debug","location","search","includes","console","fieldNames","url","URL","searchParams","set","join","toString","data","fetch","credentials","headers","JSON_HEADERS","json","ok","status","ResponseStatus","attributes","e","ingest","_ref2","submitData","value","type","source","wapo_login_id","Error","attributeInfo","name","collection_behavior","jucid","localStorage","getItem","ga","payload","metadata","response","method","body","JSON","stringify","scriptSrc","staticAssets","DESelect","label","dataDictionaryConfig","defaultValue","disabled","submit","onChange","onFinished","valuesFilter","children","config","setConfig","useState","selected","setSelected","scriptStatus","useScript","useEffect","fetchConfig","_window","__twpdeu","getFieldConfigs","error","warn","ScriptStatus","READY","submitSelected","_window2","result","push","explicit","isError","isFinished","defaultValueProp","isLoading","disabledProp","values","sort","a","b","order","filter","archived","React","SelectWrapper","Select","Root","onValueChange","Trigger","Label","Value","Content","css","zIndex","theme","zIndices","page","map","Item","key","styled","boxSizing","display","marginBottom","flexDirection","padding"],"mappings":";;;;;MAQaA,mBAAmB,GAAG;EACjCC,OAAO,EAAE,SAAS;EAClBC,cAAc,EAAE;;MAeLC,eAAe,GAAG;EAC7BC,OAAO,EAAE;;MAGEC,UAAU,GAAG;EACxBC,QAAQ,EAAE,UAAU;EACpBC,QAAQ,EAAE;;MAGCC,mBAAmB,GAAG;EACjCJ,OAAO,EAAE,KAAK;EACdK,YAAY,EAAE,KAAK;EACnBC,YAAY,EAAE,KAAK;EACnBC,kBAAkB,EAAE,KAAK;EACzBC,YAAY,EAAE,KAAK;EACnBC,4BAA4B,E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AAY,EAAE,MAAM;EACpBC,aAAa,EAAE,QAAQ;EACvB,UAAU,EAAE;IACVC,OAAO,EAAE;GACV;EACD,KAAK,EAAE;IAAEJ,SAAS,EAAE;;CACrB,CAAC;;;;"}
|
|
1
|
+
{"version":3,"file":"subs-de-inputs.esm.js","sources":["../src/interfaces/index.ts","../src/utils/hasRequiredPrivacyCookies.ts","../src/services/dataEnrichment.ts","../src/components/DESelect/Dropdown.tsx","../src/components/DESelect/index.tsx"],"sourcesContent":["export type AttributeValue = {\n name: string;\n date_created: Number;\n last_modified_date: Number;\n archived: boolean;\n order: number;\n};\n\nexport const CollectionBehaviors = {\n COLLECT: 'COLLECT',\n DO_NOT_COLLECT: 'DO_NOT_COLLECT',\n} as const;\n\nexport type Attribute = {\n name: string;\n approved_for_use?: boolean;\n collection_behavior?: (typeof CollectionBehaviors)[keyof typeof CollectionBehaviors];\n datatype: 'string';\n explicit: boolean;\n multiple_value: boolean;\n last_modified_date: Number;\n date_created: Number;\n values: Array<AttributeValue>;\n};\n\nexport const AttributesState = {\n SUCCESS: '100',\n} as const;\n\nexport const IngestType = {\n EXPLICIT: 'explicit',\n IMPLICIT: 'implicit',\n} as const;\n\nexport const IngestResponseState = {\n SUCCESS: '100',\n SYSTEM_ERROR: '101',\n INVALID_TYPE: '102',\n INVALID_IDENTIFIER: '103',\n INVALID_DATA: '104',\n INVALID_ATTRIBUTE_DEFINITION: '105',\n INVALID_META_DEFINITION: '106',\n UNAUTHENTICATED: '107',\n MISMATCHED_IDENTIFIER: '108',\n DISABLED_ATTRIBUTE_DEFINITION: '109',\n DO_NOT_COLLECT: '110',\n} as const;\n","import { WPGeo, getCookie } from '@washingtonpost/subs-sdk';\n\nexport const hasRequiredPrivacyCookies = () => {\n if (typeof window === 'undefined') {\n return false;\n }\n\n const wp_usp = getCookie('wp_usp');\n\n const countryCode = WPGeo()?.country_code;\n\n return !!(wp_usp && countryCode === 'US');\n};\n","import {\n ENDPOINTS,\n ResponseStatus,\n JSON_HEADERS,\n getCookie,\n} from '@washingtonpost/subs-sdk';\nimport {\n Attribute,\n CollectionBehaviors,\n IngestResponseState,\n IngestType,\n} from '../interfaces';\nimport { hasRequiredPrivacyCookies } from '../utils/hasRequiredPrivacyCookies';\n\nconst base = `${ENDPOINTS.base}/de/v1`;\n\nconst attributesCache: Record<string, any> = {};\nexport const getAttributes: GetAttributesType = async ({\n fieldName,\n}: {\n fieldName: string;\n}) => {\n if (attributesCache[fieldName]) {\n return attributesCache[fieldName];\n }\n\n const fieldNames = [fieldName];\n\n try {\n const url = new URL(`${base}/attributes`);\n url.searchParams.set('attributes', fieldNames.join(','));\n\n const data = await fetch(url.toString(), {\n credentials: 'include',\n headers: JSON_HEADERS,\n });\n const json = await data.json();\n\n if (data.ok && json.status === ResponseStatus.SUCCESS) {\n const attributes = json.attributes || [];\n attributesCache[fieldName] = attributes;\n return attributes;\n } else {\n return [];\n }\n } catch (e) {\n console.debug(e);\n return [];\n }\n};\n\ntype GetAttributesType = ({\n fieldName,\n}: {\n fieldName: string;\n}) => Promise<Attribute[]>;\n\nexport const ingest: IngestType = async ({\n submitData: { fieldName, value },\n type = IngestType.IMPLICIT,\n source,\n}) => {\n const url = `${base}/ingest`;\n\n const wapo_login_id = getCookie('wapo_login_id');\n\n if (!hasRequiredPrivacyCookies()) {\n throw new Error('does not satisfy cookie check');\n }\n\n let attributeInfo = attributesCache[fieldName];\n if (!attributeInfo) {\n attributeInfo = await getAttributes({ fieldName });\n }\n\n if (\n attributeInfo[0] &&\n attributeInfo[0].name === fieldName &&\n attributeInfo[0].collection_behavior === CollectionBehaviors.DO_NOT_COLLECT\n ) {\n throw new Error('do not collect');\n }\n\n const jucid = localStorage.getItem('uuid');\n const ga = getCookie('_ga');\n\n const payload = {\n jucid,\n ga,\n type,\n wapo_login_id, // TODO: move this to BE to read from cookie headers\n data: {\n [fieldName]: [value],\n },\n metadata: { source },\n };\n\n try {\n const response = await fetch(url, {\n method: 'POST',\n credentials: 'include',\n headers: JSON_HEADERS,\n body: JSON.stringify(payload),\n });\n\n const json = await response.json();\n\n return json;\n } catch (e) {\n console.debug(e);\n return null;\n }\n};\n\ntype IngestType = ({\n submitData: { fieldName, value },\n source,\n}: {\n submitData: {\n fieldName: string;\n value: string;\n };\n type?: (typeof IngestType)[keyof typeof IngestType];\n source: string;\n}) => Promise<{\n status: ResponseStatus;\n state: (typeof IngestResponseState)[keyof typeof IngestResponseState];\n} | null>;\n","import React, { useEffect, useState } from 'react';\nimport { Icon, Select, styled, theme } from '@washingtonpost/wpds-ui-kit';\nimport { useWindowSize } from '@washingtonpost/subs-hooks';\nimport { ChevronDown } from '@washingtonpost/wpds-assets';\n\ninterface IDropdownProps {\n id: string;\n label: string;\n values: Array<string>;\n required?: boolean;\n defaultValue?: string;\n onChange?: (value: string) => void;\n disabled?: boolean;\n}\n\nconst StyledMobileSelect = styled('select', {\n padding: '12px 16px 12px 6px',\n display: 'flex',\n justifyContent: 'space-between',\n width: '100%',\n backgroundColor: '$secondary',\n color: '$primary',\n fontFamily: '$meta',\n fontSize: '$100',\n fontWeight: '$light',\n lineHeight: '$125',\n paddingBlockRight: '$125',\n textOverflow: 'ellipsis',\n position: 'relative',\n borderColor: 'transparent',\n borderRightWidth: '10px',\n borderRightColor: 'transparent',\n appearance: 'none',\n '-webkit-appearance': 'none',\n '&:disabled': {\n backgroundColor: theme.colors.disabled,\n borderColor: theme.colors.disabled,\n color: theme.colors.onDisabled,\n cursor: 'not-allowed',\n },\n});\n\nconst StyledSelectWrapper = styled('div', {\n width: '100%',\n maxWidth: '380px',\n borderRadius: '$012',\n borderColor: '$subtle',\n borderStyle: 'solid',\n borderWidth: '1px',\n backgroundColor: '$secondary',\n position: 'relative',\n});\n\nconst StyledMobileOption = styled('option', {\n fontFamily: 'inherit',\n fontSize: 'inherit',\n color: 'inherit',\n});\n\n/**\n * Dropdown component. Uses wpds-ui-kit on desktop and native select on mobile.\n * @param {IDropdownProps} props The props.\n * @returns {React.ReactElement} The dropdown.\n */\nexport const Dropdown = ({\n id,\n label,\n values,\n required = false,\n defaultValue,\n onChange = () => {},\n disabled = false,\n}: IDropdownProps) => {\n const [answer, setAnswer] = useState<string>();\n const { isMobileSize } = useWindowSize();\n\n useEffect(() => {\n if (answer) onChange(answer);\n }, [answer]);\n\n const disabledProp = disabled ? { disabled: true } : {};\n\n // helps maintain state between WPDS and native dropdowns\n const defaultValueProp = answer\n ? { defaultValue: answer }\n : defaultValue\n ? { defaultValue }\n : {};\n\n const defaultValuePropMobile = (value: string) => {\n if (answer) {\n return value === answer ? { selected: true } : {};\n }\n return value === defaultValue ? { selected: true } : {};\n };\n\n return isMobileSize ? (\n <StyledSelectWrapper>\n <StyledMobileSelect\n id=\"\"\n required={required}\n onChange={(e) => setAnswer(e.target.value)}\n placeholder={label}\n {...disabledProp}\n >\n <label>{label}</label>\n <StyledMobileOption\n value=\"\"\n disabled\n selected\n style={{ color: '#666666' }}\n >\n {label}\n </StyledMobileOption>\n {values.map((value) => (\n <StyledMobileOption\n value={value}\n key={value}\n {...defaultValuePropMobile(value)}\n >\n {value}\n </StyledMobileOption>\n ))}\n </StyledMobileSelect>\n <Icon\n label=\"\"\n size=\"100\"\n fill={theme.colors['gray80']}\n style={{\n pointerEvents: 'none',\n position: 'absolute',\n right: '10px',\n top: '50%',\n transform: 'translateY(-50%)',\n }}\n >\n <ChevronDown style={{ position: 'absolute', right: '10px' }} />\n </Icon>\n </StyledSelectWrapper>\n ) : (\n <Select.Root\n onValueChange={(e) => setAnswer(e)}\n required={required}\n {...defaultValueProp}\n {...disabledProp}\n >\n <Select.Trigger data-test-id={`${id}-select-trigger`}>\n <Select.Label>{label}</Select.Label>\n <Select.Value />\n </Select.Trigger>\n <Select.Content\n css={{ zIndex: theme.zIndices.page }}\n data-test-id={`${id}-select-content`}\n >\n {values.map((value) => (\n <Select.Item value={value} key={value}>\n {value}\n </Select.Item>\n ))}\n </Select.Content>\n </Select.Root>\n );\n};\n","import React, { useState, useEffect } from 'react';\nimport { Select, styled } from '@washingtonpost/wpds-ui-kit';\nimport { Attribute, AttributeValue, IngestType } from '../../interfaces';\nimport { ENDPOINTS, ResponseStatus } from '@washingtonpost/subs-sdk';\nimport { useScript, ScriptStatus } from '@washingtonpost/subs-hooks';\nimport { Dropdown } from './Dropdown';\n\ninterface DESelectProps {\n source: string;\n fieldName: string;\n label?: string;\n dataDictionaryConfig?: Attribute;\n defaultValue?: string;\n disabled?: boolean;\n submit: boolean;\n onChange?: ({ value }: { value: string }) => void;\n onFinished?: ({\n isFinished,\n isError,\n }: {\n isFinished: boolean;\n isError: boolean;\n }) => void;\n valuesFilter?: (value: AttributeValue) => boolean;\n selectProps?: {\n root?: any;\n trigger?: any;\n label?: any;\n value?: any;\n content?: any;\n item?: any;\n };\n children?: React.ReactNode;\n}\n\nconst scriptSrc = `${\n ENDPOINTS.staticAssets === 'https://subscribe.washingtonpost.com/static'\n ? 'https://www.washingtonpost.com/subscribe/static/'\n : ENDPOINTS.staticAssets\n}/de-utils/twpdeu.min.js`;\n\nexport const DESelect: React.FC<DESelectProps> = ({\n source,\n fieldName,\n label,\n dataDictionaryConfig,\n defaultValue,\n disabled,\n submit,\n onChange = () => {},\n onFinished = () => {},\n valuesFilter = () => true,\n children,\n}) => {\n const [config, setConfig] = useState(dataDictionaryConfig);\n\n const [selected, setSelected] = useState('');\n\n const scriptStatus = useScript(scriptSrc);\n\n useEffect(() => {\n const fetchConfig = async () => {\n try {\n const config = await window?.__twpdeu?.getFieldConfigs({ fieldName });\n if (config) {\n setConfig(config[0]);\n } else {\n console.error('unable to get config', fieldName);\n }\n } catch (e) {\n console.warn('unable to get config', fieldName, e);\n }\n };\n\n if (scriptStatus === ScriptStatus.READY && !(children || config)) {\n fetchConfig();\n }\n }, [scriptStatus]);\n\n useEffect(() => {\n const submitSelected = async () => {\n try {\n // TODO: Log to GA?\n\n const result = await window?.__twpdeu?.push({\n submitData: { fieldName, value: selected },\n type: config?.explicit ? IngestType.EXPLICIT : IngestType.IMPLICIT,\n source,\n });\n\n const isError = result\n ? result.status !== ResponseStatus.SUCCESS\n : true;\n\n onFinished({\n isFinished: true,\n isError,\n });\n } catch (e) {\n onFinished({\n isFinished: false,\n isError: true,\n });\n }\n };\n\n if (scriptStatus === ScriptStatus.READY && submit && selected) {\n submitSelected();\n }\n }, [scriptStatus, submit]);\n\n const defaultValueProp = defaultValue && config ? { defaultValue } : {};\n\n const isLoading = !(children || config);\n\n const disabledProp = disabled || isLoading ? { disabled: true } : {};\n\n // sort and filter out archived values\n const values = config\n ? config.values\n .sort((a, b) => a.order - b.order)\n .filter((value) => value.archived !== true)\n .filter(valuesFilter)\n : [];\n\n return (\n <SelectWrapper>\n {children && (\n <Select.Root\n onValueChange={(e) => {\n setSelected(e);\n onChange({ value: e });\n }}\n {...defaultValueProp}\n {...disabledProp}\n >\n {children}\n </Select.Root>\n )}\n {!children && !config && (\n <Dropdown\n id={'loading'}\n label={'Loading...'}\n values={[]}\n disabled={true}\n />\n )}\n {!children && config && (\n <Dropdown\n id={config.name}\n label={label || config.name}\n onChange={(e) => {\n setSelected(e);\n onChange({ value: e });\n }}\n values={values.map((value) => value.name)}\n defaultValue={defaultValue}\n disabled={disabled}\n />\n )}\n </SelectWrapper>\n );\n};\n\nconst SelectWrapper = styled('div', {\n boxSizing: 'border-box',\n display: 'flex',\n marginBottom: '$100',\n flexDirection: 'column',\n '& button': {\n padding: '1px 6px',\n },\n '& *': { boxSizing: 'border-box' },\n});\n"],"names":["CollectionBehaviors","COLLECT","DO_NOT_COLLECT","AttributesState","SUCCESS","IngestType","EXPLICIT","IMPLICIT","IngestResponseState","SYSTEM_ERROR","INVALID_TYPE","INVALID_IDENTIFIER","INVALID_DATA","INVALID_ATTRIBUTE_DEFINITION","INVALID_META_DEFINITION","UNAUTHENTICATED","MISMATCHED_IDENTIFIER","DISABLED_ATTRIBUTE_DEFINITION","hasRequiredPrivacyCookies","window","wp_usp","getCookie","countryCode","_WPGeo","WPGeo","country_code","base","ENDPOINTS","attributesCache","getAttributes","_ref","fieldName","fieldNames","url","URL","searchParams","set","join","data","fetch","toString","credentials","headers","JSON_HEADERS","json","ok","status","ResponseStatus","attributes","e","console","debug","ingest","_ref2","submitData","value","type","source","wapo_login_id","Error","attributeInfo","name","collection_behavior","jucid","localStorage","getItem","ga","payload","metadata","response","method","body","JSON","stringify","StyledMobileSelect","styled","padding","display","justifyContent","width","backgroundColor","color","fontFamily","fontSize","fontWeight","lineHeight","paddingBlockRight","textOverflow","position","borderColor","borderRightWidth","borderRightColor","appearance","theme","colors","disabled","onDisabled","cursor","StyledSelectWrapper","maxWidth","borderRadius","borderStyle","borderWidth","StyledMobileOption","Dropdown","id","label","values","required","defaultValue","onChange","answer","setAnswer","useState","isMobileSize","useWindowSize","useEffect","disabledProp","defaultValueProp","defaultValuePropMobile","selected","React","target","placeholder","style","map","key","Icon","size","fill","pointerEvents","right","top","transform","ChevronDown","Select","Root","onValueChange","Trigger","Label","Value","Content","css","zIndex","zIndices","page","Item","scriptSrc","staticAssets","DESelect","dataDictionaryConfig","submit","onFinished","valuesFilter","children","config","setConfig","setSelected","scriptStatus","useScript","fetchConfig","_window","__twpdeu","getFieldConfigs","error","warn","ScriptStatus","READY","submitSelected","_window2","result","push","explicit","isError","isFinished","isLoading","sort","a","b","order","filter","archived","SelectWrapper","boxSizing","marginBottom","flexDirection"],"mappings":";;;;;;MAQaA,mBAAmB,GAAG;EACjCC,OAAO,EAAE,SAAS;EAClBC,cAAc,EAAE;;MAeLC,eAAe,GAAG;EAC7BC,OAAO,EAAE;;MAGEC,UAAU,GAAG;EACxBC,QAAQ,EAAE,UAAU;EACpBC,QAAQ,EAAE;;MAGCC,mBAAmB,GAAG;EACjCJ,OAAO,EAAE,KAAK;EACdK,YAAY,EAAE,KAAK;EACnBC,YAAY,EAAE,KAAK;EACnBC,kBAAkB,EAAE,KAAK;EACzBC,YAAY,EAAE,KAAK;EACnBC,4BAA4B,EAAE,KAAK;EACnCC,uBAAuB,EAAE,KAAK;EAC9BC,eA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3G,MAAM,CAAC,KAAK,EAAE;EAClC4G,SAAS,EAAE,YAAY;EACvB1G,OAAO,EAAE,MAAM;EACf2G,YAAY,EAAE,MAAM;EACpBC,aAAa,EAAE,QAAQ;EACvB,UAAU,EAAE;IACV7G,OAAO,EAAE;GACV;EACD,KAAK,EAAE;IAAE2G,SAAS,EAAE;;CACrB,CAAC;;;;"}
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.
|
|
2
|
+
"version": "0.3.0",
|
|
3
3
|
"license": "UNLICENSED",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"typings": "dist/index.d.ts",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"name": "de-inputs: utils",
|
|
37
37
|
"path": "dist/subs-de-inputs.esm.js",
|
|
38
38
|
"import": "{ getAttributes, ingest }",
|
|
39
|
-
"limit": "1 KB"
|
|
39
|
+
"limit": "1.5 KB"
|
|
40
40
|
},
|
|
41
41
|
{
|
|
42
42
|
"name": "de-inputs: DESelect",
|