sevago-library 1.2.2 → 1.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # sevago-library
2
2
 
3
+ ## 1.2.4
4
+
5
+ ### Patch Changes
6
+
7
+ - fix: update type definitions to include 'any' for time parameters in utility functions
8
+
9
+ ## 1.2.3
10
+
11
+ ### Patch Changes
12
+
13
+ - feat: add AdvancedFilterDialog component and its story
14
+
3
15
  ## 1.2.2
4
16
 
5
17
  ### Patch Changes
package/dist/index.cjs.js CHANGED
@@ -75226,6 +75226,220 @@ const parseDateMacroToTimestamp = (macroStr) => {
75226
75226
  }
75227
75227
  return { fromDate: start2.unix(), toDate: end2.unix() };
75228
75228
  };
75229
+ const createDefaultState = (fields) => {
75230
+ return fields.reduce((acc, field) => {
75231
+ acc[field.key] = field.defaultValue;
75232
+ return acc;
75233
+ }, {});
75234
+ };
75235
+ const createRowsFromValue = (fields, value) => {
75236
+ const activeRows = fields.filter((field) => ((value == null ? void 0 : value[field.key]) ?? field.defaultValue) !== field.defaultValue).map((field) => ({
75237
+ id: generateId(),
75238
+ fieldKey: field.key,
75239
+ value: (value == null ? void 0 : value[field.key]) ?? field.defaultValue
75240
+ }));
75241
+ if (activeRows.length > 0) return activeRows;
75242
+ const firstField = fields[0];
75243
+ if (!firstField) return [];
75244
+ return [
75245
+ {
75246
+ id: generateId(),
75247
+ fieldKey: firstField.key,
75248
+ value: (value == null ? void 0 : value[firstField.key]) ?? firstField.defaultValue
75249
+ }
75250
+ ];
75251
+ };
75252
+ const AdvancedFilterDialog = ({
75253
+ open: open2,
75254
+ title = "Tùy chỉnh bộ lọc",
75255
+ fields,
75256
+ value,
75257
+ anchorEl,
75258
+ offset: offset2,
75259
+ onClose,
75260
+ onApply
75261
+ }) => {
75262
+ const defaults = React.useMemo(() => createDefaultState(fields), [fields]);
75263
+ const fieldOptions = React.useMemo(() => fields.map((field) => ({ label: field.label, value: field.key })), [fields]);
75264
+ const [rows, setRows] = React.useState(() => createRowsFromValue(fields, value));
75265
+ const [draggingIndex, setDraggingIndex] = React.useState(null);
75266
+ React.useEffect(() => {
75267
+ if (open2) {
75268
+ setRows(createRowsFromValue(fields, value));
75269
+ setDraggingIndex(null);
75270
+ }
75271
+ }, [fields, open2, value]);
75272
+ const handleReset = () => {
75273
+ const firstField = fields[0];
75274
+ if (!firstField) {
75275
+ setRows([]);
75276
+ return;
75277
+ }
75278
+ setRows([{ id: generateId(), fieldKey: firstField.key, value: firstField.defaultValue }]);
75279
+ };
75280
+ const handleRemove = (index) => {
75281
+ setRows((prev) => {
75282
+ const next = prev.filter((_, currentIndex) => currentIndex !== index);
75283
+ if (next.length > 0) return next;
75284
+ const firstField = fields[0];
75285
+ if (!firstField) return [];
75286
+ return [{ id: generateId(), fieldKey: firstField.key, value: firstField.defaultValue }];
75287
+ });
75288
+ };
75289
+ const handleAdd = () => {
75290
+ setRows((prev) => {
75291
+ const usedFieldKeys = new Set(prev.map((row) => row.fieldKey));
75292
+ const nextField = fields.find((field) => !usedFieldKeys.has(field.key));
75293
+ if (!nextField) return prev;
75294
+ return [...prev, { id: generateId(), fieldKey: nextField.key, value: nextField.defaultValue }];
75295
+ });
75296
+ };
75297
+ const handleDrop = (dropIndex) => {
75298
+ if (draggingIndex === null || dropIndex === draggingIndex) return;
75299
+ setRows((prev) => {
75300
+ const next = [...prev];
75301
+ const [movedRow] = next.splice(draggingIndex, 1);
75302
+ next.splice(dropIndex, 0, movedRow);
75303
+ return next;
75304
+ });
75305
+ setDraggingIndex(null);
75306
+ };
75307
+ const handleApply = () => {
75308
+ const mergedValue = { ...defaults };
75309
+ rows.forEach((row) => {
75310
+ if (row.fieldKey) mergedValue[row.fieldKey] = row.value;
75311
+ });
75312
+ onApply(mergedValue);
75313
+ onClose();
75314
+ };
75315
+ const canAddRow = rows.length < fields.length;
75316
+ return /* @__PURE__ */ jsxRuntime.jsx(
75317
+ material.Popover,
75318
+ {
75319
+ open: open2,
75320
+ anchorEl,
75321
+ onClose,
75322
+ disableScrollLock: true,
75323
+ anchorOrigin: { vertical: "bottom", horizontal: "left" },
75324
+ transformOrigin: { vertical: "top", horizontal: "left" },
75325
+ slotProps: {
75326
+ paper: {
75327
+ sx: {
75328
+ mt: `${(offset2 == null ? void 0 : offset2.y) ?? 8}px`,
75329
+ ml: `${(offset2 == null ? void 0 : offset2.x) ?? 0}px`,
75330
+ minWidth: 320,
75331
+ maxWidth: "calc(100vw - 48px)",
75332
+ borderRadius: BORDER_RADIUS_ELEMENT_MIDDLE,
75333
+ border: `1px solid ${NEUTRAL[300]}`,
75334
+ boxShadow: "0 8px 24px rgba(15, 23, 42, 0.12)",
75335
+ overflow: "hidden"
75336
+ }
75337
+ }
75338
+ },
75339
+ children: /* @__PURE__ */ jsxRuntime.jsx(material.Box, { sx: { backgroundColor: WHITE[50], padding: 2 }, children: /* @__PURE__ */ jsxRuntime.jsxs(StackAlignCenter, { sx: { alignItems: "stretch", gap: 2 }, children: [
75340
+ /* @__PURE__ */ jsxRuntime.jsxs(StackRowAlignCenterJustBetween, { sx: { gap: 1 }, children: [
75341
+ /* @__PURE__ */ jsxRuntime.jsx(material.Typography, { sx: { ...TYPOGRAPHY.textMd.semiBold }, children: title }),
75342
+ /* @__PURE__ */ jsxRuntime.jsx(material.IconButton, { onClick: onClose, sx: { padding: PADDING_GAP_ITEM_SMALL }, children: /* @__PURE__ */ jsxRuntime.jsx(IconElement, { icon: "close" }) })
75343
+ ] }),
75344
+ /* @__PURE__ */ jsxRuntime.jsx(StackAlignCenter, { sx: { alignItems: "stretch", gap: 1.25 }, children: rows.map((row, index) => {
75345
+ const field = fields.find((currentField) => currentField.key === row.fieldKey);
75346
+ if (!field) return null;
75347
+ const usedFieldKeys = new Set(rows.map((currentRow) => currentRow.fieldKey));
75348
+ const selectableFieldOptions = fieldOptions.filter(
75349
+ (option) => option.value === row.fieldKey || !usedFieldKeys.has(option.value)
75350
+ );
75351
+ return /* @__PURE__ */ jsxRuntime.jsxs(
75352
+ StackRowAlignCenter,
75353
+ {
75354
+ onDragOver: (event) => event.preventDefault(),
75355
+ onDrop: () => handleDrop(index),
75356
+ sx: { gap: 1, alignItems: "flex-end" },
75357
+ children: [
75358
+ /* @__PURE__ */ jsxRuntime.jsx(
75359
+ material.Box,
75360
+ {
75361
+ draggable: true,
75362
+ onDragStart: () => setDraggingIndex(index),
75363
+ onDragEnd: () => setDraggingIndex(null),
75364
+ sx: { paddingBottom: "10px", cursor: "grab" },
75365
+ children: /* @__PURE__ */ jsxRuntime.jsx(IconElement, { icon: "drag_indicator", sx: { color: NEUTRAL[500] } })
75366
+ }
75367
+ ),
75368
+ /* @__PURE__ */ jsxRuntime.jsx(material.Box, { sx: { flex: 1, minWidth: 220 }, children: /* @__PURE__ */ jsxRuntime.jsx(
75369
+ TextFieldSelectElement,
75370
+ {
75371
+ label: "",
75372
+ value: row.fieldKey,
75373
+ options: selectableFieldOptions,
75374
+ placeholder: "",
75375
+ onChange: (event) => {
75376
+ const nextFieldKey = event.target.value;
75377
+ const nextField = fields.find((currentField) => currentField.key === nextFieldKey);
75378
+ if (!nextField) return;
75379
+ setRows(
75380
+ (prev) => prev.map(
75381
+ (currentRow, currentIndex) => currentIndex === index ? {
75382
+ ...currentRow,
75383
+ fieldKey: nextFieldKey,
75384
+ value: nextField.defaultValue
75385
+ } : currentRow
75386
+ )
75387
+ );
75388
+ }
75389
+ }
75390
+ ) }),
75391
+ /* @__PURE__ */ jsxRuntime.jsx(material.Box, { sx: { flex: 1, minWidth: 220 }, children: /* @__PURE__ */ jsxRuntime.jsx(
75392
+ TextFieldSelectElement,
75393
+ {
75394
+ label: "",
75395
+ value: row.value ?? field.defaultValue,
75396
+ options: field.options,
75397
+ placeholder: "Tất cả",
75398
+ onChange: (event) => {
75399
+ const nextValue = event.target.value;
75400
+ setRows(
75401
+ (prev) => prev.map(
75402
+ (currentRow, currentIndex) => currentIndex === index ? { ...currentRow, value: nextValue } : currentRow
75403
+ )
75404
+ );
75405
+ }
75406
+ }
75407
+ ) }),
75408
+ /* @__PURE__ */ jsxRuntime.jsx(material.IconButton, { onClick: () => handleRemove(index), children: /* @__PURE__ */ jsxRuntime.jsx(IconElement, { icon: "delete_outline" }) })
75409
+ ]
75410
+ },
75411
+ row.id
75412
+ );
75413
+ }) }),
75414
+ canAddRow && /* @__PURE__ */ jsxRuntime.jsx(
75415
+ ButtonElement,
75416
+ {
75417
+ content: "Thêm điều kiện",
75418
+ onClick: handleAdd,
75419
+ startIcon: "add",
75420
+ variant: "text",
75421
+ sx: { color: PRIMARY[500], minWidth: 0, paddingX: 0 }
75422
+ }
75423
+ ),
75424
+ /* @__PURE__ */ jsxRuntime.jsxs(StackRowAlignCenterJustBetween, { sx: { marginTop: 1 }, children: [
75425
+ /* @__PURE__ */ jsxRuntime.jsx(
75426
+ ButtonElement,
75427
+ {
75428
+ content: "Mặc định",
75429
+ onClick: handleReset,
75430
+ variant: "text",
75431
+ sx: { color: PRIMARY[500], minWidth: 0, paddingX: 0 }
75432
+ }
75433
+ ),
75434
+ /* @__PURE__ */ jsxRuntime.jsxs(StackRowAlignCenter, { sx: { gap: 1 }, children: [
75435
+ /* @__PURE__ */ jsxRuntime.jsx(ButtonElement, { onClick: onClose, variant: "outlined", content: "Hủy" }),
75436
+ /* @__PURE__ */ jsxRuntime.jsx(ButtonElement, { onClick: handleApply, variant: "contained", content: "Áp dụng" })
75437
+ ] })
75438
+ ] })
75439
+ ] }) })
75440
+ }
75441
+ );
75442
+ };
75229
75443
  const FilterValueInput = ({ field, rowValue, onChange }) => {
75230
75444
  switch (field.type) {
75231
75445
  case "select":
@@ -78442,6 +78656,7 @@ const SearchDropdownComponent = ({
78442
78656
  ] });
78443
78657
  };
78444
78658
  exports.APPS = apps_const;
78659
+ exports.AdvancedFilterDialog = AdvancedFilterDialog;
78445
78660
  exports.AdvancedOperatorFilterDialog = AdvancedOperatorFilterDialog;
78446
78661
  exports.AppGrid = AppGrid;
78447
78662
  exports.AppGridItem = AppGridItem;