useMissingValues.js 632 B

12345678910111213141516171819
  1. import * as React from 'react';
  2. import { toPathOptions } from "../utils/treeUtil";
  3. export default function useMissingValues(options, fieldNames) {
  4. return React.useCallback(function (rawValues) {
  5. var missingValues = [];
  6. var existsValues = [];
  7. rawValues.forEach(function (valueCell) {
  8. var pathOptions = toPathOptions(valueCell, options, fieldNames);
  9. if (pathOptions.every(function (opt) {
  10. return opt.option;
  11. })) {
  12. existsValues.push(valueCell);
  13. } else {
  14. missingValues.push(valueCell);
  15. }
  16. });
  17. return [existsValues, missingValues];
  18. }, [options, fieldNames]);
  19. }