placementt-core 11.0.892 → 11.0.951
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/lib/constants.d.ts +1 -0
- package/lib/constants.js +47 -1
- package/lib/constants.js.map +1 -1
- package/lib/hooks.d.ts +57 -15
- package/lib/hooks.js +217 -43
- package/lib/hooks.js.map +1 -1
- package/lib/typeDefinitions.d.ts +91 -4
- package/lib/util.d.ts +25 -1
- package/lib/util.js +329 -2
- package/lib/util.js.map +1 -1
- package/package.json +1 -1
- package/src/constants.ts +49 -0
- package/src/hooks.tsx +247 -47
- package/src/typeDefinitions.ts +96 -20
- package/src/util.ts +350 -4
package/lib/hooks.js
CHANGED
|
@@ -11,6 +11,7 @@ exports.useAlumniPaginator = useAlumniPaginator;
|
|
|
11
11
|
exports.useVeryOldInstitutePlacementList = useVeryOldInstitutePlacementList;
|
|
12
12
|
exports.useFilterTablePaginator = useFilterTablePaginator;
|
|
13
13
|
exports.useProviderContactPaginator = useProviderContactPaginator;
|
|
14
|
+
exports.useNewCohortUserPaginator = useNewCohortUserPaginator;
|
|
14
15
|
exports.useCohortUserPaginator = useCohortUserPaginator;
|
|
15
16
|
exports.useAdmissionsPaginator = useAdmissionsPaginator;
|
|
16
17
|
exports.useLazyLoadQueryList = useLazyLoadQueryList;
|
|
@@ -38,6 +39,7 @@ const util_1 = require("./firebase/util");
|
|
|
38
39
|
const writeDatabase_1 = require("./firebase/writeDatabase");
|
|
39
40
|
const algoliasearch_1 = __importDefault(require("algoliasearch"));
|
|
40
41
|
const storage_1 = require("firebase/storage");
|
|
42
|
+
const util_2 = require("./util");
|
|
41
43
|
const DEFAULTQUERYLIMIT = 5;
|
|
42
44
|
function useStudentPlacementList({ user, student, queryConstraint, ql = DEFAULTQUERYLIMIT }) {
|
|
43
45
|
const [loadMoreIcon, setLoadMoreIcon] = (0, react_1.useState)(true);
|
|
@@ -241,7 +243,7 @@ function useOldInstitutePlacementList({ id, user, cohort, queryConstraint, ql =
|
|
|
241
243
|
};
|
|
242
244
|
return ({ ...{ placements, loadMoreIcon, loadMorePlacements, setQuery, setInitialQueryLimit, reset, changeQueryConstraints } });
|
|
243
245
|
}
|
|
244
|
-
function useNewInstitutePlacementList({ id, user, filters, view, cohort, queryConstraints, ql = DEFAULTQUERYLIMIT, inProgress }) {
|
|
246
|
+
function useNewInstitutePlacementList({ id, user, uid, filters, initialSort, initialSearch, view, cohort, queryConstraints, ql = DEFAULTQUERYLIMIT, inProgress }) {
|
|
245
247
|
const [query, setQuery] = (0, react_1.useState)();
|
|
246
248
|
const sorts = {
|
|
247
249
|
["Student Forename - Asc"]: {
|
|
@@ -265,7 +267,7 @@ function useNewInstitutePlacementList({ id, user, filters, view, cohort, queryCo
|
|
|
265
267
|
direction: "asc",
|
|
266
268
|
},
|
|
267
269
|
["Student Email - Desc"]: {
|
|
268
|
-
value: "
|
|
270
|
+
value: "studentEmail",
|
|
269
271
|
direction: "desc",
|
|
270
272
|
},
|
|
271
273
|
["Provider email - Asc"]: {
|
|
@@ -282,25 +284,31 @@ function useNewInstitutePlacementList({ id, user, filters, view, cohort, queryCo
|
|
|
282
284
|
if (!(user.studentFilter && user.studentFilterValues))
|
|
283
285
|
return false;
|
|
284
286
|
const student = await (0, readDatabase_1.getUserById)(placement.uid).catch(() => false);
|
|
285
|
-
if (!student)
|
|
287
|
+
if (!student) {
|
|
288
|
+
console.log("No student");
|
|
286
289
|
return;
|
|
290
|
+
}
|
|
291
|
+
;
|
|
287
292
|
if (!user.studentFilterValues.includes(student.details[user.studentFilter])) {
|
|
293
|
+
console.log("filter not included. Filteres: ", user.studentFilterValues, "value", user.studentFilter, "-", student.details[user.studentFilter]);
|
|
288
294
|
return false;
|
|
289
295
|
}
|
|
290
296
|
}
|
|
291
297
|
return { ...placement, id: k };
|
|
292
298
|
};
|
|
293
|
-
const { tableData, pageUp, pageDown, setFilters, page, setView, loading, updateSearch, updateSort, sort } = useDataViewerPaginator({ view, filters, sorts, queryLimit: ql, data: query, additionalEntryProcessing: additionalProcessing, onSearch: async (s, sort, page, filters, limit) => await algoliaPlacementSearch(user, s, sort, page, filters, limit, cohort, inProgress) });
|
|
299
|
+
const { tableData, pageUp, pageDown, setFilters, page, setView, loading, updateSearch, updateSort, sort } = useDataViewerPaginator({ view, filters, sorts, queryLimit: ql, initialSort, initialSearch, data: query, additionalEntryProcessing: additionalProcessing, onSearch: async (s, sort, page, filters, limit) => await algoliaPlacementSearch(query || [], user, s, sort, page, filters, limit, cohort, inProgress) });
|
|
294
300
|
(0, react_1.useEffect)(() => {
|
|
295
301
|
var _a;
|
|
302
|
+
console.log("SET QUERY", user, queryConstraints, cohort);
|
|
296
303
|
// Sets the query of for the DataViewerPaginator
|
|
297
304
|
if (user.product !== "institutes" || user.userType !== "Staff") {
|
|
298
305
|
setQuery(undefined);
|
|
299
306
|
return;
|
|
300
307
|
}
|
|
301
|
-
if (((user.userGroup === "admin" || (cohort && user.viewCohorts === "some" && ((_a = user === null || user === void 0 ? void 0 : user.visibleCohorts) === null || _a === void 0 ? void 0 : _a.includes(cohort))) || (user.viewCohorts === "all" && user.viewStudents
|
|
308
|
+
if (((user.userGroup === "admin" || (cohort && user.viewCohorts === "some" && ((_a = user === null || user === void 0 ? void 0 : user.visibleCohorts) === null || _a === void 0 ? void 0 : _a.includes(cohort))) || (user.viewCohorts === "all" && user.viewStudents !== "none")))) {
|
|
302
309
|
const constraints = [["oId", "==", user.oId], ["draft", "==", false]];
|
|
303
310
|
cohort && constraints.push(["cohort", "==", cohort]);
|
|
311
|
+
uid && constraints.push(["uid", "==", uid]);
|
|
304
312
|
queryConstraints && constraints.unshift(...queryConstraints);
|
|
305
313
|
inProgress !== undefined && constraints.push(["inProgress", "==", inProgress]);
|
|
306
314
|
setQuery([{
|
|
@@ -382,7 +390,7 @@ function useAlumniPaginator({ user, alumniConvoUser, filters, view, school, quer
|
|
|
382
390
|
}, [tableData]);
|
|
383
391
|
return { tableData, page, loading, setFilters, setView, pageUp, pageDown, sorts };
|
|
384
392
|
}
|
|
385
|
-
const algoliaPlacementSearch = async (user, query, sort, page, filters, limit, cohort, inProgress) => {
|
|
393
|
+
const algoliaPlacementSearch = async (data, user, query, sort, page, filters, limit, cohort, inProgress) => {
|
|
386
394
|
const algoliaClient = (0, algoliasearch_1.default)(process.env.NODE_ENV === "development" ? "A0ZB50I7VS" : "XMPXCMUUOJ", user.algoliaKey);
|
|
387
395
|
const placementsIndex = algoliaClient.initIndex(sort ? Object.values(sort[1]).join("_") : "placements");
|
|
388
396
|
// const usersIndex = algoliaClient.initIndex("users");
|
|
@@ -793,7 +801,7 @@ function useProviderContactPaginator({ data, user, view, filters }) {
|
|
|
793
801
|
}
|
|
794
802
|
return v;
|
|
795
803
|
};
|
|
796
|
-
const { tableData, pageUp, pageDown, setFilters, page, setView, loading } = useDataViewerPaginator({ view, filters, queryLimit:
|
|
804
|
+
const { tableData, pageUp, pageDown, setFilters, page, setView, loading } = useDataViewerPaginator({ view, filters, queryLimit: 10, data: query, additionalEntryProcessing: getAdditionalData });
|
|
797
805
|
(0, react_1.useEffect)(() => {
|
|
798
806
|
const constraints = [
|
|
799
807
|
[`savedBy.${user.oId}.exists`, "==", true],
|
|
@@ -808,6 +816,159 @@ function useProviderContactPaginator({ data, user, view, filters }) {
|
|
|
808
816
|
}, [user]);
|
|
809
817
|
return ({ ...{ tableData, pageUp, pageDown, setFilters, page, setView, loading } });
|
|
810
818
|
}
|
|
819
|
+
const algoliaUsersSearch = async (data, user, query, sort, page, filters, limit, cohort) => {
|
|
820
|
+
const algoliaClient = (0, algoliasearch_1.default)(process.env.NODE_ENV === "development" ? "A0ZB50I7VS" : "XMPXCMUUOJ", user.algoliaKey);
|
|
821
|
+
console.log("SORT", sort);
|
|
822
|
+
const userIndex = algoliaClient.initIndex(sort ? `users_${Object.values(sort[1]).join("_")}` : "users");
|
|
823
|
+
const constraints = data[0].where;
|
|
824
|
+
if (!(constraints === null || constraints === void 0 ? void 0 : constraints.length))
|
|
825
|
+
return {};
|
|
826
|
+
let userSearchString = constraints.map(([k, e, v]) => {
|
|
827
|
+
if (e === "==")
|
|
828
|
+
return `${k}:${v}`; // Equality check
|
|
829
|
+
if (e === "!=")
|
|
830
|
+
return `${k}:-${v}`; // Not equal check
|
|
831
|
+
if (e === "<")
|
|
832
|
+
return `${k}:<${v}`; // Less than check
|
|
833
|
+
if (e === "<=")
|
|
834
|
+
return `${k}:<=${v}`; // Less than or equal check
|
|
835
|
+
if (e === ">")
|
|
836
|
+
return `${k}:>${v}`; // Greater than check
|
|
837
|
+
if (e === ">=")
|
|
838
|
+
return `${k}:>=${v}`; // Greater than or equal check
|
|
839
|
+
if (e === "array-contains")
|
|
840
|
+
return `${k}:${v}`; // Array contains check (string format)
|
|
841
|
+
if (e === "array-contains-any")
|
|
842
|
+
return `${k}:"${v.join('","')}"`; // Array contains any of the values (string format)
|
|
843
|
+
if (e === "in")
|
|
844
|
+
return `(${v.map((value) => `${k}:${value}`).join(' OR ')})`; // In check
|
|
845
|
+
if (e === "not-in")
|
|
846
|
+
return v.map((value) => `${k}:-${value}`).join(' AND '); // In check
|
|
847
|
+
return;
|
|
848
|
+
}).join(" AND ");
|
|
849
|
+
filters && Object.entries(filters).filter(([, filter]) => filter.value).map(([id, filter]) => {
|
|
850
|
+
userSearchString = userSearchString + ` AND ${id}:${filter.value}`;
|
|
851
|
+
});
|
|
852
|
+
console.log("QUERY", userSearchString);
|
|
853
|
+
const options = {
|
|
854
|
+
filters: userSearchString,
|
|
855
|
+
hitsPerPage: limit,
|
|
856
|
+
page: page ? page - 1 : undefined,
|
|
857
|
+
};
|
|
858
|
+
const searchUsersHits = await userIndex.search(query || "", options);
|
|
859
|
+
console.log(searchUsersHits.hits);
|
|
860
|
+
const i = (searchUsersHits ? (await Promise.all(searchUsersHits.hits.map(async (hit) => {
|
|
861
|
+
return [hit.objectID, hit];
|
|
862
|
+
}))) : []).filter((e) => e !== undefined);
|
|
863
|
+
return Object.fromEntries(i);
|
|
864
|
+
};
|
|
865
|
+
function useNewCohortUserPaginator({ user, institute, initialSort, filters, view, cohort, queryConstraints, ql = DEFAULTQUERYLIMIT, userType }) {
|
|
866
|
+
const [query, setQuery] = (0, react_1.useState)();
|
|
867
|
+
const firebaseQuery = new firebaseQuery_1.default();
|
|
868
|
+
const sorts = {
|
|
869
|
+
["Student Forename - Asc"]: {
|
|
870
|
+
value: "details.forename",
|
|
871
|
+
direction: "asc",
|
|
872
|
+
},
|
|
873
|
+
["Student Forename - Desc"]: {
|
|
874
|
+
value: "details.forename",
|
|
875
|
+
direction: "desc",
|
|
876
|
+
},
|
|
877
|
+
["Student Surname - Asc"]: {
|
|
878
|
+
value: "details.surname",
|
|
879
|
+
direction: "asc",
|
|
880
|
+
},
|
|
881
|
+
["Student Surname - Desc"]: {
|
|
882
|
+
value: "details.surname",
|
|
883
|
+
direction: "desc",
|
|
884
|
+
},
|
|
885
|
+
["Student Email - Asc"]: {
|
|
886
|
+
value: "email",
|
|
887
|
+
direction: "asc",
|
|
888
|
+
},
|
|
889
|
+
["Student Email - Desc"]: {
|
|
890
|
+
value: "email",
|
|
891
|
+
direction: "desc",
|
|
892
|
+
}
|
|
893
|
+
};
|
|
894
|
+
(0, react_1.useEffect)(() => {
|
|
895
|
+
const getAccess = async () => {
|
|
896
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
897
|
+
// Sets the query of for the DataViewerPaginator
|
|
898
|
+
if (user.product !== "institutes" || user.userType !== "Staff") {
|
|
899
|
+
setQuery(undefined);
|
|
900
|
+
return;
|
|
901
|
+
}
|
|
902
|
+
const constraints = [["oId", "==", user.oId], ["userType", "==", userType]];
|
|
903
|
+
cohort && constraints.push(["cohort", "==", cohort]);
|
|
904
|
+
queryConstraints && constraints.unshift(...queryConstraints);
|
|
905
|
+
const mSetQuery = (clear) => {
|
|
906
|
+
setQuery(clear ? undefined : [{
|
|
907
|
+
path: ["users"],
|
|
908
|
+
where: constraints
|
|
909
|
+
}]);
|
|
910
|
+
return;
|
|
911
|
+
};
|
|
912
|
+
if (institute.package === "institutes-one") {
|
|
913
|
+
if (user.userGroup === "admin" || (user.viewCohorts === "all" && user.viewStudents === "all"))
|
|
914
|
+
return mSetQuery();
|
|
915
|
+
if (!user.viewCohorts || user.viewCohorts === "none" || !user.viewStudents || user.viewStudents === "none" || (user.viewCohorts === "some" && !((_a = user.visibleCohorts) === null || _a === void 0 ? void 0 : _a.length)) || (user.viewStudents === "some" && !((_b = user.studentFilterValues) === null || _b === void 0 ? void 0 : _b.length)))
|
|
916
|
+
return mSetQuery(true);
|
|
917
|
+
if (user.viewStudents === "some") {
|
|
918
|
+
constraints.push([`details.${user.studentFilter}`, "in", user.studentFilterValues]);
|
|
919
|
+
}
|
|
920
|
+
if (cohort) {
|
|
921
|
+
const canViewCohort = user.viewCohorts === "all" || (user.viewCohorts === "some" && ((_c = user.visibleCohorts) === null || _c === void 0 ? void 0 : _c.includes("cohort")));
|
|
922
|
+
return mSetQuery(canViewCohort);
|
|
923
|
+
}
|
|
924
|
+
else {
|
|
925
|
+
// No cohort.
|
|
926
|
+
if (user.viewCohorts === "all")
|
|
927
|
+
return mSetQuery();
|
|
928
|
+
if (user.viewCohorts === "some" && user.visibleCohorts) {
|
|
929
|
+
constraints.push(["cohort", "in", user.visibleCohorts]);
|
|
930
|
+
return mSetQuery();
|
|
931
|
+
}
|
|
932
|
+
return mSetQuery(true);
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
if (institute.package === "institutes-two") {
|
|
936
|
+
if (user.userGroup === "admin" || (user.viewSchools === "all" && user.viewCohorts === "all" && user.viewStudents === "all"))
|
|
937
|
+
return mSetQuery();
|
|
938
|
+
if (!user.viewCohorts || !user.viewSchools || user.viewSchools === "none" || user.viewCohorts === "none")
|
|
939
|
+
return mSetQuery(true);
|
|
940
|
+
if (!user.viewStudents || user.viewStudents === "none" || (user.viewStudents === "some" && !((_d = user.studentFilterValues) === null || _d === void 0 ? void 0 : _d.length)) || (user.viewCohorts === "some" && !((_e = user.visibleCohorts) === null || _e === void 0 ? void 0 : _e.length)) || (user.viewSchools === "some" && !((_f = user.visibleSchools) === null || _f === void 0 ? void 0 : _f.length)))
|
|
941
|
+
return mSetQuery(true);
|
|
942
|
+
if (user.viewStudents === "some") {
|
|
943
|
+
constraints.push([`details.${user.studentFilter}`, "in", user.studentFilterValues]);
|
|
944
|
+
}
|
|
945
|
+
if (cohort) {
|
|
946
|
+
if (user.viewCohorts === "some" && !((_g = user.visibleCohorts) === null || _g === void 0 ? void 0 : _g.includes(cohort)))
|
|
947
|
+
return mSetQuery(true);
|
|
948
|
+
if (user.viewSchools === "some") {
|
|
949
|
+
const cohortData = await firebaseQuery.getDocData(["cohorts", cohort]);
|
|
950
|
+
if (!cohortData.schoolId || !((_h = user.visibleSchools) === null || _h === void 0 ? void 0 : _h.includes(cohortData.schoolId)))
|
|
951
|
+
return mSetQuery(true);
|
|
952
|
+
}
|
|
953
|
+
}
|
|
954
|
+
else {
|
|
955
|
+
if (user.viewCohorts === "some" && user.visibleCohorts) {
|
|
956
|
+
constraints.push(["cohort", "in", user.visibleCohorts]);
|
|
957
|
+
}
|
|
958
|
+
else if (user.viewSchools === "some" && user.visibleSchools) {
|
|
959
|
+
const cohorts = await firebaseQuery.getDocsWhere("cohorts", [(0, firestore_1.where)("oId", "==", user.oId), (0, firestore_1.where)("schoolId", "in", user.visibleSchools)]);
|
|
960
|
+
constraints.push(["cohort", "in", Object.keys(cohorts || {})]);
|
|
961
|
+
}
|
|
962
|
+
}
|
|
963
|
+
return mSetQuery();
|
|
964
|
+
}
|
|
965
|
+
setQuery(undefined);
|
|
966
|
+
};
|
|
967
|
+
getAccess();
|
|
968
|
+
}, [user, queryConstraints, cohort]);
|
|
969
|
+
const { tableData, pageUp, pageDown, setFilters, page, setView, loading, updateSearch, updateSort, sort } = useDataViewerPaginator({ view, filters, initialSort, sorts, queryLimit: ql, data: query, onSearch: async (s, sort, page, filters, limit) => await algoliaUsersSearch(query || [], user, s, sort, page, filters, limit, cohort) });
|
|
970
|
+
return { tableData, page, loading, updateSearch, setFilters, setView, pageUp, pageDown, sorts, updateSort, sort };
|
|
971
|
+
}
|
|
811
972
|
function useCohortUserPaginator({ user, cohort, data, search, userType, sort }) {
|
|
812
973
|
const [tableData, setTableData] = (0, react_1.useState)({});
|
|
813
974
|
const [queryAnchor, setQueryAnchor] = (0, react_1.useState)({ startDoc: undefined, endDoc: undefined, startQueryPos: 0, endQueryPos: 0 });
|
|
@@ -1683,7 +1844,7 @@ const useRefDimensions = () => {
|
|
|
1683
1844
|
return { dimensions, refCallback };
|
|
1684
1845
|
};
|
|
1685
1846
|
exports.useRefDimensions = useRefDimensions;
|
|
1686
|
-
const cohortStages = ["info", "name", "placementType", "review", "created"];
|
|
1847
|
+
const cohortStages = ["info", "name", "placementType", "database", "review", "created"];
|
|
1687
1848
|
const defaultCohortData = {
|
|
1688
1849
|
name: "",
|
|
1689
1850
|
stage: "info",
|
|
@@ -2617,7 +2778,7 @@ function useGetIndividualPlacementForPlacementPage({ user, placementId, organisa
|
|
|
2617
2778
|
}
|
|
2618
2779
|
if (e === "noInsurance") {
|
|
2619
2780
|
if (!eliData) {
|
|
2620
|
-
const storageRef = (0, storage_1.ref)(firebaseConfig_1.storage, `insurance/${placement.
|
|
2781
|
+
const storageRef = (0, storage_1.ref)(firebaseConfig_1.storage, `insurance/${placement.providerContactId}.pdf`);
|
|
2621
2782
|
const file = await (0, storage_1.getDownloadURL)(storageRef).catch(() => placement.insuranceSkippedReason);
|
|
2622
2783
|
setELIData(file);
|
|
2623
2784
|
}
|
|
@@ -3152,7 +3313,7 @@ function useLoadApplications({ user, applicationType, listingId, queryConstraint
|
|
|
3152
3313
|
};
|
|
3153
3314
|
return { applications, type, setType, onScrollBottom, loading, changeQueryConstraints };
|
|
3154
3315
|
}
|
|
3155
|
-
function useDataViewerPaginator({ view: initialView, sorts, queryLimit = 10, additionalEntryProcessing, formatItems, snapshot, filters: initialFilters, onSearch, data }) {
|
|
3316
|
+
function useDataViewerPaginator({ view: initialView, sorts, queryLimit = 10, additionalEntryProcessing, formatItems, snapshot, filters: initialFilters, initialSort, initialSearch, onSearch, data }) {
|
|
3156
3317
|
const [tableData, setTableData] = (0, react_1.useState)(Array.isArray(data) ? Object.fromEntries(Object.entries(data).slice(0, queryLimit)) : {});
|
|
3157
3318
|
const [page, setPage] = (0, react_1.useState)([1, 0]);
|
|
3158
3319
|
const [view, setView] = (0, react_1.useState)(initialView);
|
|
@@ -3162,12 +3323,14 @@ function useDataViewerPaginator({ view: initialView, sorts, queryLimit = 10, add
|
|
|
3162
3323
|
const [dataListenerUnsubscribe, setDataListenerUnsubscribe] = (0, react_1.useState)();
|
|
3163
3324
|
const [loading, setLoading] = (0, react_1.useState)(true);
|
|
3164
3325
|
const [searchString, setSearchString] = (0, react_1.useState)();
|
|
3165
|
-
const [sort, setSort] = (0, react_1.useState)();
|
|
3326
|
+
const [sort, setSort] = (0, react_1.useState)((initialSort && sorts && sorts[initialSort]) ? [initialSort, sorts[initialSort]] : undefined);
|
|
3327
|
+
const [fData, setFData] = (0, react_1.useState)(data);
|
|
3328
|
+
console.log("SORT", sort, initialSort, sorts, sorts === null || sorts === void 0 ? void 0 : sorts[initialSort || ""]);
|
|
3166
3329
|
const processedData = async (k, v) => additionalEntryProcessing ? await additionalEntryProcessing(k, v) : v;
|
|
3167
3330
|
const setTableDataFromDefinedData = async () => {
|
|
3168
|
-
if (!
|
|
3331
|
+
if (!fData || Array.isArray(fData))
|
|
3169
3332
|
return;
|
|
3170
|
-
const dataWithAdditionalProcessingPossibleNulls = (await Promise.all(Object.entries(
|
|
3333
|
+
const dataWithAdditionalProcessingPossibleNulls = (await Promise.all(Object.entries(fData).map(async ([k, v]) => [k, await processedData(k, v)])));
|
|
3171
3334
|
const dataWithAdditionalProcessing = dataWithAdditionalProcessingPossibleNulls.filter(([k, v]) => v);
|
|
3172
3335
|
const searchedData = searchString ? dataWithAdditionalProcessing.filter(([, v]) => {
|
|
3173
3336
|
const values = Object.values(v).join(", ");
|
|
@@ -3191,7 +3354,7 @@ function useDataViewerPaginator({ view: initialView, sorts, queryLimit = 10, add
|
|
|
3191
3354
|
throw new Error("Tables must have a limit defined.");
|
|
3192
3355
|
const newData = filteredData.slice((page[0] - 1) * queryLimit, page[0] * queryLimit);
|
|
3193
3356
|
setTableData(Object.fromEntries(newData));
|
|
3194
|
-
if (Object.keys(Object.fromEntries(newData)).pop() === Object.keys(
|
|
3357
|
+
if (Object.keys(Object.fromEntries(newData)).pop() === Object.keys(fData).pop()) {
|
|
3195
3358
|
setLoading("loaded");
|
|
3196
3359
|
}
|
|
3197
3360
|
else {
|
|
@@ -3207,7 +3370,7 @@ function useDataViewerPaginator({ view: initialView, sorts, queryLimit = 10, add
|
|
|
3207
3370
|
const getDataFromQuery = async (itemList = {}, currentQueryAnchor = queryAnchor, cursorDirection, prevEntries = prevEntryIds, loadMoreFromQuery = false) => {
|
|
3208
3371
|
// if (!filters) return;
|
|
3209
3372
|
setLoading(true);
|
|
3210
|
-
if (!Array.isArray(
|
|
3373
|
+
if (!Array.isArray(fData)) {
|
|
3211
3374
|
setTableDataFromDefinedData();
|
|
3212
3375
|
return;
|
|
3213
3376
|
}
|
|
@@ -3216,8 +3379,8 @@ function useDataViewerPaginator({ view: initialView, sorts, queryLimit = 10, add
|
|
|
3216
3379
|
if (onSearch && (searchString || sort)) {
|
|
3217
3380
|
if (typeof onSearch === "boolean")
|
|
3218
3381
|
throw new Error("When using Firestore queries, an onSearch function should be passed to retrieve data externally. Additional processing is however completed in this hook.");
|
|
3219
|
-
const
|
|
3220
|
-
const dataWithAdditionalProcessing = await Promise.all(Object.entries(
|
|
3382
|
+
const searchData = await onSearch(searchString, sort, page[0], filters, queryLimit);
|
|
3383
|
+
const dataWithAdditionalProcessing = await Promise.all(Object.entries(searchData).map(async ([k, v]) => [k, await processedData(k, v)]));
|
|
3221
3384
|
setTableData((old) => {
|
|
3222
3385
|
if (view === "table") {
|
|
3223
3386
|
return { ...Object.fromEntries(dataWithAdditionalProcessing) };
|
|
@@ -3239,7 +3402,7 @@ function useDataViewerPaginator({ view: initialView, sorts, queryLimit = 10, add
|
|
|
3239
3402
|
else {
|
|
3240
3403
|
cursorPos = currentQueryAnchor.startQueryPos;
|
|
3241
3404
|
}
|
|
3242
|
-
const querySchema =
|
|
3405
|
+
const querySchema = fData[cursorPos];
|
|
3243
3406
|
const createQuery = (queryData) => {
|
|
3244
3407
|
const constraints = [];
|
|
3245
3408
|
queryData.where && queryData.where.forEach((w) => {
|
|
@@ -3298,7 +3461,7 @@ function useDataViewerPaginator({ view: initialView, sorts, queryLimit = 10, add
|
|
|
3298
3461
|
}
|
|
3299
3462
|
// Function to handle query snapshot
|
|
3300
3463
|
async function handleQuerySnapshot(querySnapshot) {
|
|
3301
|
-
if (!Array.isArray(
|
|
3464
|
+
if (!Array.isArray(fData))
|
|
3302
3465
|
throw new Error("Called querySnapshot but data is defined.");
|
|
3303
3466
|
if (!queryLimit)
|
|
3304
3467
|
throw new Error("Firestore queries must have a limit defined.");
|
|
@@ -3342,7 +3505,7 @@ function useDataViewerPaginator({ view: initialView, sorts, queryLimit = 10, add
|
|
|
3342
3505
|
setPrevEntryIds(prevEntries);
|
|
3343
3506
|
if (querySnapshot.size < queryLimit && Object.keys(itemList).length < queryLimit) {
|
|
3344
3507
|
// If we have ran out of entries, increase or decrease the index.
|
|
3345
|
-
if (page[0] > page[1] && cursorPos + 1 <
|
|
3508
|
+
if (page[0] > page[1] && cursorPos + 1 < fData.length) {
|
|
3346
3509
|
return getDataFromQuery(itemList, { ...currentQueryAnchor, endQueryPos: currentQueryAnchor.endQueryPos + 1 }, "increase", prevEntries);
|
|
3347
3510
|
}
|
|
3348
3511
|
else if (page[0] < page[1] && cursorPos > 0) {
|
|
@@ -3355,7 +3518,7 @@ function useDataViewerPaginator({ view: initialView, sorts, queryLimit = 10, add
|
|
|
3355
3518
|
}
|
|
3356
3519
|
if (querySnapshot.size === 0 &&
|
|
3357
3520
|
Object.keys(itemList).length === 0 &&
|
|
3358
|
-
currentQueryAnchor.endQueryPos + 1 ===
|
|
3521
|
+
currentQueryAnchor.endQueryPos + 1 === fData.length &&
|
|
3359
3522
|
page[0] > 1) {
|
|
3360
3523
|
if (view === "table") {
|
|
3361
3524
|
setTableData({});
|
|
@@ -3389,28 +3552,33 @@ function useDataViewerPaginator({ view: initialView, sorts, queryLimit = 10, add
|
|
|
3389
3552
|
setDataListenerUnsubscribe(undefined);
|
|
3390
3553
|
};
|
|
3391
3554
|
(0, react_1.useEffect)(() => {
|
|
3392
|
-
|
|
3393
|
-
if (!filters)
|
|
3555
|
+
if ((0, util_2.objectsEqualNew)(fData, data))
|
|
3394
3556
|
return;
|
|
3395
|
-
console.log("
|
|
3396
|
-
|
|
3397
|
-
}, [filters]);
|
|
3398
|
-
(0, react_1.useEffect)(() => {
|
|
3399
|
-
console.log("View reset.");
|
|
3400
|
-
reset();
|
|
3401
|
-
}, [view]);
|
|
3402
|
-
(0, react_1.useEffect)(() => {
|
|
3403
|
-
console.log("search reset.");
|
|
3404
|
-
reset();
|
|
3405
|
-
}, [searchString]);
|
|
3406
|
-
(0, react_1.useEffect)(() => {
|
|
3407
|
-
console.log("data reset.");
|
|
3557
|
+
console.log("data reset.", fData, data);
|
|
3558
|
+
setFData(data);
|
|
3408
3559
|
reset();
|
|
3409
3560
|
}, [data]);
|
|
3410
|
-
|
|
3411
|
-
|
|
3561
|
+
const updateFilters = (fFilters) => {
|
|
3562
|
+
if (!(0, util_2.objectsEqualNew)(fFilters, filters)) {
|
|
3563
|
+
console.log("FILTER RESET", fFilters, filters);
|
|
3564
|
+
setFilters(fFilters);
|
|
3565
|
+
reset();
|
|
3566
|
+
}
|
|
3567
|
+
};
|
|
3568
|
+
const updateSearch = (search) => {
|
|
3569
|
+
if (searchString === search)
|
|
3570
|
+
return;
|
|
3571
|
+
console.log("SEARCH RESET", searchString, search);
|
|
3572
|
+
setSearchString(search);
|
|
3573
|
+
reset();
|
|
3574
|
+
};
|
|
3575
|
+
const updateView = (v) => {
|
|
3576
|
+
if (v === view)
|
|
3577
|
+
return;
|
|
3578
|
+
console.log("View reset", view, v);
|
|
3579
|
+
setView(v);
|
|
3412
3580
|
reset();
|
|
3413
|
-
}
|
|
3581
|
+
};
|
|
3414
3582
|
// Fetch new data when queries or page change
|
|
3415
3583
|
(0, react_1.useEffect)(() => {
|
|
3416
3584
|
getDataFromQuery();
|
|
@@ -3423,11 +3591,17 @@ function useDataViewerPaginator({ view: initialView, sorts, queryLimit = 10, add
|
|
|
3423
3591
|
setPage((p) => ([p[0] - 1, p[0]]));
|
|
3424
3592
|
};
|
|
3425
3593
|
const updateSort = (sortLabel) => {
|
|
3426
|
-
if (!
|
|
3427
|
-
|
|
3428
|
-
|
|
3594
|
+
if (!sortLabel) {
|
|
3595
|
+
setSort(undefined);
|
|
3596
|
+
}
|
|
3597
|
+
else {
|
|
3598
|
+
if (!sorts || !sorts[sortLabel])
|
|
3599
|
+
return;
|
|
3600
|
+
setSort([sortLabel, sorts[sortLabel]]);
|
|
3601
|
+
}
|
|
3602
|
+
reset();
|
|
3429
3603
|
};
|
|
3430
|
-
return ({ ...{ tableData, pageUp, pageDown, setFilters, page: page[0], sorts, loading, sort, updateSort: updateSort, setView, updateSearch
|
|
3604
|
+
return ({ ...{ tableData, pageUp, pageDown, search: searchString, setFilters: updateFilters, page: page[0], sorts, loading, sort, updateSort: updateSort, setView: updateView, updateSearch } });
|
|
3431
3605
|
}
|
|
3432
3606
|
;
|
|
3433
3607
|
//# sourceMappingURL=hooks.js.map
|