@griddo/ax 11.7.3 → 11.7.4-rc.0

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@griddo/ax",
3
3
  "description": "Griddo Author Experience",
4
- "version": "11.7.3",
4
+ "version": "11.7.4-rc.0",
5
5
  "authors": [
6
6
  "Álvaro Sánchez' <alvaro.sanches@secuoyas.com>",
7
7
  "Diego M. Béjar <diego.bejar@secuoyas.com>",
@@ -223,5 +223,5 @@
223
223
  "publishConfig": {
224
224
  "access": "public"
225
225
  },
226
- "gitHead": "35cccad9fe3f0eaf9e2331184ac382d5312c60fb"
226
+ "gitHead": "8434d0fcbd72920360133228104819ad375a9892"
227
227
  }
package/src/api/sites.tsx CHANGED
@@ -114,6 +114,11 @@ const SERVICES: { [key: string]: IServiceConfig } = {
114
114
  endpoint: "/select/sites",
115
115
  method: "GET",
116
116
  },
117
+ SET_SITE_ACTIVITY: {
118
+ ...template,
119
+ endpoint: "/site-activity/",
120
+ method: "POST",
121
+ },
117
122
  };
118
123
 
119
124
  const getAllSites = async (params: IGetSitesParams = { recentSitesNumber: 7 }) => {
@@ -371,6 +376,14 @@ const unpublishSiteBulk = (ids: number[]) => sendRequest(SERVICES.UNPUBLISH_SITE
371
376
 
372
377
  const getSelectSites = () => sendRequest(SERVICES.GET_SELECT_SITES);
373
378
 
379
+ const setSiteActivity = async (siteID: number) => {
380
+ const { host, endpoint } = SERVICES.SET_SITE_ACTIVITY;
381
+
382
+ SERVICES.SET_SITE_ACTIVITY.dynamicUrl = `${host}${endpoint}${siteID}`;
383
+
384
+ return sendRequest(SERVICES.SET_SITE_ACTIVITY);
385
+ };
386
+
374
387
  export default {
375
388
  getAllSites,
376
389
  getSiteInfo,
@@ -393,4 +406,5 @@ export default {
393
406
  removePageBulk,
394
407
  removeUsersBulk,
395
408
  getSelectSites,
409
+ setSiteActivity,
396
410
  };
package/src/api/utils.tsx CHANGED
@@ -31,16 +31,24 @@ const getLang = (): Record<string, unknown> => {
31
31
  return { lang };
32
32
  };
33
33
 
34
+ const getSite = (): Record<string, unknown> => {
35
+ const site = JSON.parse(localStorage.getItem("siteID") || "{}");
36
+
37
+ return { site };
38
+ };
39
+
34
40
  const getHeaders = (headers: Record<string, unknown>, hasToken: boolean) => {
35
41
  return hasToken
36
42
  ? {
37
43
  ...headers,
38
44
  ...getToken(),
39
45
  ...getLang(),
46
+ ...getSite(),
40
47
  }
41
48
  : {
42
49
  ...headers,
43
50
  ...getLang(),
51
+ ...getSite(),
44
52
  };
45
53
  };
46
54
 
@@ -50,6 +50,7 @@ import {
50
50
  ISiteListConfig,
51
51
  IQueryValue,
52
52
  IThemeElements,
53
+ IRootState,
53
54
  } from "@ax/types";
54
55
  import { sites, languages, dataPack, social, structuredData, analytics, pages } from "@ax/api";
55
56
  import { appActions } from "@ax/containers/App";
@@ -87,6 +88,7 @@ function setSitesByLang(sitesList: ISite[]): ISetSitesByLangAction {
87
88
  }
88
89
 
89
90
  function setCurrentSiteInfo(currentSiteInfo: ISite | null): ISetCurrentSiteInfoAction {
91
+ localStorage.setItem("siteID", JSON.stringify(currentSiteInfo?.id || "global"));
90
92
  return { type: SET_CURRENT_SITE_INFO, payload: { currentSiteInfo } };
91
93
  }
92
94
 
@@ -161,7 +163,7 @@ function getSites(params: IGetSitesParams = { recentSitesNumber: 7 }): (dispatch
161
163
  };
162
164
  }
163
165
 
164
- function getSite(siteID: number): (dispatch: Dispatch, getState: any) => Promise<void> {
166
+ function getSite(siteID: number): (dispatch: Dispatch, getState: () => IRootState) => Promise<void> {
165
167
  return async (dispatch, getState) => {
166
168
  try {
167
169
  const responseActions = {
@@ -201,7 +203,7 @@ function getSitesByLang(params: IGetSitesParams): (dispatch: Dispatch) => Promis
201
203
  };
202
204
  }
203
205
 
204
- function saveSettings(form: ISettingsForm): (dispatch: Dispatch, getState: any) => Promise<boolean> {
206
+ function saveSettings(form: ISettingsForm): (dispatch: Dispatch, getState: () => IRootState) => Promise<boolean> {
205
207
  return async (dispatch, getState) => {
206
208
  try {
207
209
  const {
@@ -233,7 +235,7 @@ function saveSettings(form: ISettingsForm): (dispatch: Dispatch, getState: any)
233
235
  };
234
236
  }
235
237
 
236
- function getGlobalPages(params: IGetGlobalPagesParams, filterQuery: string): (dispatch: any) => Promise<void> {
238
+ function getGlobalPages(params: IGetGlobalPagesParams, filterQuery: string): (dispatch: Dispatch) => Promise<void> {
237
239
  return async (dispatch) => {
238
240
  try {
239
241
  const responseActions = {
@@ -249,13 +251,13 @@ function getGlobalPages(params: IGetGlobalPagesParams, filterQuery: string): (di
249
251
 
250
252
  await handleRequest(callback, responseActions, [appActions.setIsLoading])(dispatch);
251
253
  } catch (e) {
252
- console.log("error");
253
- console.log(e); // FIXME: capturar errores
254
+ console.log(e);
254
255
  }
255
256
  };
256
257
  }
257
258
 
258
- function setSiteInfo(currentSiteInfo: ISite): (dispatch: any, getState: any) => Promise<void> {
259
+ // TODO: refactor
260
+ function setSiteInfo(currentSiteInfo: ISite): (dispatch: Dispatch, getState: () => IRootState) => Promise<void> {
259
261
  return async (dispatch, getState) => {
260
262
  try {
261
263
  const {
@@ -266,7 +268,7 @@ function setSiteInfo(currentSiteInfo: ISite): (dispatch: any, getState: any) =>
266
268
  dispatch(appActions.setIsLoading(true));
267
269
 
268
270
  resetSiteValues(currentSiteInfo.id)(dispatch);
269
- dispatch(structuredDataActions.resetStructuredData());
271
+ structuredDataActions.resetStructuredData()(dispatch);
270
272
  dispatch(setCurrentSiteInfo(currentSiteInfo));
271
273
  await getRoles({ siteId: currentSiteInfo.id }, undefined, false)(dispatch);
272
274
 
@@ -287,7 +289,7 @@ function setSiteInfo(currentSiteInfo: ISite): (dispatch: any, getState: any) =>
287
289
  dispatch(setLanguage(lang));
288
290
  dispatch(setCurrentSiteLanguages(siteLanguages));
289
291
  } else {
290
- console.log("Error en sites getSiteLanguages"); // FIXME: capturar errores mejor
292
+ console.log("Error en sites getSiteLanguages");
291
293
  }
292
294
 
293
295
  // get site activated dataPacks
@@ -297,10 +299,10 @@ function setSiteInfo(currentSiteInfo: ISite): (dispatch: any, getState: any) =>
297
299
  const data = dataPackResponse.data.items;
298
300
  const orderedData = data.sort(sortBy("title", false));
299
301
  dispatch(dataPacksActions.setActivated(orderedData));
300
- dispatch(dataPacksActions.getSiteModules());
301
- dispatch(dataPacksActions.getSiteTemplates());
302
+ dataPacksActions.getSiteModules()(dispatch, getState);
303
+ dataPacksActions.getSiteTemplates()(dispatch, getState);
302
304
  } else {
303
- console.log("Error en sites getSiteDataPacks"); // FIXME: capturar errores mejor
305
+ console.log("Error en sites getSiteDataPacks");
304
306
  }
305
307
 
306
308
  // get site socials
@@ -308,7 +310,7 @@ function setSiteInfo(currentSiteInfo: ISite): (dispatch: any, getState: any) =>
308
310
  if (isReqOk(socialResponse.status)) {
309
311
  dispatch(socialActions.setSocial(socialResponse.data));
310
312
  } else {
311
- console.log("Error en sites getSocial"); // FIXME: capturar errores mejor
313
+ console.log("Error en sites getSocial");
312
314
  }
313
315
 
314
316
  // get structuredData
@@ -325,7 +327,7 @@ function setSiteInfo(currentSiteInfo: ISite): (dispatch: any, getState: any) =>
325
327
  structuredDataActions.setStructuredData({ ...currentStructuredData, site: structuredDataValues.site })
326
328
  );
327
329
  } else {
328
- console.log("Error en sites getStructuredData"); // TODO: capturar errores mejor
330
+ console.log("Error en sites getStructuredData");
329
331
  }
330
332
 
331
333
  // get analytics
@@ -333,17 +335,19 @@ function setSiteInfo(currentSiteInfo: ISite): (dispatch: any, getState: any) =>
333
335
  if (isReqOk(socialResponse.status)) {
334
336
  dispatch(analyticsActions.setAnalytics(analyticsResponse.data));
335
337
  } else {
336
- console.log("Error en sites getAnalytics"); // FIXME: capturar errores mejor
338
+ console.log("Error en sites getAnalytics");
337
339
  }
338
340
 
339
341
  getUserCurrentPermissions()(dispatch, getState);
342
+
343
+ await sites.setSiteActivity(currentSiteInfo.id);
340
344
  } catch (e) {
341
- console.log(e); // FIXME: capturar errores
345
+ console.log(e);
342
346
  }
343
347
  };
344
348
  }
345
349
 
346
- function getFilteredContent(filter: any): (dispatch: any, getState: any) => Promise<void> {
350
+ function getFilteredContent(filter: any): (dispatch: Dispatch, getState: () => IRootState) => Promise<void> {
347
351
  return async (dispatch, getState) => {
348
352
  try {
349
353
  const { value, fromPage } = filter;
@@ -354,6 +358,8 @@ function getFilteredContent(filter: any): (dispatch: any, getState: any) => Prom
354
358
  app: { token },
355
359
  } = getState();
356
360
 
361
+ if (!currentSiteInfo) return;
362
+
357
363
  if (value === "unique-pages" || fromPage) {
358
364
  const params = {
359
365
  siteID: currentSiteInfo.id,
@@ -366,11 +372,11 @@ function getFilteredContent(filter: any): (dispatch: any, getState: any) => Prom
366
372
  token,
367
373
  ...DEFAULT_PARAMS,
368
374
  };
369
- dispatch(structuredDataActions.setSelectedStructuredData(value, "site"));
375
+ structuredDataActions.setSelectedStructuredData(value, "site")(dispatch, getState);
370
376
  structuredDataActions.getStructuredDataContents(params, currentSiteInfo.id)(dispatch, getState);
371
377
  }
372
378
  } catch (e) {
373
- console.log(e); // FIXME: capturar errores mejor
379
+ console.log(e);
374
380
  }
375
381
  };
376
382
  }
@@ -379,7 +385,7 @@ function getSitePages(
379
385
  params: IGetSitePagesParams,
380
386
  structuredData?: string | null,
381
387
  filterQuery?: string
382
- ): (dispatch: any) => Promise<void> {
388
+ ): (dispatch: Dispatch) => Promise<void> {
383
389
  return async (dispatch) => {
384
390
  try {
385
391
  dispatch(appActions.setIsLoading(true));
@@ -396,12 +402,12 @@ function getSitePages(
396
402
  }
397
403
  dispatch(appActions.setIsLoading(false));
398
404
  } catch (e) {
399
- console.log(e); // FIXME: capturar errores mejor
405
+ console.log(e);
400
406
  }
401
407
  };
402
408
  }
403
409
 
404
- function getAllSitePages(params: IGetSitePagesParams): (dispatch: any) => Promise<void> {
410
+ function getAllSitePages(params: IGetSitePagesParams): (dispatch: Dispatch) => Promise<void> {
405
411
  return async (dispatch) => {
406
412
  try {
407
413
  const responseActions = {
@@ -416,12 +422,12 @@ function getAllSitePages(params: IGetSitePagesParams): (dispatch: any) => Promis
416
422
 
417
423
  await handleRequest(callback, responseActions, [])(dispatch);
418
424
  } catch (e) {
419
- console.log(e); // FIXME: capturar errores mejor
425
+ console.log(e);
420
426
  }
421
427
  };
422
428
  }
423
429
 
424
- function getSiteLanguages(siteID: number): (dispatch: any) => Promise<void> {
430
+ function getSiteLanguages(siteID: number): (dispatch: Dispatch) => Promise<void> {
425
431
  return async (dispatch) => {
426
432
  try {
427
433
  dispatch(appActions.setIsLoading(true));
@@ -538,13 +544,15 @@ function resetSiteValues(siteID: number): (dispatch: Dispatch) => void {
538
544
  };
539
545
  }
540
546
 
541
- function saveCurrentSiteInfo(): (dispatch: Dispatch, getState: any) => Promise<void> {
547
+ function saveCurrentSiteInfo(): (dispatch: Dispatch, getState: () => IRootState) => Promise<void> {
542
548
  return async (dispatch, getState) => {
543
549
  try {
544
550
  const {
545
551
  sites: { currentSiteInfo },
546
552
  } = getState();
547
553
 
554
+ if (!currentSiteInfo) return;
555
+
548
556
  dispatch(setSavedSiteInfo(currentSiteInfo));
549
557
  dispatch(setCurrentSiteInfo(null));
550
558
  } catch (e) {
@@ -553,13 +561,17 @@ function saveCurrentSiteInfo(): (dispatch: Dispatch, getState: any) => Promise<v
553
561
  };
554
562
  }
555
563
 
556
- function importPageFromGlobal(pageID: number | number[]): (dispatch: any, getState: any) => Promise<boolean> {
564
+ function importPageFromGlobal(
565
+ pageID: number | number[]
566
+ ): (dispatch: Dispatch, getState: () => IRootState) => Promise<boolean> {
557
567
  return async (dispatch, getState) => {
558
568
  try {
559
569
  const {
560
570
  sites: { currentSiteInfo, currentFilter },
561
571
  } = getState();
562
572
 
573
+ if (!currentSiteInfo) return false;
574
+
563
575
  const responseActions = {
564
576
  handleSuccess: () => {
565
577
  const params = {
@@ -609,7 +621,7 @@ function removeUsersBulk(siteId: number, users: number[]): (dispatch: Dispatch)
609
621
  function removePageFromSite(
610
622
  pageID: number | number[],
611
623
  refresh = true
612
- ): (dispatch: any, getState: any) => Promise<boolean> {
624
+ ): (dispatch: Dispatch, getState: () => IRootState) => Promise<boolean> {
613
625
  return async (dispatch, getState) => {
614
626
  try {
615
627
  const {
@@ -617,6 +629,8 @@ function removePageFromSite(
617
629
  structuredData: { currentStructuredData },
618
630
  } = getState();
619
631
 
632
+ if (!currentSiteInfo) return false;
633
+
620
634
  const responseActions = {
621
635
  handleSuccess: () => {
622
636
  const params = {
@@ -654,13 +668,15 @@ function removePageFromSite(
654
668
  function deleteAndRemoveFromSiteBulk(
655
669
  pageIds: number[],
656
670
  globalPageIds: number[]
657
- ): (dispatch: Dispatch, getState: any) => Promise<boolean> {
671
+ ): (dispatch: Dispatch, getState: () => IRootState) => Promise<boolean> {
658
672
  return async (dispatch, getState) => {
659
673
  try {
660
674
  const {
661
675
  sites: { currentSiteInfo },
662
676
  } = getState();
663
677
 
678
+ if (!currentSiteInfo) return false;
679
+
664
680
  let responseErrorPages: any = { data: { code: null, message: null } };
665
681
 
666
682
  const getMessageErrors = () => {
@@ -48,7 +48,10 @@ const config: ISiteListConfig = {
48
48
  displayRecentSites: false,
49
49
  mode: "grid",
50
50
  filter: "&order=lastAccess-desc",
51
- filterValues: { order: "desc", liveStatus: [{ value: "all", label: "All" }] },
51
+ filterValues: {
52
+ order: [{ value: "lastAccess-desc", label: "lastAccess-desc" }],
53
+ liveStatus: [{ value: "all", label: "All" }],
54
+ },
52
55
  sortedListStatus: {
53
56
  isAscending: false,
54
57
  sortedByDateCreated: false,
@@ -50,6 +50,12 @@ const Editor = (props: IProps) => {
50
50
  content = schema.configTabs[0].fields;
51
51
  }
52
52
 
53
+ content.forEach((field) => {
54
+ if (field.type === "FieldGroup" && field.fields) {
55
+ content = [...content, ...field.fields];
56
+ }
57
+ });
58
+
53
59
  return content.filter((field: ISchemaField) => field.type === "FormFieldArray");
54
60
  };
55
61
 
@@ -1,5 +1,5 @@
1
1
  import { useEffect, useRef, useState } from "react";
2
- import { IQueryValue, ISitesQueryValues } from "@ax/types";
2
+ import { IQueryValue } from "@ax/types";
3
3
 
4
4
  const useSortedListStatus = () => {
5
5
  const sortedInitialState: {
@@ -28,10 +28,7 @@ const useFilterQuery = (defaultValues?: { order: IQueryValue[]; liveStatus: IQue
28
28
  liveStatus: [{ value: "all", label: "All" }],
29
29
  };
30
30
 
31
- const [query, setQuery] = useState(defaultValues || initialQueryValues);
32
- const [currentFilterQuery, setCurrentFilterQuery] = useState("");
33
-
34
- const setFilterQuery = (filterValues: ISitesQueryValues) => {
31
+ const getFiltersQuery = (filterValues: Record<string, IQueryValue[]>): string => {
35
32
  const { order, liveStatus } = filterValues;
36
33
 
37
34
  let filterQuery = "";
@@ -39,7 +36,7 @@ const useFilterQuery = (defaultValues?: { order: IQueryValue[]; liveStatus: IQue
39
36
  return values.length && values[0].value !== "all" ? `&${pointer}=${values[0].value}` : "";
40
37
  };
41
38
 
42
- const isNotInitialValue = (pointer: keyof ISitesQueryValues) => {
39
+ const isNotInitialValue = (pointer: keyof Record<string, IQueryValue[]>) => {
43
40
  return filterValues[pointer] && initialQueryValues[pointer] !== filterValues[pointer];
44
41
  };
45
42
 
@@ -48,11 +45,18 @@ const useFilterQuery = (defaultValues?: { order: IQueryValue[]; liveStatus: IQue
48
45
  filterQuery = `${filterQuery}${query}`;
49
46
  }
50
47
 
51
- if (isNotInitialValue("order")) {
52
- const query = currentQuery("order", order);
53
- filterQuery = `${filterQuery}${query}`;
54
- }
48
+ const query = currentQuery("order", order);
49
+ filterQuery = `${filterQuery}${query}`;
50
+
51
+ return filterQuery;
52
+ };
53
+
54
+ const [query, setQuery] = useState(defaultValues || initialQueryValues);
55
+ const initialFilterQuery = getFiltersQuery(defaultValues || initialQueryValues);
56
+ const [currentFilterQuery, setCurrentFilterQuery] = useState(initialFilterQuery);
55
57
 
58
+ const setFilterQuery = (filterValues: Record<string, IQueryValue[]>) => {
59
+ const filterQuery = getFiltersQuery(filterValues);
56
60
  setCurrentFilterQuery(filterQuery);
57
61
  };
58
62
 
@@ -172,7 +172,7 @@ export interface ISiteListConfig {
172
172
  displayRecentSites: boolean;
173
173
  mode: string;
174
174
  filter: string;
175
- filterValues: { order: string; liveStatus: IQueryValue[] };
175
+ filterValues: { order: IQueryValue[]; liveStatus: IQueryValue[] };
176
176
  sortedListStatus: {
177
177
  isAscending: boolean;
178
178
  sortedByDateCreated: boolean;