{"version":3,"file":"fetchData.cjs","names":["_i18n","require","fetchData","dataQueryParams","errorMessageProp","getData","setData","setErrorMessage","setIsLoading","incomingData","error","odysseyTranslate","exports"],"sources":["../../../../src/labs/DataView/fetchData.ts"],"sourcesContent":["/*!\n * Copyright (c) 2024-present, Okta, Inc. and/or its affiliates. All rights reserved.\n * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the \"License.\")\n *\n * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n *\n * See the License for the specific language governing permissions and limitations under the License.\n */\n\nimport { MRT_RowData } from \"material-react-table\";\nimport { Dispatch, SetStateAction } from \"react\";\n\nimport { translate as odysseyTranslate } from \"../../i18n.generated/i18n.js\";\nimport { UniversalProps } from \"./componentTypes.js\";\nimport { DataQueryParamsType } from \"./dataTypes.js\";\n\ntype DataRequestType<TData extends MRT_RowData> = {\n  dataQueryParams: DataQueryParamsType;\n  errorMessageProp: UniversalProps<TData>[\"errorMessage\"];\n  getData: UniversalProps<TData>[\"getData\"];\n  setData: Dispatch<SetStateAction<TData[]>>;\n  setErrorMessage: Dispatch<\n    SetStateAction<UniversalProps<TData>[\"errorMessage\"]>\n  >;\n  setIsLoading?: Dispatch<SetStateAction<boolean>>;\n};\n\nexport const fetchData = async <TData extends MRT_RowData>({\n  dataQueryParams,\n  errorMessageProp,\n  getData,\n  setData,\n  setErrorMessage,\n  setIsLoading,\n}: DataRequestType<TData>) => {\n  setIsLoading?.(true);\n  setErrorMessage(errorMessageProp);\n  try {\n    const incomingData = await getData?.(dataQueryParams);\n    setData(incomingData);\n  } catch (error) {\n    setErrorMessage(\n      typeof error === \"string\" ? error : odysseyTranslate(\"table.error\"),\n    );\n  } finally {\n    setIsLoading?.(false);\n  }\n};\n"],"mappings":";;;;;;AAeA,IAAAA,KAAA,GAAAC,OAAA;AAfA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAoBO,MAAMC,SAAS,GAAG,MAAAA,CAAkC;EACzDC,eAAe;EACfC,gBAAgB;EAChBC,OAAO;EACPC,OAAO;EACPC,eAAe;EACfC;AACsB,CAAC,KAAK;EAC5BA,YAAY,GAAG,IAAI,CAAC;EACpBD,eAAe,CAACH,gBAAgB,CAAC;EACjC,IAAI;IACF,MAAMK,YAAY,GAAG,MAAMJ,OAAO,GAAGF,eAAe,CAAC;IACrDG,OAAO,CAACG,YAAY,CAAC;EACvB,CAAC,CAAC,OAAOC,KAAK,EAAE;IACdH,eAAe,CACb,OAAOG,KAAK,KAAK,QAAQ,GAAGA,KAAK,GAAG,IAAAC,eAAgB,EAAC,aAAa,CACpE,CAAC;EACH,CAAC,SAAS;IACRH,YAAY,GAAG,KAAK,CAAC;EACvB;AACF,CAAC;AAACI,OAAA,CAAAV,SAAA,GAAAA,SAAA","ignoreList":[]}