tachybase_todo/packages/core/utils/src/common.ts

48 lines
1.1 KiB
TypeScript
Raw Normal View History

feat(parse-variables): support to parse variables in filter params (#1558) * fix: add field linkage on setting default datetime * fix: fix dateonly timezone problem * fix: improve test * docs(DatePicker): add demos * fix(DatePicker): should return the beginning of a second * feat(DatePicker): support non-UTC * refactor: rename * fix(RangePicker): get correct end date * test(mapDatePicker): add test * test(mapRangePicker): add test * feat(Filter): use non-UTC to filter * feat(FilterBlock): use non-UTC to filter * feat: add '$dateBetween' operator in datetime * feat: use RangePicker on toggled to 'dateBetween' operator * feat: set ranges for RangePicker * feat: backend support to parse 'dateBetween' operator * fix: fix build error * fix: adaptive content width * feat: support to use var on data scope * feat: add parse-variables plugin * feat: support to parse variables * feat: support only to set system variables * test: rename * feat: cover all * fix: fix build error * feat(RangePicker): extend more shortcut keys * feat(parse-variables): support more date var * feat: support user variables * feat: disable unmatched options * fix: use component name to filter option * fix: fix build error * feat: remove some operator of id * chore: remove useless operators * fix: built in plugin * refactor: move to core from plugin * refactor: remove code of plugin * refactor: remove useless code * fix: should after acl * Update server.ts * fix: compatible with old version * feat: test cases * refactor: rename to 'is between' * refactor: parse filter * fix: improve code * feat: test cases * fix: fix error * fix: improve parse date * fix: date variables * fix: day range * fix: test error * fix: typo * fix: test error * feat: $user variable * fix: toDate * fix: fix the value range of shortcuts * feat: add quarter and test * feat: support to use user's association fields to filter * refactor: use maxDepth * refactor: remove useless code * fix: make AssociationSelect.Designer to support variables * fix: getField * fix: parse utc * fix: remove only * fix: filter by ctx.db.getFieldByPath * fix: avoid error * fix: add translation * fix(RangePicker): can be set to empty * feat(utils): add hasEmptyValue * fix: should not save empty * fix: last few days should include today * fix: limit user variable type to display * fix: parse filter error * fix: empty * test: [skip ci] * fix: remove ';' * feat: improve code --------- Co-authored-by: chenos <chenlinxh@gmail.com>
2023-03-30 23:49:57 +08:00
export const isString = (value: any): value is string => {
return typeof value === 'string';
};
export const isArray = (value: any): value is Array<any> => {
return Array.isArray(value);
};
feat(filter-blocks): support filter-blocks (#1505) * refactor: audit log (#1516) * refactor: audit-log * refactor: audit-log fix view action * refactor: audit-log view fix * refactor(audit-log): collection field fix * refactor: audit-log view field fix * refactor(audit-log): support fixedBlock * refactor(audit-log): i18n fix * feat(filter-blocks): support form-block * feat(filter-blocks): add FilterProvider * feat: filter data blocks * perf: use useMemo * refactor: rename * feat: collect filter params * refactor: rename * refactor: remove useless code * feat: add 'Connect data blocks' option * feat: support 'x-filter-targets' to save data-blocks * refactor: extract Form.FilterFormDesigner * feat: extract FormItem.FilterFormDesigner * refactor: extract common editing options * feat: support to set operator * feat: use operator created by user * fix: improve loading * fix: merge prev params * feat: support reset * refactor: rename * chore: left a TODO * feat: add Table.FilterDesigner * feat: support filter-table * refactor: reduce code * feat: handle click event of table row * feat: support to connect association collection * feat: support Collapse * feat: show empty * refactor: optimize readability * fix: keep state as latest * fix: highlight row on selected * feat: highlight data block on hover * fix: avoid misuse * chore: reduce code * fix(Table): support to cancel select * fix(Collapse): merge multiple filter params * chore: make to pass CI * feat: merge all filter params * refactor: remove useless code * fix: undefined * fix(Form): fix bug with association fields * chore: fix typo * fix: use title * chore: avoid infinite loops * test: cancel comments * fix: make ci normal * fix: filter down non-association fields * fix: fix page crash * fix: use correct operator * fix: avoid infinte loops * style: optimize style on hover * fix: avoid crash * chore: optimize empty description * fix: avoid targetKey empty * refactor: use getTargetKey instead * fix: filter out unfilterable fields * refactor: avoid to invoke hook multiple times * refactor: reduce the judgment conditions of component * fix: group fields in the right way * fix: fix error of type * fix: fix error on no FilterBlockProvider * fix(Table): fix fexed-block bug * chore: reduce gap * fix(Form): use AssociationSelect by default * fix: remove g2plot blocks * fix(Form): remove 'Display association fields' * fix(Table): use radio * fix(Table): no need Actions * fix: fix template problem * fix(Table): keep only 'filter' and 'refresh' * fix: use collection name as identifier for data blocks * fix: make sure all fields are editable * fix(Form): remove custom actions * fix(Details): display empty component on no data * feat(Form): support association fields * refactor: rename * feat(Form): support for deep-level association fields * Revert "fix(Table): keep only 'filter' and 'refresh'" This reverts commit 61a1d101a7d15223cfd3523adb33567fff545568. * Revert "fix(Table): no need Actions" This reverts commit 8314629e92fb3b5b7ec1c97904a42c76c43e4d4a. * Revert "fix(Table): use radio" This reverts commit c6f009740e1835f9762653a721ff64f52d0994cf. * feat(Table): highlight row on selected * feat: support to cacel highlight * fix: type error * feat: remove Table from filter list * fix(Table): highlight rows problem * refactor: remove usless code * refactor(Collapse): detach from Table * fix(Table): highlighting row problem * fix: translate problem * fix(Collapse): fix error of useProps * fix(Table): avoid undefined * Update Details.tsx * Update DetailsBlockProvider.tsx * refactor: rename target.name to target.uid * fix: add translate * style: add padding --------- Co-authored-by: anuoua <anuoua@gmail.com> Co-authored-by: chenos <chenlinxh@gmail.com>
2023-03-20 17:40:16 +08:00
export const isEmpty = (value: unknown) => {
if (isPlainObject(value)) {
return Object.keys(value).length === 0;
}
if (Array.isArray(value)) {
return value.length === 0;
}
return !value;
};
export const isPlainObject = (value) => {
if (Object.prototype.toString.call(value) !== '[object Object]') {
return false;
}
const prototype = Object.getPrototypeOf(value);
return prototype === null || prototype === Object.prototype;
};
feat(parse-variables): support to parse variables in filter params (#1558) * fix: add field linkage on setting default datetime * fix: fix dateonly timezone problem * fix: improve test * docs(DatePicker): add demos * fix(DatePicker): should return the beginning of a second * feat(DatePicker): support non-UTC * refactor: rename * fix(RangePicker): get correct end date * test(mapDatePicker): add test * test(mapRangePicker): add test * feat(Filter): use non-UTC to filter * feat(FilterBlock): use non-UTC to filter * feat: add '$dateBetween' operator in datetime * feat: use RangePicker on toggled to 'dateBetween' operator * feat: set ranges for RangePicker * feat: backend support to parse 'dateBetween' operator * fix: fix build error * fix: adaptive content width * feat: support to use var on data scope * feat: add parse-variables plugin * feat: support to parse variables * feat: support only to set system variables * test: rename * feat: cover all * fix: fix build error * feat(RangePicker): extend more shortcut keys * feat(parse-variables): support more date var * feat: support user variables * feat: disable unmatched options * fix: use component name to filter option * fix: fix build error * feat: remove some operator of id * chore: remove useless operators * fix: built in plugin * refactor: move to core from plugin * refactor: remove code of plugin * refactor: remove useless code * fix: should after acl * Update server.ts * fix: compatible with old version * feat: test cases * refactor: rename to 'is between' * refactor: parse filter * fix: improve code * feat: test cases * fix: fix error * fix: improve parse date * fix: date variables * fix: day range * fix: test error * fix: typo * fix: test error * feat: $user variable * fix: toDate * fix: fix the value range of shortcuts * feat: add quarter and test * feat: support to use user's association fields to filter * refactor: use maxDepth * refactor: remove useless code * fix: make AssociationSelect.Designer to support variables * fix: getField * fix: parse utc * fix: remove only * fix: filter by ctx.db.getFieldByPath * fix: avoid error * fix: add translation * fix(RangePicker): can be set to empty * feat(utils): add hasEmptyValue * fix: should not save empty * fix: last few days should include today * fix: limit user variable type to display * fix: parse filter error * fix: empty * test: [skip ci] * fix: remove ';' * feat: improve code --------- Co-authored-by: chenos <chenlinxh@gmail.com>
2023-03-30 23:49:57 +08:00
export const hasEmptyValue = (objOrArr: object | any[]) => {
let result = true;
for (const key in objOrArr) {
result = false;
if (isArray(objOrArr[key]) && objOrArr[key].length === 0) {
return true;
}
if (!objOrArr[key]) {
return true;
}
if (isPlainObject(objOrArr[key]) || isArray(objOrArr[key])) {
return hasEmptyValue(objOrArr[key]);
}
}
return result;
};
export const nextTick = (fn: () => void) => {
setTimeout(fn);
};