@algorithm-shift/design-system 1.3.114 → 1.3.115

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -4019,7 +4019,6 @@ function DataTable({
4019
4019
  onPageChange,
4020
4020
  pageSize = 10,
4021
4021
  paginationMode = "client",
4022
- totalRecords = 0,
4023
4022
  onSortChange,
4024
4023
  onFilterChange,
4025
4024
  onGlobalSearch,
@@ -4032,13 +4031,17 @@ function DataTable({
4032
4031
  tableId,
4033
4032
  manageColumns = false,
4034
4033
  preferenceUrl,
4035
- axiosInstance
4034
+ axiosInstance,
4035
+ meta,
4036
+ enableTotalRecords,
4037
+ getRowCount
4036
4038
  }) {
4037
4039
  const [columnFilters, setColumnFilters] = React11.useState([]);
4038
4040
  const [columnVisibility, setColumnVisibility] = React11.useState({});
4039
4041
  const hasLoadedInitialState = React11.useRef(false);
4040
4042
  const isSavingRef = React11.useRef(false);
4041
4043
  const isFetchingRef = React11.useRef(false);
4044
+ const [fetchLoading, setFetchLoading] = React11.useState(false);
4042
4045
  const transformApiToFrontend = React11.useCallback((apiSettings, allColumnIds) => {
4043
4046
  if (!apiSettings || !apiSettings.columns || !apiSettings.columns.visible) {
4044
4047
  return {};
@@ -4207,8 +4210,10 @@ function DataTable({
4207
4210
  React11.useEffect(() => {
4208
4211
  if (paginationMode === "client") {
4209
4212
  setLocalPageSize(pageSize);
4213
+ } else if (paginationMode === "server" && meta?.limit != null) {
4214
+ setLocalPageSize(meta.limit);
4210
4215
  }
4211
- }, [pageSize, paginationMode]);
4216
+ }, [pageSize, paginationMode, meta?.limit]);
4212
4217
  const table = useReactTable({
4213
4218
  data: finalData,
4214
4219
  columns: dynamicCols,
@@ -4223,8 +4228,8 @@ function DataTable({
4223
4228
  columnVisibility,
4224
4229
  rowSelection,
4225
4230
  pagination: {
4226
- pageIndex: paginationMode === "server" ? controlledPageIndex ?? 0 : localPageIndex,
4227
- pageSize: localPageSize
4231
+ pageIndex: paginationMode === "server" ? meta?.page != null ? meta.page - 1 : controlledPageIndex ?? 0 : localPageIndex,
4232
+ pageSize: paginationMode === "server" && meta?.limit != null ? meta.limit : localPageSize
4228
4233
  }
4229
4234
  },
4230
4235
  enableRowSelection: !!enableRowSelection,
@@ -4262,7 +4267,7 @@ function DataTable({
4262
4267
  getFilteredRowModel: getFilteredRowModel(),
4263
4268
  getPaginationRowModel: pagination && paginationMode === "client" ? getPaginationRowModel() : void 0,
4264
4269
  manualPagination: paginationMode === "server",
4265
- pageCount: paginationMode === "server" ? Math.ceil(totalRecords / localPageSize) : void 0,
4270
+ // pageCount: paginationMode === 'server' ? Math.ceil(totalRecords / localPageSize) : undefined,
4266
4271
  onPaginationChange: (updater) => {
4267
4272
  if (isUpdatingPageSizeRef.current) {
4268
4273
  isUpdatingPageSizeRef.current = false;
@@ -4320,19 +4325,30 @@ function DataTable({
4320
4325
  if (paginationMode === "client") {
4321
4326
  return [5, 10, 20, 50, 100];
4322
4327
  }
4323
- const options = [5, 10, 20, 50, 100].filter((size) => size < totalRecords);
4324
- if (options.length === 0) {
4325
- options.push(5);
4328
+ const base = [5, 10, 20, 50, 100];
4329
+ if (meta?.limit != null && !base.includes(meta.limit)) {
4330
+ const withMeta = [...base, meta.limit].sort((a, b) => a - b);
4331
+ return withMeta;
4326
4332
  }
4327
- return options;
4328
- }, [paginationMode, totalRecords]);
4333
+ return base;
4334
+ }, [paginationMode, meta?.limit]);
4329
4335
  return /* @__PURE__ */ jsxs30("div", { className: "overflow-hidden rounded-md w-full", children: [
4330
4336
  !loading && /* @__PURE__ */ jsxs30("div", { className: "flex justify-between p-2 bg-gray-50", children: [
4331
4337
  /* @__PURE__ */ jsxs30("div", { className: "flex items-center gap-4 w-full", children: [
4332
- !!totalRecords && /* @__PURE__ */ jsxs30("p", { className: "text-sm font-medium", children: [
4333
- "Total Records : ",
4334
- totalRecords.toLocaleString("en-IN") || 0
4335
- ] }),
4338
+ enableTotalRecords && /* @__PURE__ */ jsx51(
4339
+ Button,
4340
+ {
4341
+ size: "sm",
4342
+ className: "bg-[#12715B] text-white text-xs h-auto py-2 px-3 cursor-pointer",
4343
+ onClick: async () => {
4344
+ setFetchLoading(true);
4345
+ await getRowCount?.();
4346
+ setFetchLoading(false);
4347
+ },
4348
+ disabled: fetchLoading,
4349
+ children: fetchLoading ? "Fetching..." : "Get Total Records"
4350
+ }
4351
+ ),
4336
4352
  globalSearch && /* @__PURE__ */ jsxs30("div", { className: "flex items-center gap-2 w-full max-w-sm", children: [
4337
4353
  /* @__PURE__ */ jsxs30("div", { className: "relative w-full", children: [
4338
4354
  /* @__PURE__ */ jsx51(
@@ -4532,18 +4548,18 @@ function DataTable({
4532
4548
  j
4533
4549
  );
4534
4550
  }) }, i)) }) : table.getRowModel().rows.length ? table.getRowModel().rows.map((row) => /* @__PURE__ */ jsx51(TableRow, { children: row.getVisibleCells().map((cell, cellIndex, arr) => {
4535
- const meta = cell.column.columnDef.meta || {};
4536
- const isClickable = meta?.isClickable;
4551
+ const meta2 = cell.column.columnDef.meta || {};
4552
+ const isClickable = meta2?.isClickable;
4537
4553
  const isLastCell = cellIndex === arr.length - 1;
4538
4554
  return /* @__PURE__ */ jsxs30(
4539
4555
  TableCell,
4540
4556
  {
4541
- className: `break-words whitespace-normal align-top ${meta?.cellClass ?? ""} ${isClickable ? "cursor-pointer hover:bg-gray-100 underline text-blue-500" : ""} relative py-2 `,
4557
+ className: `break-words whitespace-normal align-top ${meta2?.cellClass ?? ""} ${isClickable ? "cursor-pointer hover:bg-gray-100 underline text-blue-500" : ""} relative py-2 `,
4542
4558
  style: {
4543
4559
  width: cell.column.getSize(),
4544
4560
  minWidth: cell.column.columnDef.minSize,
4545
4561
  maxWidth: cell.column.columnDef.maxSize,
4546
- ...meta?.cellStyle ?? {}
4562
+ ...meta2?.cellStyle ?? {}
4547
4563
  },
4548
4564
  onClick: () => {
4549
4565
  if (isClickable && onCellClick) {
@@ -4582,7 +4598,7 @@ function DataTable({
4582
4598
  !loading && /* @__PURE__ */ jsx51("div", { className: "flex gap-2 items-center", children: /* @__PURE__ */ jsx51(
4583
4599
  "select",
4584
4600
  {
4585
- value: localPageSize,
4601
+ value: paginationMode === "server" && meta?.limit != null ? meta.limit : localPageSize,
4586
4602
  onChange: handlePageSizeChange,
4587
4603
  className: "ml-2 border rounded py-1 text-sm cursor-pointer border-blue-600",
4588
4604
  children: pageSizeOptions.map((size) => /* @__PURE__ */ jsxs30("option", { value: size, children: [
@@ -4596,7 +4612,7 @@ function DataTable({
4596
4612
  "button",
4597
4613
  {
4598
4614
  onClick: () => table.previousPage(),
4599
- disabled: !table.getCanPreviousPage?.(),
4615
+ disabled: paginationMode === "server" && meta != null ? (meta.page ?? 1) <= 1 : !table.getCanPreviousPage?.(),
4600
4616
  className: "px-2 py-1 border rounded disabled:opacity-50 cursor-pointer",
4601
4617
  children: "Prev"
4602
4618
  }
@@ -4605,7 +4621,7 @@ function DataTable({
4605
4621
  "button",
4606
4622
  {
4607
4623
  onClick: () => table.nextPage(),
4608
- disabled: !table.getCanNextPage?.(),
4624
+ disabled: paginationMode === "server" && meta != null ? !meta.hasMore : !table.getCanNextPage?.(),
4609
4625
  className: "px-2 py-1 border rounded disabled:opacity-50 cursor-pointer",
4610
4626
  children: "Next"
4611
4627
  }
@@ -4656,7 +4672,6 @@ var Table2 = ({
4656
4672
  onPageChange?.({ page: pageIndex + 1, itemsPerPage: pageSize });
4657
4673
  },
4658
4674
  paginationMode,
4659
- totalRecords,
4660
4675
  onSortChange: (col, dir) => onSortChange?.({ sort_by: col, sort_order: dir }),
4661
4676
  onFilterChange: (filters) => onFilterChange?.({ columnKey: filters.columnKey, columnTerm: filters.columnTerm }),
4662
4677
  onGlobalSearch: (term) => onGlobalSearch?.({ searchTerm: term }),
@@ -5670,8 +5685,10 @@ var StagesComponent = ({
5670
5685
  const currentIndex = stages.findIndex((s) => s[dataKey] === activeStage);
5671
5686
  const isCompletedStage = isAllStagesCompleted || index <= currentIndex;
5672
5687
  const isActive = !isAllStagesCompleted && index === currentIndex;
5688
+ const isLastStageWhenCompleted = isAllStagesCompleted && index === stages.length - 1;
5689
+ const showAsActive = isActive || isLastStageWhenCompleted;
5673
5690
  let stageColor = `text-[${primaryColor}] border-2 border-[${primaryColor}]`;
5674
- let stageStyle = { borderColor: primaryColor, color: isActive ? "white" : primaryColor, backgroundColor: isActive ? primaryColor : "transparent" };
5691
+ let stageStyle = { borderColor: primaryColor, color: showAsActive ? "white" : primaryColor, backgroundColor: showAsActive ? primaryColor : "transparent" };
5675
5692
  if (stage.hasOwnProperty("isSuccess") && stage.isSuccess === false) {
5676
5693
  stageColor = `bg-red-50 text-red-700 border-2 border-red-700`;
5677
5694
  stageStyle = { borderColor: "red", color: "red", backgroundColor: "transparent" };
@@ -5694,7 +5711,7 @@ var StagesComponent = ({
5694
5711
  min-w-[70px] sm:min-w-[80px] w-full sm:w-auto px-3 sm:px-4 py-1.5 sm:py-2
5695
5712
  rounded-full text-xs sm:text-sm font-medium transition-colors duration-200
5696
5713
  whitespace-normal sm:whitespace-nowrap flex-shrink-0 max-w-[150px] text-ellipsis overflow-hidden
5697
- ${isActive ? `bg-[${primaryColor}] text-white shadow-md` : isCompletedStage ? stageColor : "bg-white border border-gray-200"}
5714
+ ${showAsActive ? `bg-[${primaryColor}] text-white shadow-md` : isCompletedStage ? stageColor : "bg-white border border-gray-200"}
5698
5715
  ${isMobile ? "flex-1 text-center py-2.5" : ""}
5699
5716
  `,
5700
5717
  onClick: () => {
@@ -5819,7 +5836,8 @@ function Navbar({
5819
5836
  isBuilder = false,
5820
5837
  source,
5821
5838
  navList,
5822
- onSearch
5839
+ onSearch,
5840
+ primaryColor = "#2a55a3"
5823
5841
  }) {
5824
5842
  const router = useRouter2();
5825
5843
  const [screenMode, setScreenMode] = useState14(
@@ -5912,7 +5930,7 @@ function Navbar({
5912
5930
  /* @__PURE__ */ jsxs41(DropdownMenu, { children: [
5913
5931
  /* @__PURE__ */ jsx67(DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ jsxs41("div", { className: "flex items-center space-x-2 cursor-pointer", children: [
5914
5932
  !isMobile && showName && /* @__PURE__ */ jsx67("h4", { className: "text-gray-900 dark:text-gray-300 text-sm", children: userName }),
5915
- /* @__PURE__ */ jsx67(Avatar, { className: "h-8 w-8", children: profileType === "avatar" ? /* @__PURE__ */ jsx67(AvatarImage, { src: "/images/appbuilder/toolset/profile.svg", alt: "profile" }) : /* @__PURE__ */ jsx67("div", { className: "bg-green-700 text-white h-full w-full rounded-full flex items-center justify-center text-xs", children: getInitials(userName) }) }),
5933
+ /* @__PURE__ */ jsx67(Avatar, { className: "h-8 w-8", children: profileType === "avatar" ? /* @__PURE__ */ jsx67(AvatarImage, { src: "/images/appbuilder/toolset/profile.svg", alt: "profile" }) : /* @__PURE__ */ jsx67("div", { className: `bg-[${primaryColor}] text-white h-full w-full rounded-full flex items-center justify-center text-xs`, style: { backgroundColor: primaryColor }, children: getInitials(userName) }) }),
5916
5934
  (isMobile || isTablet) && /* @__PURE__ */ jsx67(Button, { variant: "ghost", size: "icon", children: /* @__PURE__ */ jsx67(Menu2, { className: "h-6 w-6" }) })
5917
5935
  ] }) }),
5918
5936
  /* @__PURE__ */ jsxs41(DropdownMenuContent, { align: "end", className: "bg-white dark:bg-gray-800", children: [
@@ -6105,15 +6123,6 @@ var ChartComponent = ({
6105
6123
  }
6106
6124
  return /* @__PURE__ */ jsxs42("div", { className: `${className} h-[450px]`, style, children: [
6107
6125
  isPaginationEnabled && rawMeta && /* @__PURE__ */ jsxs42("div", { className: "flex items-center justify-between mb-4 px-2", children: [
6108
- /* @__PURE__ */ jsxs42("div", { className: "text-sm text-gray-600 hidden sm:block", children: [
6109
- "Page ",
6110
- rawMeta.page,
6111
- " of ",
6112
- rawMeta.pages,
6113
- " (",
6114
- rawMeta.total.toLocaleString(),
6115
- " total records)"
6116
- ] }),
6117
6126
  /* @__PURE__ */ jsxs42("div", { className: "flex items-center space-x-2 sm:hidden w-full justify-center", children: [
6118
6127
  /* @__PURE__ */ jsx68(
6119
6128
  "button",