saleor-dashboard/testUtils/filters.ts

21 lines
535 B
TypeScript
Raw Normal View History

import { IFilter } from "@dashboard/components/Filter";
import clone from "lodash/clone";
2020-01-13 14:26:10 +00:00
export function getExistingKeys(o: {}): string[] {
2020-01-13 14:26:10 +00:00
return Object.keys(o).filter(key => o[key] !== undefined && o[key] !== null);
}
export function setFilterOptsStatus<T extends string>(
opts: IFilter<T>,
status: boolean,
2020-01-13 14:26:10 +00:00
): IFilter<T> {
const newOpts = clone(opts);
for (const optName in opts) {
if (Object.prototype.hasOwnProperty.call(newOpts, optName)) {
newOpts[optName].active = status;
}
}
return newOpts;
}