id
stringlengths 12
53
| messages
listlengths 3
3
|
|---|---|
code_store-header_40e21df1
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of store-header/react/Spacer.tsx from the store-header VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```tsx\nimport type { PropsWithChildren } from 'react'\nimport React from 'react'\nimport type { CssHandlesTypes } from 'vtex.css-handles'\nimport { useCssHandles } from 'vtex.css-handles'\n\nconst CSS_HANDLES = ['headerSpacer'] as const\n\ninterface Props {\n classes?: CssHandlesTypes.CustomClasses<typeof CSS_HANDLES>\n}\n\n/**\n * @deprecated Use a simple inline element instead\n */\nfunction Spacer({ classes }: PropsWithChildren<Props>) {\n const { handles } = useCssHandles(CSS_HANDLES, {\n classes,\n })\n\n return <div className={`${handles.headerSpacer} flex flex-grow-1`} />\n}\n\nexport default Spacer\n\n```"
}
] |
code_store-header_963e5bda
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of store-header/react/ForceCenter.tsx from the store-header VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```tsx\nimport type { PropsWithChildren } from 'react'\nimport React from 'react'\nimport type { CssHandlesTypes } from 'vtex.css-handles'\nimport { useCssHandles } from 'vtex.css-handles'\n\nconst CSS_HANDLES = ['forceCenter', 'forceCenterInnerContainer'] as const\n\ninterface Props {\n classes?: CssHandlesTypes.CustomClasses<typeof CSS_HANDLES>\n}\n\n/**\n * @deprecated Use `vtex.sticky-layout` and inline elements instead.\n */\nfunction ForceCenter({ children, classes }: PropsWithChildren<Props>) {\n const { handles } = useCssHandles(CSS_HANDLES, {\n classes,\n })\n\n return (\n <div\n className={`${handles.forceCenter} absolute left-0 right-0 flex justify-center z-1`}\n style={{ pointerEvents: 'none' }}\n >\n <div\n className={handles.forceCenterInnerContainer}\n style={{ pointerEvents: 'all' }}\n >\n {children}\n </div>\n </div>\n )\n}\n\nexport default ForceCenter\n\n```"
}
] |
code_store-header_3017f73a
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of store-header/react/package.json from the store-header VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```json\n{\n \"version\": \"2.29.2\",\n \"name\": \"vtex.header\",\n \"description\": \"A Header Component.\",\n \"license\": \"ISC\",\n \"scripts\": {\n \"pretest\": \"yarn\",\n \"test\": \"vtex-test-tools test\",\n \"test:coverage\": \"vtex-test-tools test --collectCoverage\",\n \"gen:coveralls\": \"yarn test:coverage && cat ./coverage/lcov.info | coveralls\",\n \"lint\": \"tsc --noEmit && eslint --ext ts,tsx .\"\n },\n \"devDependencies\": {\n \"@types/classnames\": \"^2.2.7\",\n \"@vtex/test-tools\": \"^0.1.3\",\n \"apollo-client\": \"^2.5.1\",\n \"vtex.css-handles\": \"http://vtex.vtexassets.com/_v/public/typings/v1/vtex.css-handles@1.0.0/public/@types/vtex.css-handles\",\n \"vtex.category-menu\": \"http://vtex.vtexassets.com/_v/public/typings/v1/vtex.category-menu@2.15.0/public/_types/react\",\n \"vtex.device-detector\": \"http://vtex.vtexassets.com/_v/public/typings/v1/vtex.device-detector@0.2.5/public/@types/vtex.device-detector\",\n \"vtex.locale-switcher\": \"http://vtex.vtexassets.com/_v/public/typings/v1/vtex.locale-switcher@0.5.5/public/@types/vtex.locale-switcher\",\n \"vtex.login\": \"http://vtex.vtexassets.com/_v/public/typings/v1/vtex.login@2.39.1/public/_types/react\",\n \"vtex.menu\": \"http://vtex.vtexassets.com/_v/public/typings/v1/vtex.menu@2.27.0/public/@types/vtex.menu\",\n \"vtex.minicart\": \"http://vtex.vtexassets.com/_v/public/typings/v1/vtex.minicart@2.54.2/public/@types/vtex.minicart\",\n \"vtex.render-runtime\": \"http://vtex.vtexassets.com/_v/public/typings/v1/vtex.render-runtime@8.126.4/public/@types/vtex.render-runtime\",\n \"vtex.rich-text\": \"http://vtex.vtexassets.com/_v/public/typings/v1/vtex.rich-text@0.11.2/public/@types/vtex.rich-text\",\n \"vtex.sandbox\": \"http://vtex.vtexassets.com/_v/public/typings/v1/vtex.sandbox@0.5.0/public/@types/vtex.sandbox\",\n \"vtex.store-components\": \"http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-components@3.136.2/public/@types/vtex.store-components\",\n \"vtex.store-drawer\": \"http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-drawer@0.15.0/public/@types/vtex.store-drawer\",\n \"vtex.store-icons\": \"http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-icons@0.18.0/public/@types/vtex.store-icons\",\n \"vtex.styleguide\": \"http://vtex.vtexassets.com/_v/public/typings/v1/vtex.styleguide@9.134.0/public/@types/vtex.styleguide\",\n \"vtex.telemarketing\": \"http://vtex.vtexassets.com/_v/public/typings/v1/vtex.telemarketing@2.10.2/public/@types/vtex.telemarketing\"\n },\n \"dependencies\": {\n \"@types/react-resize-detector\": \"^3.1.1\",\n \"classnames\": \"^2.2.6\",\n \"debounce\": \"^1.2.0\",\n \"hoist-non-react-statics\": \"^3.0.1\",\n \"react\": \"^16.3.2\",\n \"react-adopt\": \"^0.6.0\",\n \"react-dom\": \"^16.3.2\",\n \"react-intl\": \"^2.4.0\",\n \"react-media\": \"^1.9.2\",\n \"react-resize-detector\": \"^4.0.5\",\n \"react-spring\": \"^8.0.7\",\n \"throttleit\": \"^1.0.0\"\n },\n \"vtexScriptsOverride\": {\n \"srcPath\": \".\"\n }\n}\n\n```"
}
] |
code_store-header_c3a7a440
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of store-header/react/Layout.tsx from the store-header VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```tsx\nimport type { PropsWithChildren } from 'react'\nimport React from 'react'\n\nimport StickyRows from './components/StickyRows'\n\n/**\n * @deprecated Use the `vtex.sticky-layout` app instead\n */\n// eslint-disable-next-line @typescript-eslint/ban-types\nfunction Layout({ children }: PropsWithChildren<{}>) {\n return <StickyRows>{children}</StickyRows>\n}\n\nexport default Layout\n\n```"
}
] |
code_store-header_5a360b4d
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of store-header/react/Row.tsx from the store-header VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```tsx\nimport type { PropsWithChildren } from 'react'\nimport React from 'react'\nimport classNames from 'classnames'\nimport { Container } from 'vtex.store-components'\nimport type { CssHandlesTypes } from 'vtex.css-handles'\nimport { useCssHandles } from 'vtex.css-handles'\n\nimport StickyRow from './components/StickyRow'\n\nconst CSS_HANDLES = [\n 'headerRowContainer',\n 'headerRow',\n 'headerRowBackground',\n 'headerRowContentContainer',\n] as const\n\ninterface Props {\n /**\n * Define if the row behaves in a sticky manner\n * @default false\n * */\n sticky?: boolean\n zIndex?: number\n /**\n * Define if the element takes the full width of its container\n * @default false\n * */\n fullWidth?: boolean\n /**\n * Define if the row should have inverted background and text colors\n * @default false\n * */\n inverted?: boolean\n classes?: CssHandlesTypes.CustomClasses<typeof CSS_HANDLES>\n}\n\n/**\n * @deprecated Use the `vtex.sticky-layout` app instead.\n */\nfunction Row({\n children,\n sticky,\n zIndex,\n fullWidth,\n inverted,\n classes,\n}: PropsWithChildren<Props>) {\n const { handles } = useCssHandles(CSS_HANDLES, {\n classes,\n })\n\n const content = (\n <div className={`${handles.headerRowContainer} w-100 flex items-center`}>\n {children}\n </div>\n )\n\n return (\n <StickyRow sticky={sticky} zIndex={zIndex}>\n <div className={handles.headerRow}>\n <div\n className={classNames(\n `${handles.headerRowBackground} w-100`,\n inverted\n ? 'bg-base--inverted c-on-base--inverted'\n : 'bg-base c-on-base'\n )}\n >\n {fullWidth ? (\n content\n ) : (\n <Container\n className={`${handles.headerRowContentContainer} w-100 flex`}\n >\n {content}\n </Container>\n )}\n </div>\n </div>\n </StickyRow>\n )\n}\n\nexport default Row\n\n```"
}
] |
code_store-header_d0ed4cec
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of store-header/store/blocks.json from the store-header VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```json\n{\n \"header\": {\n \"blocks\": [\"telemarketing\", \"logo\"]\n },\n \"header.full\": {\n \"blocks\": [\"header-layout.desktop\", \"header-layout.mobile\"]\n },\n \"header-layout.desktop\": {\n \"children\": [\"header-row#desktop-1\", \"header-row#desktop-2\"]\n },\n \"header-row#desktop-1\": {\n \"children\": [\"telemarketing\"],\n \"props\": {\n \"fullWidth\": true\n }\n },\n \"header-row#desktop-2\": {\n \"children\": [\n \"logo#header\",\n \"header-spacer\",\n \"search-bar\",\n \"login\",\n \"minicart\"\n ],\n \"props\": {\n \"sticky\": true\n }\n },\n \"header-row#desktop-3\": {\n \"children\": [\"category-menu\"]\n },\n \"header-layout.mobile\": {\n \"children\": [\"header-row#mobile-2\"]\n },\n \"header-row#mobile-1\": {\n \"children\": [\"telemarketing\"],\n \"props\": {\n \"fullWidth\": true,\n \"sticky\": true\n }\n },\n \"header-row#mobile-2\": {\n \"children\": [\n \"logo#header\",\n \"header-spacer\",\n \"login#header-mobile\",\n \"minicart\"\n ],\n \"props\": {\n \"sticky\": true\n }\n },\n \"login#header-mobile\": {\n \"props\": {\n \"showIconProfile\": true\n }\n },\n \"logo#header\": {\n \"props\": {\n \"width\": 132,\n \"height\": 32,\n \"mobileWidth\": 90,\n \"mobileHeight\": 32\n }\n }\n}\n\n```"
}
] |
code_store-header_adae273b
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of store-header/store/interfaces.json from the store-header VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```json\n{\n \"header\": {\n \"allowed\": [\n \"minicart\",\n \"minicart-base-content\",\n \"login\",\n \"category-menu\",\n \"search-bar\",\n \"locale-switcher\",\n \"theme\",\n \"user-address\",\n \"menu\",\n \"unstable--menu\",\n \"menu-link\",\n \"telemarketing\",\n \"logo\",\n \"sandbox\",\n \"header-layout.desktop\",\n \"header-layout.mobile\",\n \"header-layout.desktop-scroll\",\n \"header-layout.mobile-scroll\",\n \"unstable--header-layout.desktop\",\n \"unstable--header-layout.mobile\",\n \"unstable--header-layout.desktop-scroll\",\n \"unstable--header-layout.mobile-scroll\"\n ],\n \"component\": \"index\"\n },\n \"header.full\": {},\n \"header-layout\": {\n \"allowed\": [\"header-row\", \"header-border\"],\n \"component\": \"Layout\",\n \"composition\": \"children\"\n },\n \"header-layout.desktop\": {\n \"device\": \"desktop\"\n },\n \"header-layout.mobile\": {\n \"device\": \"mobile\"\n },\n \"header-layout.desktop-scroll\": {},\n \"header-layout.mobile-scroll\": {},\n \"header-spacer\": {\n \"component\": \"Spacer\"\n },\n \"header-row\": {\n \"allowed\": [\n \"telemarketing\",\n \"notification\",\n \"logo\",\n \"minicart\",\n \"minicart-base-content\",\n \"sandbox\",\n \"login\",\n \"search-bar\",\n \"locale-switcher\",\n \"menu-link\",\n \"category-menu\",\n \"menu\",\n \"unstable--menu\",\n \"theme\",\n \"user-address\",\n \"header-spacer\",\n \"rich-text\",\n \"drawer\",\n \"header-force-center\"\n ],\n \"component\": \"Row\",\n \"composition\": \"children\"\n },\n \"header-border\": {\n \"component\": \"Border\"\n },\n \"theme\": {},\n\n \"unstable--header-layout\": {\n \"allowed\": [\"unstable--header-row\", \"unstable--header-border\"],\n \"component\": \"Layout\",\n \"composition\": \"children\"\n },\n \"unstable--header-layout.desktop\": {\n \"device\": \"desktop\"\n },\n \"unstable--header-layout.mobile\": {\n \"device\": \"mobile\"\n },\n \"unstable--header-layout.desktop-scroll\": {\n \"device\": \"desktop\"\n },\n \"unstable--header-layout.mobile-scroll\": {\n \"device\": \"mobile\"\n },\n \"_\": {\n \"component\": \"Spacer\"\n },\n \"unstable--header-row\": {\n \"allowed\": [\n \"telemarketing\",\n \"logo\",\n \"minicart\",\n \"login\",\n \"search-bar\",\n \"locale-switcher\",\n \"menu-link\",\n \"category-menu\",\n \"menu\",\n \"unstable--menu\",\n \"theme\",\n \"user-address\",\n \"_\"\n ],\n \"component\": \"Row\",\n \"composition\": \"children\"\n },\n \"unstable--header-border\": {\n \"component\": \"Border\"\n },\n \"header-force-center\": {\n \"component\": \"ForceCenter\",\n \"composition\": \"children\",\n \"allowed\": \"*\"\n }\n}\n\n```"
}
] |
code_store-header_54631692
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of store-header/react/legacy/index.js from the store-header VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```javascript\nimport React, { Fragment, useEffect, useState } from 'react'\nimport classNames from 'classnames'\nimport PropTypes from 'prop-types'\nimport { ExtensionPoint, useRuntime } from 'vtex.render-runtime'\nimport TopMenu from './components/TopMenu'\nimport Spacer from './components/Helpers/Spacer'\nimport { logo, collapsible, icons, searchBar, login } from './defaults'\n\nimport styles from './store-header.css'\nimport useDevice from './hooks/useDevice'\n\n/**\n * Main header component\n */\nconst Header = ({\n leanWhen,\n linkUrl,\n logoUrl,\n logoTitle,\n logoSize,\n showSearchBar,\n showLogin,\n iconClasses,\n labelClasses,\n collapsibleAnimation,\n}) => {\n const { page, getSettings } = useRuntime()\n const { mobile } = useDevice()\n const [containerHeight, setContainerHeight] = useState(null)\n const { storeName } = getSettings('vtex.store')\n\n useEffect(() => {\n if (document) {\n const containerElement = document.querySelector(\n '.vtex-store-header-2-x-container'\n )\n const elementHeight = containerElement && containerElement.offsetHeight\n setContainerHeight(elementHeight)\n }\n })\n\n const topMenuOptions = {\n linkUrl,\n logoUrl,\n logoTitle: logoTitle || storeName || '',\n logoSize,\n showSearchBar,\n showLogin,\n iconClasses,\n labelClasses,\n collapsibleAnimation,\n mobile,\n }\n\n const isLeanMode = () => {\n const acceptedPaths = new RegExp(leanWhen)\n return acceptedPaths.test(page)\n }\n\n const containerClasses = classNames(\n styles.container,\n 'fixed top-0 z-4 w-100',\n isLeanMode() ? styles.leanMode : ''\n )\n\n return (\n <Fragment>\n <div className={containerClasses}>\n <TopMenu\n {...topMenuOptions}\n leanMode={isLeanMode()}\n extraHeaders={\n <div\n className=\"left-0 w-100\"\n style={{\n transform: 'translateZ(0)', //Avoid shaking\n }}\n >\n <ExtensionPoint id=\"telemarketing\" />\n <ExtensionPoint id=\"menu-link\" />\n </div>\n }\n />\n </div>\n <Spacer containerHeight={containerHeight} />\n </Fragment>\n )\n}\n\nHeader.propTypes = {\n /** Cases in which the menu is in lean mode */\n leanWhen: PropTypes.string,\n ...login.propTypes,\n ...searchBar.propTypes,\n ...icons.propTypes,\n ...logo.propTypes,\n ...collapsible.propTypes,\n}\n\nHeader.defaultProps = {\n leanWhen: 'a^',\n ...login.defaultProps,\n ...searchBar.defaultProps,\n ...icons.defaultProps,\n ...logo.defaultProps,\n ...collapsible.defaultProps,\n}\n\nHeader.schema = {\n title: 'admin/editor.header.title',\n description: 'admin/editor.header.description',\n type: 'object',\n properties: {\n logoUrl: {\n type: 'string',\n title: 'admin/editor.header.logo.image',\n widget: {\n 'ui:widget': 'image-uploader',\n },\n },\n linkUrl: {\n type: 'string',\n title: 'admin/editor.header.link.url',\n },\n showSearchBar: {\n title: 'admin/editor.header.show.searchbar.title',\n type: 'boolean',\n default: true,\n isLayout: true,\n },\n showLogin: {\n title: 'admin/editor.header.show.login.title',\n type: 'boolean',\n default: true,\n isLayout: true,\n },\n },\n}\n\nexport default Header\n\n```"
}
] |
code_store-header_eedea79b
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of store-header/react/legacy/store-header.css from the store-header VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```css\n.logoLink {\n font-size: 0px;\n}\n\n.container {\n}\n.leanMode {\n}\n\n.topMenuLogo {\n}\n.topMenuSearchBar {\n}\n.topMenuIcons {\n}\n.topMenuContainer {\n}\n\n.topMenuCollapsible {\n}\n\n.topMenuCompatibilityContainer {\n}\n```"
}
] |
code_store-header_5eb19a76
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of store-header/react/legacy/defaults.js from the store-header VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```javascript\nimport PropTypes from 'prop-types'\n\nexport const lean = {\n propTypes: {\n /** If it is leanMode or not */\n leanMode: PropTypes.bool,\n },\n defaultProps: {\n leanMode: false,\n },\n}\n\nexport const logo = {\n propTypes: {\n /** Address opened when the user clicks the logo */\n linkUrl: PropTypes.string,\n /** URL of the logo image */\n logoUrl: PropTypes.string,\n /** Alt text for the logo */\n logoTitle: PropTypes.string,\n /** Size of the logo */\n logoSize: PropTypes.shape({\n /** Size on desktop */\n desktop: PropTypes.shape({\n width: PropTypes.number,\n height: PropTypes.number,\n }),\n /** Size on mobile */\n mobile: PropTypes.shape({\n width: PropTypes.number,\n height: PropTypes.number,\n }),\n }),\n },\n defaultProps: {\n linkUrl: '/',\n logoUrl: '',\n logoSize: {\n desktop: {\n width: 132,\n height: 40,\n },\n mobile: {\n width: 90,\n height: 40,\n },\n },\n },\n}\n\nexport const searchBar = {\n propTypes: {\n /** Sets whether the search bar is visible or not */\n showSearchBar: PropTypes.bool,\n },\n defaultProps: {\n showSearchBar: true,\n },\n}\n\nexport const login = {\n propTypes: {\n /** Sets whether the login button is displayed or not*/\n showLogin: PropTypes.bool,\n },\n defaultProps: {\n showLogin: true,\n },\n}\n\nexport const icons = {\n propTypes: {\n /** Classes for icons */\n iconClasses: PropTypes.string,\n /** Classes for labels */\n labelClasses: PropTypes.string,\n },\n defaultProps: {\n iconClasses: 'c-on-base',\n labelClasses: 'c-on-base',\n },\n}\n\nexport const collapsible = {\n propTypes: {\n collapsibleAnimation: PropTypes.shape({\n /** If should animate on scroll */\n onScroll: PropTypes.bool,\n /** If should animate on every scroll up or down */\n always: PropTypes.bool,\n /** Scroll value that animation starts to be active */\n anchor: PropTypes.number,\n /** Initial height */\n from: PropTypes.number,\n /** Target height */\n to: PropTypes.number,\n /** Animation configuration presets: know more @ https://www.react-spring.io/docs/hooks/api */\n preset: PropTypes.oneOf([\n 'default',\n 'gentle',\n 'wobbly',\n 'stiff',\n 'slow',\n 'molasses',\n ]),\n /** Animation configuration: know more @ https://www.react-spring.io/docs/hooks/api */\n config: PropTypes.shape({\n mass: PropTypes.number,\n tension: PropTypes.number,\n friction: PropTypes.number,\n clamp: PropTypes.bool,\n precision: PropTypes.number,\n velocity: PropTypes.number,\n duration: PropTypes.number,\n easing: PropTypes.func,\n }),\n }),\n },\n\n defaultProps: {\n collapsibleAnimation: {\n onScroll: true,\n always: true,\n anchor: 100,\n from: 4,\n to: 0,\n preset: 'default',\n config: {},\n },\n },\n}\n\nexport const spacer = {\n propTypes: {\n /** Height on mobile mode */\n spacerHeightMobile: PropTypes.number,\n /** Height on desktop mode */\n spacerHeightDesktop: PropTypes.number,\n /** Width on mobile and desktop */\n spacerWidth: PropTypes.number,\n },\n\n defaultProps: {\n spacerHeightMobile: 96,\n spacerHeightDesktop: 160,\n spacerWidth: 0,\n },\n}\n\n```"
}
] |
code_store-header_200bf6d8
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of store-header/react/components/StickyRow.tsx from the store-header VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```tsx\nimport type { FunctionComponent, CSSProperties } from 'react'\nimport React, { useContext } from 'react'\nimport ReactResizeDetector from 'react-resize-detector'\nimport { useCssHandles } from 'vtex.css-handles'\nimport type { CssHandlesTypes } from 'vtex.css-handles'\n\nimport { RowContext } from './StickyRows'\n\nconst CSS_HANDLES = ['headerStickyRow'] as const\n\ninterface Props {\n /**\n * Define if the element behaves in a sticky manner\n * @default false\n * */\n sticky?: boolean\n zIndex?: number\n classes?: CssHandlesTypes.CustomClasses<typeof CSS_HANDLES>\n}\n\nconst StickyRow: FunctionComponent<Props> = ({\n children,\n sticky,\n zIndex,\n classes,\n}) => {\n const { handles } = useCssHandles(CSS_HANDLES, {\n classes,\n })\n\n const { offset, onResize } = useContext(RowContext)\n\n const stickyStyle: CSSProperties = {\n top: offset,\n zIndex,\n }\n\n return (\n <div\n style={sticky ? stickyStyle : undefined}\n className={`${handles.headerStickyRow} ${\n sticky ? `sticky ${!zIndex ? 'z-999' : ''}` : ''\n }`}\n >\n {children}\n\n {sticky && (\n <ReactResizeDetector\n handleHeight\n onResize={(_, height) => {\n onResize(height)\n }}\n />\n )}\n </div>\n )\n}\n\nexport default StickyRow\n\n```"
}
] |
code_store-header_b300577e
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of store-header/react/components/CustomHeader.tsx from the store-header VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```tsx\nimport type { FunctionComponent } from 'react'\nimport React from 'react'\nimport { Block } from 'vtex.render-runtime'\nimport { useDevice } from 'vtex.device-detector'\n\nconst enum Device {\n mobile = 'mobile',\n desktop = 'desktop',\n}\n\nconst CustomHeaderLayout = React.memo(({ device }: { device: Device }) => {\n switch (device) {\n case Device.mobile:\n return (\n <>\n <Block id=\"header-layout.mobile\" />\n <Block id=\"unstable--header-layout.mobile\" />\n </>\n )\n\n case Device.desktop:\n // falls through\n\n default:\n return (\n <>\n <Block id=\"header-layout.desktop\" />\n <Block id=\"unstable--header-layout.desktop\" />\n </>\n )\n }\n})\n\nCustomHeaderLayout.displayName = 'CustomHeaderLayout'\n\nconst CustomHeader: FunctionComponent = () => {\n const { isMobile } = useDevice()\n\n return (\n <CustomHeaderLayout device={isMobile ? Device.mobile : Device.desktop} />\n )\n}\n\nexport default CustomHeader\n\n```"
}
] |
code_store-header_3c887451
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of store-header/react/components/StickyRows.tsx from the store-header VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```tsx\nimport type { PropsWithChildren } from 'react'\nimport React from 'react'\n\nimport useCumulativeHeightState from '../hooks/useCumulativeHeightState'\n\ntype RowContextType = {\n /** Callback executed when element is resized */\n onResize(height: number): void\n /** Vertical Offset from top of container */\n offset: number\n}\n\nconst RowContext = React.createContext<RowContextType>({\n onResize: () => {},\n offset: 0,\n})\n\n/**\n * @deprecated Use the `vtex.sticky-layout` app instead\n */\n// eslint-disable-next-line @typescript-eslint/ban-types\nfunction StickyRows({ children }: PropsWithChildren<{}>) {\n const { updateRowHeight, getAccumulatedHeight } = useCumulativeHeightState()\n\n return (\n <>\n {React.Children.map(children, (child, index) => (\n <RowContext.Provider\n value={{\n onResize: (height: number) => updateRowHeight({ height, index }),\n offset: getAccumulatedHeight(index),\n }}\n >\n {child}\n </RowContext.Provider>\n ))}\n </>\n )\n}\n\nexport default StickyRows\n\nexport { RowContext }\n\n```"
}
] |
code_store-header_57728cb1
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of store-header/react/__tests__/Header.test.tsx from the store-header VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```tsx\nimport React from 'react'\nimport { render } from '@vtex/test-tools/react'\nimport { useRuntime } from 'vtex.render-runtime'\n\nimport Header from '../legacy/index'\n\ndescribe('Header Component', () => {\n beforeEach(() => {\n const { setHints } = useRuntime()\n\n setHints({ mobile: false, desktop: true })\n })\n\n it('should be rendered', () => {\n const component = render(<Header />)\n\n expect(component).toBeTruthy()\n })\n\n it('should match snapshot without leanmode', () => {\n const component = render(<Header />)\n\n expect(component.asFragment()).toMatchSnapshot()\n })\n\n it('should match snapshot with leanmode', () => {\n const component = render(<Header leanWhen=\"test\" />)\n\n expect(component.asFragment()).toMatchSnapshot()\n })\n\n it('should match snapshot mobile without leanmode', () => {\n const { setHints } = useRuntime()\n\n setHints({ mobile: true, desktop: false })\n\n const component = render(<Header />)\n\n expect(component.asFragment()).toMatchSnapshot()\n })\n\n it('should match snapshot mobile with leanmode', () => {\n const { setHints } = useRuntime()\n\n setHints({ mobile: true, desktop: false })\n\n const component = render(<Header leanWhen=\"test\" />)\n\n expect(component.asFragment()).toMatchSnapshot()\n })\n})\n\n```"
}
] |
code_store-header_8d2e8ffe
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of store-header/react/hooks/useCumulativeHeightState.tsx from the store-header VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```tsx\nimport React from 'react'\n\ninterface State {\n [id: string]: number\n}\n\nconst enum ActionTypes {\n UPDATE = 'update',\n}\n\ninterface UpdateAction {\n type: ActionTypes.UPDATE\n payload: {\n index: number\n height: number\n }\n}\n\ntype Actions = UpdateAction\n\nconst reducer = (state: State, action: Actions) => {\n switch (action.type) {\n case 'update':\n return {\n ...state,\n [action.payload.index]: action.payload.height,\n }\n\n default:\n return state\n }\n}\n\nconst useCumulativeHeightState = () => {\n const [state, dispatch]: [\n State,\n React.Dispatch<UpdateAction>\n ] = React.useReducer(reducer, {})\n\n const updateRowHeight = ({\n height,\n index,\n }: {\n height: number\n index: number\n }) => {\n if (state[index] === height) {\n return\n }\n\n dispatch({\n payload: {\n height,\n index,\n },\n type: ActionTypes.UPDATE,\n })\n }\n\n const getAccumulatedHeight = (index: number) => {\n const sortedIndices = Object.keys(state)\n .map((key) => parseInt(key, 10))\n .sort((a, b) => a - b)\n\n const indices = sortedIndices.slice(0, sortedIndices.indexOf(index))\n\n return indices.reduce((acc, cur) => (state[cur] || 0) + acc, 0)\n }\n\n return {\n getAccumulatedHeight,\n updateRowHeight,\n }\n}\n\nexport default useCumulativeHeightState\n\n```"
}
] |
code_store-header_0e06f9c4
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of store-header/react/testUtils/setupTests.js from the store-header VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```javascript\n// react-testing-library renders your components to document.body,\n// this will ensure they're removed after each test.\nimport 'react-testing-library/cleanup-after-each'\n\n// this adds jest-dom's custom assertions\nimport 'jest-dom/extend-expect'\n\n```"
}
] |
code_store-header_ccdcb75b
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of store-header/react/testUtils/test-utils.js from the store-header VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```javascript\nimport React from 'react'\nimport * as reactTestingLibrary from 'react-testing-library'\nimport { IntlProvider } from 'react-intl'\n\nimport defaultStrings from '../../messages/en.json'\n\nconst customRender = (node, options) => {\n const rendered = reactTestingLibrary.render(\n <IntlProvider messages={defaultStrings} locale=\"en-US\">\n {node}\n </IntlProvider>,\n options\n )\n\n return {\n ...rendered,\n rerender: (newUi) =>\n customRender(newUi, {\n container: rendered.container,\n baseElement: rendered.baseElement,\n }),\n }\n}\n\n// re-export everything\nmodule.exports = {\n ...reactTestingLibrary,\n render: customRender,\n}\n\n```"
}
] |
code_store-header_5a2b54fb
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of store-header/react/legacy/components/FixedContent.js from the store-header VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```javascript\nimport React, { Fragment, useState } from 'react'\nimport { ExtensionPoint } from 'vtex.render-runtime'\nimport PropTypes from 'prop-types'\nimport { Container } from 'vtex.store-components'\nimport classNames from 'classnames'\nimport Logo from './Logo'\nimport SearchBar from './SearchBar'\nimport Actions from './Actions'\nimport { logo, icons, lean, searchBar, login } from '../defaults'\n\nimport styles from '../store-header.css'\n\n/**\n * Component that deals with content thats always fixed on top\n * Also handles the toggle between mobile search and mobile navbar\n */\nconst FixedContent = ({\n leanMode,\n logoUrl,\n linkUrl,\n logoTitle,\n logoSize,\n showSearchBar,\n showLogin,\n iconClasses,\n labelClasses,\n mobile,\n}) => {\n const [mobileSearchActive, toggleSearch] = useState(false)\n const containerClasses = classNames(\n `${\n styles.topMenuContainer\n } relative flex justify-center bg-base h3 bb bw0 b--white`\n )\n const contentClasses = classNames(\n 'w-100 mw9 flex justify-center',\n leanMode ? 'pv0' : 'pv6-l pv2-m'\n )\n\n return (\n <div className=\"w-100 bg-base\">\n <Container\n className={containerClasses}\n style={{\n transform: 'translateZ(0)', //Avoid shaking\n }}\n >\n <div className={contentClasses} style={{ pointerEvents: 'none' }}>\n <div\n className=\"flex w-100 justify-between-m items-center pv3\"\n style={{\n pointerEvents: 'auto',\n }}\n >\n {mobileSearchActive ? (\n mobile &&\n showSearchBar && (\n <div className=\"flex justify-start pa2 relative w-100\">\n <SearchBar\n mobile={mobile}\n iconClasses={iconClasses}\n onCancel={() => toggleSearch(false)}\n />\n </div>\n )\n ) : (\n <Fragment>\n {!leanMode && mobile && (\n <ExtensionPoint\n id=\"category-menu\"\n mobileMode\n iconClasses={iconClasses}\n />\n )}\n\n <Logo\n logoUrl={logoUrl}\n logoTitle={logoTitle}\n linkUrl={linkUrl}\n logoSize={logoSize}\n mobile={mobile}\n />\n\n {!leanMode && !mobile && showSearchBar && (\n <div className=\"dn db-ns flex-grow-1\">\n <SearchBar mobile={mobile} />\n </div>\n )}\n\n <ExtensionPoint id=\"locale-switcher\"/>\n\n <Actions\n iconClasses={iconClasses}\n labelClasses={labelClasses}\n showSearchBar={showSearchBar}\n showSearchIcon={showSearchBar}\n leanMode={leanMode}\n showLogin={showLogin}\n onActiveSearch={() => toggleSearch(true)}\n mobile={mobile}\n />\n\n {!mobile && (\n <ExtensionPoint id=\"user-address\" variation=\"inline\" />\n )}\n </Fragment>\n )}\n </div>\n </div>\n </Container>\n </div>\n )\n}\n\nFixedContent.propTypes = {\n /** If it's mobile mode */\n mobile: PropTypes.bool.isRequired,\n ...lean.propTypes,\n ...login.propTypes,\n ...searchBar.propTypes,\n ...logo.propTypes,\n ...icons.propTypes,\n}\n\nFixedContent.defaultProps = {\n ...lean.defaultProps,\n ...login.defaultProps,\n ...searchBar.defaultProps,\n ...logo.defaultProps,\n ...icons.defaultProps,\n}\n\nexport default FixedContent\n\n```"
}
] |
code_store-header_46234e08
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of store-header/react/legacy/components/Collapsible.js from the store-header VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```javascript\nimport React from 'react'\nimport classNames from 'classnames'\nimport { NoSSR, ExtensionPoint } from 'vtex.render-runtime'\nimport PropTypes from 'prop-types'\nimport {\n useSpring,\n animated,\n config as springPresets,\n} from 'react-spring/web.cjs'\nimport useScrollDirection from '../hooks/useScrollDirection'\nimport Border from './Helpers/Border'\nimport { collapsible, lean } from '../defaults'\n\nimport styles from '../store-header.css'\n\n/**\n * Represents a collapsible part of the header\n */\nconst Collapsible = ({ children, leanMode, collapsibleAnimation, mobile }) => {\n const { scroll, scrollingUp } = useScrollDirection()\n const {\n onScroll,\n anchor,\n always,\n from,\n to,\n preset,\n config,\n } = collapsibleAnimation\n\n let animationTrigger = true\n\n if (onScroll) {\n const animateWhen = scroll < anchor\n const elastic = always ? scrollingUp : false\n animationTrigger = animateWhen || elastic\n }\n\n const animationStyle =\n !!window.requestAnimationFrame && // Fix SSR Issues\n useSpring({\n config: preset ? springPresets[preset] : config,\n transform: animationTrigger\n ? `translate3d(0, ${to}rem, 0)`\n : `translate3d(0, ${-from}rem, 0)`,\n })\n\n const collapsibleClassnames = classNames(\n styles.topMenuCollapsible,\n 'bg-base flex justify-center relative bb bw1 b--muted-4'\n )\n\n const fallback = <div className={collapsibleClassnames}>{children}</div>\n\n return (\n <React.Fragment>\n {!mobile && !leanMode ? (\n <NoSSR onSSR={fallback}>\n <animated.div\n className={collapsibleClassnames}\n style={{ ...animationStyle, zIndex: -2 }}\n >\n {children}\n </animated.div>\n </NoSSR>\n ) : (\n <Border />\n )}\n {mobile && !leanMode && (\n <ExtensionPoint id=\"user-address\" variation=\"bar\" />\n )}\n </React.Fragment>\n )\n}\n\nCollapsible.propTypes = {\n /** If it's mobile mode */\n mobile: PropTypes.bool.isRequired,\n ...lean.propTypes,\n ...collapsible.propTypes,\n}\n\nCollapsible.defaultProps = {\n ...lean.defaultProps,\n ...collapsible.defaultProps,\n}\n\nexport default Collapsible\n\n```"
}
] |
code_store-header_bd6cc85e
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of store-header/react/legacy/components/TopMenu.js from the store-header VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```javascript\nimport React, { Fragment } from 'react'\nimport PropTypes from 'prop-types'\nimport { ExtensionPoint, useChildBlock } from 'vtex.render-runtime'\nimport Collapsible from './Collapsible'\nimport FixedContent from './FixedContent'\nimport { logo, collapsible, icons, lean, searchBar, login } from '../defaults'\nimport styles from '../store-header.css'\n\n/**\n * Top menu that contains the fixed and collapsible parts\n */\nconst TopMenu = ({\n extraHeaders,\n leanMode,\n logoUrl,\n linkUrl,\n logoTitle,\n logoSize,\n showLogin,\n showSearchBar,\n iconClasses,\n labelClasses,\n collapsibleAnimation,\n mobile,\n}) => {\n const hasMenu = !!useChildBlock({ id: 'menu' })\n const hasUnstableMenu = !!useChildBlock({ id: 'unstable--menu' })\n\n if (hasUnstableMenu) {\n console.warn(\n 'The flag `unstable--` from the menu component will be deprecated soon, in favor of just `menu`. The `second-level-menu` will also be deprecated in favor of `menu`.'\n )\n }\n\n return (\n <Fragment>\n {extraHeaders}\n\n <FixedContent\n leanMode={leanMode}\n logoUrl={logoUrl}\n linkUrl={linkUrl}\n logoSize={logoSize}\n logoTitle={logoTitle}\n showSearchBar={showSearchBar}\n showLogin={showLogin}\n iconClasses={iconClasses}\n labelClasses={labelClasses}\n mobile={mobile}\n />\n\n <Collapsible\n collapsibleAnimation={collapsibleAnimation}\n leanMode={leanMode}\n mobile={mobile}\n >\n {hasMenu || hasUnstableMenu ? (\n <div className={styles.topMenuCompatibilityContainer}>\n <div className=\"flex flex-grow-1\" />\n <ExtensionPoint id={hasMenu ? 'menu' : 'unstable--menu'} />\n <div className=\"flex flex-grow-1\" />\n </div>\n ) : (\n <ExtensionPoint id=\"category-menu\" />\n )}\n </Collapsible>\n </Fragment>\n )\n}\n\nTopMenu.propTypes = {\n /** If it's mobile mode */\n mobile: PropTypes.bool.isRequired,\n /** Very top aditional sections */\n extraHeaders: PropTypes.element,\n ...lean.propTypes,\n ...login.propTypes,\n ...searchBar.propTypes,\n ...logo.propTypes,\n ...icons.propTypes,\n ...collapsible.propTypes,\n}\n\nTopMenu.defaultProps = {\n ...lean.defaultProps,\n ...login.defaultProps,\n ...searchBar.defaultProps,\n ...logo.defaultProps,\n ...icons.defaultProps,\n ...collapsible.defaultProps,\n}\n\nexport default TopMenu\n\n```"
}
] |
code_store-header_49c28640
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of store-header/react/legacy/components/Actions.js from the store-header VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```javascript\nimport React from 'react'\nimport PropTypes from 'prop-types'\nimport { ExtensionPoint } from 'vtex.render-runtime'\nimport { FormattedMessage } from 'react-intl'\nimport { ButtonWithIcon } from 'vtex.styleguide'\nimport { IconSearch } from 'vtex.store-icons'\nimport { lean, icons, searchBar, login } from '../defaults'\n\nimport styles from '../store-header.css'\n\n/**\n * Represents the header icon buttons\n */\nconst Actions = ({\n showSearchBar,\n leanMode,\n iconClasses,\n labelClasses,\n showLogin,\n onActiveSearch,\n mobile,\n}) => {\n return (\n <div\n className={`${\n styles.topMenuIcons\n } flex justify-end flex-grow-1 flex-grow-0-ns items-center order-1-s ml-auto-s order-2-ns`}\n >\n {mobile && (\n <div className=\"flex mr3\">\n {showSearchBar && !leanMode && (\n <ButtonWithIcon\n icon={\n <span className={iconClasses}>\n <IconSearch />\n </span>\n }\n variation=\"tertiary\"\n onClick={onActiveSearch}\n />\n )}\n\n {showLogin && (\n <ExtensionPoint\n id=\"login\"\n iconClasses={iconClasses}\n labelClasses={labelClasses}\n />\n )}\n\n {!leanMode && (\n <ExtensionPoint\n id=\"minicart\"\n iconClasses={iconClasses}\n labelClasses={labelClasses}\n />\n )}\n </div>\n )}\n\n {!mobile && (\n <div className=\"flex\">\n {showLogin && (\n <ExtensionPoint\n id=\"login\"\n iconClasses={iconClasses}\n labelClasses={labelClasses}\n iconLabel={\n <FormattedMessage id=\"store/header.topMenu.login.icon.label\" />\n }\n />\n )}\n\n {!leanMode && (\n <ExtensionPoint\n id=\"minicart\"\n iconClasses={iconClasses}\n labelClasses={labelClasses}\n iconLabel={\n <FormattedMessage id=\"store/header.topMenu.minicart.icon.label\" />\n }\n />\n )}\n </div>\n )}\n </div>\n )\n}\n\nActions.propTypes = {\n /** If it's mobile mode */\n mobile: PropTypes.bool.isRequired,\n /** Callback function for search active */\n onActiveSearch: PropTypes.func,\n ...lean.propTypes,\n ...login.propTypes,\n ...searchBar.propTypes,\n ...icons.propTypes,\n}\n\nActions.defaultProps = {\n onActiveSearch: () => {},\n ...lean.defaultProps,\n ...login.defaultProps,\n ...searchBar.defaultProps,\n ...icons.defaultProps,\n}\n\nexport default Actions\n\n```"
}
] |
code_store-header_f4595eae
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of store-header/react/legacy/components/SearchBar.js from the store-header VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```javascript\nimport React from 'react'\nimport PropTypes from 'prop-types'\nimport { FormattedMessage } from 'react-intl'\nimport { Adopt } from 'react-adopt'\nimport { ExtensionPoint } from 'vtex.render-runtime'\nimport { Button } from 'vtex.styleguide'\nimport classNames from 'classnames'\nimport { icons } from '../defaults'\n\nimport styles from '../store-header.css'\n\n/**\n * Represents the search bar of the header\n */\nconst SearchBar = ({ onCancel, iconClasses, mobile }) => {\n const searchBarClassNames = classNames(\n `${styles.topMenuSearchBar} flex pa2-m flex-grow-1`,\n mobile ? 'justify-between' : 'justify-center'\n )\n\n const cancelClassNames = classNames(`${iconClasses} ttl`)\n\n return (\n <div className={searchBarClassNames}>\n <div className=\"w-75\">\n <Adopt\n mapper={{\n placeholder: <FormattedMessage id=\"store/header.search-placeholder\" />,\n emptyPlaceholder: (\n <FormattedMessage id=\"store/header.search-emptyPlaceholder\" />\n ),\n }}\n >\n {({ placeholder, emptyPlaceholder }) => (\n <ExtensionPoint\n id=\"search-bar\"\n placeholder={placeholder}\n emptyPlaceholder={emptyPlaceholder}\n autoFocus={mobile}\n hasIconLeft={mobile}\n iconClasses={iconClasses}\n />\n )}\n </Adopt>\n </div>\n {mobile && (\n <div className=\"w-25 pa2-m pt2-s\">\n <Button size=\"small\" variation=\"tertiary\" onClick={onCancel}>\n <span className={cancelClassNames}>\n <FormattedMessage id=\"store/header.search-cancel\" />\n </span>\n </Button>\n </div>\n )}\n </div>\n )\n}\n\nSearchBar.propTypes = {\n /** If it's mobile mode */\n mobile: PropTypes.bool.isRequired,\n /** Callback function on cancel */\n onCancel: PropTypes.func,\n ...icons.propTypes,\n}\n\nSearchBar.defaultProps = {\n onCancel: () => {},\n ...icons.defaultProps,\n}\n\nexport default SearchBar\n\n```"
}
] |
code_store-header_5ae42549
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of store-header/react/legacy/components/Logo.js from the store-header VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```javascript\nimport React from 'react'\nimport { ExtensionPoint, Link } from 'vtex.render-runtime'\nimport PropTypes from 'prop-types'\nimport { logo } from '../defaults'\n\nimport styles from '../store-header.css'\n\n/**\n * Represents the header logo\n */\nconst Logo = ({ logoUrl, logoTitle, linkUrl, logoSize, mobile }) => {\n return (\n <div className={`${styles.topMenuLogo} pv2 mr5`}>\n <Link to={linkUrl} className={`outline-0 ${styles.logoLink}`}>\n <ExtensionPoint\n id=\"logo\"\n url={logoUrl}\n title={logoTitle}\n width={mobile ? logoSize.mobile.width : logoSize.desktop.width}\n height={mobile ? logoSize.mobile.height : logoSize.desktop.height}\n isMobile={mobile}\n />\n </Link>\n </div>\n )\n}\n\nLogo.propTypes = {\n /** If it's mobile mode */\n mobile: PropTypes.bool.isRequired,\n ...logo.propTypes,\n}\n\nLogo.defaultProps = {\n ...logo.defaultProps,\n}\n\nexport default Logo\n\n```"
}
] |
code_store-header_a46825aa
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of store-header/react/legacy/hooks/useScrollDirection.js from the store-header VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```javascript\nimport { useState, useEffect } from 'react'\nimport useScroll from './useScroll'\n\n/**\n * Hook that handles the scroll direction\n * @returns {Number, Boolean, Boolean} - the current scroll value and if the scroll is up, or down\n */\nconst useScrollDirection = () => {\n const { scroll } = useScroll()\n const [scrollingUp, setScrollingUp] = useState(false)\n const [lastScroll, setLastScroll] = useState(0)\n\n useEffect(() => {\n setLastScroll(scroll)\n setScrollingUp(lastScroll > scroll)\n }, [scroll])\n\n return { scroll, scrollingUp }\n}\n\nexport default useScrollDirection\n\n```"
}
] |
code_store-header_be4ffbf2
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of store-header/react/legacy/hooks/useScroll.js from the store-header VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```javascript\nimport { useState, useEffect } from 'react'\nimport throttle from 'throttleit'\n\n/**\n * Hook that handles the scroll position\n * @returns {Number} - scroll position value\n */\nconst useScroll = () => {\n const [scroll, setScroll] = useState(0)\n\n useEffect(() => {\n const handleScroll = () => {\n setScroll(window.scrollY)\n }\n const throttled = throttle(handleScroll, 100)\n window.addEventListener('scroll', throttled)\n return () => window.removeEventListener('scroll', throttled)\n }, [])\n\n return { scroll }\n}\n\nexport default useScroll\n\n```"
}
] |
code_store-header_4720a3e1
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of store-header/react/legacy/hooks/useDevice.js from the store-header VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```javascript\nimport { useState, useLayoutEffect } from 'react'\nimport { useRuntime } from 'vtex.render-runtime'\nimport { debounce } from 'debounce'\n\n/**\n * Hook that handles dynamic device change on resize\n * @param {Number} mobileBreakpoint - break point of mobile change\n * @returns {Boolean, Boolean} - if its mobile or desktop\n */\nconst useDevice = (mobileBreakpoint = 640) => {\n const { hints } = useRuntime()\n\n const isMobile = !!window.innerWidth\n ? window.innerWidth <= mobileBreakpoint\n : hints.mobile\n\n const [mobile, setMobile] = useState(isMobile)\n const [desktop, setDesktop] = useState(!isMobile)\n\n useLayoutEffect(() => {\n const handleResize = () => {\n setMobile(window.innerWidth <= mobileBreakpoint)\n setDesktop(window.innerWidth > mobileBreakpoint)\n }\n const debounced = debounce(handleResize, 100)\n window.addEventListener('resize', debounced)\n window.addEventListener('load', handleResize)\n return () => {\n window.removeEventListener('resize', debounced)\n window.removeEventListener('load', handleResize)\n }\n }, [mobileBreakpoint])\n\n return {\n mobile,\n desktop,\n }\n}\n\nexport default useDevice\n\n```"
}
] |
code_store-header_1e87bfa8
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of store-header/react/legacy/components/Helpers/Spacer.js from the store-header VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```javascript\nimport React from 'react'\nimport { spacer } from '../../defaults'\nimport useDevice from '../../hooks/useDevice'\n\n/**\n * Spacer necessary to content due fixed Header\n */\nconst Spacer = ({ spacerHeightDesktop, spacerHeightMobile, spacerWidth, containerHeight }) => {\n const { desktop } = useDevice()\n\n const height = containerHeight || (desktop ? spacerHeightDesktop : spacerHeightMobile)\n\n return (\n <div\n className=\"z-1 bg-base w-100 relative\"\n style={{\n height,\n width: spacerWidth,\n }}\n />\n )\n}\n\nSpacer.propTypes = {\n ...spacer.propTypes,\n}\n\nSpacer.defaultProps = {\n ...spacer.defaultProps,\n}\n\nexport default Spacer\n\n```"
}
] |
code_store-header_994b879c
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of store-header/react/legacy/components/Helpers/Border.js from the store-header VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```javascript\nimport React from 'react'\n\n/**\n * Simple border\n */\nconst Border = () => {\n return (\n <div\n className=\"bb bw1 b--muted-4 relative\"\n style={{\n top: 'inherit',\n boxSizing: 'content-box',\n zIndex: -2,\n }}\n />\n )\n}\n\nexport default Border\n\n```"
}
] |
code_spreadsheet-event-broadcaster_20e6706b
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of spreadsheet-event-broadcaster/docs/README.md from the spreadsheet-event-broadcaster VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```markdown\n\n\n# Service Example\n\nA reference app implementing a VTEX IO service with HTTP route handlers.\n\n\n\nWe use [**KoaJS**](https://koajs.com/) as the web framework, so you might want to get into that\n\nWe also use the [**node-vtex-api**](https://github.com/vtex/node-vtex-api), a VTEX set of utilities for Node services. You can import this package using NPM from `@vtex/api` (already imported on this project)\n\n- Start from `node/index.ts` and follow the comments and imports :)\n\n## Recipes\n\n### Defining routes on _service.json_ \n```json\n{\n \"memory\": 256,\n \"ttl\": 10,\n \"timeout\": 2,\n \"minReplicas\": 2,\n \"maxReplicas\": 4,\n \"routes\": {\n \"status\": {\n \"path\": \"/_v/status/:code\",\n \"public\": true\n }\n }\n}\n```\n\nThe `service.json` file that sits on the root of the `node` folder holds informations about this service, like the maximum timeout and number of replicas, what might be discontinued on the future, but also **sets its routes**. \n\nKoa uses the [path-to-regexp](https://github.com/pillarjs/path-to-regexp) format for defining routes and, as seen on the example, we use the `:code` notation for declaring a **route param** named code, in this case. A HTTP request for `https://{{workspace}}--{{account}}.myvtex.com/_v/status/500` will match the route we've defined. \n\nFor cach _key_ on the `routes` object, there should be a **corresponding entry** on the exported Service object on `node/index.ts`, this will hook your code to a specific route.\n\n### Access Control\nYou can also provide a `public` option for each route. If `true`, that resource will be reachable for everyone on the internet. If `false`, VTEX credentials will be requested as well.\n\nAnother way of controlling access to specific routes is using **ReBACs (Resource-based access)**, that supports more robust configuration. You can read more [on this document](https://docs.google.com/document/d/1ZxNHMFIXfXz3BgTN9xyrHL3V5dYz14wivYgQjRBZ6J8/edit#heading=h.z7pad3qd2qw7) (VTEX only).\n\n#### Query String\nFor `?accepting=query-string`, you **don't need to declare anything**, as any query provided to the URL will already be available for you to use on the code as `ctx.query`, already parsed as an object, or `ctx.queryString`, taken directly from the URL as a string.\n\n#### Route Params\nRoute Params will be available for you to use on the code as `ctx.vtex.params`, already parsed as an object.\nFor a path like `/_v/status/:code`, if you receive the request `/_v/status/200`, `ctx.vtex.params` will return `{ code: '200' }`\n\n#### HTTP methods\nWhen you define a route on the `service.json`, your NodeJS handlers for that route will be triggered **on every HTTP method** (GET, POST, PUT...), so, if you need to handle them separately you need to implement a \"sub-router\". Fortunately, the _node-vtex-api_ provides a helper function `method`, exported from `@vtex/api`, to accomplish that behaviour. Instead of passing your handlers directly to the corresponding route on `index.ts`, you pass a `method` call passing **an object with the desired method as key and one handler as its corresponding value**. Check this example:\n```typescript\nimport { method } from '@vtex/api'\n...\n\nexport default new Service<Clients, State>({\n clients,\n routes: {\n status: method({\n GET: statusGetHandler,\n POST: statusPostHandler,\n }),\n },\n})\n```\n\n### Throwing errors\n\nWhen building a HTTP service, we should follow HTTP rules regarding data types, cache, authorization, and status code. Our example app sets a `ctx.status` value that will be used as a HTTP status code return value, but often we also want to give proper information about errors as well.\n\nThe **node-vtex-api** already exports a handful of **custom error classes** that can be used for that purpose, like the `NotFoundError`. You just need to throw them inside one of the the route handlers that the appropriate response will be sent to the server.\n\n```typescript\nimport { UserInputError } from '@vtex/api'\n\nexport async function validate(ctx: Context, next: () => Promise<any>) {\n const { code } = ctx.vtex.route.params\n if (isNaN(code) || code < 100 || code > 600) {\n throw new UserInputError('Code must be a number between 100 and 600')\n }\n...\n```\n\nYou can check all the available errors [here](https://github.com/vtex/node-vtex-api/tree/fd6139349de4e68825b1074f1959dd8d0c8f4d5b/src/errors), but some are not useful for just-HTTP services. Check the most useful ones:\n\n|Error Class | HTTP Code |\n|--|:--:|\n| `UserInputError` | 400 |\n| `AuthenticationError` | 401 |\n| `ForbiddenError` | 403 |\n| `NotFoundError` | 404 |\n\nYou can also **create your custom error**, just see how it's done above ;)\n\n### Reading a JSON body\n\nWhen writing POST or PUT handlers, for example, often you need to have access to the **request body** that comes as a JSON format, which is not provided directly by the handler function.\n\nFor this, you have to use the [co-body](https://www.npmjs.com/package/co-body) package that will parse the request into a readable JSON object, used as below: \n```typescript\nimport { json } from 'co-body'\nexport async function method(ctx: Context, next: () => Promise<any>) {\n const body = await json(ctx.req)\n```\n\n### Other example apps\n\nWe use Node services across all VTEX, and there are a lot inspiring examples. If you want to dive deeper on learning about this subject, don't miss those internal apps: [builder-hub](https://github.com/vtex/builder-hub) or [store-sitemap](https://github.com/vtex-apps/store-sitemap)\n\n\n## Testing\n\n`@vtex/test-tools` and `@types/jest` should be installed on `./node` package as `devDependencies`.\n\nRun `vtex test` and [Jest](https://jestjs.io/) will do its thing.\n\nCheck the `node/__tests__/simple.test.ts` test case and also [Jest's Documentation](https://jestjs.io/docs/en/getting-started).\n\n## Splunk Dashboard\n\nWe have an (for now, VTEX-only, internal) Splunk dashboard to show all metrics related to your app. You can find it [here](https://splunk7.vtex.com/en-US/app/vtex_colossus/node_app_metrics).\n\nAfter linking this app and making some requests, you can select `vtex.service-example` and see the metrics for your app. **Don't forget to check the box Development, as you are linking your app in a development workspace**.\n\nFor convenience, the link for the current version: https://splunk7.vtex.com/en-US/app/vtex_colossus/node_app_metrics?form.time.earliest=-30m%40m&form.time.latest=%40m&form.picked_context=false&form.picked_region=aws-us-east-*&form.picked_service=vtex.service-example\n\n```"
}
] |
code_spreadsheet-event-broadcaster_800dd66b
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of spreadsheet-event-broadcaster/node/service.json from the spreadsheet-event-broadcaster VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```json\n{\n \"memory\": 256,\n \"ttl\": 10,\n \"timeout\": 30,\n \"minReplicas\": 2,\n \"maxReplicas\": 4,\n \"workers\": 1,\n \"routes\": {\n \"notify\": {\n \"path\": \"/notify\",\n \"public\": false,\n \"access\": \"authorized\",\n \"policies\": [\n {\n \"effect\": \"allow\",\n \"actions\": [\"post\"],\n \"principals\": [\"vrn:apps:*:{{account}}:{{workspace}}:app/*.*@*\"]\n }\n ]\n }\n },\n \"events\": {\n \"eventBroadcaster\": {\n \"sender\": \"vtex.spreadsheet-event-broadcaster\",\n \"keys\": [\"event.chain\"]\n }\n }\n}\n\n```"
}
] |
code_spreadsheet-event-broadcaster_f26eca60
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of spreadsheet-event-broadcaster/node/package.json from the spreadsheet-event-broadcaster VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```json\n{\n \"dependencies\": {\n \"@vtex/clients\": \"^2.19.4\",\n \"async-busboy\": \"^1.1.0\",\n \"co-body\": \"^6.0.0\",\n \"get-stream\": \"^6.0.1\",\n \"ramda\": \"^0.25.0\",\n \"uuid\": \"^8.3.2\",\n \"xlsx\": \"^0.17.5\"\n },\n \"devDependencies\": {\n \"@types/async-busboy\": \"^1.1.1\",\n \"@types/co-body\": \"^0.0.3\",\n \"@types/jest\": \"^24.0.18\",\n \"@types/node\": \"^12.0.0\",\n \"@types/ramda\": \"types/npm-ramda#dist\",\n \"@types/uuid\": \"^8.3.4\",\n \"@vtex/api\": \"6.48.0\",\n \"@vtex/test-tools\": \"^1.0.0\",\n \"@vtex/tsconfig\": \"^0.5.6\",\n \"typescript\": \"3.9.7\",\n \"vtex.spreadsheet-event-broadcaster\": \"http://vtex.vtexassets.com/_v/public/typings/v1/vtex.spreadsheet-event-broadcaster@0.1.0/public/_types/react\"\n },\n \"scripts\": {\n \"lint\": \"tsc --noEmit --pretty\"\n },\n \"version\": \"0.2.3\"\n}\n\n```"
}
] |
code_spreadsheet-event-broadcaster_753df196
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of spreadsheet-event-broadcaster/node/index.ts from the spreadsheet-event-broadcaster VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport type {\n ClientsConfig,\n ServiceContext,\n RecorderState,\n EventContext,\n} from '@vtex/api'\nimport { method, Service } from '@vtex/api'\n\nimport { Clients } from './clients'\nimport { broadcast } from './middlewares/broadcaster/broadcast'\nimport { splitPayload } from './middlewares/broadcaster/splitPayload'\nimport { verifyUniqueness } from './middlewares/broadcaster/verifyUniqueness'\nimport { parseFile } from './middlewares/notify/parseFile'\nimport { startEventChain } from './middlewares/notify/startEventChain'\n\nconst TIMEOUT_MS = 6000\n\nconst clients: ClientsConfig<Clients> = {\n implementation: Clients,\n options: {\n default: {\n retries: 2,\n timeout: TIMEOUT_MS,\n },\n },\n}\n\ndeclare global {\n type Context = ServiceContext<Clients, State>\n\n interface State extends RecorderState {\n payload: unknown[]\n senderAppId: string\n clientAppId: string\n }\n\n interface BroadcasterEventContext extends EventContext<Clients> {\n body: {\n eventId: string\n payload: unknown[]\n senderAppId: string\n clientAppId: string\n }\n }\n}\n\nexport default new Service({\n clients,\n routes: {\n notify: method({\n POST: [parseFile, startEventChain],\n }),\n },\n events: {\n eventBroadcaster: [verifyUniqueness, splitPayload, broadcast],\n },\n})\n\n```"
}
] |
code_spreadsheet-event-broadcaster_4c6ddf18
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of spreadsheet-event-broadcaster/masterdata/eventRegistry/schema.json from the spreadsheet-event-broadcaster VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```json\n{\n \"$schema\": \"http://json-schema.org/schema#\",\n \"title\": \"Event Registry\",\n \"type\": \"object\",\n \"properties\": {\n \"hasBeenProcessed\": {\n \"type\": \"boolean\"\n }\n },\n \"required\": [\"hasBeenProcessed\"],\n \"v-cache\": false\n}\n\n```"
}
] |
code_spreadsheet-event-broadcaster_1e6ae01b
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of spreadsheet-event-broadcaster/node/clients/index.ts from the spreadsheet-event-broadcaster VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { IOClients } from '@vtex/api'\nimport { masterDataFor } from '@vtex/clients'\nimport type { EventRegistry } from 'vtex.spreadsheet-event-broadcaster'\n\nexport class Clients extends IOClients {\n public get eventRegistry() {\n return this.getOrSet(\n 'eventRegistry',\n masterDataFor<EventRegistry>('eventRegistry')\n )\n }\n}\n\n```"
}
] |
code_spreadsheet-event-broadcaster_95c6a57e
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of spreadsheet-event-broadcaster/node/typings/notify.ts from the spreadsheet-event-broadcaster VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport type { FileReadStream } from 'async-busboy'\n\nexport type NotifyInputParameters = {\n fields: {\n appId?: string\n }\n files: [FileReadStream]\n}\n\n```"
}
] |
code_spreadsheet-event-broadcaster_a4d3990c
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of spreadsheet-event-broadcaster/node/utils/constants.ts from the spreadsheet-event-broadcaster VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nexport const APP_ID = 'vtex.spreadsheet-event-broadcaster'\n\nexport const EVENT_CHAIN_KEY = 'event.chain'\n\nexport const OUTPUT_EVENT_KEY = 'row.output'\n\nexport const MASTER_DATA_NO_CHANGES_RESPONSE_STATUS = 304\n\nconst _1GB = 1024 ** 3\n\nexport const MAXIMUM_FILE_SIZE = _1GB\n\nexport const MAXIMUM_FILE_SIZE_STRING = '1GB'\n\nexport const ARRAY_SIZE_TARGET = 1000\n\nexport const ARRAY_SIZE_PAYLOAD = 5000\n\nexport const ARRAY_SPLIT_FACTOR = 100\n\n```"
}
] |
code_spreadsheet-event-broadcaster_c9ffe481
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of spreadsheet-event-broadcaster/node/utils/parsing.ts from the spreadsheet-event-broadcaster VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport type { IncomingMessage } from 'http'\n\nimport Busboy from 'busboy'\n\nexport async function busboyWrapper<T>(req: IncomingMessage): Promise<T> {\n let result\n let clientAppId\n\n try {\n const parsedData = await parseForm(req)\n result = parsedData.files\n clientAppId = parsedData.fields.appId\n } catch (e) {\n throw new Error(e)\n }\n\n return {\n fields: { appId: clientAppId },\n files: [result],\n } as unknown as T\n}\n\nasync function parseForm(req: IncomingMessage): Promise<{ fields: any, files: any }> {\n try {\n return new Promise((resolve, reject) => {\n const bb = new Busboy({ headers: req.headers as { 'content-type': string } })\n const fields: any = {}\n const files: any = []\n\n bb.on('file', (_, file) => {\n const fileData: Buffer[] = []\n\n file.on('data', (data) => {\n fileData.push(data)\n })\n\n file.on('end', () => {\n files.push(Buffer.concat(fileData))\n })\n })\n\n bb.on('field', (fieldname, val) => {\n fields[fieldname] = val\n })\n\n bb.on('finish', () => {\n resolve({ fields, files })\n })\n\n bb.on('error', (err: any) => {\n reject(err)\n })\n\n req.pipe(bb)\n })\n } catch (error) {\n throw new Error(error)\n }\n}\n\nexport function senderAppIdFromHeaders(headers: IncomingMessage['headers']) {\n const appIdWithVersion = headers['x-vtex-caller'] as string\n\n return appIdWithVersion.split('@')[0]\n}\n\n```"
}
] |
code_spreadsheet-event-broadcaster_6579587e
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of spreadsheet-event-broadcaster/node/services/eventRegistry.ts from the spreadsheet-event-broadcaster VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport type { MasterDataEntity } from '@vtex/clients'\nimport type { EventRegistry } from 'vtex.spreadsheet-event-broadcaster'\n\nimport { MASTER_DATA_NO_CHANGES_RESPONSE_STATUS } from '../utils/constants'\n\nexport class EventRegistryService {\n private client: MasterDataEntity<EventRegistry>\n constructor(client: MasterDataEntity<EventRegistry>) {\n this.client = client\n }\n\n public async isEventUnique(eventId: string) {\n try {\n await this.client.saveOrUpdate({\n id: eventId,\n hasBeenProcessed: true,\n })\n } catch (error) {\n if (error?.response?.status === MASTER_DATA_NO_CHANGES_RESPONSE_STATUS) {\n return false\n }\n }\n\n return true\n }\n}\n\n```"
}
] |
code_spreadsheet-event-broadcaster_f11375ae
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of spreadsheet-event-broadcaster/node/middlewares/notify/startEventChain.ts from the spreadsheet-event-broadcaster VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { v4 as uuid } from 'uuid'\n\nimport {\n APP_ID as thisAppId,\n EVENT_CHAIN_KEY as eventKey,\n ARRAY_SIZE_PAYLOAD,\n} from '../../utils/constants'\n\nexport async function startEventChain(ctx: Context) {\n const {\n state: { payload, senderAppId, clientAppId },\n clients: { events },\n } = ctx\n\n if (payload.length > ARRAY_SIZE_PAYLOAD) {\n const chunkSize = ARRAY_SIZE_PAYLOAD\n for (let i = 0; i < payload.length; i += chunkSize) {\n const eventId = uuid()\n const chunk = payload.slice(i, i + chunkSize)\n\n events.sendEvent(thisAppId, eventKey, {\n eventId,\n payload: chunk,\n senderAppId,\n clientAppId,\n })\n }\n } else {\n const eventId = uuid()\n events.sendEvent(thisAppId, eventKey, {\n eventId,\n payload,\n senderAppId,\n clientAppId,\n })\n }\n\n ctx.status = 200\n ctx.message = 'The spreadsheet is being processed'\n}\n\n```"
}
] |
code_spreadsheet-event-broadcaster_56431c26
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of spreadsheet-event-broadcaster/node/middlewares/notify/parseFile.ts from the spreadsheet-event-broadcaster VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { buffer } from 'get-stream'\nimport { read, utils } from 'xlsx'\n\nimport type { NotifyInputParameters } from '../../typings/notify'\nimport {\n MAXIMUM_FILE_SIZE,\n MAXIMUM_FILE_SIZE_STRING,\n} from '../../utils/constants'\nimport { busboyWrapper, senderAppIdFromHeaders } from '../../utils/parsing'\n\nexport async function parseFile(ctx: Context, next: () => Promise<unknown>) {\n const {\n req,\n vtex: { logger },\n } = ctx\n\n const senderAppId = senderAppIdFromHeaders(req.headers)\n\n try {\n const {\n fields: { appId: clientAppId },\n files: [file],\n } = await busboyWrapper<NotifyInputParameters>(req)\n\n if (!file) {\n const errorMessage = 'No file was sent'\n\n logger.error(errorMessage)\n\n ctx.status = 400\n ctx.message = errorMessage\n\n return\n }\n\n const bufferedStream = await buffer(file, {\n maxBuffer: MAXIMUM_FILE_SIZE,\n }).catch(() => {\n const errorMessage = `Input file cannot be larger than ${MAXIMUM_FILE_SIZE_STRING}`\n\n logger.error(errorMessage)\n\n ctx.status = 413\n ctx.message = errorMessage\n })\n\n if (!bufferedStream) {\n return\n }\n const workbook = read(bufferedStream)\n\n const [sheetName] = workbook.SheetNames\n\n const sheet = workbook.Sheets[sheetName]\n\n const payload = utils.sheet_to_json(sheet)\n\n ctx.state.payload = payload\n ctx.state.senderAppId = senderAppId\n ctx.state.clientAppId = clientAppId ?? ''\n } catch (error) {\n logger.error(error.message)\n\n ctx.status = 500\n ctx.message = error.message\n\n throw new Error(error)\n }\n\n await next()\n}\n\n```"
}
] |
code_spreadsheet-event-broadcaster_08e291b7
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of spreadsheet-event-broadcaster/node/middlewares/broadcaster/splitPayload.ts from the spreadsheet-event-broadcaster VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { v4 as uuid } from 'uuid'\n\nimport {\n APP_ID as thisAppId,\n EVENT_CHAIN_KEY as eventKey,\n ARRAY_SIZE_TARGET,\n ARRAY_SPLIT_FACTOR,\n} from '../../utils/constants'\n\nexport async function splitPayload(\n ctx: BroadcasterEventContext,\n next: () => Promise<unknown>\n) {\n const {\n clients: { events },\n body: { payload, senderAppId, clientAppId },\n } = ctx\n\n if (payload.length > ARRAY_SIZE_TARGET) {\n const chunkSize = Math.ceil(payload.length / ARRAY_SPLIT_FACTOR)\n\n for (let i = 0; i < payload.length; i += chunkSize) {\n const eventId = uuid()\n\n const chunk = payload.slice(i, i + chunkSize)\n\n events.sendEvent(thisAppId, eventKey, {\n eventId,\n payload: chunk,\n senderAppId,\n clientAppId,\n })\n }\n\n return\n }\n\n await next()\n}\n\n```"
}
] |
code_spreadsheet-event-broadcaster_f357ffe7
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of spreadsheet-event-broadcaster/node/middlewares/broadcaster/broadcast.ts from the spreadsheet-event-broadcaster VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { OUTPUT_EVENT_KEY as eventKey } from '../../utils/constants'\n\nexport async function broadcast(\n ctx: BroadcasterEventContext,\n next: () => Promise<unknown>\n) {\n const {\n clients: { events },\n body: { payload, senderAppId, clientAppId },\n } = ctx\n\n payload.forEach((row) => {\n events.sendEvent(clientAppId, eventKey, {\n data: row,\n senderAppId,\n })\n })\n\n await next()\n}\n\n```"
}
] |
code_spreadsheet-event-broadcaster_d5688da9
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of spreadsheet-event-broadcaster/node/middlewares/broadcaster/verifyUniqueness.ts from the spreadsheet-event-broadcaster VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { EventRegistryService } from '../../services/eventRegistry'\n\nexport async function verifyUniqueness(\n ctx: BroadcasterEventContext,\n next: () => Promise<unknown>\n) {\n const {\n clients: { eventRegistry },\n body: { eventId },\n } = ctx\n\n const registryService = new EventRegistryService(eventRegistry)\n\n const isUnique = await registryService.isEventUnique(eventId)\n\n if (!isUnique) return\n\n await next()\n}\n\n```"
}
] |
code_tab-layout_32ead82d
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of tab-layout/messages/pt.json from the tab-layout VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```json\n{\n \"admin/editor.tabLayout.title\": \"Tab Layout\",\n \"admin/editor.tabLayout.description\": \"Container for tabbed layout structure\",\n \"admin/editor.tabList.title\": \"Tab List\",\n \"admin/editor.tabList.description\": \"Container for tab buttons\",\n \"admin/editor.tabListItem.title\": \"Tab List Item\",\n \"admin/editor.tabListItem.label\": \"Título da aba\",\n \"admin/editor.tabListItem.description\": \"Button with a tabId and label to control visibility of a matching Tab Content Item\",\n \"admin/editor.tabContent.title\": \"Tab Content\",\n \"admin/editor.tabContent.description\": \"Container for the tab panes\",\n \"admin/editor.tabContentItem.title\": \"Tab Content Item\",\n \"admin/editor.tabContentItem.description\": \"A content area which will be shown or hidden depending on which tab is active\"\n}\n```"
}
] |
code_tab-layout_60812162
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of tab-layout/messages/en.json from the tab-layout VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```json\n{\n \"admin/editor.tabLayout.title\": \"Tab Layout\",\n \"admin/editor.tabLayout.description\": \"Container for tabbed layout structure\",\n \"admin/editor.tabList.title\": \"Tab List\",\n \"admin/editor.tabList.description\": \"Container for tab buttons\",\n \"admin/editor.tabListItem.title\": \"Tab List Item\",\n \"admin/editor.tabListItem.label\": \"Tab label\",\n \"admin/editor.tabListItem.description\": \"Button with a tabId and label to control visibility of a matching Tab Content Item\",\n \"admin/editor.tabContent.title\": \"Tab Content\",\n \"admin/editor.tabContent.description\": \"Container for the tab panes\",\n \"admin/editor.tabContentItem.title\": \"Tab Content Item\",\n \"admin/editor.tabContentItem.description\": \"A content area which will be shown or hidden depending on which tab is active\"\n}\n```"
}
] |
code_tab-layout_58623653
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of tab-layout/messages/context.json from the tab-layout VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```json\n{\n \"admin/editor.tabLayout.title\": \"admin/editor.tabLayout.title\",\n \"admin/editor.tabLayout.description\": \"admin/editor.tabLayout.description\",\n \"admin/editor.tabList.title\": \"admin/editor.tabList.title\",\n \"admin/editor.tabList.description\": \"admin/editor.tabList.description\",\n \"admin/editor.tabListItem.title\": \"admin/editor.tabListItem.title\",\n \"admin/editor.tabListItem.label\": \"Tab label\",\n \"admin/editor.tabListItem.description\": \"admin/editor.tabListItem.description\",\n \"admin/editor.tabContent.title\": \"admin/editor.tabContent.title\",\n \"admin/editor.tabContent.description\": \"admin/editor.tabContent.description\",\n \"admin/editor.tabContentItem.title\": \"admin/editor.tabContentItem.title\",\n \"admin/editor.tabContentItem.description\": \"admin/editor.tabContentItem.description\"\n}\n```"
}
] |
code_tab-layout_11c92151
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of tab-layout/messages/es.json from the tab-layout VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```json\n{\n \"admin/editor.tabLayout.title\": \"Tab Layout\",\n \"admin/editor.tabLayout.description\": \"Container for tabbed layout structure\",\n \"admin/editor.tabList.title\": \"Tab List\",\n \"admin/editor.tabList.description\": \"Container for tab buttons\",\n \"admin/editor.tabListItem.title\": \"Tab List Item\",\n \"admin/editor.tabListItem.label\": \"Título de la pestaña\",\n \"admin/editor.tabListItem.description\": \"Button with a tabId and label to control visibility of a matching Tab Content Item\",\n \"admin/editor.tabContent.title\": \"Tab Content\",\n \"admin/editor.tabContent.description\": \"Container for the tab panes\",\n \"admin/editor.tabContentItem.title\": \"Tab Content Item\",\n \"admin/editor.tabContentItem.description\": \"A content area which will be shown or hidden depending on which tab is active\"\n}\n```"
}
] |
code_tab-layout_ba1e8b31
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of tab-layout/docs/README.md from the tab-layout VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```markdown\n> 📢 Use this project, [contribute](https://github.com/vtex-apps/tab-layout) to it or open issues to help evolve it using [Store Discussion](https://github.com/vtex-apps/store-discussion).\n\n# Tab Layout\n\n<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->\n[](#contributors-)\n<!-- ALL-CONTRIBUTORS-BADGE:END -->\n\nThe Tab Layout app provides you the needed structure to create different layouts within the store's main one from the use of *tabs*.\n\n||\n|----|\n|Example of a storefront with tabs (`Perfumes até 40%off`, `Presentes`, and `Best Sellers`) displaying different content for users.|\n\n## Configuration\n\n1. Add the Tab Layout app to your theme's dependencies in the `manifest.json` file:\n\n```diff\n{\n \"dependencies\": {\n \"vtex.tab-layout\": \"0.x\"\n }\n}\n```\n\nNow, you are able to use all the blocks exported by the `tab-layout` app. Check out the full list below:\n\n| Block name | Description |\n| :----------: | :------------------------: |\n| `tab-layout` |  Parent block that merely defines the logic (via its children blocks) for the layout structure, declaring the desired list of tabs and its content. |\n| `tab-list` |  Defines the list of tabs to be rendered. It only accepts the `tab-list.item` block as a child. | \n| `tab-list.item` |  Defines the rendering for a given tab. Notice that it does not define the tab content, which is handled by the `tab-content.item` block. |\n| `tab-list.item.children` | Flexible alternative to `tab-list.item`. Defines the rendering for a given tab and also accepts any array of blocks as its children. |\n| `tab-content` |  Defines the list of content to be rendered in each tab. It only accepts the `tab-content.item` block as a child. |\n| `tab-content.item` |  Defines the content for a given tab. | \n\n2. In the desired page template (e.g., `store.home`), add the `tab-layout` block:\n\n```json\n{\n \"store.home\": {\n \"blocks\": [\n \"tab-layout#home\"\n ]\n },\n```\n\n3. Declare the `tab-list` and the `tab-content` blocks as `tab-layout`'s children. Do not forget to use the `tab-layout`'s props, for example:\n\n```diff\n{\n \"store.home\": {\n \"blocks\": [\n \"tab-layout#home\"\n ]\n },\n \"tab-layout#home\": {\n \"children\": [\n \"tab-list#home\",\n \"tab-content#home\"\n ],\n \"props\": {\n \"blockClass\": \"home\",\n \"defaultActiveTabId\": \"home1\"\n }\n }\n}\n``` \n\n4. Add and then declare the desired `tab-list.item` blocks as `tab-list`'s children:\n\n```diff\n{\n \"store.home\": {\n \"blocks\": [\n \"tab-layout#home\"\n ]\n },\n \"tab-layout#home\": {\n \"children\": [\n \"tab-list#home\",\n \"tab-content#home\"\n ],\n \"props\": {\n \"blockClass\": \"home\",\n \"defaultActiveTabId\": \"home1\"\n }\n },\n \"tab-list#home\": {\n \"children\": [\n \"tab-list.item#home1\",\n \"tab-list.item#home2\"\n ]\n },\n \"tab-list.item#home1\": {\n \"props\": {\n \"tabId\": \"home1\",\n \"label\": \"Home 1\",\n \"defaultActiveTab\": true\n }\n },\n \"tab-list.item#home2\": {\n \"props\": {\n \"tabId\": \"home2\",\n \"label\": \"Home 2\"\n }\n }\n}\n```\n \n5. Add and then declare the desired `tab-content.item` blocks as `tab-content`'s children:\n\n```diff\n{\n \"store.home\": {\n \"blocks\": [\n \"tab-layout#home\"\n ]\n },\n \"tab-layout#home\": {\n \"children\": [\n \"tab-list#home\",\n \"tab-content#home\"\n ],\n \"props\": {\n \"blockClass\": \"home\",\n \"defaultActiveTabId\": \"home1\"\n }\n },\n \"tab-list#home\": {\n \"children\": [\n \"tab-list.item#home1\",\n \"tab-list.item#home2\"\n ]\n },\n \"tab-list.item#home1\": {\n \"props\": {\n \"tabId\": \"home1\",\n \"label\": \"Home 1\",\n \"defaultActiveTab\": true\n }\n },\n \"tab-list.item#home2\": {\n \"props\": {\n \"tabId\": \"home2\",\n \"label\": \"Home 2\"\n }\n },\n \"tab-content#home\": {\n \"children\": [\n \"tab-content.item#home1\",\n \"tab-content.item#home2\"\n ]\n },\n \"tab-content.item#home1\": {\n \"children\": [\n \"carousel#home\"\n ],\n \"props\": {\n \"tabId\": \"home1\"\n }\n },\n \"tab-content.item#home2\": {\n \"children\": [\n \"shelf#home\",\n \"info-card#home\",\n \"rich-text#question\",\n \"rich-text#link\",\n \"newsletter\"\n ],\n \"props\": {\n \"tabId\": \"home2\"\n }\n }\n}\n```\n\n> ⚠️ Make sure to declare the `tab-content.item`'s children blocks in order to properly render the tab content.\n\n### `tab-layout` props\n\n| Prop name | Type | Description | Default value |\n| ------------ | ---------- | ------------------------------------------------ | ------------- |\n| `defaultActiveTabId` | `string` | ID of the desired tab to be rendered as the default one. If no value is provided, the first tab declared in the theme will be used as default. | `undefined` |\n| `blockClass` | `string` | Block ID of your choosing to be used in [CSS customization](https://developers.vtex.com/docs/guides/vtex-io-documentation-using-css-handles-for-store-customization). | `undefined` |\n\n### `tab-list` props\n\n| Prop name | Type | Description | Default value |\n| ------------ | ---------- | ------------------------------------------------ | ------------- |\n| `blockClass` | `string` | Block ID of your choosing to be used in [CSS customization](https://developers.vtex.com/docs/guides/vtex-io-documentation-using-css-handles-for-store-customization). | `undefined` |\n\n### `tab-list.item` props\n\n| Prop name | Type | Description | Default value |\n| ------------ | ---------- | ------------------------------------------------ | ------------- |\n| `blockClass` | `string` | Block ID of your choosing to be used in [CSS customization](https://developers.vtex.com/docs/guides/vtex-io-documentation-using-css-handles-for-store-customization). | `undefined` |\n| `tabId` | `string` | Tab ID of your choosing. It will be used to match the tab to its content (defined by the `tab-content.item` block). | `undefined` |\n| `label` | `string` | Defines the tab's text label. | `undefined` |\n| `defaultActiveTab` | `boolean` | Defines the item as the default active tab. | `false` |\n\n### `tab-list.item.children` props\n\n| Prop name | Type | Description | Default value |\n| ------------ | ---------- | ------------------------------------------------ | ------------- |\n| `blockClass` | `string` | Block ID of your choosing to be used in [CSS customization](https://developers.vtex.com/docs/guides/vtex-io-documentation-using-css-handles-for-store-customization). | `undefined` |\n| `tabId` | `string` | Tab ID of your choosing. It will be used to match the tab to a given content (defined by the `tab-content.item` block). | `undefined` |\n\n### `tab-content` props\n\n| Prop name | Type | Description | Default value |\n| ------------ | ---------- | ------------------------------------------------ | ------------- |\n| `blockClass` | `string` | Block ID of your choosing to be used in [CSS customization](https://developers.vtex.com/docs/guides/vtex-io-documentation-using-css-handles-for-store-customization). | `undefined` |\n\n### `tab-content.item` props\n\n| Prop name | Type | Description | Default value |\n| ------------ | ---------- | ------------------------------------------------ | ------------- |\n| `blockClass` | `string` | Block ID of your choosing to be used in [CSS customization](https://developers.vtex.com/docs/guides/vtex-io-documentation-using-css-handles-for-store-customization). | `undefined` |\n| `tabId` | `string` | Tab ID of your choosing. It will be used to match the content to a given tab (defined by the `tab-list.item` / `tab-list.item.children` blocks). | `undefined` |\n\n> ⚠️ Be mindful of the `tabID` specified in both `tab-list.item` and `tab-content.item` blocks, as this parameter couples a tab and its corresponding content.\n\n## Customization\n\nIn order to apply CSS customizations in this and other blocks, follow the instructions given in the recipe on [Using CSS Handles for store customization](https://developers.vtex.com/docs/guides/vtex-io-documentation-using-css-handles-for-store-customization).\n\n| CSS Handle |\n| ---------- |\n| `container` |\n| `contentContainer` |\n| `contentItem` |\n| `listContainer` |\n| `listItem` |\n| `listItemActive` |\n| `listItemChildren` |\n| `listItemChildrenActive` |\n\n<!-- DOCS-IGNORE:start -->\n\n## Contributors ✨\n\nThanks goes to these wonderful people:\n\n<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->\n<!-- prettier-ignore-start -->\n<!-- markdownlint-disable -->\n<table>\n <tr>\n <td align=\"center\"><a href=\"https://github.com/JNussens\"><img src=\"https://avatars0.githubusercontent.com/u/7662734?v=4\" width=\"100px;\" alt=\"\"/><br /><sub><b>Jean Nussenzveig</b></sub></a><br /><a href=\"https://github.com/vtex-apps/tab-layout/commits?author=JNussens\" title=\"Code\">💻</a></td>\n <td align=\"center\"><a href=\"https://github.com/lucasayb\"><img src=\"https://avatars2.githubusercontent.com/u/17356081?v=4\" width=\"100px;\" alt=\"\"/><br /><sub><b>Lucas Yamamoto</b></sub></a><br /><a href=\"https://github.com/vtex-apps/tab-layout/commits?author=lucasayb\" title=\"Code\">💻</a></td>\n <td align=\"center\"><a href=\"https://acct.global/\"><img src=\"https://avatars0.githubusercontent.com/u/38354801?v=4\" width=\"100px;\" alt=\"\"/><br /><sub><b>weslybrandao</b></sub></a><br /><a href=\"https://github.com/vtex-apps/tab-layout/commits?author=weslybrandao\" title=\"Code\">💻</a></td>\n </tr>\n</table>\n\n<!-- markdownlint-enable -->\n<!-- prettier-ignore-end -->\n<!-- ALL-CONTRIBUTORS-LIST:END -->\n\nThis project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!\n\n<!-- DOCS-IGNORE:end -->\n\n```"
}
] |
code_tab-layout_66de6037
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of tab-layout/react/TabContent.tsx from the tab-layout VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```tsx\nimport React from 'react'\nimport { defineMessages } from 'react-intl'\nimport { useCssHandles } from 'vtex.css-handles'\n\nconst CSS_HANDLES = ['contentContainer'] as const\n\nconst TabContent: StorefrontFunctionComponent = props => {\n const { children } = props\n const handles = useCssHandles(CSS_HANDLES)\n\n return (\n <div className={`${handles.contentContainer} w-100`}>\n {React.Children.map(children, (child, index) => React.cloneElement(child as any, { position: index }))}\n </div>\n )\n}\n\nconst messages = defineMessages({\n title: {\n defaultMessage: '',\n id: 'admin/editor.tabContent.title',\n },\n description: {\n defaultMessage: '',\n id: 'admin/editor.tabContent.description',\n },\n})\n\nTabContent.schema = {\n title: messages.title.id,\n description: messages.description.id,\n}\n\nexport default TabContent\n```"
}
] |
code_tab-layout_efa43514
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of tab-layout/react/TabListItemChildren.tsx from the tab-layout VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```tsx\nimport React from 'react'\nimport { defineMessages } from 'react-intl'\n\nimport { useCssHandles } from 'vtex.css-handles'\n\nimport { useTabState, useTabDispatch } from './components/TabLayoutContext'\nimport { useDeprecatedDefaultActiveTab } from './modules/useDeprecatedDefaultActiveTab'\n\nconst CSS_HANDLES = ['listItemChildren', 'listItemChildrenActive'] as const\n\ninterface Props {\n tabId: string\n defaultActiveTab: boolean //deprecated\n position: number\n}\n\nconst TabListItemChildren: StorefrontFunctionComponent<Props> = props => {\n const { tabId, defaultActiveTab, position, children } = props\n const handles = useCssHandles(CSS_HANDLES)\n const { activeTab } = useTabState()\n const dispatch = useTabDispatch()\n\n useDeprecatedDefaultActiveTab(defaultActiveTab, tabId)\n\n const isActive = activeTab === tabId || (!activeTab && position === 0)\n\n const handleClick = () =>\n dispatch({\n type: 'changeActiveTab',\n payload: { newActiveTab: tabId },\n })\n\n return (\n <div\n role=\"button\"\n onClick={handleClick}\n className={`${handles.listItemChildren} ${\n isActive ? handles.listItemChildrenActive : ''\n } ph2 pv2 ma2`}\n >\n {children}\n </div>\n )\n}\n\nconst messages = defineMessages({\n title: {\n defaultMessage: '',\n id: 'admin/editor.tabListItem.title',\n },\n description: {\n defaultMessage: '',\n id: 'admin/editor.tabListItem.description',\n },\n})\n\nTabListItemChildren.schema = {\n title: messages.title.id,\n description: messages.description.id,\n}\n\nexport default TabListItemChildren\n\n```"
}
] |
code_tab-layout_41e53d4f
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of tab-layout/react/TabListItem.tsx from the tab-layout VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```tsx\nimport React from 'react'\nimport { defineMessages } from 'react-intl'\n\nimport { Button } from 'vtex.styleguide'\nimport { IOMessage } from 'vtex.native-types'\nimport { useCssHandles } from 'vtex.css-handles'\n\nimport { useTabState, useTabDispatch } from './components/TabLayoutContext'\nimport { useDeprecatedDefaultActiveTab } from './modules/useDeprecatedDefaultActiveTab'\n\nconst CSS_HANDLES = ['listItem', 'listItemActive'] as const\n\ninterface Props {\n tabId: string\n label: string\n /**\n * @deprecated This prop should not be used\n */\n defaultActiveTab: boolean\n position: number\n}\n\nfunction TabListItem(props: Props) {\n const { tabId, label, defaultActiveTab, position } = props\n const handles = useCssHandles(CSS_HANDLES)\n const { activeTab } = useTabState()\n const dispatch = useTabDispatch()\n\n useDeprecatedDefaultActiveTab(defaultActiveTab, tabId)\n\n const isActive = activeTab === tabId || (!activeTab && position === 0)\n\n const handleClick = () =>\n dispatch({\n type: 'changeActiveTab',\n payload: { newActiveTab: tabId },\n })\n\n if (!label || label === '') {\n return null\n }\n\n return (\n <div\n className={`${handles.listItem} ${\n isActive ? handles.listItemActive : ''\n } ph2 pv2 ma2`}\n >\n <Button\n variation={isActive ? 'primary' : 'tertiary'}\n onClick={handleClick}\n >\n <IOMessage id={label} />\n </Button>\n </div>\n )\n}\n\nconst messages = defineMessages({\n title: {\n id: 'admin/editor.tabListItem.title',\n },\n description: {\n id: 'admin/editor.tabListItem.description',\n },\n})\n\nTabListItem.schema = {\n title: messages.title.id,\n description: messages.description.id,\n}\n\nexport default TabListItem\n\n```"
}
] |
code_tab-layout_a8d4910b
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of tab-layout/react/package.json from the tab-layout VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```json\n{\n \"dependencies\": {\n \"ramda\": \"^0.26.1\",\n \"react\": \"^16.8.6\",\n \"react-intl\": \"^2.9.0\"\n },\n \"devDependencies\": {\n \"@types/graphql\": \"^14.2.0\",\n \"@types/jest\": \"^24.0.11\",\n \"@types/node\": \"^11.13.2\",\n \"@types/ramda\": \"^0.26.8\",\n \"@types/react\": \"^16.8.13\",\n \"@types/react-intl\": \"^2.3.17\",\n \"eslint\": \"5.15.1\",\n \"eslint-config-vtex\": \"10.1.0\",\n \"eslint-config-vtex-react\": \"4.1.0\",\n \"vtex.render-runtime\": \"http://vtex.vteximg.com.br/_v/public/typings/v1/vtex.render-runtime@8.65.0/public/_types/react\",\n \"vtex.styleguide\": \"http://vtex.vteximg.com.br/_v/public/typings/v1/vtex.styleguide@9.79.4/public/_types/react\"\n },\n \"version\": \"0.4.6\"\n}\n\n```"
}
] |
code_tab-layout_32342fa4
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of tab-layout/react/TabList.tsx from the tab-layout VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```tsx\nimport React from 'react'\nimport { defineMessages } from 'react-intl'\nimport { useCssHandles } from 'vtex.css-handles'\n\nconst CSS_HANDLES = ['listContainer'] as const\n\nconst TabList: StorefrontFunctionComponent = props => {\n const { children } = props\n const handles = useCssHandles(CSS_HANDLES)\n\n return (\n <div className={`${handles.listContainer} flex w-100 flex-wrap justify-center`}>\n {React.Children.map(children, (child, index) => React.cloneElement(child as any, { position: index }))}\n </div>\n )\n}\n\nconst messages = defineMessages({\n title: {\n defaultMessage: '',\n id: 'admin/editor.tabList.title',\n },\n description: {\n defaultMessage: '',\n id: 'admin/editor.tabList.description',\n },\n})\n\nTabList.schema = {\n title: messages.title.id,\n description: messages.description.id,\n}\n\nexport default TabList\n```"
}
] |
code_tab-layout_52c153fc
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of tab-layout/react/TabLayout.tsx from the tab-layout VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```tsx\nimport React from 'react'\nimport { defineMessages } from 'react-intl'\nimport { useCssHandles } from 'vtex.css-handles'\n\nimport {\n TabLayoutContextProvider\n} from './components/TabLayoutContext'\n\nconst CSS_HANDLES = ['container'] as const\n\ninterface Props {\n defaultActiveTabId?: string\n}\n\nconst TabLayout: StorefrontFunctionComponent<Props> = props => {\n const { children, defaultActiveTabId = '' } = props\n const handles = useCssHandles(CSS_HANDLES)\n\n return (\n <TabLayoutContextProvider activeTab={defaultActiveTabId}>\n <div className={handles.container}>\n {children}\n </div>\n </TabLayoutContextProvider>\n )\n}\n\nconst messages = defineMessages({\n title: {\n defaultMessage: '',\n id: 'admin/editor.tabLayout.title',\n },\n description: {\n defaultMessage: '',\n id: 'admin/editor.tabLayout.description',\n },\n})\n\nTabLayout.schema = {\n title: messages.title.id,\n description: messages.description.id,\n}\n\nexport default TabLayout\n```"
}
] |
code_tab-layout_8847e61d
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of tab-layout/react/TabContentItem.tsx from the tab-layout VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```tsx\nimport React from 'react'\nimport { defineMessages } from 'react-intl'\nimport { useCssHandles } from 'vtex.css-handles'\n\nimport {\n useTabState\n} from './components/TabLayoutContext'\n\nconst CSS_HANDLES = ['contentItem'] as const\n\ninterface Props {\n tabId: string\n position: number\n}\n\nconst TabContentItem: StorefrontFunctionComponent<Props> = props => {\n const { tabId, children, position } = props\n const handles = useCssHandles(CSS_HANDLES)\n const { activeTab } = useTabState()\n\n const shouldShow = activeTab === tabId || (!activeTab && position === 0)\n\n if (!shouldShow) return null\n\n return (\n <div className={`${handles.contentItem} w-100`}>\n {children}\n </div>\n )\n}\n\nconst messages = defineMessages({\n title: {\n defaultMessage: '',\n id: 'admin/editor.tabContentItem.title',\n },\n description: {\n defaultMessage: '',\n id: 'admin/editor.tabContentItem.description',\n },\n})\n\nTabContentItem.schema = {\n title: messages.title.id,\n description: messages.description.id,\n}\n\nexport default TabContentItem\n```"
}
] |
code_tab-layout_91a18805
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of tab-layout/store/contentSchemas.json from the tab-layout VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```json\n{\n \"definitions\": {\n \"TabListItem\": {\n \"type\": \"object\",\n \"properties\": {\n \"label\": {\n \"title\": \"admin/editor.tabListItem.label\",\n \"$ref\": \"app:vtex.native-types#/definitions/text\",\n \"default\": \"\"\n }\n }\n }\n }\n}\n```"
}
] |
code_tab-layout_5b122b5e
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of tab-layout/store/interfaces.json from the tab-layout VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```json\n{\n \"tab-layout\": {\n \"component\": \"TabLayout\",\n \"composition\": \"children\",\n \"allowed\": \"*\"\n },\n \"tab-list\": {\n \"component\": \"TabList\",\n \"composition\": \"children\",\n \"allowed\": [\"tab-list.item\"]\n },\n \"tab-list.item\": {\n \"component\": \"TabListItem\",\n \"content\": {\n \"$ref\": \"app:vtex.tab-layout#/definitions/TabListItem\"\n }\n },\n \"tab-list.item.children\": {\n \"component\": \"TabListItemChildren\",\n \"composition\": \"children\"\n },\n \"tab-content\": {\n \"component\": \"TabContent\",\n \"composition\": \"children\",\n \"allowed\": \"*\"\n },\n \"tab-content.item\": {\n \"component\": \"TabContentItem\",\n \"composition\": \"children\",\n \"allowed\": \"*\"\n }\n}\n```"
}
] |
code_tab-layout_16e72074
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of tab-layout/react/typings/vtex.css-handles.d.ts from the tab-layout VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\ndeclare module 'vtex.css-handles' {\n type CssHandlesInput = readonly string[]\n type ValueOf<T extends readonly any[]> = T[number]\n type CssHandles<T extends CssHandlesInput> = Record<ValueOf<T>, string>\n interface CssHandlesOptions {\n migrationFrom?: string | string[]\n }\n\n export const useCssHandles: <T extends CssHandlesInput>(\n handles: T,\n options: CssHandlesOptions = {}\n ) => CssHandles<T>\n export const applyModifiers: (\n handles: string,\n modifier: string | string[]\n ) => string\n}\n\n```"
}
] |
code_tab-layout_ed0b2d97
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of tab-layout/react/typings/global.d.ts from the tab-layout VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { FunctionComponent } from 'react'\n\ndeclare global {\n interface StorefrontFunctionComponent<P = {}> extends FunctionComponent<P> {\n schema?: object\n getSchema?(props?: P): object\n }\n\n interface StorefrontComponent<P = {}, S = {}> extends Component<P, S> {\n schema?: object\n getSchema?(props: P): object\n }\n\n interface StorefrontElement extends ReactElement {\n schema?: object\n getSchema?(props: P): object\n }\n}\n```"
}
] |
code_tab-layout_8db738ac
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of tab-layout/react/typings/css.d.ts from the tab-layout VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\ndeclare module '*.css' {\n const css: any\n export default css\n }\n```"
}
] |
code_tab-layout_fccf9bce
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of tab-layout/react/typings/vtex.styleguide.d.ts from the tab-layout VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\ndeclare module 'vtex.styleguide' {\n export const Button\n}\n```"
}
] |
code_tab-layout_5d89077c
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of tab-layout/react/components/TabLayoutContext.tsx from the tab-layout VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```tsx\nimport React, { FunctionComponent, useContext, useReducer } from 'react'\n\ninterface TabLayoutContextProps {\n activeTab: string\n}\n\ninterface ChangeActiveTabAction {\n type: 'changeActiveTab'\n payload: {\n newActiveTab: string\n }\n}\n\ntype Dispatch = (action: ChangeActiveTabAction) => void\n\nconst initialState = {\n activeTab: \"\"\n}\n\nconst TabLayoutStateContext = React.createContext<TabLayoutContextProps>(initialState)\nconst TabLayoutDispatchContext = React.createContext<Dispatch | undefined>(undefined)\n\nfunction reducer(state: TabLayoutContextProps, action: ChangeActiveTabAction): TabLayoutContextProps {\n switch (action.type) {\n case 'changeActiveTab':\n if (action.payload.newActiveTab === state.activeTab) {\n return state\n }\n return {\n ...state,\n activeTab: action.payload.newActiveTab\n }\n default:\n return state\n }\n}\n\nconst TabLayoutContextProvider: FunctionComponent<\n TabLayoutContextProps\n> = ({ children, activeTab }) => {\n const [state, dispatch] = useReducer(reducer, {\n activeTab,\n })\n return (\n <TabLayoutStateContext.Provider value={state}>\n <TabLayoutDispatchContext.Provider value={dispatch}>\n {children}\n </TabLayoutDispatchContext.Provider>\n </TabLayoutStateContext.Provider>\n )\n}\n\nfunction useTabState() {\n const context = useContext(TabLayoutStateContext)\n if (context === undefined) {\n throw new Error(\n 'useTabState must be used within a TabLayoutStateContextProvider'\n )\n }\n return context\n}\n\nfunction useTabDispatch() {\n const context = useContext(TabLayoutDispatchContext)\n\n if (context === undefined) {\n throw new Error(\n 'useTabDispatch must be used within a TabLayoutDispatchContextProvider'\n )\n }\n return context\n}\n\nexport { TabLayoutContextProvider, useTabDispatch, useTabState }\n```"
}
] |
code_tab-layout_6acd46b4
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of tab-layout/react/modules/useDeprecatedDefaultActiveTab.ts from the tab-layout VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { useEffect } from 'react'\nimport { useTabState, useTabDispatch } from '../components/TabLayoutContext'\n\nexport const useDeprecatedDefaultActiveTab = (defaultActiveTab: boolean, tabId: string) => {\n const { activeTab } = useTabState()\n const dispatch = useTabDispatch()\n\n useEffect(() => {\n // defaultActiveTab has been deprecated, keep this for compatibility\n if (defaultActiveTab && activeTab === '') {\n dispatch({\n type: 'changeActiveTab',\n payload: { newActiveTab: tabId },\n })\n }\n }, [])\n}\n```"
}
] |
code_shopback_bc25a942
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of shopback/docs/README.md from the shopback VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```markdown\n# Shopback\n\nOpen the VTEX APP Store and install the app on your store.\n\nor\n\nRun the following command:\n\n```sh\nvtex install vtex.shopback@0.x\n```\n\nNext, open the app settings on your admin and fill the form with your Shopback Id.\n```"
}
] |
code_shopback_8e239b58
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of shopback/react/index.tsx from the shopback VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```tsx\nimport { PixelMessage } from './typings/events'\nimport { canUseDOM } from 'vtex.render-runtime'\n\nfunction handleMessages(event: PixelMessage) {\n const {\n data,\n data: { eventName },\n } = event\n if (eventName === 'vtex:orderPlaced') {\n const { transactionSubtotal: valor, transactionId: order_id } = data\n window._cv_data = {\n order_id,\n valor,\n }\n let script = document.createElement('script')\n script.type = 'text/javascript'\n script.async = true\n script.src = '//app.shoptarget.com.br/js/tracking.js'\n let firstScript = document.getElementsByTagName('script')[0]\n if (firstScript && firstScript.parentNode) {\n firstScript.parentNode.insertBefore(script, firstScript)\n }\n }\n}\n\nif (canUseDOM) {\n window.addEventListener('message', handleMessages)\n}\n\n```"
}
] |
code_shopback_47d68fda
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of shopback/react/package.json from the shopback VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```json\n{\n \"scripts\": {\n \"test\": \"vtex-test-tools test\"\n },\n \"devDependencies\": {\n \"@types/graphql\": \"^14.2.0\",\n \"@types/jest\": \"^24.0.11\",\n \"@types/node\": \"^11.13.0\",\n \"@types/ramda\": \"^0.26.5\",\n \"@vtex/test-tools\": \"^1.1.0\",\n \"eslint\": \"^5.15.1\",\n \"eslint-config-vtex\": \"^10.1.0\",\n \"eslint-config-vtex-react\": \"^4.1.0\",\n \"prettier\": \"^1.18.2\",\n \"tslint-eslint-rules\": \"^5.4.0\",\n \"typescript\": \"3.5.2\",\n \"vtex.pixel-interfaces\": \"http://vtex.vteximg.com.br/_v/public/typings/v1/vtex.pixel-interfaces@1.1.0/public/_types/react\",\n \"vtex.render-runtime\": \"http://vtex.vteximg.com.br/_v/public/typings/v1/vtex.render-runtime@8.58.0/public/_types/react\"\n }\n}\n\n```"
}
] |
code_shopback_ee52ccfe
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of shopback/store/interfaces.json from the shopback VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```json\n{\n \"pixel.shopback\": {\n \"component\": \"index\"\n }\n}\n\n```"
}
] |
code_shopback_138955b3
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of shopback/react/typings/events.d.ts from the shopback VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nexport interface PixelMessage extends MessageEvent {\n data: OrderPlacedData\n}\n\nexport interface EventData {\n event: string\n eventName: string\n currency: string\n}\n\nexport interface OrderPlacedData extends Order, EventData {\n event: 'orderPlaced'\n eventName: 'vtex:orderPlaced'\n transactionSubtotal: string\n}\n\nexport interface Order {\n currency: string\n accountName: string\n orderGroup: string\n salesChannel: string\n coupon: string\n visitorType: string\n visitorContactInfo: string[]\n transactionId: string\n transactionDate: string\n transactionAffiliation: string\n transactionTotal: number\n transactionShipping: number\n transactionTax: number\n transactionCurrency: string\n transactionPaymentType: PaymentType[]\n transactionShippingMethod: ShippingMethod[]\n transactionProducts: ProductOrder[]\n transactionPayment: {\n id: string\n }\n}\n\ninterface PaymentType {\n group: string\n paymentSystemName: string\n installments: number\n value: number\n}\n\ninterface ShippingMethod {\n itemId: string\n selectedSla: string\n}\n\ninterface ProductOrder {\n id: string\n name: string\n sku: string\n skuRefId: string\n skuName: string\n brand: string\n brandId: string\n seller: string\n sellerId: string\n category: string\n categoryId: string\n categoryTree: string[]\n categoryIdTree: string[]\n originalPrice: number\n price: number\n sellingPrice: number\n tax: number\n quantity: number\n components: any[]\n measurementUnit: string\n unitMultiplier: number\n}\n\n```"
}
] |
code_shopback_2958618c
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of shopback/react/typings/vtex.render-runtime.d.ts from the shopback VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\ndeclare module 'vtex.render-runtime' {\n export const canUseDOM: boolean\n}\n\n```"
}
] |
code_shopback_b1f266cb
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of shopback/react/typings/global.d.ts from the shopback VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\ninterface Window extends Window {\n _st_account: string\n _cv_data: CVData\n}\n\ninterface CVData {\n order_id: string\n valor: string\n}\n\n```"
}
] |
code_paginated-table_83c72037
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of paginated-table/messages/it-IT.json from the paginated-table VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```json\n{\n \"admin/table.show-rows\": \"Mostra righe\",\n \"admin/table.of\": \"di\",\n \"admin/table.item-label\": \"{total, plural, one {elemento} other {elementi}}\"\n}\n\n```"
}
] |
code_paginated-table_e343b2d7
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of paginated-table/messages/th-TH.json from the paginated-table VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```json\n{\n \"admin/table.show-rows\": \"แสดงแถว\",\n \"admin/table.of\": \"ของ\",\n \"admin/table.item-label\": \"{total, plural, one {รายการ} other {รายการ}}\"\n}\n\n```"
}
] |
code_paginated-table_f00f6ea9
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of paginated-table/messages/ko-KR.json from the paginated-table VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```json\n{\n \"admin/table.show-rows\": \"행 표시\",\n \"admin/table.of\": \"/\",\n \"admin/table.item-label\": \"{total, plural, one {항목} other {항목}}\"\n}\n```"
}
] |
code_paginated-table_b5cd53b3
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of paginated-table/messages/ja-JP.json from the paginated-table VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```json\n{\n \"admin/table.show-rows\": \"表示行数\",\n \"admin/table.of\": \"/\",\n \"admin/table.item-label\": \"{total, plural, one {項目} other {項目}}\"\n}\n```"
}
] |
code_paginated-table_dd7584f3
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of paginated-table/messages/bg-BG.json from the paginated-table VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```json\n{\n \"admin/table.show-rows\": \"Показване на редове\",\n \"admin/table.of\": \"от\",\n \"admin/table.item-label\": \"{total, plural, one {артикул} other {артикули}}\"\n}\n```"
}
] |
code_paginated-table_64cd632d
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of paginated-table/messages/pt.json from the paginated-table VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```json\n{\n \"admin/table.show-rows\": \"Mostrar linhas\",\n \"admin/table.of\": \"de\",\n \"admin/table.item-label\": \"{total, plural, one {unidade} other {unidades}}\"\n}\n```"
}
] |
code_paginated-table_cfc16f6e
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of paginated-table/messages/en.json from the paginated-table VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```json\n{\n \"admin/table.show-rows\": \"Show rows\",\n \"admin/table.of\": \"of\",\n \"admin/table.item-label\": \"{total, plural, one {item} other {items}}\"\n}\n```"
}
] |
code_paginated-table_463791a4
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of paginated-table/messages/ro-RO.json from the paginated-table VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```json\n{\n \"admin/table.show-rows\": \"Arată rânduri\",\n \"admin/table.of\": \"din\",\n \"admin/table.item-label\": \"{total, plural, one {articol} few {articole} other {articole}}\"\n}\n\n```"
}
] |
code_paginated-table_e439bfd2
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of paginated-table/messages/de-DE.json from the paginated-table VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```json\n{\n \"admin/table.show-rows\": \"Zeilen anzeigen\",\n \"admin/table.of\": \"von\",\n \"admin/table.item-label\": \"{total, plural, one {Artikel} other {Artikel}}\"\n}\n```"
}
] |
code_paginated-table_6e1c601f
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of paginated-table/messages/fr-FR.json from the paginated-table VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```json\n{\n \"admin/table.show-rows\": \"Afficher les lignes\",\n \"admin/table.of\": \"de\",\n \"admin/table.item-label\": \"{total, plural, one {article} other {articles}}\"\n}\n\n```"
}
] |
code_paginated-table_42b7a392
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of paginated-table/messages/nl-NL.json from the paginated-table VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```json\n{\n \"admin/table.show-rows\": \"Toon rijen\",\n \"admin/table.of\": \"van\",\n \"admin/table.item-label\": \"{total, plural, one {item} other {items}}\"\n}\n\n```"
}
] |
code_paginated-table_a9856bcb
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of paginated-table/messages/es.json from the paginated-table VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```json\n{\n \"admin/table.show-rows\": \"Mostrar filas\",\n \"admin/table.of\": \"de\",\n \"admin/table.item-label\": \"{total, plural, one {ítem} other {ítems}}\"\n}\n```"
}
] |
code_paginated-table_9030a6b0
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of paginated-table/docs/README.md from the paginated-table VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```markdown\n> :warning: **Unmantained**: This repository is currently unmaintaned and is considered obsolete. It's based on VTEX Styleguide, which is no longer being worked on. Please consider migrating to [ADMIN UI's table and hooks](https://admin-ui.vercel.app/components/table), some of these functionalities are already provided by it and it's flexible enough to allow for the others. Feel free to re-use code from the hooks implemented here in your project if it makes sense to you\n> \n> If you'd like to keep updating this repository you are able to contribute and make new releases as long as you are in the `tech` team on vtex-apps. It is no longer adviseble to evolve functionalities based on styleguide's table though.\n\n# Paginated Table\n\n## Description\n\nThe Paginated Table is a wrapper to the VTEX Styleguide Table that abstracts some of the logic that normally one should write to handle pagination with GraphQL\n\n## Table of Contents\n\n- [Paginated Table](#paginated-table)\n - [Description](#description)\n - [Table of Contents](#table-of-contents)\n - [Usage](#usage)\n - [PaginatedTable](#paginatedtable)\n - [PersistedPaginatedTable](#persistedpaginatedtable)\n - [Troubleshooting](#troubleshooting)\n - [Contributing](#contributing)\n\n## Usage\n\nThis app uses our styleguide as the Table engine. To know more about the VTEX Styleguide [click here.](https://styleguide.vtex.com/)\n\nTo use this app, you need to import it in your dependencies in `manifest.json`.\n\n```json\n dependencies: {\n \"vtex.paginated-table\": \"0.x\"\n }\n```\n\nThen, import the `PaginatedTable` component into your app as\n\n```jsx\nimport { PaginatedTable } from 'vtex.paginated-table'\n```\n\nIf you prefer to use the `PersistedPaginatedTable`, you can do it as follows\n\n```jsx\nimport { PersistedPaginatedTable } from 'vtex.paginated-table'\n```\n\nIf you want to use the table V2 and its hooks you can import just the hooks you will be using.\n\n```jsx\nimport { ExtendedTable, useDynamicMeasures, useInverseTableSort } from 'vtex.paginated-table'\n```\n\n## Table V2\n\n### ExtendedTable\n\nThis table works like styleguide's table V2 with some extra optional params to add the following features:\n\n- Sorting with default ordering = 'DSC'\n- Dynamic row heights\n- Detecting on rowHover\n- Expandable rows (rows that can be expanded vertically to show more info)\n\n#### To use hovering:\n\nAdd parameter `hovering`\n\n```jsx\nconst hovering = {\n // called when hovering a row\n onMouseEnter = (id: string) => void\n // called when mouse leaves table (so it's no longer hovering any row)\n onMouseLeave = () => void\n}\n```\n\n#### To use dynamic rowHeights:\n\nAdd parameter `measuringRef` to table and use `useDynamicMeasures` to get the parameter `measures` and ref\n\n```jsx\nconst { ref, measures } = useDynamicMeasures({\n lenght: items.length || 0,\n })\n\n <ExtendedTable\n measures={measures}\n measuringRef={ref}\n {...}\n />\n```\n\n#### To use sorting with default sort order:\n\nUse either hook `useInverseTableSort` or `usePersistedTableSort` with defaultSortOrder parameter to get `sorting` and feed it to the table\n\n```jsx\nconst { sortOrder, sortedBy: sortBy, sorting } = usePersistedTableSort({\n defaultSortOrder: 'DSC',\n })\n\n <ExtendedTable\n sorting={sorting}\n />\n```\n\n### To use row expansion functionality\n\nYou must add `rowExpansion` prop which contains a map indicating what rows are expanded. You can use the `useExpandableRows` hook as the value for `rowExpansion`.\n\nAdditionally, to the data of each item on the table you must add the props:\n\n```jsx\n{\n // indicates if this row will be expandable, set it to always true if you want all rows\n // to be expandable\n isExpandable?: boolean\n // what will be rendered inside the expanded area for this row\n extendedRowRenderer?: React.ReactNode,\n}\n```\n\nInside any cell rendered for a column you will get the addtional info `isExpanded` in case you want to change the style based on that. (be aware you will only get this data if this column is defined with `isExtended` the prop that makes the cell get the full rowData)\n\n```jsx\n const items = rawData.map((item: any) => ({\n name: item.fullName\n // REQUIRED parameters:\n id: item.ID,\n isExpandable: true,\n extendedRowRenderer: <ExtraInfoComponent item={item} />,\n }))\n\n // the items array MUST have id for each item, this is used to control what rows are expanded\n const rowExpansion = useExpandableRows({\n items,\n })\n\n\n <ExtendedTable\n onRowClick={({\n rowData: { id },\n }: {\n rowData: {\n id: any\n }\n }) => {\n rowExpansion.toggleExpandRow(id)\n }}\n rowExpansion={rowExpansion}\n />\n```\n\n## Table V1\n\n### PaginatedTable\n\nAlong the usual [Styleguide Table's props](https://styleguide.vtex.com/#/Components/Display/Table), this table has the following props:\n\n| Prop name | Type | Description | Default value |\n| --------------------- | ---------- | ----------------------------------------------------------------------------------------------------- | ------------- |\n| `fetchMore` | `Function` | A React Apollo `fetchMore` function to fetch data for the next/last page | Required |\n| `total` | `Number` | The total number of items in your data | Required |\n| `updateQuery` | `Function` | A React Apollo `updateQuery` function that runs the `fetchMore` function in order to update your data | Required |\n| `updatePaginationKey` | `String` | A key to force a table update when it changes | `''` |\n| `onSortChange` | `Function` | A callback to be called whenever there is a Sort change in the Table | `() => {}` |\n\n**OBS:**\n\n- Detailed specifications for `fetchMore` and `updateQuery` can be seen in [this Apollo link](https://www.apollographql.com/docs/react/data/pagination/)\n- The callback provided to `onSortChange` should have the following signature `(newSortedBy: string, newSortOrder: 'ASC' | 'DESC') => void`\n\n### PersistedPaginatedTable\n\nThe `PersistedPaginatedTable` uses the page's query string to persist the table pagination state. It is meant to be used whenever the page has interactive elements that make the user to leave the page that contains the table without resetting the table state or to share a specific table state between users (e.g. by providing a link to the page that contains the table).\n\nAlong the usual [Styleguide Table's props](https://styleguide.vtex.com/#/Components/Display/Table), this table has the following props:\n\n| Prop name | Type | Description | Default value |\n| ------------------------ | -------------------------- | -------------------------------------------------------- | ------------- |\n| `total` | `Number` | The total number of items in your data | Required |\n| `updatePaginationKey` | `String` | A key to force a table update when it changes | `''` |\n| `defaultElementsPerPage` | `Number` | The default number of elements per table page | `15` |\n| `defaultSortOrder` | One of [`'ASC'`, `'DESC'`] | The default sort order for the page | `'ASC'` |\n| `defaultSortedBy` | `String` | The default column by which the table is to be sorted by | `''` |\n\n```"
}
] |
code_paginated-table_ca1dfaf4
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of paginated-table/react/PaginatedTable.tsx from the paginated-table VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```tsx\nimport React, { useState, useEffect } from 'react'\nimport { Table } from 'vtex.styleguide'\nimport { GraphqlQueryControls } from 'react-apollo'\nimport { JSONSchema6Type } from 'json-schema'\nimport { defineMessages, useIntl } from 'react-intl'\n\nconst INITIAL_ELEMENTS_PER_PAGE = 15\n\ntype Props<TItem, TQueryVariables, TSchema extends JSONSchema6Type> = {\n fetchMore: GraphqlQueryControls<TQueryVariables>['fetchMore']\n total: number\n updateQuery: any\n updatePaginationKey?: string\n onSortChange?: (sortedBy: string, sortOrder: string) => void\n} & TableProps<TItem, TSchema>\n\ntype TableProps<TItem, TSchema extends JSONSchema6Type> = {\n items: TItem[]\n schema: TSchema\n loading?: boolean\n emptyStateLabel?: React.ReactNode\n emptyStateChildren?: React.ReactNode\n onRowClick?: OnRowClickHandler<TItem>\n totalizers?: any\n filters?: any\n toolbar?: {\n inputSearch?: {\n value: IntlMessage\n placeholder: React.ReactNode\n onChange: React.ChangeEventHandler<HTMLInputElement>\n onClear: React.ChangeEventHandler<HTMLInputElement>\n onSubmit: React.MouseEventHandler<HTMLSpanElement>\n }\n density?: {\n buttonLabel: IntlMessage\n lowOptionLabel: IntlMessage\n mediumOptionLabel: IntlMessage\n highOptionLabel: IntlMessage\n }\n fields?: {\n label: IntlMessage\n showAllLabel: IntlMessage\n hideAllLabel: IntlMessage\n }\n download?: {\n label: IntlMessage\n handleCallback: () => void\n }\n upload?: {\n label: IntlMessage\n handleCallback: () => void\n }\n extraActions?: {\n label: IntlMessage\n actions: {\n label: IntlMessage\n handleCallback: () => void\n }[]\n }\n newLine?: {\n label: IntlMessage\n handleCallback: () => void\n }\n }\n lineActions?: {\n label: () => IntlMessage\n isDangerous?: boolean\n onClick: Function\n }[]\n bulkActions?: {\n texts: {\n secondaryActionsLabel: string\n rowsSelected: Function\n selectAll: string\n allRowsSelected: Function\n }\n totalItems?: number\n main: {\n label: string\n handleCallback: Function\n }\n others: {\n label: string\n handleCallback: Function\n }[]\n }\n}\n\nexport type OnRowClickHandler<TItem> = ({ rowData }: { rowData: TItem }) => void\nexport type IntlMessage = string | JSX.Element\n\nconst messages = defineMessages({\n of: {\n id: 'admin/table.of',\n defaultMessage: 'of',\n },\n showRowsLabel: {\n id: 'admin/table.show-rows',\n defaultMessage: 'Show rows',\n },\n})\n\nconst PaginatedTable = <\n TItem,\n TQueryVariables extends { to: number; from: number },\n TSchema extends JSONSchema6Type\n>(\n props: Props<TItem, TQueryVariables, TSchema>\n) => {\n const [from, setFrom] = useState(0)\n const [to, setTo] = useState(INITIAL_ELEMENTS_PER_PAGE)\n const [currentPage, setCurrentPage] = useState(0)\n const [elementsPerPage, setElementsPerPage] = useState(INITIAL_ELEMENTS_PER_PAGE)\n const [sortedBy, setSortedBy] = useState('')\n const [sortOrder, setSortOrder] = useState('ASC')\n\n const { formatMessage } = useIntl()\n\n const {\n items = [],\n updateQuery,\n total,\n fetchMore,\n updatePaginationKey,\n onSortChange = () => {},\n ...tableProps\n } = props\n\n useEffect(() => {\n setFrom(0)\n setTo(elementsPerPage)\n setCurrentPage(0)\n }, [updatePaginationKey])\n\n const onPageChange = (\n newPage: number,\n currentElementsPerPage: number = elementsPerPage\n ) => async () => {\n const from = newPage * currentElementsPerPage\n\n const to = Math.min((newPage + 1) * currentElementsPerPage, total)\n\n if (items.slice(from, to).length !== to - from) {\n await fetchMore({\n updateQuery,\n variables: { from, to },\n })\n }\n\n setTo(to)\n setFrom(from)\n setCurrentPage(newPage)\n }\n\n const totalPages = Math.ceil(total / elementsPerPage)\n\n const nextPage = (currentPage + 1) % totalPages\n\n const previousPage = totalPages - 1 - ((totalPages - currentPage) % totalPages)\n\n return (\n <Table\n fullWidth\n items={items.slice(from, to)}\n pagination={{\n currentItemFrom: from + 1,\n currentItemTo: to,\n onNextClick: onPageChange(nextPage),\n onPrevClick: onPageChange(previousPage),\n rowsOptions: [10, 15, 25],\n selectedOption: elementsPerPage,\n onRowsChange: async (e: React.ChangeEvent<HTMLSelectElement>) => {\n setElementsPerPage(parseInt(e.target.value))\n onPageChange(currentPage, parseInt(e.target.value))()\n },\n textOf: formatMessage(messages.of),\n textShowRows: formatMessage(messages.showRowsLabel),\n totalItems: total,\n }}\n density=\"low\"\n sort={{\n sortedBy,\n sortOrder,\n }}\n onSort={({\n sortOrder: newSortOrder,\n sortedBy: newSortedBy,\n }: {\n sortOrder: string\n sortedBy: string\n }) => {\n setSortOrder(newSortOrder)\n setSortedBy(newSortedBy)\n onSortChange(newSortedBy, newSortOrder)\n }}\n {...tableProps}\n />\n )\n}\n\nexport default PaginatedTable\n\n```"
}
] |
code_paginated-table_bf62f252
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of paginated-table/react/useInverseTableSort.tsx from the paginated-table VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```tsx\nimport { useState } from 'react'\n\nexport default function useInverseTableSort(initialState?: { by: string; order: string }) {\n const [by, setBy] = useState<string | undefined>(initialState?.by)\n const [order, setOrder] = useState<string | undefined>(initialState?.order)\n\n const sort = (id: string) => {\n if (!by || by !== id) {\n setOrder('DSC')\n setBy(id)\n } else {\n setOrder((currentOrder: string | undefined) => {\n return currentOrder === 'DSC' ? 'ASC' : 'DSC'\n })\n setBy(id)\n }\n }\n\n const clear = () => {\n setBy(undefined)\n setOrder(undefined)\n }\n\n return {\n sorted: {\n order: order,\n by: by,\n },\n sort: sort,\n clear: clear,\n defaultOrder: 'DSC',\n }\n}\n\n```"
}
] |
code_paginated-table_7d78022b
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of paginated-table/react/usePersistedPagination.tsx from the paginated-table VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```tsx\nimport { useRuntime } from 'vtex.render-runtime'\nimport { useState, useCallback, useEffect, useRef } from 'react'\nimport { useIntl, defineMessages } from 'react-intl'\n\nconst INITIAL_ELEMENTS_PER_PAGE = 15\n\nconst messages = defineMessages({\n itemLabel: {\n defaultMessage: '{total, plural, one {item} other {items}}',\n id: 'admin/table.item-label',\n },\n of: {\n defaultMessage: 'of',\n id: 'admin/table.of',\n },\n showRowsLabel: {\n defaultMessage: 'Show rows',\n id: 'admin/table.show-rows',\n },\n})\n\nexport default function usePersistedPagination(props: {\n hasPageTopIndicator?: boolean\n defaultElementsPerPage?: number\n resetPaginationOnChangeKey: string\n}) {\n const {\n defaultElementsPerPage = INITIAL_ELEMENTS_PER_PAGE,\n hasPageTopIndicator = false,\n resetPaginationOnChangeKey,\n } = props\n\n const { formatMessage } = useIntl()\n const [total, setTotal] = useState(defaultElementsPerPage)\n const { setQuery, query } = useRuntime()\n const didMountRef = useRef(false)\n\n const elementsPerPage = parseInt(query.elements, 10) || defaultElementsPerPage\n\n const onPageChange = (\n currentFrom: number,\n currentElementsPerPage: number,\n direction: string\n ) => () => {\n const c = direction === 'next' ? 1 : -1\n\n const newFrom = currentFrom + c * currentElementsPerPage\n\n const newTo = Math.min(newFrom + currentElementsPerPage, total)\n\n setQuery({ to: newTo, from: newFrom, elements: currentElementsPerPage })\n }\n\n const resetPagination = useCallback(() => {\n setQuery({ to: elementsPerPage, from: 0, elements: elementsPerPage })\n }, [elementsPerPage, setQuery])\n\n const from = parseInt(query.from, 10) || 0\n const to = parseInt(query.to, 10) || elementsPerPage\n\n useEffect(() => {\n if (didMountRef.current) {\n resetPagination()\n } else {\n didMountRef.current = true\n }\n }, [resetPaginationOnChangeKey])\n\n return {\n resetPagination,\n from,\n to,\n setTotal,\n paginationProps: {\n currentItemFrom: from + 1,\n currentItemTo: to,\n hasPageTopIndicator,\n onNextClick: onPageChange(from, elementsPerPage, 'next'),\n onPrevClick: onPageChange(from, elementsPerPage, 'prev'),\n onRowsChange: (e: React.ChangeEvent<HTMLSelectElement>) => {\n const newElementsPerPage = parseInt(e.target.value, 10)\n const currentPage = Math.floor(from / newElementsPerPage)\n const newFrom = currentPage * newElementsPerPage\n setQuery({\n elements: newElementsPerPage,\n from: newFrom,\n to: newFrom + newElementsPerPage,\n })\n },\n rowsOptions: [10, 15, 25],\n selectedOption: elementsPerPage,\n textOf: formatMessage(messages.of),\n textShowRows: formatMessage(messages.showRowsLabel),\n totalItems: total,\n },\n }\n}\n\n```"
}
] |
code_paginated-table_4c36909b
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of paginated-table/react/useExpandableRows.tsx from the paginated-table VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```tsx\nimport { useState, useEffect, useMemo } from 'react'\n\nexport type IdMap = Record<string, boolean> | undefined\n\nexport default function useExpandableRows(props: { items: Array<{ id: string }> }) {\n const idsSummarizedString = props.items.reduce(\n (acc: string, currentItem) => `${acc}.${currentItem.id}`,\n ''\n )\n const itemsQuant = props.items.length\n\n const [expandedRowsAmount, setExpandedRowsAmount] = useState(0)\n const [isRowExpandedMap, setIsRowExpandedMap] = useState<IdMap>()\n\n const allExpandedMap = useMemo(() => {\n return props.items.reduce(\n (acc: IdMap, currentItem) => ({\n ...acc,\n [currentItem.id]: true,\n }),\n {}\n )\n // since props.items is an array and useMemo doesn't perform\n // deep compare idsSummarizedString is replacing props.items here\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [idsSummarizedString])\n\n useEffect(() => {\n setIsRowExpandedMap({})\n // since props.items is an array and useEffect doesn't perform\n // deep compare idsSummarizedString is replacing props.items here\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [idsSummarizedString])\n\n const toggleRow = (id: string) => {\n if (!isRowExpandedMap || !isRowExpandedMap[id]) {\n setExpandedRowsAmount(current => current + 1)\n } else {\n setExpandedRowsAmount(current => current - 1)\n }\n\n setIsRowExpandedMap(currentMap => ({\n ...currentMap,\n [id]: currentMap ? !currentMap[id] : false,\n }))\n }\n\n const expandAll = () => {\n setIsRowExpandedMap(allExpandedMap)\n setExpandedRowsAmount(itemsQuant)\n }\n\n const collapseAll = () => {\n setIsRowExpandedMap({})\n setExpandedRowsAmount(0)\n }\n\n return {\n toggleExpandRow: toggleRow,\n isRowExpandedMap,\n expandAll,\n collapseAll,\n expandedRowsAmount,\n }\n}\n\n```"
}
] |
code_paginated-table_90f01b77
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of paginated-table/react/package.json from the paginated-table VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```json\n{\n \"dependencies\": {\n \"apollo-client\": \"^2.4.7\",\n \"graphql\": \"^14.0.2\",\n \"react\": \"^16.6.3\",\n \"react-apollo\": \"^2.3.1\",\n \"react-dom\": \"^16.0.0\",\n \"react-intl\": \"^3.9.2\"\n },\n \"devDependencies\": {\n \"@apollo/react-testing\": \"^4.0.0\",\n \"@types/jest\": \"^24.0.11\",\n \"@types/json-schema\": \"^7.0.3\",\n \"@types/node\": \"^10.12.17\",\n \"@types/react\": \"^16.8.23\",\n \"@vtex/styleguide\": \"^9.125.0\",\n \"@vtex/test-tools\": \"^3.1.0\",\n \"prettier\": \"^1.16.4\",\n \"tslint\": \"^5.12.0\",\n \"tslint-config-vtex\": \"^2.1.0\",\n \"typescript\": \"3.9.7\"\n },\n \"scripts\": {\n \"lint\": \"tsc --noEmit && tslint -c tslint.json './**/*.ts'\",\n \"test\": \"vtex-test-tools test\"\n },\n \"version\": \"0.14.0\"\n}\n\n```"
}
] |
code_paginated-table_54d170e9
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of paginated-table/react/useDynamicMeasures.tsx from the paginated-table VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```tsx\nimport { useCallback, useLayoutEffect, useState } from 'react'\n\nconst getHeight = (node: HTMLElement) => {\n const rect = node.getBoundingClientRect()\n\n return rect.height\n}\n\nconst BASE_ROW_HEIGHT = 48\nconst TABLE_HEADER_HEIGHT = 36\nconst EMPTY_STATE_SIZE = 5 * BASE_ROW_HEIGHT\n\nexport function calculateTableHeight(\n rowHeight: number,\n tableSize: number,\n headless?: boolean\n): number {\n const multiplicator = Boolean(tableSize) ? tableSize * rowHeight : EMPTY_STATE_SIZE\n return (headless ? 0 : TABLE_HEADER_HEIGHT) + multiplicator\n}\n\nconst useDynamicMeasures = ({ lenght, headless }: { lenght: number; headless?: boolean }) => {\n const [node, setNode] = useState<HTMLElement | null>(null)\n const [tableHeight, setTableHeight] = useState(\n calculateTableHeight(BASE_ROW_HEIGHT, lenght, headless)\n )\n\n const ref = useCallback((element: HTMLElement) => {\n setNode(element)\n }, [])\n\n const measure = (bodyNode: HTMLElement) => {\n window.requestAnimationFrame(() => {\n const bodyHeight = getHeight(bodyNode)\n const newHeight = bodyHeight >= BASE_ROW_HEIGHT ? bodyHeight : EMPTY_STATE_SIZE\n setTableHeight(newHeight + TABLE_HEADER_HEIGHT)\n })\n }\n\n useLayoutEffect(() => {\n if (!node) {\n return\n }\n measure(node)\n\n window.addEventListener('resize', () => measure(node))\n\n return () => {\n window.removeEventListener('resize', () => measure(node))\n }\n }, [node])\n\n return {\n measures: { tableHeight, rowHeight: 'auto' },\n ref,\n triggerResize: node ? () => measure(node) : () => {},\n }\n}\n\nexport default useDynamicMeasures\n\n```"
}
] |
code_paginated-table_e055c562
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of paginated-table/react/ExtendedTable.tsx from the paginated-table VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```tsx\nimport React from 'react'\nimport { EXPERIMENTAL_Table as Table } from 'vtex.styleguide'\nimport { IdMap } from './useExpandableRows'\n\ninterface Column {\n id?: string\n title?: any\n width?: number | string\n sortable?: boolean\n cellRenderer?: any\n extended?: boolean\n condensed?: string[]\n}\n\n\ninterface TableProps {\n /** Return of the useTableMeasures hook */\n measures: any\n /** Array of columns */\n columns: Column[]\n /** Array of items */\n items: object[]\n /** Function that generates row keys */\n rowKey?: (data: { rowData: unknown }) => string\n /** If the table is empty or not */\n empty?: boolean\n /** If the Table is loading or not */\n loading?: { renderAs: () => React.ReactNode } | boolean\n /** Function trigged on a row click */\n onRowClick?: (data: { rowData: any }) => void\n /** Function that defines if a row is active or not */\n isRowActive?: (data: unknown) => boolean\n /** Table EmptyState component */\n emptyState?: any\n /** Sorting properties */\n sorting?: {\n sorted?: {\n by?: string,\n order?: string,\n },\n sort: (id: string) => void,\n clear: () => void\n // prop specific to this component\n defaultOrder?: string\n }\n /** Base testId */\n testId?: string\n /** If the rows should be highlighted on :hover */\n highlightOnHover?: boolean\n /** If the header is sticky or not */\n stickyHeader?: boolean\n\n // props specific to this component\n hovering?: any\n measuringRef?: any\n // return of useExpandableRows hook\n rowExpansion?: {\n isRowExpandedMap?: IdMap\n }\n children?: any\n}\n\nconst HeadWithoutUpperLine = () => (\n <Table.Sections.Head>\n {({ props, column, key }: any) => {\n return (\n <Table.Sections.Head.Cell key={key} {...props} style={{borderTopStyle: \"none\"}}>\n {column.title}\n </Table.Sections.Head.Cell>\n )\n }}\n </Table.Sections.Head>\n)\n\nconst HeadWithDefaultSorting = ({sorting}: {sorting: {\n sorted?: {\n by?: string,\n order?: string,\n },\n sort: (id: string) => void,\n clear: () => void\n defaultOrder?: string\n}}) => {\n return (<Table.Sections.Head>\n {({ props, column, key }: any) => {\n const isCurrentlySortedColumn = sorting.sorted?.by === column.id\n const sortingDefaultOrder = sorting.defaultOrder || 'ASC'\n const isAscending = !isCurrentlySortedColumn ? sortingDefaultOrder === 'ASC' : sorting.sorted?.order == 'ASC'\n return (\n <Table.Sections.Head.Cell key={key} {...props} style={{borderTopStyle: \"none\"}}>\n {column.title}\n <Table.Sections.Head.Cell.Suffix sorting={isCurrentlySortedColumn} ascending={isAscending} />\n </Table.Sections.Head.Cell>\n )\n }}\n</Table.Sections.Head> )\n}\n\nconst CollapsableRow = (props: {key: string,\n onMouseEnter: () => void,\n onRowClick: (data: { rowData: any }) => void,\n isExpanded: boolean\n columns: Column[],\n data: any\n}) => {\n const { columns, isExpanded, onRowClick, ...rowProps} = props\n\n const rowPropsWithExtraInfo = {\n ...rowProps,\n data: {\n ...rowProps.data,\n isExpanded\n }\n }\n\n return (\n <>\n <Table.Sections.Body.Row\n {...rowPropsWithExtraInfo}\n >\n {({ key, props, content }: any) => (\n <Table.Sections.Body.Row.Cell key={key} \n style= {isExpanded && {backgroundColor: '#EDF4FE', borderBottomStyle: \"none\"}}\n {...props}\n >\n {content}\n </Table.Sections.Body.Row.Cell>\n )}\n </Table.Sections.Body.Row>\n {\n isExpanded && <tr onClick={() => onRowClick({ rowData: rowPropsWithExtraInfo.data })}><td colSpan={columns.length} className=\"bb b--muted-4\" style={{backgroundColor: '#EDF4FE'}}>\n <div className=\"flex justify-center items-center pointer\">\n {rowProps.data.extendedRowRenderer}\n </div>\n </td></tr>\n }\n </>\n )\n}\n\nconst CustomTable = (props: TableProps) => {\n const { children, measuringRef, hovering, ...tableProps } = props\n\n const { onMouseEnter = () => {}, onMouseLeave = () => {} } = hovering || {}\n const { sorting } = tableProps\n return (\n <Table composableSections {...tableProps}>\n {children}\n <Table.Sections>\n {\n !sorting ? \n <HeadWithoutUpperLine />\n : (\n <HeadWithDefaultSorting sorting={sorting} />\n )\n }\n <Table.Sections.Body ref={measuringRef} onMouseLeave={onMouseLeave}>\n {({ key, props: rowProps }: { key: string; props: any }) => {\n return !rowProps.data.isExpandable || !props.rowExpansion?.isRowExpandedMap ? (\n <Table.Sections.Body.Row\n key={key}\n onMouseEnter={() => onMouseEnter(rowProps.data.id)}\n {...rowProps}\n />\n ) : (\n <CollapsableRow\n key={key}\n onMouseEnter={() => onMouseEnter(rowProps.data.id)}\n onRowClick={tableProps.onRowClick}\n columns={props.columns}\n isExpanded ={props.rowExpansion?.isRowExpandedMap[rowProps.data.id]}\n {...rowProps}\n />\n )\n }}\n </Table.Sections.Body>\n </Table.Sections>\n </Table>\n )\n}\n\nexport default CustomTable\n\n```"
}
] |
code_paginated-table_1f83ffe9
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of paginated-table/react/PersistedPaginatedTable.tsx from the paginated-table VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```tsx\nimport { JSONSchema6Type } from 'json-schema'\nimport React, { useEffect, useRef } from 'react'\nimport { defineMessages, useIntl } from 'react-intl'\n\nimport { useRuntime } from 'vtex.render-runtime'\nimport { Table } from 'vtex.styleguide'\n\nconst INITIAL_ELEMENTS_PER_PAGE = 15\n\ntype Props<TItem, TSchema extends JSONSchema6Type> = {\n total: number\n updatePaginationKey?: string\n defaultElementsPerPage?: number\n defaultSortOrder?: string\n defaultSortedBy?: string\n} & TableProps<TItem, TSchema>\n\ninterface TableProps<TItem, TSchema extends JSONSchema6Type> {\n items: TItem[]\n schema: TSchema\n loading?: boolean\n fullWidth?: boolean\n density?: 'low' | 'medium' | 'high'\n emptyStateLabel?: React.ReactNode\n emptyStateChildren?: React.ReactNode\n dynamicRowHeight?: boolean\n onRowClick?: OnRowClickHandler<TItem>\n onRowHover?: () => void\n totalizers?: any\n filters?: any\n toolbar?: {\n inputSearch?: {\n value: IntlMessage\n placeholder: React.ReactNode\n onChange: React.ChangeEventHandler<HTMLInputElement>\n onClear: React.ChangeEventHandler<HTMLInputElement>\n onSubmit: React.FormEventHandler<HTMLFormElement>\n }\n density?: {\n buttonLabel: IntlMessage\n lowOptionLabel: IntlMessage\n mediumOptionLabel: IntlMessage\n highOptionLabel: IntlMessage\n }\n fields?: {\n label: IntlMessage\n showAllLabel: IntlMessage\n hideAllLabel: IntlMessage\n }\n download?: {\n label: IntlMessage\n handleCallback: () => void\n }\n upload?: {\n label: IntlMessage\n handleCallback: () => void\n }\n extraActions?: {\n label: IntlMessage\n actions: Array<{\n label: IntlMessage\n handleCallback: () => void\n }>\n }\n newLine?: {\n label: IntlMessage\n handleCallback: () => void\n }\n }\n lineActions?: Array<{\n label: () => IntlMessage\n isDangerous?: boolean\n onClick: () => void\n }>\n bulkActions?: {\n texts: {\n secondaryActionsLabel: string\n rowsSelected: (qty: number) => void\n selectAll: string\n allRowsSelected: () => void\n }\n totalItems?: number\n main: {\n label: string\n handleCallback: (params: { selectedRows: TItem[] }) => void\n }\n others: Array<{\n label: string\n handleCallback: (params: { selectedRows: TItem[] }) => void\n }>\n }\n pagination?: {\n hasPageTopIndicator: boolean\n }\n}\n\nexport type OnRowClickHandler<TItem> = ({ rowData }: { rowData: TItem }) => void\nexport type IntlMessage = string | JSX.Element\n\nconst messages = defineMessages({\n itemLabel: {\n defaultMessage: '{total, plural, one {item} other {items}}',\n id: 'admin/table.item-label',\n },\n of: {\n defaultMessage: 'of',\n id: 'admin/table.of',\n },\n showRowsLabel: {\n defaultMessage: 'Show rows',\n id: 'admin/table.show-rows',\n },\n})\n\nconst PersistedPaginatedTable = <TItem, TSchema extends JSONSchema6Type>(\n props: Props<TItem, TSchema>\n) => {\n const didMountRef = useRef(false)\n\n const { setQuery, query } = useRuntime()\n const { formatMessage } = useIntl()\n\n const {\n items = [],\n total,\n updatePaginationKey,\n defaultSortOrder = 'ASC',\n defaultElementsPerPage = INITIAL_ELEMENTS_PER_PAGE,\n defaultSortedBy = '',\n pagination: { hasPageTopIndicator } = { hasPageTopIndicator: false },\n ...tableProps\n } = props\n\n const elementsPerPage = parseInt(query.elements, 10) || defaultElementsPerPage\n\n useEffect(() => {\n if (didMountRef.current) {\n setQuery({ to: elementsPerPage, from: 0, elements: elementsPerPage })\n } else {\n didMountRef.current = true\n }\n }, [updatePaginationKey])\n\n useEffect(() => {\n if (total && total < query.to) {\n setQuery({ to: elementsPerPage, from: 0, elements: elementsPerPage })\n }\n }, [total])\n\n const onPageChange = (\n currentFrom: number,\n currentElementsPerPage: number,\n direction: string\n ) => async () => {\n const c = direction === 'next' ? 1 : -1\n\n const newFrom = currentFrom + c * currentElementsPerPage\n\n const newTo = Math.min(newFrom + currentElementsPerPage, total)\n\n setQuery({ to: newTo, from: newFrom, elements: currentElementsPerPage })\n }\n\n const from = parseInt(query.from, 10) || 0\n const to = parseInt(query.to, 10) || elementsPerPage\n const sortOrder = query.sortOrder || defaultSortOrder\n const sortedBy = query.sortedBy || defaultSortedBy\n\n return (\n <Table\n fullWidth\n items={items}\n pagination={{\n currentItemFrom: from + 1,\n currentItemTo: to,\n hasPageTopIndicator,\n itemLabel: formatMessage(messages.itemLabel, { total }),\n onNextClick: onPageChange(from, elementsPerPage, 'next'),\n onPrevClick: onPageChange(from, elementsPerPage, 'prev'),\n onRowsChange: async (e: React.ChangeEvent<HTMLSelectElement>) => {\n const newElementsPerPage = parseInt(e.target.value, 10)\n const currentPage = Math.floor(from / newElementsPerPage)\n const newFrom = currentPage * newElementsPerPage\n setQuery({\n elements: newElementsPerPage,\n from: newFrom,\n to: newFrom + newElementsPerPage,\n })\n },\n rowsOptions: [10, 15, 25],\n selectedOption: elementsPerPage,\n textOf: formatMessage(messages.of),\n textShowRows: formatMessage(messages.showRowsLabel),\n totalItems: total,\n }}\n density=\"low\"\n sort={{\n preferentialSortOrder: defaultSortOrder,\n sortOrder,\n sortedBy,\n }}\n onSort={({\n sortOrder: newSortOrder,\n sortedBy: newSortedBy,\n }: {\n sortOrder: string\n sortedBy: string\n }) => {\n setQuery({ sortOrder: newSortOrder, sortedBy: newSortedBy })\n }}\n {...tableProps}\n />\n )\n}\n\nexport default PersistedPaginatedTable\n\n```"
}
] |
code_paginated-table_644fa249
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of paginated-table/react/usePersistedTableSort.tsx from the paginated-table VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```tsx\nimport { useRuntime } from 'vtex.render-runtime'\n\nconst reverse = (order: string) => {\n if (order === 'DSC') {\n return 'ASC'\n }\n return 'DSC'\n}\n\nexport default function usePersistedTableSort({\n defaultSortOrder = 'ASC',\n}: {\n defaultSortOrder?: string\n}) {\n const { setQuery, query } = useRuntime()\n\n const { sortOrder } = query\n const { sortedBy } = query\n\n const sort = (id: string) => {\n if (!sortedBy || sortedBy !== id) {\n setQuery({\n sortOrder: defaultSortOrder,\n sortedBy: id,\n })\n } else {\n setQuery({\n sortOrder: reverse(sortOrder),\n sortedBy: id,\n })\n }\n }\n\n const clear = () => {\n setQuery({\n sortOrder: undefined,\n sortedBy: undefined,\n })\n }\n\n return {\n sortOrder,\n sortedBy,\n sorting: {\n sorted: {\n order: sortOrder,\n by: sortedBy,\n },\n sort,\n clear: clear,\n defaultOrder: defaultSortOrder,\n },\n }\n}\n\n```"
}
] |
code_paginated-table_8c141686
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of paginated-table/react/__tests__/tableRowHovering.test.tsx from the paginated-table VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```tsx\nimport React, { useState } from 'react'\nimport { render, fireEvent, getNodeText } from '@vtex/test-tools/react'\nimport ExtendedTable from '../ExtendedTable'\n\nObject.defineProperty(window, 'matchMedia', {\n writable: true,\n value: jest.fn().mockImplementation(_query => ({\n matches: false,\n addListener: jest.fn(),\n removeListener: jest.fn(),\n })),\n})\n\nconst TableWithRowHovering = ({ items }: { items: any[] }) => {\n const [hoveredId, setHoveredId] = useState(null)\n\n const columns = [\n {\n id: 'name',\n title: 'Name',\n cellRenderer: ({ data }: { data: string }) => <div data-testid=\"name-cell\">{data}</div>,\n },\n {\n id: 'hoverIndicator',\n title: '',\n cellRenderer: ({ data }: { data: { id: string } }) => (\n <div data-testid=\"hover-indicator-cell\">\n {data.id === hoveredId ? 'This row is hovered' : 'This row is NOT hovered'}\n </div>\n ),\n extended: true,\n },\n ]\n\n const hovering = {\n onMouseEnter: (id: string) => {\n setHoveredId(id)\n },\n onMouseLeave: () => {\n setHoveredId(null)\n },\n }\n\n return (\n <ExtendedTable\n measures={{ tableHeight: items.length * 100 }}\n items={items}\n columns={columns}\n loading={false}\n hovering={hovering}\n />\n )\n}\n\ntest('should indicate hovered rows with text', () => {\n const mockItems = [\n {\n id: 1,\n name: 'Product',\n },\n {\n id: 2,\n name: 'Product',\n },\n {\n id: 3,\n name: 'Product',\n },\n {\n id: 4,\n name: 'Product',\n },\n {\n id: 5,\n name: 'Product',\n },\n {\n id: 6,\n name: 'Product',\n },\n ]\n\n const { getAllByTestId } = render(<TableWithRowHovering items={mockItems} />)\n\n const firstNameCell = getAllByTestId('name-cell')[0]\n const secondtNameCell = getAllByTestId('name-cell')[1]\n const firstHoverCell = getAllByTestId('hover-indicator-cell')[0]\n const secondHoverCell = getAllByTestId('hover-indicator-cell')[1]\n fireEvent.mouseOver(firstNameCell)\n\n expect(getNodeText(firstHoverCell)).toBe('This row is hovered')\n expect(getNodeText(secondHoverCell)).toBe('This row is NOT hovered')\n\n fireEvent.mouseOver(secondtNameCell)\n\n expect(getNodeText(secondHoverCell)).toBe('This row is hovered')\n expect(getNodeText(firstHoverCell)).toBe('This row is NOT hovered')\n})\n\n```"
}
] |
code_paginated-table_c3e4424b
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of paginated-table/react/__tests__/tableSorting.test.tsx from the paginated-table VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```tsx\nimport React from 'react'\nimport { render, fireEvent, getNodeText } from '@vtex/test-tools/react'\nimport ExtendedTable from '../ExtendedTable'\nimport usePersistedTableSort from '../usePersistedTableSort'\n\nObject.defineProperty(window, 'matchMedia', {\n writable: true,\n value: jest.fn().mockImplementation(_query => ({\n matches: false,\n addListener: jest.fn(),\n removeListener: jest.fn(),\n })),\n})\n\nconst TableWithInverseSorting = ({ items }: { items: any[] }) => {\n const { sortOrder, sortedBy: sortBy, sorting } = usePersistedTableSort({\n defaultSortOrder: 'DSC',\n })\n\n const columns = [\n {\n id: 'name',\n title: 'Name',\n cellRenderer: ({ data }: { data: string }) => <div data-testid=\"name-cell\">{data}</div>,\n },\n {\n id: 'price',\n title: 'Price',\n cellRenderer: ({ data }: { data: number }) => <div data-testid=\"price-cell\">{data}</div>,\n sortable: true,\n },\n ]\n\n const sortedItems =\n sortBy == 'price' && sortOrder\n ? items.sort((itemA: any, itemB: any) => {\n return sortOrder === 'ASC' ? itemA.price - itemB.price : itemB.price - itemA.price\n })\n : items\n\n return (\n <ExtendedTable\n measures={{ tableHeight: items.length * 100 }}\n items={sortedItems}\n columns={columns}\n sorting={sorting}\n loading={false}\n />\n )\n}\n\ntest('should sort in reverse order (dsc first)', () => {\n const mostExpensiveName = 'Most expensive'\n const leastExpensiveName = 'Least expensive'\n\n const mockItems = [\n {\n id: 1,\n name: 'Product',\n price: 5,\n },\n {\n id: 2,\n name: 'Product',\n price: 5,\n },\n {\n id: 3,\n name: 'Product',\n price: 5,\n },\n {\n id: 4,\n name: mostExpensiveName,\n price: 20,\n },\n {\n id: 5,\n name: leastExpensiveName,\n price: 1,\n },\n {\n id: 6,\n name: 'Product',\n price: 5,\n },\n ]\n\n const { getByText, getAllByTestId } = render(<TableWithInverseSorting items={mockItems} />)\n\n const priceHeader = getByText(/price/i)\n fireEvent.click(priceHeader)\n\n let firstNameCell = getAllByTestId('name-cell')[0]\n\n expect(getNodeText(firstNameCell)).toBe(mostExpensiveName)\n\n fireEvent.click(priceHeader)\n\n firstNameCell = getAllByTestId('name-cell')[0]\n\n expect(getNodeText(firstNameCell)).toBe(leastExpensiveName)\n})\n\n```"
}
] |
code_paginated-table_42594878
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of paginated-table/react/__tests__/usePersistedPagination.test.ts from the paginated-table VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { act, renderHook } from '@vtex/test-tools/react'\n\nimport usePersistedPagination from '../usePersistedPagination'\n\nconst DEFAULT_TOTAL_ITEMS = 200\n\njest.mock('react-intl', () => ({\n defineMessages: (messages: any) => messages,\n useIntl: () => ({\n formatMessage: ({ defaultMessage }: any) => defaultMessage,\n }),\n}))\n\nconst setupHook = (totalItems?: number) => {\n const hook = renderHook(props => usePersistedPagination(props), {\n initialProps: { resetPaginationOnChangeKey: '' }\n })\n\n act(() => {\n hook.result.current.setTotal(totalItems || DEFAULT_TOTAL_ITEMS)\n })\n\n return hook\n}\n\nconst selectEvent = (rows: number) =>\n ({\n target: {\n value: rows.toString(),\n },\n } as any)\n\ntest('navigating to last doesnt surpass total', () => {\n const totalItems = 37\n const { result } = setupHook(totalItems)\n\n expect(result.current.from).toBe(0)\n expect(result.current.to).toBe(15)\n\n act(() => result.current.paginationProps.onNextClick())\n\n expect(result.current.from).toBe(15)\n expect(result.current.to).toBe(30)\n\n act(() => result.current.paginationProps.onNextClick())\n\n expect(result.current.from).toBe(30)\n expect(result.current.to).toBe(totalItems)\n})\n\ntest('changing resetPaginationOnChangeKey redirects back to first page', () => {\n const { result, rerender } = setupHook()\n\n act(() => result.current.paginationProps.onRowsChange(selectEvent(25)))\n\n act(() => result.current.paginationProps.onNextClick())\n act(() => result.current.paginationProps.onNextClick())\n\n expect(result.current.from).toBe(50)\n expect(result.current.to).toBe(75)\n\n rerender({ resetPaginationOnChangeKey: '..' })\n\n expect(result.current.from).toBe(0)\n expect(result.current.to).toBe(25)\n})\n\ntest('adjusting elements per page floors page to closest multiple', () => {\n const { result } = setupHook()\n\n act(() => result.current.paginationProps.onNextClick())\n\n expect(result.current.paginationProps.selectedOption).toBe(15)\n expect(result.current.from).toBe(15)\n expect(result.current.to).toBe(30)\n\n act(() => result.current.paginationProps.onRowsChange(selectEvent(10)))\n\n expect(result.current.paginationProps.selectedOption).toBe(10)\n expect(result.current.from).toBe(10)\n expect(result.current.to).toBe(20)\n\n act(() => result.current.paginationProps.onRowsChange(selectEvent(25)))\n\n expect(result.current.paginationProps.selectedOption).toBe(25)\n expect(result.current.from).toBe(0)\n expect(result.current.to).toBe(25)\n\n act(() => result.current.paginationProps.onNextClick())\n act(() => result.current.paginationProps.onRowsChange(selectEvent(10)))\n\n\n expect(result.current.paginationProps.selectedOption).toBe(10)\n expect(result.current.from).toBe(20)\n expect(result.current.to).toBe(30)\n})\n\n```"
}
] |
code_paginated-table_b228ed15
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of paginated-table/react/__tests__/tablePagination.test.tsx from the paginated-table VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```tsx\nimport React, { useEffect } from 'react'\nimport { render, fireEvent } from '@vtex/test-tools/react'\nimport ExtendedTable from '../ExtendedTable'\nimport usePersistedPagination from '../usePersistedPagination'\nimport { EXPERIMENTAL_Table as Table } from 'vtex.styleguide'\n\nObject.defineProperty(window, 'matchMedia', {\n writable: true,\n value: jest.fn().mockImplementation(_query => ({\n matches: false,\n addListener: jest.fn(),\n removeListener: jest.fn(),\n })),\n})\n\nconst buildMockItems = (lenght: number) =>\n Array.from(Array(lenght), (_, i) => ({\n id: `${i + 1}`,\n name: `Product ${i + 1}`,\n }))\n\nconst TableWithPagination = ({ items, colorFilter }: { items: any[]; colorFilter?: string }) => {\n const columns = [\n {\n id: 'name',\n title: 'Name',\n cellRenderer: ({ data }: { data: string }) => <div data-testid=\"name-cell\">{data}</div>,\n },\n ]\n\n const totalItems = items.length\n\n const { to, from, setTotal, paginationProps } = usePersistedPagination({\n defaultElementsPerPage: 15,\n resetPaginationOnChangeKey: `${colorFilter}`,\n })\n\n useEffect(() => {\n setTotal(totalItems)\n })\n\n const paginatedItems = items.slice(from, to)\n\n return (\n <>\n <ExtendedTable\n measures={{ tableHeight: items.length * 100 }}\n items={paginatedItems}\n columns={columns}\n loading={false}>\n <Table.Pagination {...paginationProps} />\n </ExtendedTable>\n <div onClick={() => paginationProps.onNextClick()}>Next Page button</div>\n </>\n )\n}\n\ntest('pagination resets on filter change', () => {\n const itemsMock = buildMockItems(37)\n\n const { getByText, rerender } = render(<TableWithPagination items={itemsMock} />)\n\n expect(getByText('Product 1')).toBeDefined()\n expect(getByText('Product 15')).toBeDefined()\n\n fireEvent.click(getByText(/next page button/i))\n\n expect(getByText('Product 16')).toBeDefined()\n\n rerender(<TableWithPagination items={itemsMock} colorFilter={'pink'} />)\n\n expect(getByText('Product 1')).toBeDefined()\n expect(getByText('Product 15')).toBeDefined()\n})\n\n```"
}
] |
code_paginated-table_f650469d
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of paginated-table/react/__tests__/usePersistedTableSort.test.ts from the paginated-table VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { act, renderHook } from '@vtex/test-tools/react'\n\nimport usePersistedTableSort from '../usePersistedTableSort'\n\nconst columnId = 'column_id'\nconst differentColumnId = 'column_id2'\n\ntest('performing sort updates sort values correctly', () => {\n\n const { result } = renderHook(() => usePersistedTableSort({}))\n\n act(() => result.current.sorting.sort(columnId))\n\n expect(result.current.sortOrder).toBe('ASC')\n expect(result.current.sortedBy).toBe(columnId)\n\n act(() => result.current.sorting.sort(columnId))\n\n expect(result.current.sortOrder).toBe('DSC')\n expect(result.current.sortedBy).toBe(columnId)\n\n act(() => result.current.sorting.sort(differentColumnId))\n\n expect(result.current.sortOrder).toBe('ASC')\n expect(result.current.sortedBy).toBe(differentColumnId)\n})\n\ntest('performing clear clears sort', () => {\n\n const { result } = renderHook(() => usePersistedTableSort({}))\n\n act(() => result.current.sorting.sort(columnId))\n act(() => result.current.sorting.clear())\n\n expect(result.current.sortOrder).toBe(undefined)\n expect(result.current.sortedBy).toBe(undefined)\n})\n\ntest('performing sort with dsc default order starts ordering by dsc', () => {\n\n const { result } = renderHook(() => usePersistedTableSort({ defaultSortOrder: 'DSC' }))\n\n act(() => result.current.sorting.sort(columnId))\n\n expect(result.current.sortOrder).toBe('DSC')\n expect(result.current.sortedBy).toBe(columnId)\n\n act(() => result.current.sorting.sort(columnId))\n\n expect(result.current.sortOrder).toBe('ASC')\n expect(result.current.sortedBy).toBe(columnId)\n\n act(() => result.current.sorting.sort(differentColumnId))\n\n expect(result.current.sortOrder).toBe('DSC')\n expect(result.current.sortedBy).toBe(differentColumnId)\n})\n\n\n```"
}
] |
code_paginated-table_5fc7325c
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of paginated-table/react/__tests__/tableRowExpansion.test.tsx from the paginated-table VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```tsx\nimport React from 'react'\nimport { render, fireEvent } from '@vtex/test-tools/react'\nimport ExtendedTable from '../ExtendedTable'\nimport useExpandableRows from '../useExpandableRows'\n\nObject.defineProperty(window, 'matchMedia', {\n writable: true,\n value: jest.fn().mockImplementation(_query => ({\n matches: false,\n addListener: jest.fn(),\n removeListener: jest.fn(),\n })),\n})\n\nconst TableWithRowExpansion = ({ items }: { items: any[] }) => {\n const columns = [\n {\n id: 'name',\n title: 'Name',\n cellRenderer: ({ data }: { data: string }) => <div data-testid=\"name-cell\">{data}</div>,\n },\n ]\n\n const rowExpansion = useExpandableRows({\n items,\n })\n\n return (\n <ExtendedTable\n measures={{ tableHeight: items.length * 100 }}\n items={items}\n columns={columns}\n loading={false}\n onRowClick={({\n rowData: { id },\n }: {\n rowData: {\n id: any\n }\n }) => {\n rowExpansion.toggleExpandRow(id)\n }}\n rowExpansion={rowExpansion}\n />\n )\n}\n\ntest('should toggle collapsed info on row click', () => {\n const mockItems = [\n {\n id: 1,\n name: 'Product',\n isExpandable: true,\n extendedRowRenderer: <div>Extra hidden data for product 1</div>,\n },\n {\n id: 2,\n name: 'Product',\n isExpandable: true,\n extendedRowRenderer: <div>Extra hidden data for product 2</div>,\n },\n {\n id: 3,\n name: 'Product',\n isExpandable: true,\n extendedRowRenderer: <div>Extra hidden data for product 3</div>,\n },\n {\n id: 4,\n name: 'Product',\n isExpandable: true,\n extendedRowRenderer: <div>Extra hidden data for product 4</div>,\n },\n {\n id: 5,\n name: 'Product',\n isExpandable: true,\n extendedRowRenderer: <div>Extra hidden data for product 5</div>,\n },\n {\n id: 6,\n name: 'Product',\n isExpandable: true,\n extendedRowRenderer: <div>Extra hidden data for product 6</div>,\n },\n ]\n\n const { getAllByTestId, getByText, findByText } = render(\n <TableWithRowExpansion items={mockItems} />\n )\n\n const firstNameCell = getAllByTestId('name-cell')[0]\n const secondNameCell = getAllByTestId('name-cell')[1]\n\n fireEvent.click(firstNameCell)\n\n expect(getByText('Extra hidden data for product 1')).toBeDefined\n expect(findByText('Extra hidden data for product 2')).not.toBeDefined\n\n fireEvent.click(secondNameCell)\n\n expect(getByText('Extra hidden data for product 1')).toBeDefined\n expect(getByText('Extra hidden data for product 2')).toBeDefined\n\n fireEvent.click(firstNameCell)\n\n expect(findByText('Extra hidden data for product 1')).not.toBeDefined\n expect(getByText('Extra hidden data for product 2')).toBeDefined\n})\n\n```"
}
] |
code_paginated-table_677d9954
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of paginated-table/react/__tests__/useExpandableRows.test.ts from the paginated-table VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { act, renderHook } from '@vtex/test-tools/react'\n\nimport useExpandableRows from '../useExpandableRows'\n\nconst mockItems = [\n {\n id: \"1\",\n },\n {\n id: \"2\",\n },\n {\n id: \"3\",\n },\n {\n id: \"4\",\n },\n {\n id: \"5\",\n },\n {\n id: \"6\",\n },\n {\n id: \"7\",\n },\n {\n id: \"8\",\n }\n]\n\ntest('starts with no rows expanded', () => {\n\n const { result } = renderHook(() => useExpandableRows({ items: mockItems }))\n\n expect(result.current.expandedRowsAmount).toBe(0)\n expect(result.current.isRowExpandedMap[\"1\"]).toBeFalsy()\n})\n\ntest('toggling rows updates expanded rows map and amount', () => {\n\n const { result } = renderHook(() => useExpandableRows({ items: mockItems }))\n\n act(() => result.current.toggleExpandRow(\"1\"))\n act(() => result.current.toggleExpandRow(\"4\"))\n act(() => result.current.toggleExpandRow(\"5\"))\n\n expect(result.current.expandedRowsAmount).toBe(3)\n expect(result.current.isRowExpandedMap[\"1\"]).toBeTruthy()\n expect(result.current.isRowExpandedMap[\"4\"]).toBeTruthy()\n expect(result.current.isRowExpandedMap[\"5\"]).toBeTruthy()\n\n act(() => result.current.toggleExpandRow(\"4\"))\n act(() => result.current.toggleExpandRow(\"5\"))\n\n expect(result.current.expandedRowsAmount).toBe(1)\n expect(result.current.isRowExpandedMap[\"4\"]).toBeFalsy()\n expect(result.current.isRowExpandedMap[\"5\"]).toBeFalsy()\n\n})\n\ntest('expanding all updates all rows to expanded', () => {\n\n const { result } = renderHook(() => useExpandableRows({ items: mockItems }))\n\n act(() => result.current.expandAll())\n\n expect(result.current.expandedRowsAmount).toBe(mockItems.length)\n expect(result.current.isRowExpandedMap[\"1\"]).toBeTruthy()\n expect(result.current.isRowExpandedMap[\"4\"]).toBeTruthy()\n expect(result.current.isRowExpandedMap[\"5\"]).toBeTruthy()\n\n act(() => result.current.toggleExpandRow(\"5\"))\n\n expect(result.current.expandedRowsAmount).not.toBe(mockItems.length)\n\n act(() => result.current.expandAll())\n expect(result.current.expandedRowsAmount).toBe(mockItems.length)\n expect(result.current.isRowExpandedMap[\"5\"]).toBeTruthy()\n\n})\n\ntest('collapse all updates all rows to collapsed', () => {\n\n const { result } = renderHook(() => useExpandableRows({ items: mockItems }))\n\n act(() => result.current.expandAll())\n act(() => result.current.collapseAll())\n\n expect(result.current.expandedRowsAmount).toBe(0)\n expect(result.current.isRowExpandedMap[\"1\"]).toBeFalsy()\n expect(result.current.isRowExpandedMap[\"4\"]).toBeFalsy()\n expect(result.current.isRowExpandedMap[\"5\"]).toBeFalsy()\n\n act(() => result.current.toggleExpandRow(\"5\"))\n act(() => result.current.collapseAll())\n\n expect(result.current.expandedRowsAmount).toBe(0)\n expect(result.current.isRowExpandedMap[\"5\"]).toBeFalsy()\n\n})\n\n\n```"
}
] |
code_store-media_57c41622
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of store-media/messages/pt.json from the store-media VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```json\n{\n \"admin/editor.media.title\": \"Mídia\",\n \"admin/editor.media.description\": \"Bloco de mídia que suporta imagens e vídeos\",\n \"admin/editor.mediaType.title\": \"Tipo de mídia\",\n \"admin/editor.mediaType.image\": \"Imagem\",\n \"admin/editor.mediaType.video\": \"Vídeo\",\n \"admin/editor.mediaList.title\": \"Lista de Mídias\",\n \"admin/editor.mediaList.description\": \"Bloco de Lista de Mídias que suporta uma lista de imagens e vídeos\",\n \"admin/editor.mediaList.mobileVideo.title\": \"URL para mobile\"\n}\n\n```"
}
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.