@bigbinary/neeto-molecules 3.8.2 → 3.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"ToggleFeatureCard.js","sources":["../src/components/ToggleFeatureCard/hooks/useScrollIntoView.js","../src/components/ToggleFeatureCard/ToolTipSwitch.jsx","../src/components/ToggleFeatureCard/index.jsx"],"sourcesContent":["import { useEffect } from \"react\";\n\nconst useScrollIntoView = ({ elementId, trigger }) => {\n useEffect(() => {\n if (!trigger) return;\n document.getElementById(elementId)?.scrollIntoView();\n }, [trigger]);\n};\n\nexport default useScrollIntoView;\n","import { Tooltip } from \"neetoui\";\nimport { Switch as FormikSwitch } from \"neetoui/formik\";\n\nconst TooltipSwitch = ({\n enabledCondition,\n name = \"\",\n isDisabled = false,\n switchDataCy,\n tooltipProps = {},\n ...otherProps\n}) => {\n const { enabledSwitchText, disabledSwitchText, ...neetoUITooltipProps } =\n tooltipProps;\n\n const tooltipContent = enabledCondition\n ? enabledSwitchText\n : disabledSwitchText;\n\n return (\n <Tooltip\n content={tooltipContent}\n disabled={!tooltipContent}\n position=\"top\"\n {...neetoUITooltipProps}\n >\n <span>\n <FormikSwitch\n data-cy={switchDataCy}\n data-testid=\"toggle-feature-card-switch\"\n disabled={isDisabled}\n {...{ name, ...otherProps }}\n />\n </span>\n </Tooltip>\n );\n};\n\nexport default TooltipSwitch;\n","import { useRef, useState, useEffect } from \"react\";\n\nimport classnames from \"classnames\";\nimport { useFormikContext } from \"formik\";\nimport { slugify } from \"neetocist\";\nimport useOnClickOutside from \"neetocommons/react-utils/useOnClickOutside\";\nimport useHotkeys from \"neetohotkeys\";\nimport { Close } from \"neetoicons\";\nimport { Typography, Label, Button } from \"neetoui\";\nimport { Input } from \"neetoui/formik\";\nimport PropTypes from \"prop-types\";\nimport { isEmpty } from \"ramda\";\nimport { useTranslation } from \"react-i18next\";\n\nimport { SIZES } from \"./constants\";\nimport useScrollIntoView from \"./hooks/useScrollIntoView\";\nimport \"./toggleFeatureCard.scss\";\nimport TooltipSwitch from \"./ToolTipSwitch\";\n\nconst ToggleFeatureCard = ({\n title = \"\",\n description = null,\n switchName = \"switch\",\n titleDataCy = \"\",\n switchDataCy = \"\",\n descriptionDataCy = \"\",\n isDisabled = false,\n children = null,\n inputProps,\n switchProps = {},\n editButtonProps = {},\n}) => {\n const { t } = useTranslation();\n const cardRef = useRef();\n const id = slugify(title);\n\n const [isEditing, setIsEditing] = useState(false);\n\n const { setFieldValue, values, submitCount, errors, initialValues } =\n useFormikContext();\n\n useEffect(() => {\n if (!(submitCount >= 1 && isEmpty(errors))) return;\n setIsEditing(false);\n }, [submitCount]);\n\n useEffect(() => {\n if (isEmpty(errors)) return;\n setIsEditing(true);\n }, [values, errors]);\n\n const [shouldHighlight, setShouldHighlight] = useState(\n location.hash.split(\"#\")[1] === id\n );\n\n const hasInput = values?.[switchName] && inputProps?.name;\n const enabledCondition = values?.[switchName];\n\n const handleInputReset = () => {\n setIsEditing(false);\n hasInput &&\n setFieldValue(inputProps?.name, initialValues?.[inputProps?.name]);\n };\n\n useOnClickOutside(cardRef, () => setShouldHighlight(false));\n\n useScrollIntoView({ elementId: id, trigger: shouldHighlight });\n\n const inputRef = useHotkeys(\"enter\", () => setIsEditing(false), {\n mode: \"scoped\",\n });\n\n return (\n <div\n {...{ id }}\n data-cy=\"feature-card-container\"\n data-testid=\"toggle-feature-card\"\n ref={cardRef}\n className={classnames(\n \"neeto-ui-bg-white neeto-ui-rounded-lg flex flex-col space-y-2 border p-4\",\n { \"neeto-ui-border-gray-300\": !shouldHighlight },\n { \"toggle-feature-card--highlighted\": shouldHighlight }\n )}\n >\n <Label className=\"flex flex-row items-center gap-2\">\n <TooltipSwitch\n {...{\n enabledCondition,\n isDisabled,\n switchDataCy,\n ...switchProps,\n }}\n name={switchName}\n />\n <Typography\n component=\"span\"\n data-cy={titleDataCy}\n data-testid=\"toggle-feature-card-title\"\n style=\"h4\"\n weight=\"semibold\"\n >\n {title}\n </Typography>\n </Label>\n <Typography\n className=\"mb-4 whitespace-pre-line\"\n data-cy={descriptionDataCy}\n data-testid=\"toggle-feature-card-description\"\n style=\"body2\"\n >\n {description}\n </Typography>\n {hasInput && !isEditing && (\n <div className=\"m-0 flex flex-row items-center space-x-2\">\n {inputProps?.display}\n <Button\n data-cy={inputProps?.editButtonDataCy}\n data-testid=\"toggle-feature-card-input-display-edit\"\n label={t(\"neetoMolecules.common.actions.edit\")}\n size=\"small\"\n style=\"link\"\n type=\"button\"\n onClick={() => setIsEditing(true)}\n {...editButtonProps}\n />\n </div>\n )}\n {hasInput && isEditing && (\n <Input\n autoFocus\n data-cy={inputProps?.dataCy}\n data-testid=\"toggle-feature-card-input-field\"\n label={inputProps?.label}\n name={inputProps?.name}\n placeholder={inputProps?.placeholder}\n ref={inputRef}\n size=\"medium\"\n suffix={\n <Button\n data-testid=\"toggle-feature-card-input-reset\"\n icon={Close}\n size=\"small\"\n style=\"text\"\n type=\"button\"\n onClick={handleInputReset}\n />\n }\n {...inputProps}\n />\n )}\n {children}\n </div>\n );\n};\n\nToggleFeatureCard.propTypes = {\n /**\n * The title that will be displayed for the card.\n */\n title: PropTypes.string,\n /**\n * The descripton text for the particular feature or setting.\n */\n description: PropTypes.string,\n /**\n * The formik name of the feature or setting to be toggled. eg:\n {switchName: \"enableEmails\"}.\n */\n switchName: PropTypes.string,\n /**\n * Can be used to disable the toggle switch conditionally.\n */\n isDisabled: PropTypes.bool,\n /**\n * Custom child components to be displayed in the card.\n */\n children: PropTypes.node,\n /**\n * Can be used to add an input field for a setting or a feature.\n For example, `Enable email notifications` card can have an email input field.\n */\n inputProps: PropTypes.shape({\n name: PropTypes.string,\n display: PropTypes.node,\n label: PropTypes.string,\n editButtonTooltip: PropTypes.string,\n editButtonDataCy: PropTypes.string,\n placeholder: PropTypes.string,\n dataCy: PropTypes.string,\n onChange: PropTypes.func,\n suffix: PropTypes.node,\n prefix: PropTypes.node,\n className: PropTypes.string,\n nakedInput: PropTypes.bool,\n size: PropTypes.oneOf(Object.values(SIZES)),\n type: PropTypes.string,\n maxLength: PropTypes.number,\n contentSize: PropTypes.number,\n unlimitedChars: PropTypes.bool,\n }),\n /**\n * Can be used to add props to the switch component.\n */\n switchProps: PropTypes.shape({\n onChange: PropTypes.func,\n className: PropTypes.string,\n checked: PropTypes.bool,\n tooltipProps: PropTypes.shape({\n enabledSwitchText: PropTypes.string,\n disabledSwitchText: PropTypes.string,\n }),\n }),\n /**\n * Can be used to add props to the edit button component.\n */\n editButtonProps: PropTypes.shape({\n onClick: PropTypes.func,\n className: PropTypes.string,\n style: PropTypes.string,\n size: PropTypes.string,\n type: PropTypes.string,\n tooltipProps: PropTypes.object,\n }),\n};\n\nexport default ToggleFeatureCard;\n"],"names":["useScrollIntoView","_ref","elementId","trigger","useEffect","_document$getElementB","document","getElementById","scrollIntoView","TooltipSwitch","enabledCondition","_ref$name","name","_ref$isDisabled","isDisabled","switchDataCy","_ref$tooltipProps","tooltipProps","otherProps","_objectWithoutProperties","_excluded","enabledSwitchText","disabledSwitchText","neetoUITooltipProps","_excluded2","tooltipContent","_jsx","Tooltip","_objectSpread","content","disabled","position","children","FormikSwitch","ToggleFeatureCard","_ref$title","title","_ref$description","description","_ref$switchName","switchName","_ref$titleDataCy","titleDataCy","_ref$switchDataCy","_ref$descriptionDataC","descriptionDataCy","_ref$children","inputProps","_ref$switchProps","switchProps","_ref$editButtonProps","editButtonProps","_useTranslation","useTranslation","t","cardRef","useRef","id","slugify","_useState","useState","_useState2","_slicedToArray","isEditing","setIsEditing","_useFormikContext","useFormikContext","setFieldValue","values","submitCount","errors","initialValues","isEmpty","_useState3","location","hash","split","_useState4","shouldHighlight","setShouldHighlight","hasInput","handleInputReset","useOnClickOutside","inputRef","useHotkeys","mode","_jsxs","ref","className","classnames","Label","Typography","component","style","weight","display","Button","editButtonDataCy","label","size","type","onClick","Input","autoFocus","dataCy","placeholder","suffix","icon","Close"],"m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,CAAE0D,WAAY;AACrClB,MAAAA,GAAG,EAAEJ,QAAS;AACdgB,MAAAA,IAAI,EAAC,QAAQ;MACbO,MAAM,eACJhF,GAAA,CAACsE,MAAM,EAAA;AACL,QAAA,aAAA,EAAY,iCAAiC;AAC7CW,QAAAA,IAAI,EAAEC,KAAM;AACZT,QAAAA,IAAI,EAAC,OAAO;AACZN,QAAAA,KAAK,EAAC,MAAM;AACZO,QAAAA,IAAI,EAAC,QAAQ;AACbC,QAAAA,OAAO,EAAEpB,gBAAAA;OACV,CAAA;AACF,KAAA,EACGlC,UAAU,CACf,CACF,EACAf,QAAQ,CAAA;AAAA,GACN,CAAC,CAAA;AAEV;;;;"}
1
+ {"version":3,"file":"ToggleFeatureCard.js","sources":["../src/components/ToggleFeatureCard/hooks/useScrollIntoView.js","../src/components/ToggleFeatureCard/ToolTipSwitch.jsx","../src/components/ToggleFeatureCard/index.jsx"],"sourcesContent":["import { useEffect } from \"react\";\n\nconst useScrollIntoView = ({ elementId, trigger }) => {\n useEffect(() => {\n if (!trigger) return;\n document.getElementById(elementId)?.scrollIntoView();\n }, [trigger]);\n};\n\nexport default useScrollIntoView;\n","import { Tooltip } from \"neetoui\";\nimport { Switch as FormikSwitch } from \"neetoui/formik\";\n\nconst TooltipSwitch = ({\n enabledCondition,\n name = \"\",\n isDisabled = false,\n switchDataCy,\n tooltipProps = {},\n ...otherProps\n}) => {\n const { enabledSwitchText, disabledSwitchText, ...neetoUITooltipProps } =\n tooltipProps;\n\n const tooltipContent = enabledCondition\n ? enabledSwitchText\n : disabledSwitchText;\n\n return (\n <Tooltip\n content={tooltipContent}\n disabled={!tooltipContent}\n position=\"top\"\n {...neetoUITooltipProps}\n >\n <span>\n <FormikSwitch\n data-cy={switchDataCy}\n data-testid=\"toggle-feature-card-switch\"\n disabled={isDisabled}\n {...{ name, ...otherProps }}\n />\n </span>\n </Tooltip>\n );\n};\n\nexport default TooltipSwitch;\n","import { useRef, useState, useEffect } from \"react\";\n\nimport classnames from \"classnames\";\nimport { useFormikContext } from \"formik\";\nimport { slugify } from \"neetocist\";\nimport useOnClickOutside from \"neetocommons/react-utils/useOnClickOutside\";\nimport useHotkeys from \"neetohotkeys\";\nimport { Close } from \"neetoicons\";\nimport { Typography, Label, Button } from \"neetoui\";\nimport { Input } from \"neetoui/formik\";\nimport PropTypes from \"prop-types\";\nimport { isEmpty } from \"ramda\";\nimport { useTranslation } from \"react-i18next\";\n\nimport { SIZES } from \"./constants\";\nimport useScrollIntoView from \"./hooks/useScrollIntoView\";\nimport \"./toggleFeatureCard.scss\";\nimport TooltipSwitch from \"./ToolTipSwitch\";\n\nconst ToggleFeatureCard = ({\n title = \"\",\n description = null,\n switchName = \"switch\",\n titleDataCy = \"\",\n switchDataCy = \"\",\n descriptionDataCy = \"\",\n isDisabled = false,\n children = null,\n inputProps,\n switchProps = {},\n editButtonProps = {},\n className = \"\",\n}) => {\n const { t } = useTranslation();\n const cardRef = useRef();\n const id = slugify(title);\n\n const [isEditing, setIsEditing] = useState(false);\n\n const { setFieldValue, values, submitCount, errors, initialValues } =\n useFormikContext();\n\n useEffect(() => {\n if (!(submitCount >= 1 && isEmpty(errors))) return;\n setIsEditing(false);\n }, [submitCount]);\n\n useEffect(() => {\n if (isEmpty(errors)) return;\n setIsEditing(true);\n }, [values, errors]);\n\n const [shouldHighlight, setShouldHighlight] = useState(\n location.hash.split(\"#\")[1] === id\n );\n\n const hasInput = values?.[switchName] && inputProps?.name;\n const enabledCondition = values?.[switchName];\n\n const handleInputReset = () => {\n setIsEditing(false);\n hasInput &&\n setFieldValue(inputProps?.name, initialValues?.[inputProps?.name]);\n };\n\n useOnClickOutside(cardRef, () => setShouldHighlight(false));\n\n useScrollIntoView({ elementId: id, trigger: shouldHighlight });\n\n const inputRef = useHotkeys(\"enter\", () => setIsEditing(false), {\n mode: \"scoped\",\n });\n\n return (\n <div\n {...{ id }}\n data-cy=\"feature-card-container\"\n data-testid=\"toggle-feature-card\"\n ref={cardRef}\n className={classnames(\n \"neeto-ui-bg-white neeto-ui-rounded-lg flex flex-col space-y-2 border p-4\",\n { \"neeto-ui-border-gray-300\": !shouldHighlight },\n { \"toggle-feature-card--highlighted\": shouldHighlight },\n className\n )}\n >\n <Label className=\"flex flex-row items-center gap-2\">\n <TooltipSwitch\n {...{\n enabledCondition,\n isDisabled,\n switchDataCy,\n ...switchProps,\n }}\n name={switchName}\n />\n <Typography\n component=\"span\"\n data-cy={titleDataCy}\n data-testid=\"toggle-feature-card-title\"\n style=\"h4\"\n weight=\"semibold\"\n >\n {title}\n </Typography>\n </Label>\n <Typography\n className=\"mb-4 whitespace-pre-line\"\n data-cy={descriptionDataCy}\n data-testid=\"toggle-feature-card-description\"\n style=\"body2\"\n >\n {description}\n </Typography>\n {hasInput && !isEditing && (\n <div className=\"m-0 flex flex-row items-center space-x-2\">\n {inputProps?.display}\n <Button\n data-cy={inputProps?.editButtonDataCy}\n data-testid=\"toggle-feature-card-input-display-edit\"\n label={t(\"neetoMolecules.common.actions.edit\")}\n size=\"small\"\n style=\"link\"\n type=\"button\"\n onClick={() => setIsEditing(true)}\n {...editButtonProps}\n />\n </div>\n )}\n {hasInput && isEditing && (\n <Input\n autoFocus\n data-cy={inputProps?.dataCy}\n data-testid=\"toggle-feature-card-input-field\"\n label={inputProps?.label}\n name={inputProps?.name}\n placeholder={inputProps?.placeholder}\n ref={inputRef}\n size=\"medium\"\n suffix={\n <Button\n data-testid=\"toggle-feature-card-input-reset\"\n icon={Close}\n size=\"small\"\n style=\"text\"\n type=\"button\"\n onClick={handleInputReset}\n />\n }\n {...inputProps}\n />\n )}\n {children}\n </div>\n );\n};\n\nToggleFeatureCard.propTypes = {\n /**\n * The title that will be displayed for the card.\n */\n title: PropTypes.string,\n /**\n * The descripton text for the particular feature or setting.\n */\n description: PropTypes.string,\n /**\n * The formik name of the feature or setting to be toggled. eg:\n {switchName: \"enableEmails\"}.\n */\n switchName: PropTypes.string,\n /**\n * Can be used to disable the toggle switch conditionally.\n */\n isDisabled: PropTypes.bool,\n /**\n * Custom child components to be displayed in the card.\n */\n children: PropTypes.node,\n /**\n * Can be used to add an input field for a setting or a feature.\n For example, `Enable email notifications` card can have an email input field.\n */\n inputProps: PropTypes.shape({\n name: PropTypes.string,\n display: PropTypes.node,\n label: PropTypes.string,\n editButtonTooltip: PropTypes.string,\n editButtonDataCy: PropTypes.string,\n placeholder: PropTypes.string,\n dataCy: PropTypes.string,\n onChange: PropTypes.func,\n suffix: PropTypes.node,\n prefix: PropTypes.node,\n className: PropTypes.string,\n nakedInput: PropTypes.bool,\n size: PropTypes.oneOf(Object.values(SIZES)),\n type: PropTypes.string,\n maxLength: PropTypes.number,\n contentSize: PropTypes.number,\n unlimitedChars: PropTypes.bool,\n }),\n /**\n * Can be used to add props to the switch component.\n */\n switchProps: PropTypes.shape({\n onChange: PropTypes.func,\n className: PropTypes.string,\n checked: PropTypes.bool,\n tooltipProps: PropTypes.shape({\n enabledSwitchText: PropTypes.string,\n disabledSwitchText: PropTypes.string,\n }),\n }),\n /**\n * Can be used to add props to the edit button component.\n */\n editButtonProps: PropTypes.shape({\n onClick: PropTypes.func,\n className: PropTypes.string,\n style: PropTypes.string,\n size: PropTypes.string,\n type: PropTypes.string,\n tooltipProps: PropTypes.object,\n }),\n /**\n * To specify external classnames as overrides to the ToggleFeatureCard wrapper.\n */\n className: PropTypes.string,\n};\n\nexport default ToggleFeatureCard;\n"],"names":["useScrollIntoView","_ref","elementId","trigger","useEffect","_document$getElementB","document","getElementById","scrollIntoView","TooltipSwitch","enabledCondition","_ref$name","name","_ref$isDisabled","isDisabled","switchDataCy","_ref$tooltipProps","tooltipProps","otherProps","_objectWithoutProperties","_excluded","enabledSwitchText","disabledSwitchText","neetoUITooltipProps","_excluded2","tooltipContent","_jsx","Tooltip","_objectSpread","content","disabled","position","children","FormikSwitch","ToggleFeatureCard","_ref$title","title","_ref$description","description","_ref$switchName","switchName","_ref$titleDataCy","titleDataCy","_ref$switchDataCy","_ref$descriptionDataC","descriptionDataCy","_ref$children","inputProps","_ref$switchProps","switchProps","_ref$editButtonProps","editButtonProps","_ref$className","className","_useTranslation","useTranslation","t","cardRef","useRef","id","slugify","_useState","useState","_useState2","_slicedToArray","isEditing","setIsEditing","_useFormikContext","useFormikContext","setFieldValue","values","submitCount","errors","initialValues","isEmpty","_useState3","location","hash","split","_useState4","shouldHighlight","setShouldHighlight","hasInput","handleInputReset","useOnClickOutside","inputRef","useHotkeys","mode","_jsxs","ref","classnames","Label","Typography","component","style","weight","display","Button","editButtonDataCy","label","size","type","onClick","Input","autoFocus","dataCy","placeholder","suffix","icon","Close"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAEA,IAAMA,iBAAiB,GAAG,SAApBA,iBAAiBA,CAAAC,IAAA,EAA+B;AAAA,EAAA,IAAzBC,SAAS,GAAAD,IAAA,CAATC,SAAS;IAAEC,OAAO,GAAAF,IAAA,CAAPE,OAAO,CAAA;AAC7CC,EAAAA,SAAS,CAAC,YAAM;AAAA,IAAA,IAAAC,qBAAA,CAAA;IACd,IAAI,CAACF,OAAO,EAAE,OAAA;AACd,IAAA,CAAAE,qBAAA,GAAAC,QAAQ,CAACC,cAAc,CAACL,SAAS,CAAC,MAAA,IAAA,IAAAG,qBAAA,KAAlCA,KAAAA,CAAAA,GAAAA,KAAAA,CAAAA,GAAAA,qBAAA,CAAoCG,cAAc,EAAE,CAAA;AACtD,GAAC,EAAE,CAACL,OAAO,CAAC,CAAC,CAAA;AACf,CAAC;;;;;;;;;ACJD,IAAMM,aAAa,GAAG,SAAhBA,aAAaA,CAAAR,IAAA,EAOb;AAAA,EAAA,IANJS,gBAAgB,GAAAT,IAAA,CAAhBS,gBAAgB;IAAAC,SAAA,GAAAV,IAAA,CAChBW,IAAI;AAAJA,IAAAA,IAAI,GAAAD,SAAA,KAAG,KAAA,CAAA,GAAA,EAAE,GAAAA,SAAA;IAAAE,eAAA,GAAAZ,IAAA,CACTa,UAAU;AAAVA,IAAAA,UAAU,GAAAD,eAAA,KAAG,K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A,UAAU,KAAVA,KAAAA,CAAAA,GAAAA,KAAAA,CAAAA,GAAAA,UAAU,CAAE0D,MAAO;AAC5B,MAAA,aAAA,EAAY,iCAAiC;AAC7CN,MAAAA,KAAK,EAAEpD,UAAU,KAAA,IAAA,IAAVA,UAAU,KAAVA,KAAAA,CAAAA,GAAAA,KAAAA,CAAAA,GAAAA,UAAU,CAAEoD,KAAM;AACzBvF,MAAAA,IAAI,EAAEmC,UAAU,KAAA,IAAA,IAAVA,UAAU,KAAVA,KAAAA,CAAAA,GAAAA,KAAAA,CAAAA,GAAAA,UAAU,CAAEnC,IAAK;AACvB8F,MAAAA,WAAW,EAAE3D,UAAU,KAAA,IAAA,IAAVA,UAAU,KAAVA,KAAAA,CAAAA,GAAAA,KAAAA,CAAAA,GAAAA,UAAU,CAAE2D,WAAY;AACrCjB,MAAAA,GAAG,EAAEJ,QAAS;AACde,MAAAA,IAAI,EAAC,QAAQ;MACbO,MAAM,eACJjF,GAAA,CAACuE,MAAM,EAAA;AACL,QAAA,aAAA,EAAY,iCAAiC;AAC7CW,QAAAA,IAAI,EAAEC,KAAM;AACZT,QAAAA,IAAI,EAAC,OAAO;AACZN,QAAAA,KAAK,EAAC,MAAM;AACZO,QAAAA,IAAI,EAAC,QAAQ;AACbC,QAAAA,OAAO,EAAEnB,gBAAAA;OACV,CAAA;AACF,KAAA,EACGpC,UAAU,CACf,CACF,EACAf,QAAQ,CAAA;AAAA,GACN,CAAC,CAAA;AAEV;;;;"}
@@ -0,0 +1,492 @@
1
+ 'use strict';
2
+
3
+ var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
4
+ var React = require('react');
5
+ var neetoCist = require('@bigbinary/neeto-cist');
6
+ var constants = require('@bigbinary/neeto-commons-frontend/constants');
7
+ var reactUtils = require('@bigbinary/neeto-commons-frontend/react-utils');
8
+ var NoData = require('@bigbinary/neetoui/NoData');
9
+ var Table = require('@bigbinary/neetoui/Table');
10
+ var reactI18next = require('react-i18next');
11
+ var Container = require('./Container.js');
12
+ var Header = require('./Header.js');
13
+ var PageLoader = require('./PageLoader.js');
14
+ var TableWrapper = require('./TableWrapper.js');
15
+ var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
16
+ var Typography = require('@bigbinary/neetoui/Typography');
17
+ var Modal = require('@bigbinary/neetoui/Modal');
18
+ var _defineProperty = require('@babel/runtime/helpers/defineProperty');
19
+ var jsxRuntime = require('react/jsx-runtime');
20
+ var i18next = require('i18next');
21
+ var utils = require('@bigbinary/neeto-commons-frontend/utils');
22
+ var Button = require('@bigbinary/neetoui/Button');
23
+ var reactQuery = require('@tanstack/react-query');
24
+ var axios = require('axios');
25
+ require('classnames');
26
+ require('./index-JY2zVpnv.js');
27
+ require('./_commonjsHelpers-BJu3ubxk.js');
28
+ require('./inject-css-vQvjPR2x.js');
29
+ require('./Breadcrumbs.js');
30
+ require('@bigbinary/neeto-commons-frontend/utils/general');
31
+ require('react-router-dom');
32
+ require('./HelpPopover.js');
33
+ require('@bigbinary/neeto-icons/Help');
34
+ require('@bigbinary/neetoui/Popover');
35
+ require('./MoreDropdown.js');
36
+ require('@bigbinary/neeto-icons/MenuHorizontal');
37
+ require('@bigbinary/neeto-icons/MenuVertical');
38
+ require('@bigbinary/neetoui/Dropdown');
39
+ require('@bigbinary/neetoui/Tooltip');
40
+ require('ramda');
41
+ require('./Search.js');
42
+ require('@bigbinary/neeto-commons-frontend/react-utils/useFuncDebounce');
43
+ require('@bigbinary/neeto-commons-frontend/react-utils/useQueryParams');
44
+ require('@bigbinary/neeto-commons-frontend/react-utils/useUpdateEffect');
45
+ require('@bigbinary/neeto-icons/Search');
46
+ require('@bigbinary/neetoui/Input');
47
+
48
+ var LabelledDetail = function LabelledDetail(_ref) {
49
+ var label = _ref.label,
50
+ value = _ref.value;
51
+ return /*#__PURE__*/jsxRuntime.jsx(Typography, {
52
+ className: "mb-2",
53
+ style: "body1",
54
+ children: /*#__PURE__*/jsxRuntime.jsx(reactI18next.Trans, {
55
+ components: {
56
+ strong: /*#__PURE__*/jsxRuntime.jsx("strong", {})
57
+ },
58
+ i18nKey: "neetoMolecules.auditLogs.additionalDetails.".concat(label),
59
+ values: {
60
+ value: value
61
+ }
62
+ })
63
+ });
64
+ };
65
+
66
+ var DATE_FORMATS = {
67
+ "%d/%m/%Y": "DD/MM/YYYY",
68
+ "%m/%d/%Y": "MM/DD/YYYY",
69
+ "%Y/%m/%d": "YYYY/MM/DD"
70
+ };
71
+ var DETAILS_KEYS = {
72
+ CHANGES_MADE_BY: "changesMadeBy",
73
+ ERROR_MESSAGE: "errorMessage",
74
+ NAME: "name",
75
+ ORGANIZATION_ROLE: "organizationRole",
76
+ GENERIC_DETAILS: "details",
77
+ ADDED_PERMISSIONS: "addedPermissions",
78
+ REMOVED_PERMISSIONS: "removedPermissions"
79
+ };
80
+ var EMAILS_TABLE_COLUMN_DATA = [{
81
+ title: i18next.t("neetoMolecules.auditLogs.details.emails.title"),
82
+ key: "email",
83
+ dataIndex: "email"
84
+ }];
85
+ var CHANGELOG_COLUMN_DATA = [{
86
+ title: i18next.t("neetoMolecules.auditLogs.details.changelog.field"),
87
+ key: "field",
88
+ dataIndex: "field"
89
+ }, {
90
+ title: i18next.t("neetoMolecules.auditLogs.details.changelog.from"),
91
+ key: "from",
92
+ dataIndex: "from"
93
+ }, {
94
+ title: i18next.t("neetoMolecules.auditLogs.details.changelog.to"),
95
+ key: "to",
96
+ dataIndex: "to"
97
+ }];
98
+
99
+ var formatToFromValue = function formatToFromValue(value) {
100
+ if (value === true) {
101
+ return i18next.t("neetoMolecules.auditLogs.details.changelog.true");
102
+ }
103
+ if (value === false) {
104
+ return i18next.t("neetoMolecules.auditLogs.details.changelog.false");
105
+ }
106
+ if (value === null) return "-";
107
+ return value;
108
+ };
109
+ var transformDateFormat = function transformDateFormat(rawDateFormat) {
110
+ return DATE_FORMATS[rawDateFormat];
111
+ };
112
+ var getFormattedValue = function getFormattedValue(field, value) {
113
+ return field === "dateFormat" ? transformDateFormat(value) : formatToFromValue(value);
114
+ };
115
+ var formatEmails = function formatEmails(emails) {
116
+ return emails.map(function (email) {
117
+ return {
118
+ email: email
119
+ };
120
+ });
121
+ };
122
+ var formatChangeLog = function formatChangeLog(changes) {
123
+ return Object.entries(changes).map(function (_ref) {
124
+ var _ref2 = _slicedToArray(_ref, 2),
125
+ field = _ref2[0],
126
+ _ref2$ = _ref2[1],
127
+ from = _ref2$.from,
128
+ to = _ref2$.to;
129
+ var formattedField = neetoCist._humanize(field);
130
+ return {
131
+ field: formattedField,
132
+ from: getFormattedValue(field, from),
133
+ to: getFormattedValue(field, to)
134
+ };
135
+ });
136
+ };
137
+ var getFullName = function getFullName(firstName) {
138
+ var lastName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "";
139
+ return "".concat(firstName, " ").concat(lastName).trim();
140
+ };
141
+ var getLabel = function getLabel(_ref3) {
142
+ var firstName = _ref3.firstName,
143
+ lastName = _ref3.lastName,
144
+ organizationRole = _ref3.organizationRole;
145
+ if (firstName || lastName) {
146
+ return DETAILS_KEYS.NAME;
147
+ }
148
+ if (organizationRole) {
149
+ return DETAILS_KEYS.ORGANIZATION_ROLE;
150
+ }
151
+ return DETAILS_KEYS.GENERIC_DETAILS;
152
+ };
153
+ var formatPermissionsChangeLog = function formatPermissionsChangeLog(_ref4) {
154
+ var from = _ref4.from,
155
+ to = _ref4.to;
156
+ return [{
157
+ field: i18next.t("neetoMolecules.auditLogs.details.permissions.description"),
158
+ from: getFormattedValue("description", from),
159
+ to: getFormattedValue("description", to)
160
+ }];
161
+ };
162
+ var transformPermissions = function transformPermissions(permissions) {
163
+ return permissions.map(function (permission) {
164
+ var humanizedParts = permission.split(".").map(neetoCist._humanize);
165
+ return humanizedParts.join(" - ");
166
+ }).join(", ");
167
+ };
168
+
169
+ var GenericChangelog = function GenericChangelog(_ref) {
170
+ var details = _ref.details;
171
+ var _useTranslation = reactI18next.useTranslation(),
172
+ t = _useTranslation.t;
173
+ var _details$email = details.email,
174
+ email = _details$email === void 0 ? "" : _details$email,
175
+ _details$changes = details.changes,
176
+ changes = _details$changes === void 0 ? {} : _details$changes,
177
+ _details$errorMessage = details.errorMessage,
178
+ errorMessage = _details$errorMessage === void 0 ? "" : _details$errorMessage,
179
+ status = details.status;
180
+ return /*#__PURE__*/jsxRuntime.jsxs("div", {
181
+ children: [/*#__PURE__*/jsxRuntime.jsx(LabelledDetail, {
182
+ label: DETAILS_KEYS.CHANGES_MADE_BY,
183
+ value: email
184
+ }), neetoCist.isNotEmpty(changes) && status === "success" ? /*#__PURE__*/jsxRuntime.jsx(Table, {
185
+ columnData: CHANGELOG_COLUMN_DATA,
186
+ enableColumnFreeze: false,
187
+ rowData: formatChangeLog(changes)
188
+ }) : /*#__PURE__*/jsxRuntime.jsx(LabelledDetail, {
189
+ label: DETAILS_KEYS.ERROR_MESSAGE,
190
+ value: errorMessage || t("neetoMolecules.auditLogs.noError")
191
+ })]
192
+ });
193
+ };
194
+
195
+ var PermissionsChangelog = function PermissionsChangelog(_ref) {
196
+ var details = _ref.details;
197
+ var _details$description = details.description,
198
+ description = _details$description === void 0 ? {} : _details$description,
199
+ _details$organization = details.organizationRole,
200
+ organizationRole = _details$organization === void 0 ? "" : _details$organization,
201
+ _details$addedPermiss = details.addedPermissions,
202
+ addedPermissions = _details$addedPermiss === void 0 ? [] : _details$addedPermiss,
203
+ _details$removedPermi = details.removedPermissions,
204
+ removedPermissions = _details$removedPermi === void 0 ? [] : _details$removedPermi;
205
+ return /*#__PURE__*/jsxRuntime.jsxs("div", {
206
+ children: [/*#__PURE__*/jsxRuntime.jsx(LabelledDetail, {
207
+ label: DETAILS_KEYS.ORGANIZATION_ROLE,
208
+ value: organizationRole
209
+ }), neetoCist.isNotEmpty(addedPermissions) && /*#__PURE__*/jsxRuntime.jsx(LabelledDetail, {
210
+ label: DETAILS_KEYS.ADDED_PERMISSIONS,
211
+ value: transformPermissions(addedPermissions)
212
+ }), neetoCist.isNotEmpty(removedPermissions) && /*#__PURE__*/jsxRuntime.jsx(LabelledDetail, {
213
+ label: DETAILS_KEYS.REMOVED_PERMISSIONS,
214
+ value: transformPermissions(removedPermissions)
215
+ }), neetoCist.isNotEmpty(description) && /*#__PURE__*/jsxRuntime.jsx(Table, {
216
+ columnData: CHANGELOG_COLUMN_DATA,
217
+ enableColumnFreeze: false,
218
+ rowData: formatPermissionsChangeLog(description)
219
+ })]
220
+ });
221
+ };
222
+
223
+ var Emails = function Emails(_ref) {
224
+ var details = _ref.details;
225
+ var _useTranslation = reactI18next.useTranslation(),
226
+ t = _useTranslation.t;
227
+ var _details$emails = details.emails,
228
+ emails = _details$emails === void 0 ? [] : _details$emails,
229
+ status = details.status,
230
+ _details$errorMessage = details.errorMessage,
231
+ errorMessage = _details$errorMessage === void 0 ? "" : _details$errorMessage;
232
+ return /*#__PURE__*/jsxRuntime.jsx(jsxRuntime.Fragment, {
233
+ children: neetoCist.isNotEmpty(emails) && status === "success" ? /*#__PURE__*/jsxRuntime.jsx(Table, {
234
+ columns: EMAILS_TABLE_COLUMN_DATA,
235
+ loading: false,
236
+ rowData: formatEmails(emails)
237
+ }) : /*#__PURE__*/jsxRuntime.jsx(LabelledDetail, {
238
+ label: DETAILS_KEYS.ERROR_MESSAGE,
239
+ value: errorMessage || t("neetoMolecules.auditLogs.noError")
240
+ })
241
+ });
242
+ };
243
+
244
+ var GenericDetails = function GenericDetails(_ref) {
245
+ var details = _ref.details;
246
+ var _details$firstName = details.firstName,
247
+ firstName = _details$firstName === void 0 ? "" : _details$firstName,
248
+ _details$lastName = details.lastName,
249
+ lastName = _details$lastName === void 0 ? "" : _details$lastName,
250
+ _details$organization = details.organizationRole,
251
+ organizationRole = _details$organization === void 0 ? "" : _details$organization;
252
+ var name = getFullName(firstName, lastName);
253
+ var label = getLabel({
254
+ firstName: firstName,
255
+ lastName: lastName,
256
+ organizationRole: organizationRole
257
+ });
258
+ var value = name || organizationRole || JSON.stringify(details);
259
+ return /*#__PURE__*/jsxRuntime.jsx(LabelledDetail, {
260
+ label: label,
261
+ value: value
262
+ });
263
+ };
264
+
265
+ var AUDIT_LOGS_QUERY_KEY = "audit-logs";
266
+ var ACTIONS = {
267
+ INVITED_USERS: "invitedUsers",
268
+ USER_SIGNED_UP: "userSignedUp",
269
+ UPDATED_USER: "updatedUser",
270
+ BULK_UPDATE_USERS: "bulkUpdateUsers",
271
+ UPDATED_USER_PROFILE: "updatedUserProfile",
272
+ CREATED_ROLE: "createdRole",
273
+ UPDATED_ROLE: "updatedRole",
274
+ DELETED_ROLE: "deletedRole"
275
+ };
276
+ var ADDITIONAL_DETAILS_KEYS = {
277
+ ACTION: "action",
278
+ PERFORMED_BY: "performedBy",
279
+ PERFORMED_AT: "performedAt",
280
+ PRODUCT: "product"
281
+ };
282
+ var DETAILS_COMPONENT_MAP = _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, ACTIONS.INVITED_USERS, Emails), ACTIONS.BULK_UPDATE_USERS, Emails), ACTIONS.USER_SIGNED_UP, GenericDetails), ACTIONS.UPDATED_USER, GenericChangelog), ACTIONS.UPDATED_USER_PROFILE, GenericChangelog), ACTIONS.CREATED_ROLE, GenericDetails), ACTIONS.UPDATED_ROLE, PermissionsChangelog), ACTIONS.DELETED_ROLE, GenericDetails);
283
+
284
+ var _excluded$1 = ["status"];
285
+ function ownKeys$1(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
286
+ function _objectSpread$1(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$1(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$1(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
287
+ var transformAction = function transformAction(action) {
288
+ return neetoCist.snakeToCamelCase(action.replace("audit_logs.organization.", ""));
289
+ };
290
+ var transformLogsForTable = function transformLogsForTable(logs) {
291
+ return logs.map(function (_ref) {
292
+ var id = _ref.id,
293
+ action = _ref.key,
294
+ _ref$metadata = _ref.metadata,
295
+ status = _ref$metadata.status,
296
+ restOfMetadata = _objectWithoutProperties(_ref$metadata, _excluded$1),
297
+ _ref$performer$name = _ref.performer.name,
298
+ performedBy = _ref$performer$name === void 0 ? "" : _ref$performer$name,
299
+ performedAt = _ref.updatedAt;
300
+ var transformedAction = transformAction(action);
301
+ var formattedPerformedAt = utils.dateFormat.dateTime(performedAt);
302
+ return {
303
+ id: id,
304
+ action: transformedAction,
305
+ status: neetoCist.capitalize(status),
306
+ performedAt: formattedPerformedAt,
307
+ performedBy: performedBy,
308
+ additionalDetails: _objectSpread$1(_objectSpread$1({}, restOfMetadata), {}, {
309
+ action: transformedAction,
310
+ performedAt: formattedPerformedAt,
311
+ performedBy: performedBy,
312
+ status: status
313
+ })
314
+ };
315
+ });
316
+ };
317
+ var getColumnData = function getColumnData(handleClick) {
318
+ return [{
319
+ title: i18next.t("neetoMolecules.auditLogs.table.headers.action", constants.SINGULAR),
320
+ key: "action",
321
+ dataIndex: "action",
322
+ render: function render(action, _ref2) {
323
+ var additionalDetails = _ref2.additionalDetails;
324
+ return /*#__PURE__*/jsxRuntime.jsx(Button, {
325
+ "data-testid": "action-link-button",
326
+ label: i18next.t("neetoMolecules.auditLogs.actions.".concat(action)),
327
+ style: "link",
328
+ onClick: function onClick() {
329
+ return handleClick(additionalDetails);
330
+ }
331
+ });
332
+ }
333
+ }, {
334
+ title: i18next.t("neetoMolecules.auditLogs.table.headers.status"),
335
+ key: "status",
336
+ dataIndex: "status"
337
+ }, {
338
+ title: i18next.t("neetoMolecules.auditLogs.table.headers.performedBy"),
339
+ key: "performedBy",
340
+ dataIndex: "performedBy"
341
+ }, {
342
+ title: i18next.t("neetoMolecules.auditLogs.table.headers.performedAt"),
343
+ key: "performedAt",
344
+ dataIndex: "performedAt"
345
+ }];
346
+ };
347
+ var getComponentForDetail = function getComponentForDetail(action) {
348
+ return DETAILS_COMPONENT_MAP[action] || GenericDetails;
349
+ };
350
+
351
+ var _excluded = ["message", "action", "performedBy", "performedAt", "via"];
352
+ var AdditionalDetails = function AdditionalDetails(_ref) {
353
+ var additionalDetails = _ref.additionalDetails,
354
+ isOpen = _ref.isOpen,
355
+ onClose = _ref.onClose;
356
+ var _useTranslation = reactI18next.useTranslation(),
357
+ t = _useTranslation.t;
358
+ var message = additionalDetails.message,
359
+ defaultAction = additionalDetails.action,
360
+ performedBy = additionalDetails.performedBy,
361
+ performedAt = additionalDetails.performedAt,
362
+ product = additionalDetails.via,
363
+ details = _objectWithoutProperties(additionalDetails, _excluded);
364
+ var action = message || t("neetoMolecules.auditLogs.actions.".concat(defaultAction));
365
+ var DetailComponent = getComponentForDetail(defaultAction);
366
+ return /*#__PURE__*/jsxRuntime.jsxs(Modal, {
367
+ isOpen: isOpen,
368
+ onClose: onClose,
369
+ "data-testid": "additional-details-modal",
370
+ size: "large",
371
+ children: [/*#__PURE__*/jsxRuntime.jsx(Modal.Header, {
372
+ children: /*#__PURE__*/jsxRuntime.jsx(Typography, {
373
+ style: "h2",
374
+ children: t("neetoMolecules.auditLogs.additionalDetails.title")
375
+ })
376
+ }), /*#__PURE__*/jsxRuntime.jsx(Modal.Body, {
377
+ children: /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
378
+ children: [/*#__PURE__*/jsxRuntime.jsx(LabelledDetail, {
379
+ label: ADDITIONAL_DETAILS_KEYS.ACTION,
380
+ value: action
381
+ }), /*#__PURE__*/jsxRuntime.jsx(LabelledDetail, {
382
+ label: ADDITIONAL_DETAILS_KEYS.PERFORMED_BY,
383
+ value: performedBy
384
+ }), /*#__PURE__*/jsxRuntime.jsx(LabelledDetail, {
385
+ label: ADDITIONAL_DETAILS_KEYS.PERFORMED_AT,
386
+ value: performedAt
387
+ }), /*#__PURE__*/jsxRuntime.jsx(LabelledDetail, {
388
+ label: ADDITIONAL_DETAILS_KEYS.PRODUCT,
389
+ value: neetoCist._capitalize(product)
390
+ }), /*#__PURE__*/jsxRuntime.jsx(DetailComponent, {
391
+ details: details
392
+ })]
393
+ })
394
+ })]
395
+ });
396
+ };
397
+
398
+ var fetchAuditLogs = function fetchAuditLogs(params) {
399
+ return axios.get("api/v1/audit_logs", {
400
+ params: params
401
+ });
402
+ };
403
+ var auditLogsApi = {
404
+ fetchAuditLogs: fetchAuditLogs
405
+ };
406
+
407
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
408
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
409
+ var useFetchAuditLogs = function useFetchAuditLogs(_ref) {
410
+ var params = _ref.params,
411
+ _ref$options = _ref.options,
412
+ options = _ref$options === void 0 ? {} : _ref$options;
413
+ return reactQuery.useQuery(_objectSpread({
414
+ queryKey: [AUDIT_LOGS_QUERY_KEY, params],
415
+ queryFn: function queryFn() {
416
+ return auditLogsApi.fetchAuditLogs(params);
417
+ }
418
+ }, options));
419
+ };
420
+
421
+ var AuditLogs = function AuditLogs() {
422
+ var _useState = React.useState(false),
423
+ _useState2 = _slicedToArray(_useState, 2),
424
+ isAdditionalDetailsModalOpen = _useState2[0],
425
+ setIsAdditionalDetailsModalOpen = _useState2[1];
426
+ var _useState3 = React.useState({}),
427
+ _useState4 = _slicedToArray(_useState3, 2),
428
+ additionalDetails = _useState4[0],
429
+ setAdditionalDetails = _useState4[1];
430
+ var _useTranslation = reactI18next.useTranslation(),
431
+ t = _useTranslation.t;
432
+ var _useQueryParams = reactUtils.useQueryParams(),
433
+ _useQueryParams$page = _useQueryParams.page,
434
+ page = _useQueryParams$page === void 0 ? constants.DEFAULT_PAGE_INDEX : _useQueryParams$page;
435
+ var _useFetchAuditLogs = useFetchAuditLogs({
436
+ params: {
437
+ page: page
438
+ }
439
+ }),
440
+ _useFetchAuditLogs$da = _useFetchAuditLogs.data,
441
+ _useFetchAuditLogs$da2 = _useFetchAuditLogs$da === void 0 ? {} : _useFetchAuditLogs$da,
442
+ _useFetchAuditLogs$da3 = _useFetchAuditLogs$da2.auditLogs,
443
+ auditLogs = _useFetchAuditLogs$da3 === void 0 ? [] : _useFetchAuditLogs$da3,
444
+ _useFetchAuditLogs$da4 = _useFetchAuditLogs$da2.totalCount,
445
+ totalCount = _useFetchAuditLogs$da4 === void 0 ? 0 : _useFetchAuditLogs$da4,
446
+ isLoading = _useFetchAuditLogs.isLoading,
447
+ isFetching = _useFetchAuditLogs.isFetching;
448
+ var handleClick = function handleClick(additionalDetails) {
449
+ setIsAdditionalDetailsModalOpen(true);
450
+ setAdditionalDetails(additionalDetails);
451
+ };
452
+ var handleClose = function handleClose() {
453
+ setIsAdditionalDetailsModalOpen(false);
454
+ setAdditionalDetails({});
455
+ };
456
+ if (isLoading) {
457
+ return /*#__PURE__*/jsxRuntime.jsx("div", {
458
+ className: "flex h-full w-full items-center justify-center",
459
+ children: /*#__PURE__*/jsxRuntime.jsx(PageLoader, {})
460
+ });
461
+ }
462
+ return /*#__PURE__*/jsxRuntime.jsxs(Container, {
463
+ children: [/*#__PURE__*/jsxRuntime.jsx(Header, {
464
+ title: t("neetoMolecules.auditLogs.title")
465
+ }), /*#__PURE__*/jsxRuntime.jsx(TableWrapper, {
466
+ className: "mt-5",
467
+ hasPagination: totalCount > constants.DEFAULT_PAGE_SIZE,
468
+ children: neetoCist.isPresent(auditLogs) ? /*#__PURE__*/jsxRuntime.jsx(Table, {
469
+ totalCount: totalCount,
470
+ fixedHeight: true,
471
+ columnData: getColumnData(handleClick),
472
+ currentPageNumber: parseInt(page),
473
+ "data-testid": "audit-logs-table",
474
+ defaultPageSize: constants.DEFAULT_PAGE_SIZE,
475
+ loading: isFetching,
476
+ rowData: transformLogsForTable(auditLogs)
477
+ }) : /*#__PURE__*/jsxRuntime.jsx("div", {
478
+ className: "flex h-full w-full items-center justify-center",
479
+ children: /*#__PURE__*/jsxRuntime.jsx(NoData, {
480
+ title: t("neetoMolecules.auditLogs.noData")
481
+ })
482
+ })
483
+ }), /*#__PURE__*/jsxRuntime.jsx(AdditionalDetails, {
484
+ additionalDetails: additionalDetails,
485
+ isOpen: isAdditionalDetailsModalOpen,
486
+ onClose: handleClose
487
+ })]
488
+ });
489
+ };
490
+
491
+ module.exports = AuditLogs;
492
+ //# sourceMappingURL=AuditLogs.js.map