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 +12 -0
- package/dist/index.cjs.js +215 -0
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +215 -0
- package/dist/index.esm.js.map +1 -1
- package/dist/src/common/utils/time.util.d.ts +7 -7
- package/dist/src/components/elements/filters/advanced-filter-dialog.component/advanced-filter-dialog.component.d.ts +24 -0
- package/dist/src/components/elements/filters/advanced-filter-dialog.component/advanced-filter-dialog.component.stories.d.ts +7 -0
- package/dist/src/components/elements/filters/index.d.ts +1 -0
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -75208,6 +75208,220 @@ const parseDateMacroToTimestamp = (macroStr) => {
|
|
|
75208
75208
|
}
|
|
75209
75209
|
return { fromDate: start2.unix(), toDate: end2.unix() };
|
|
75210
75210
|
};
|
|
75211
|
+
const createDefaultState = (fields) => {
|
|
75212
|
+
return fields.reduce((acc, field) => {
|
|
75213
|
+
acc[field.key] = field.defaultValue;
|
|
75214
|
+
return acc;
|
|
75215
|
+
}, {});
|
|
75216
|
+
};
|
|
75217
|
+
const createRowsFromValue = (fields, value) => {
|
|
75218
|
+
const activeRows = fields.filter((field) => ((value == null ? void 0 : value[field.key]) ?? field.defaultValue) !== field.defaultValue).map((field) => ({
|
|
75219
|
+
id: generateId(),
|
|
75220
|
+
fieldKey: field.key,
|
|
75221
|
+
value: (value == null ? void 0 : value[field.key]) ?? field.defaultValue
|
|
75222
|
+
}));
|
|
75223
|
+
if (activeRows.length > 0) return activeRows;
|
|
75224
|
+
const firstField = fields[0];
|
|
75225
|
+
if (!firstField) return [];
|
|
75226
|
+
return [
|
|
75227
|
+
{
|
|
75228
|
+
id: generateId(),
|
|
75229
|
+
fieldKey: firstField.key,
|
|
75230
|
+
value: (value == null ? void 0 : value[firstField.key]) ?? firstField.defaultValue
|
|
75231
|
+
}
|
|
75232
|
+
];
|
|
75233
|
+
};
|
|
75234
|
+
const AdvancedFilterDialog = ({
|
|
75235
|
+
open: open2,
|
|
75236
|
+
title = "Tùy chỉnh bộ lọc",
|
|
75237
|
+
fields,
|
|
75238
|
+
value,
|
|
75239
|
+
anchorEl,
|
|
75240
|
+
offset: offset2,
|
|
75241
|
+
onClose,
|
|
75242
|
+
onApply
|
|
75243
|
+
}) => {
|
|
75244
|
+
const defaults = useMemo(() => createDefaultState(fields), [fields]);
|
|
75245
|
+
const fieldOptions = useMemo(() => fields.map((field) => ({ label: field.label, value: field.key })), [fields]);
|
|
75246
|
+
const [rows, setRows] = useState(() => createRowsFromValue(fields, value));
|
|
75247
|
+
const [draggingIndex, setDraggingIndex] = useState(null);
|
|
75248
|
+
useEffect(() => {
|
|
75249
|
+
if (open2) {
|
|
75250
|
+
setRows(createRowsFromValue(fields, value));
|
|
75251
|
+
setDraggingIndex(null);
|
|
75252
|
+
}
|
|
75253
|
+
}, [fields, open2, value]);
|
|
75254
|
+
const handleReset = () => {
|
|
75255
|
+
const firstField = fields[0];
|
|
75256
|
+
if (!firstField) {
|
|
75257
|
+
setRows([]);
|
|
75258
|
+
return;
|
|
75259
|
+
}
|
|
75260
|
+
setRows([{ id: generateId(), fieldKey: firstField.key, value: firstField.defaultValue }]);
|
|
75261
|
+
};
|
|
75262
|
+
const handleRemove = (index) => {
|
|
75263
|
+
setRows((prev) => {
|
|
75264
|
+
const next = prev.filter((_, currentIndex) => currentIndex !== index);
|
|
75265
|
+
if (next.length > 0) return next;
|
|
75266
|
+
const firstField = fields[0];
|
|
75267
|
+
if (!firstField) return [];
|
|
75268
|
+
return [{ id: generateId(), fieldKey: firstField.key, value: firstField.defaultValue }];
|
|
75269
|
+
});
|
|
75270
|
+
};
|
|
75271
|
+
const handleAdd = () => {
|
|
75272
|
+
setRows((prev) => {
|
|
75273
|
+
const usedFieldKeys = new Set(prev.map((row) => row.fieldKey));
|
|
75274
|
+
const nextField = fields.find((field) => !usedFieldKeys.has(field.key));
|
|
75275
|
+
if (!nextField) return prev;
|
|
75276
|
+
return [...prev, { id: generateId(), fieldKey: nextField.key, value: nextField.defaultValue }];
|
|
75277
|
+
});
|
|
75278
|
+
};
|
|
75279
|
+
const handleDrop = (dropIndex) => {
|
|
75280
|
+
if (draggingIndex === null || dropIndex === draggingIndex) return;
|
|
75281
|
+
setRows((prev) => {
|
|
75282
|
+
const next = [...prev];
|
|
75283
|
+
const [movedRow] = next.splice(draggingIndex, 1);
|
|
75284
|
+
next.splice(dropIndex, 0, movedRow);
|
|
75285
|
+
return next;
|
|
75286
|
+
});
|
|
75287
|
+
setDraggingIndex(null);
|
|
75288
|
+
};
|
|
75289
|
+
const handleApply = () => {
|
|
75290
|
+
const mergedValue = { ...defaults };
|
|
75291
|
+
rows.forEach((row) => {
|
|
75292
|
+
if (row.fieldKey) mergedValue[row.fieldKey] = row.value;
|
|
75293
|
+
});
|
|
75294
|
+
onApply(mergedValue);
|
|
75295
|
+
onClose();
|
|
75296
|
+
};
|
|
75297
|
+
const canAddRow = rows.length < fields.length;
|
|
75298
|
+
return /* @__PURE__ */ jsx(
|
|
75299
|
+
Popover$1,
|
|
75300
|
+
{
|
|
75301
|
+
open: open2,
|
|
75302
|
+
anchorEl,
|
|
75303
|
+
onClose,
|
|
75304
|
+
disableScrollLock: true,
|
|
75305
|
+
anchorOrigin: { vertical: "bottom", horizontal: "left" },
|
|
75306
|
+
transformOrigin: { vertical: "top", horizontal: "left" },
|
|
75307
|
+
slotProps: {
|
|
75308
|
+
paper: {
|
|
75309
|
+
sx: {
|
|
75310
|
+
mt: `${(offset2 == null ? void 0 : offset2.y) ?? 8}px`,
|
|
75311
|
+
ml: `${(offset2 == null ? void 0 : offset2.x) ?? 0}px`,
|
|
75312
|
+
minWidth: 320,
|
|
75313
|
+
maxWidth: "calc(100vw - 48px)",
|
|
75314
|
+
borderRadius: BORDER_RADIUS_ELEMENT_MIDDLE,
|
|
75315
|
+
border: `1px solid ${NEUTRAL[300]}`,
|
|
75316
|
+
boxShadow: "0 8px 24px rgba(15, 23, 42, 0.12)",
|
|
75317
|
+
overflow: "hidden"
|
|
75318
|
+
}
|
|
75319
|
+
}
|
|
75320
|
+
},
|
|
75321
|
+
children: /* @__PURE__ */ jsx(Box, { sx: { backgroundColor: WHITE[50], padding: 2 }, children: /* @__PURE__ */ jsxs(StackAlignCenter, { sx: { alignItems: "stretch", gap: 2 }, children: [
|
|
75322
|
+
/* @__PURE__ */ jsxs(StackRowAlignCenterJustBetween, { sx: { gap: 1 }, children: [
|
|
75323
|
+
/* @__PURE__ */ jsx(Typography$1, { sx: { ...TYPOGRAPHY.textMd.semiBold }, children: title }),
|
|
75324
|
+
/* @__PURE__ */ jsx(IconButton$1, { onClick: onClose, sx: { padding: PADDING_GAP_ITEM_SMALL }, children: /* @__PURE__ */ jsx(IconElement, { icon: "close" }) })
|
|
75325
|
+
] }),
|
|
75326
|
+
/* @__PURE__ */ jsx(StackAlignCenter, { sx: { alignItems: "stretch", gap: 1.25 }, children: rows.map((row, index) => {
|
|
75327
|
+
const field = fields.find((currentField) => currentField.key === row.fieldKey);
|
|
75328
|
+
if (!field) return null;
|
|
75329
|
+
const usedFieldKeys = new Set(rows.map((currentRow) => currentRow.fieldKey));
|
|
75330
|
+
const selectableFieldOptions = fieldOptions.filter(
|
|
75331
|
+
(option) => option.value === row.fieldKey || !usedFieldKeys.has(option.value)
|
|
75332
|
+
);
|
|
75333
|
+
return /* @__PURE__ */ jsxs(
|
|
75334
|
+
StackRowAlignCenter,
|
|
75335
|
+
{
|
|
75336
|
+
onDragOver: (event) => event.preventDefault(),
|
|
75337
|
+
onDrop: () => handleDrop(index),
|
|
75338
|
+
sx: { gap: 1, alignItems: "flex-end" },
|
|
75339
|
+
children: [
|
|
75340
|
+
/* @__PURE__ */ jsx(
|
|
75341
|
+
Box,
|
|
75342
|
+
{
|
|
75343
|
+
draggable: true,
|
|
75344
|
+
onDragStart: () => setDraggingIndex(index),
|
|
75345
|
+
onDragEnd: () => setDraggingIndex(null),
|
|
75346
|
+
sx: { paddingBottom: "10px", cursor: "grab" },
|
|
75347
|
+
children: /* @__PURE__ */ jsx(IconElement, { icon: "drag_indicator", sx: { color: NEUTRAL[500] } })
|
|
75348
|
+
}
|
|
75349
|
+
),
|
|
75350
|
+
/* @__PURE__ */ jsx(Box, { sx: { flex: 1, minWidth: 220 }, children: /* @__PURE__ */ jsx(
|
|
75351
|
+
TextFieldSelectElement,
|
|
75352
|
+
{
|
|
75353
|
+
label: "",
|
|
75354
|
+
value: row.fieldKey,
|
|
75355
|
+
options: selectableFieldOptions,
|
|
75356
|
+
placeholder: "",
|
|
75357
|
+
onChange: (event) => {
|
|
75358
|
+
const nextFieldKey = event.target.value;
|
|
75359
|
+
const nextField = fields.find((currentField) => currentField.key === nextFieldKey);
|
|
75360
|
+
if (!nextField) return;
|
|
75361
|
+
setRows(
|
|
75362
|
+
(prev) => prev.map(
|
|
75363
|
+
(currentRow, currentIndex) => currentIndex === index ? {
|
|
75364
|
+
...currentRow,
|
|
75365
|
+
fieldKey: nextFieldKey,
|
|
75366
|
+
value: nextField.defaultValue
|
|
75367
|
+
} : currentRow
|
|
75368
|
+
)
|
|
75369
|
+
);
|
|
75370
|
+
}
|
|
75371
|
+
}
|
|
75372
|
+
) }),
|
|
75373
|
+
/* @__PURE__ */ jsx(Box, { sx: { flex: 1, minWidth: 220 }, children: /* @__PURE__ */ jsx(
|
|
75374
|
+
TextFieldSelectElement,
|
|
75375
|
+
{
|
|
75376
|
+
label: "",
|
|
75377
|
+
value: row.value ?? field.defaultValue,
|
|
75378
|
+
options: field.options,
|
|
75379
|
+
placeholder: "Tất cả",
|
|
75380
|
+
onChange: (event) => {
|
|
75381
|
+
const nextValue = event.target.value;
|
|
75382
|
+
setRows(
|
|
75383
|
+
(prev) => prev.map(
|
|
75384
|
+
(currentRow, currentIndex) => currentIndex === index ? { ...currentRow, value: nextValue } : currentRow
|
|
75385
|
+
)
|
|
75386
|
+
);
|
|
75387
|
+
}
|
|
75388
|
+
}
|
|
75389
|
+
) }),
|
|
75390
|
+
/* @__PURE__ */ jsx(IconButton$1, { onClick: () => handleRemove(index), children: /* @__PURE__ */ jsx(IconElement, { icon: "delete_outline" }) })
|
|
75391
|
+
]
|
|
75392
|
+
},
|
|
75393
|
+
row.id
|
|
75394
|
+
);
|
|
75395
|
+
}) }),
|
|
75396
|
+
canAddRow && /* @__PURE__ */ jsx(
|
|
75397
|
+
ButtonElement,
|
|
75398
|
+
{
|
|
75399
|
+
content: "Thêm điều kiện",
|
|
75400
|
+
onClick: handleAdd,
|
|
75401
|
+
startIcon: "add",
|
|
75402
|
+
variant: "text",
|
|
75403
|
+
sx: { color: PRIMARY[500], minWidth: 0, paddingX: 0 }
|
|
75404
|
+
}
|
|
75405
|
+
),
|
|
75406
|
+
/* @__PURE__ */ jsxs(StackRowAlignCenterJustBetween, { sx: { marginTop: 1 }, children: [
|
|
75407
|
+
/* @__PURE__ */ jsx(
|
|
75408
|
+
ButtonElement,
|
|
75409
|
+
{
|
|
75410
|
+
content: "Mặc định",
|
|
75411
|
+
onClick: handleReset,
|
|
75412
|
+
variant: "text",
|
|
75413
|
+
sx: { color: PRIMARY[500], minWidth: 0, paddingX: 0 }
|
|
75414
|
+
}
|
|
75415
|
+
),
|
|
75416
|
+
/* @__PURE__ */ jsxs(StackRowAlignCenter, { sx: { gap: 1 }, children: [
|
|
75417
|
+
/* @__PURE__ */ jsx(ButtonElement, { onClick: onClose, variant: "outlined", content: "Hủy" }),
|
|
75418
|
+
/* @__PURE__ */ jsx(ButtonElement, { onClick: handleApply, variant: "contained", content: "Áp dụng" })
|
|
75419
|
+
] })
|
|
75420
|
+
] })
|
|
75421
|
+
] }) })
|
|
75422
|
+
}
|
|
75423
|
+
);
|
|
75424
|
+
};
|
|
75211
75425
|
const FilterValueInput = ({ field, rowValue, onChange }) => {
|
|
75212
75426
|
switch (field.type) {
|
|
75213
75427
|
case "select":
|
|
@@ -78425,6 +78639,7 @@ const SearchDropdownComponent = ({
|
|
|
78425
78639
|
};
|
|
78426
78640
|
export {
|
|
78427
78641
|
apps_const as APPS,
|
|
78642
|
+
AdvancedFilterDialog,
|
|
78428
78643
|
AdvancedOperatorFilterDialog,
|
|
78429
78644
|
AppGrid,
|
|
78430
78645
|
AppGridItem,
|