@plone/volto 19.1.6 → 19.3.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/CHANGELOG.md +24 -0
- package/locales/af/LC_MESSAGES/volto.po +5 -0
- package/locales/af.json +1 -1
- package/locales/ar/LC_MESSAGES/volto.po +5 -0
- package/locales/ar.json +1 -1
- package/locales/bg/LC_MESSAGES/volto.po +5 -0
- package/locales/bg.json +1 -1
- package/locales/bn/LC_MESSAGES/volto.po +5 -0
- package/locales/bn.json +1 -1
- package/locales/ca/LC_MESSAGES/volto.po +5 -0
- package/locales/ca.json +1 -1
- package/locales/cs/LC_MESSAGES/volto.po +5 -0
- package/locales/cs.json +1 -1
- package/locales/cy/LC_MESSAGES/volto.po +5 -0
- package/locales/cy.json +1 -1
- package/locales/da/LC_MESSAGES/volto.po +5 -0
- package/locales/da.json +1 -1
- package/locales/de/LC_MESSAGES/volto.po +5 -0
- package/locales/de.json +1 -1
- package/locales/el/LC_MESSAGES/volto.po +5 -0
- package/locales/el.json +1 -1
- package/locales/en/LC_MESSAGES/volto.po +5 -0
- package/locales/en.json +1 -1
- package/locales/en_AU/LC_MESSAGES/volto.po +5 -0
- package/locales/en_AU.json +1 -1
- package/locales/en_GB/LC_MESSAGES/volto.po +5 -0
- package/locales/en_GB.json +1 -1
- package/locales/eo/LC_MESSAGES/volto.po +5 -0
- package/locales/eo.json +1 -1
- package/locales/es/LC_MESSAGES/volto.po +5 -0
- package/locales/es.json +1 -1
- package/locales/et/LC_MESSAGES/volto.po +5 -0
- package/locales/et.json +1 -1
- package/locales/eu/LC_MESSAGES/volto.po +5 -0
- package/locales/eu.json +1 -1
- package/locales/fa/LC_MESSAGES/volto.po +5 -0
- package/locales/fa.json +1 -1
- package/locales/fi/LC_MESSAGES/volto.po +5 -0
- package/locales/fi.json +1 -1
- package/locales/fr/LC_MESSAGES/volto.po +5 -0
- package/locales/fr.json +1 -1
- package/locales/fu/LC_MESSAGES/volto.po +5 -0
- package/locales/fu.json +1 -1
- package/locales/gl/LC_MESSAGES/volto.po +5 -0
- package/locales/gl.json +1 -1
- package/locales/he/LC_MESSAGES/volto.po +5 -0
- package/locales/he.json +1 -1
- package/locales/hi/LC_MESSAGES/volto.po +5 -0
- package/locales/hi.json +1 -1
- package/locales/hr/LC_MESSAGES/volto.po +5 -0
- package/locales/hr.json +1 -1
- package/locales/hu/LC_MESSAGES/volto.po +5 -0
- package/locales/hu.json +1 -1
- package/locales/hy/LC_MESSAGES/volto.po +5 -0
- package/locales/hy.json +1 -1
- package/locales/id/LC_MESSAGES/volto.po +5 -0
- package/locales/id.json +1 -1
- package/locales/it/LC_MESSAGES/volto.po +5 -0
- package/locales/it.json +1 -1
- package/locales/ja/LC_MESSAGES/volto.po +5 -0
- package/locales/ja.json +1 -1
- package/locales/ka/LC_MESSAGES/volto.po +5 -0
- package/locales/ka.json +1 -1
- package/locales/kn/LC_MESSAGES/volto.po +5 -0
- package/locales/kn.json +1 -1
- package/locales/ko/LC_MESSAGES/volto.po +5 -0
- package/locales/ko.json +1 -1
- package/locales/lt/LC_MESSAGES/volto.po +5 -0
- package/locales/lt.json +1 -1
- package/locales/lv/LC_MESSAGES/volto.po +5 -0
- package/locales/lv.json +1 -1
- package/locales/mi/LC_MESSAGES/volto.po +5 -0
- package/locales/mi.json +1 -1
- package/locales/mk/LC_MESSAGES/volto.po +5 -0
- package/locales/mk.json +1 -1
- package/locales/my/LC_MESSAGES/volto.po +5 -0
- package/locales/my.json +1 -1
- package/locales/nb_NO/LC_MESSAGES/volto.po +5 -0
- package/locales/nb_NO.json +1 -1
- package/locales/nl/LC_MESSAGES/volto.po +5 -0
- package/locales/nl.json +1 -1
- package/locales/nn/LC_MESSAGES/volto.po +5 -0
- package/locales/nn.json +1 -1
- package/locales/pl/LC_MESSAGES/volto.po +5 -0
- package/locales/pl.json +1 -1
- package/locales/pt/LC_MESSAGES/volto.po +5 -0
- package/locales/pt.json +1 -1
- package/locales/pt_BR/LC_MESSAGES/volto.po +5 -0
- package/locales/pt_BR.json +1 -1
- package/locales/rm/LC_MESSAGES/volto.po +5 -0
- package/locales/rm.json +1 -1
- package/locales/ro/LC_MESSAGES/volto.po +5 -0
- package/locales/ro.json +1 -1
- package/locales/ru/LC_MESSAGES/volto.po +5 -0
- package/locales/ru.json +1 -1
- package/locales/sk/LC_MESSAGES/volto.po +5 -0
- package/locales/sk.json +1 -1
- package/locales/sl/LC_MESSAGES/volto.po +5 -0
- package/locales/sl.json +1 -1
- package/locales/sm/LC_MESSAGES/volto.po +5 -0
- package/locales/sm.json +1 -1
- package/locales/sq/LC_MESSAGES/volto.po +5 -0
- package/locales/sq.json +1 -1
- package/locales/sr/LC_MESSAGES/volto.po +5 -0
- package/locales/sr.json +1 -1
- package/locales/sr@cyrl/LC_MESSAGES/volto.po +5 -0
- package/locales/sr@cyrl.json +1 -1
- package/locales/sr@latn/LC_MESSAGES/volto.po +5 -0
- package/locales/sr@latn.json +1 -1
- package/locales/sv/LC_MESSAGES/volto.po +5 -0
- package/locales/sv.json +1 -1
- package/locales/ta/LC_MESSAGES/volto.po +5 -0
- package/locales/ta.json +1 -1
- package/locales/te/LC_MESSAGES/volto.po +5 -0
- package/locales/te.json +1 -1
- package/locales/th/LC_MESSAGES/volto.po +5 -0
- package/locales/th.json +1 -1
- package/locales/to/LC_MESSAGES/volto.po +5 -0
- package/locales/to.json +1 -1
- package/locales/tr/LC_MESSAGES/volto.po +5 -0
- package/locales/tr.json +1 -1
- package/locales/uk/LC_MESSAGES/volto.po +5 -0
- package/locales/uk.json +1 -1
- package/locales/vi/LC_MESSAGES/volto.po +5 -0
- package/locales/vi.json +1 -1
- package/locales/volto.pot +6 -1
- package/locales/zh_CN/LC_MESSAGES/volto.po +5 -0
- package/locales/zh_CN.json +1 -1
- package/locales/zh_Hant/LC_MESSAGES/volto.po +5 -0
- package/locales/zh_Hant.json +1 -1
- package/locales/zh_Hant_HK/LC_MESSAGES/volto.po +5 -0
- package/locales/zh_Hant_HK.json +1 -1
- package/package.json +6 -7
- package/src/actions/querystringsearch/querystringsearch.test.js +107 -0
- package/src/actions/querystringsearch/querystringsearch.ts +135 -0
- package/src/components/manage/Blocks/Listing/getAsyncData.js +5 -0
- package/src/components/manage/Blocks/Listing/withQuerystringResults.jsx +18 -5
- package/src/components/manage/Widgets/QuerystringWidget.jsx +18 -1
- package/src/components/manage/Widgets/QuerystringWidget.test.jsx +11 -0
- package/src/config/index.js +2 -0
- package/src/config/server.js +2 -0
- package/src/express-middleware/devproxy.js +3 -3
- package/src/express-middleware/images.js +0 -1
- package/src/express-middleware/portraits.js +34 -0
- package/src/helpers/Api/APIResourceWithAuth.js +2 -2
- package/src/helpers/Api/Api.js +2 -1
- package/src/helpers/Api/Api.plone.rest.test.js +7 -0
- package/src/helpers/Api/PloneBackendAPIResourceWithAuth.js +39 -0
- package/src/helpers/Api/PloneBackendAPIResourceWithAuth.test.js +72 -0
- package/src/helpers/Pagination/Pagination.test.ts +259 -0
- package/src/helpers/Pagination/Pagination.ts +151 -0
- package/src/helpers/Sitemap/Sitemap.js +3 -3
- package/src/helpers/Url/Url.js +12 -1
- package/src/helpers/Url/Url.test.js +15 -0
- package/src/server.jsx +19 -2
- package/src/start-client.jsx +3 -0
- package/types/actions/querystringsearch/querystringsearch.d.ts +51 -3
- package/types/components/manage/Widgets/QuerystringWidget.d.ts +6 -0
- package/types/express-middleware/portraits.d.ts +1 -0
- package/types/helpers/Api/PloneBackendAPIResourceWithAuth.d.ts +1 -0
- package/types/helpers/Pagination/Pagination.d.ts +74 -0
- package/types/helpers/Url/Url.d.ts +7 -0
- package/src/actions/querystringsearch/querystringsearch.js +0 -63
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
import superagent from 'superagent';
|
|
7
7
|
import map from 'lodash/map';
|
|
8
8
|
import zlib from 'zlib';
|
|
9
|
-
import { toPublicURL } from '@plone/volto/helpers/Url/Url';
|
|
9
|
+
import { getApiSuffix, toPublicURL } from '@plone/volto/helpers/Url/Url';
|
|
10
10
|
import { addHeadersFactory } from '@plone/volto/helpers/Proxy/Proxy';
|
|
11
11
|
|
|
12
12
|
import config from '@plone/volto/registry';
|
|
@@ -22,7 +22,7 @@ export const SITEMAP_BATCH_SIZE = 5000;
|
|
|
22
22
|
export const generateSitemap = (_req, start = 0, size = undefined) =>
|
|
23
23
|
new Promise((resolve) => {
|
|
24
24
|
const { settings } = config;
|
|
25
|
-
const apiSuffix =
|
|
25
|
+
const apiSuffix = getApiSuffix();
|
|
26
26
|
const apiPath = settings.internalApiPath ?? settings.apiPath;
|
|
27
27
|
const request = superagent.get(
|
|
28
28
|
`${apiPath}${apiSuffix}/@search?metadata_fields=modified&b_start=${start}&b_size=${
|
|
@@ -64,7 +64,7 @@ export const generateSitemap = (_req, start = 0, size = undefined) =>
|
|
|
64
64
|
export const generateSitemapIndex = (_req, gzip = false) =>
|
|
65
65
|
new Promise((resolve) => {
|
|
66
66
|
const { settings } = config;
|
|
67
|
-
const apiSuffix =
|
|
67
|
+
const apiSuffix = getApiSuffix();
|
|
68
68
|
const apiPath = settings.internalApiPath ?? settings.apiPath;
|
|
69
69
|
const request = superagent.get(
|
|
70
70
|
`${apiPath}${apiSuffix}/@search?metadata_fields=modified&b_size=0&use_site_search_settings=1`,
|
package/src/helpers/Url/Url.js
CHANGED
|
@@ -182,6 +182,17 @@ export function addAppURL(url) {
|
|
|
182
182
|
: `${settings.apiPath}${url}`;
|
|
183
183
|
}
|
|
184
184
|
|
|
185
|
+
/**
|
|
186
|
+
* Get the API traversal suffix.
|
|
187
|
+
*
|
|
188
|
+
* An explicitly configured apiSuffix takes precedence over legacyTraverse.
|
|
189
|
+
* @returns {string} API traversal suffix.
|
|
190
|
+
*/
|
|
191
|
+
export function getApiSuffix() {
|
|
192
|
+
const { settings } = config;
|
|
193
|
+
return settings.apiSuffix ?? (settings.legacyTraverse ? '' : '/++api++');
|
|
194
|
+
}
|
|
195
|
+
|
|
185
196
|
/**
|
|
186
197
|
* Given a URL expands it to the backend URL
|
|
187
198
|
* Useful when you have to actually call the backend from the
|
|
@@ -193,7 +204,7 @@ export function addAppURL(url) {
|
|
|
193
204
|
*/
|
|
194
205
|
export function expandToBackendURL(path) {
|
|
195
206
|
const { settings } = config;
|
|
196
|
-
const apiSuffix =
|
|
207
|
+
const apiSuffix = getApiSuffix();
|
|
197
208
|
let adjustedPath;
|
|
198
209
|
if (path.startsWith('http://') || path.startsWith('https://')) {
|
|
199
210
|
// flattenToAppURL first if we get a full URL
|
|
@@ -24,6 +24,7 @@ import {
|
|
|
24
24
|
} from './Url';
|
|
25
25
|
|
|
26
26
|
beforeEach(() => {
|
|
27
|
+
config.settings.apiSuffix = undefined;
|
|
27
28
|
config.settings.legacyTraverse = false;
|
|
28
29
|
});
|
|
29
30
|
|
|
@@ -372,6 +373,20 @@ describe('Url', () => {
|
|
|
372
373
|
const href = `https://plone.org/api/ca/my-page`;
|
|
373
374
|
expect(expandToBackendURL(href)).toBe('https://plone.org/api/ca/my-page');
|
|
374
375
|
});
|
|
376
|
+
it('uses apiSuffix in preference to legacyTraverse', () => {
|
|
377
|
+
settings.apiPath = 'https://plone.org/api';
|
|
378
|
+
settings.legacyTraverse = true;
|
|
379
|
+
settings.apiSuffix = '/custom-api';
|
|
380
|
+
const href = `https://plone.org/api/ca/my-page`;
|
|
381
|
+
expect(expandToBackendURL(href)).toBe(
|
|
382
|
+
'https://plone.org/api/custom-api/ca/my-page',
|
|
383
|
+
);
|
|
384
|
+
});
|
|
385
|
+
it('allows apiSuffix to disable the suffix', () => {
|
|
386
|
+
settings.apiSuffix = '';
|
|
387
|
+
const href = `/ca/my-page`;
|
|
388
|
+
expect(expandToBackendURL(href)).toBe('https://plone.org/api/ca/my-page');
|
|
389
|
+
});
|
|
375
390
|
it('expandToBackendURL test full URL - deployed seamless', () => {
|
|
376
391
|
settings.apiPath = 'https://plone.org';
|
|
377
392
|
const href = `https://plone.org/ca/my-page`;
|
package/src/server.jsx
CHANGED
|
@@ -7,7 +7,6 @@ import { Provider } from 'react-intl-redux';
|
|
|
7
7
|
import express from 'express';
|
|
8
8
|
import { renderToString } from 'react-dom/server';
|
|
9
9
|
import { createMemoryHistory } from 'history';
|
|
10
|
-
import { parse as parseUrl } from 'url';
|
|
11
10
|
import keys from 'lodash/keys';
|
|
12
11
|
import locale from 'locale';
|
|
13
12
|
import { detect } from 'detect-browser';
|
|
@@ -247,7 +246,25 @@ server.get('/*', (req, res) => {
|
|
|
247
246
|
});
|
|
248
247
|
|
|
249
248
|
const url = req.originalUrl || req.url;
|
|
250
|
-
|
|
249
|
+
// Parse the request URL without the deprecated `url.parse()` (DEP0169).
|
|
250
|
+
// `req.url` is always an origin-form path here, so a plain string split
|
|
251
|
+
// reproduces the exact `url.parse()` shape (including raw, non-encoded
|
|
252
|
+
// query strings) that downstream async-connected components rely on.
|
|
253
|
+
const hashIndex = url.indexOf('#');
|
|
254
|
+
const withoutHash = hashIndex === -1 ? url : url.slice(0, hashIndex);
|
|
255
|
+
const hash = hashIndex === -1 ? null : url.slice(hashIndex);
|
|
256
|
+
const queryIndex = withoutHash.indexOf('?');
|
|
257
|
+
const pathname =
|
|
258
|
+
queryIndex === -1 ? withoutHash : withoutHash.slice(0, queryIndex);
|
|
259
|
+
const search = queryIndex === -1 ? null : withoutHash.slice(queryIndex);
|
|
260
|
+
const location = {
|
|
261
|
+
pathname,
|
|
262
|
+
search,
|
|
263
|
+
query: search ? search.slice(1) : null,
|
|
264
|
+
hash,
|
|
265
|
+
path: withoutHash,
|
|
266
|
+
href: url,
|
|
267
|
+
};
|
|
251
268
|
|
|
252
269
|
loadOnServer({ store, location, routes, api })
|
|
253
270
|
.then(() => {
|
package/src/start-client.jsx
CHANGED
|
@@ -77,6 +77,9 @@ export default function client() {
|
|
|
77
77
|
if (window.env.RAZZLE_INTERNAL_API_PATH) {
|
|
78
78
|
config.settings.internalApiPath = window.env.RAZZLE_INTERNAL_API_PATH;
|
|
79
79
|
}
|
|
80
|
+
if (typeof window.env.RAZZLE_API_SUFFIX !== 'undefined') {
|
|
81
|
+
config.settings.apiSuffix = window.env.RAZZLE_API_SUFFIX;
|
|
82
|
+
}
|
|
80
83
|
// TODO: To be removed when the use of the legacy traverse is deprecated.
|
|
81
84
|
if (window.env.RAZZLE_LEGACY_TRAVERSE) {
|
|
82
85
|
config.settings.legacyTraverse = true;
|
|
@@ -1,7 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Querystring search actions.
|
|
3
|
+
* @module actions/querystringsearch/querystringsearch
|
|
4
|
+
*/
|
|
5
|
+
import { GET_QUERYSTRING_RESULTS } from '@plone/volto/constants/ActionTypes';
|
|
6
|
+
import { type IntegerLike } from '@plone/volto/helpers/Pagination/Pagination';
|
|
7
|
+
/**
|
|
8
|
+
* A single `plone.app.querystring` criterion: index, operation, value.
|
|
9
|
+
*/
|
|
10
|
+
export interface QuerystringCriterion {
|
|
11
|
+
i: string;
|
|
12
|
+
o: string;
|
|
13
|
+
v?: unknown;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* The querystring settings stored on a block. Numeric fields are typed as
|
|
17
|
+
* `IntegerLike` because they are edited through JSON schema `number` widgets
|
|
18
|
+
* and may reach us as strings.
|
|
19
|
+
*/
|
|
20
|
+
export interface QuerystringData {
|
|
21
|
+
query?: QuerystringCriterion[];
|
|
22
|
+
sort_on?: string;
|
|
23
|
+
sort_order?: string | boolean | null;
|
|
24
|
+
b_size?: IntegerLike;
|
|
25
|
+
offset?: IntegerLike;
|
|
26
|
+
limit?: IntegerLike;
|
|
27
|
+
depth?: IntegerLike;
|
|
28
|
+
[key: string]: unknown;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* The payload sent to the `@querystring-search` endpoint. `b_start` is only
|
|
32
|
+
* present once a page or an offset places the batch past the beginning.
|
|
33
|
+
*/
|
|
34
|
+
export interface QuerystringSearchQuery extends QuerystringData {
|
|
35
|
+
b_start?: number;
|
|
36
|
+
}
|
|
37
|
+
export interface GetQueryStringResultsAction {
|
|
38
|
+
type: typeof GET_QUERYSTRING_RESULTS;
|
|
39
|
+
subrequest?: string;
|
|
40
|
+
request: {
|
|
41
|
+
op: 'get' | 'post';
|
|
42
|
+
path: string;
|
|
43
|
+
data: QuerystringSearchQuery | null;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
1
46
|
/**
|
|
2
47
|
* Get querystring results.
|
|
3
48
|
* @function getQueryStringResults
|
|
4
|
-
* @param {
|
|
5
|
-
* @
|
|
49
|
+
* @param {string} path Path to search under.
|
|
50
|
+
* @param {QuerystringData} data Querystring settings from the block.
|
|
51
|
+
* @param {string} subrequest Subrequest id used to store the results.
|
|
52
|
+
* @param {IntegerLike} page 1-based page number. Defaults to the first page.
|
|
53
|
+
* @returns {GetQueryStringResultsAction} Get querystringsearch results action.
|
|
6
54
|
*/
|
|
7
|
-
export function getQueryStringResults(path:
|
|
55
|
+
export declare function getQueryStringResults(path: string, data: QuerystringData, subrequest?: string, page?: IntegerLike): GetQueryStringResultsAction;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function portraitsMiddleware(): any;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function getPloneBackendAPIResourceWithAuth(req: any): string;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pagination helpers.
|
|
3
|
+
* @module helpers/Pagination/Pagination
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* A value that is meant to represent an integer, but which reaches us from
|
|
7
|
+
* user-editable block settings. The querystring widget stores `offset`,
|
|
8
|
+
* `limit` and `b_size` as JSON schema `number` fields, so a value may arrive
|
|
9
|
+
* as a string (`'3'`), as a float (`3.7`), or not at all.
|
|
10
|
+
*/
|
|
11
|
+
export type IntegerLike = number | string | null | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* Compute the `b_start` index for a `@querystring-search` request: the index
|
|
14
|
+
* of the first item the backend should return for the requested page.
|
|
15
|
+
*
|
|
16
|
+
* `offset` shifts the whole result set, letting a listing skip the first N
|
|
17
|
+
* items of its query while paginating over the remainder.
|
|
18
|
+
*
|
|
19
|
+
* Every parameter is coerced to an integer and the result is always a
|
|
20
|
+
* non-negative integer, so a malformed block setting degrades to a sane batch
|
|
21
|
+
* rather than sending `NaN` to the backend. When neither `bSize` nor
|
|
22
|
+
* `defaultPageSize` yields a positive batch size, paging cannot be applied and
|
|
23
|
+
* the result is `offset` alone.
|
|
24
|
+
* @function computeBStart
|
|
25
|
+
* @param {IntegerLike} page 1-based page number. Defaults to the first page.
|
|
26
|
+
* @param {IntegerLike} offset Number of leading items to skip. Defaults to 0.
|
|
27
|
+
* @param {IntegerLike} bSize Batch size configured on the block, if any.
|
|
28
|
+
* @param {IntegerLike} defaultPageSize Batch size to use when bSize is unset.
|
|
29
|
+
* @returns {number} A non-negative integer `b_start` index.
|
|
30
|
+
*/
|
|
31
|
+
export declare function computeBStart(page: IntegerLike, offset: IntegerLike, bSize: IntegerLike, defaultPageSize: IntegerLike): number;
|
|
32
|
+
/**
|
|
33
|
+
* Compute the effective `limit` for a `@querystring-search` request.
|
|
34
|
+
*
|
|
35
|
+
* A listing that skips the first `offset` items still wants `limit` items
|
|
36
|
+
* afterwards, so the backend has to return the skipped items on top of the
|
|
37
|
+
* wanted ones: `offset + limit`.
|
|
38
|
+
*
|
|
39
|
+
* A limit of zero, or one that resolves to no usable number, means "no limit"
|
|
40
|
+
* — matching `plone.app.querystring`'s querybuilder, whose `limit` defaults to
|
|
41
|
+
* 0 and is only applied when truthy. Returning `offset` in that case would cap
|
|
42
|
+
* the batch at the very items the listing is about to skip, leaving it empty.
|
|
43
|
+
* @function computeLimit
|
|
44
|
+
* @param {IntegerLike} offset Number of leading items to skip. Defaults to 0.
|
|
45
|
+
* @param {IntegerLike} limit Number of items the listing wants, if capped.
|
|
46
|
+
* @returns {number | null} A positive integer limit, or null for no limit.
|
|
47
|
+
*/
|
|
48
|
+
export declare function computeLimit(offset: IntegerLike, limit: IntegerLike): number | null;
|
|
49
|
+
/**
|
|
50
|
+
* Compute how many items a listing can actually show.
|
|
51
|
+
*
|
|
52
|
+
* The `items_total` reported by `@querystring-search` is the length of the
|
|
53
|
+
* whole result set: `plone.restapi`'s HypermediaBatch derives it from the
|
|
54
|
+
* sequence length, so `b_start` never reduces it. The items an offset skips
|
|
55
|
+
* are counted in there even though the listing never renders them.
|
|
56
|
+
* @function computeVisibleTotal
|
|
57
|
+
* @param {IntegerLike} total The `items_total` reported by the backend.
|
|
58
|
+
* @param {IntegerLike} offset Number of leading items skipped. Defaults to 0.
|
|
59
|
+
* @returns {number} A non-negative integer count of reachable items.
|
|
60
|
+
*/
|
|
61
|
+
export declare function computeVisibleTotal(total: IntegerLike, offset: IntegerLike): number;
|
|
62
|
+
/**
|
|
63
|
+
* Compute how many pages a listing spans.
|
|
64
|
+
*
|
|
65
|
+
* `total` is expected to be the reachable item count, so pass the result of
|
|
66
|
+
* `computeVisibleTotal` for an offset listing rather than the raw backend
|
|
67
|
+
* total. Otherwise the listing advertises pages that resolve to an empty batch.
|
|
68
|
+
* @function computeTotalPages
|
|
69
|
+
* @param {IntegerLike} total Number of items the listing can show.
|
|
70
|
+
* @param {IntegerLike} bSize Batch size, i.e. items per page.
|
|
71
|
+
* @returns {number} A non-negative integer page count, 0 when there is no
|
|
72
|
+
* usable batch size.
|
|
73
|
+
*/
|
|
74
|
+
export declare function computeTotalPages(total: IntegerLike, bSize: IntegerLike): number;
|
|
@@ -54,6 +54,13 @@ export function flattenHTMLToAppURL(html: string): string;
|
|
|
54
54
|
* @returns {string} New URL with app
|
|
55
55
|
*/
|
|
56
56
|
export function addAppURL(url: string): string;
|
|
57
|
+
/**
|
|
58
|
+
* Get the API traversal suffix.
|
|
59
|
+
*
|
|
60
|
+
* An explicitly configured apiSuffix takes precedence over legacyTraverse.
|
|
61
|
+
* @returns {string} API traversal suffix.
|
|
62
|
+
*/
|
|
63
|
+
export function getApiSuffix(): string;
|
|
57
64
|
/**
|
|
58
65
|
* Given a URL expands it to the backend URL
|
|
59
66
|
* Useful when you have to actually call the backend from the
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { GET_QUERYSTRING_RESULTS } from '@plone/volto/constants/ActionTypes';
|
|
2
|
-
import config from '@plone/volto/registry';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Get querystring results.
|
|
6
|
-
* @function getQueryStringResults
|
|
7
|
-
* @param {Object} data Data.
|
|
8
|
-
* @returns {Object} Get querystringsearch results action.
|
|
9
|
-
*/
|
|
10
|
-
export function getQueryStringResults(path, data, subrequest, page) {
|
|
11
|
-
const { settings } = config;
|
|
12
|
-
|
|
13
|
-
// fixes https://github.com/plone/volto/issues/1059
|
|
14
|
-
let requestData = JSON.parse(JSON.stringify(data));
|
|
15
|
-
|
|
16
|
-
if (data?.depth != null) {
|
|
17
|
-
delete requestData.depth;
|
|
18
|
-
requestData.query.forEach((q) => {
|
|
19
|
-
if (q.i === 'path') {
|
|
20
|
-
// fixes https://github.com/plone/volto/issues/8349
|
|
21
|
-
// Skip if depth is already embedded in the path value (e.g. set via object browser)
|
|
22
|
-
const hasEmbeddedDepth = /::\d+$/.test(q.v);
|
|
23
|
-
if (!hasEmbeddedDepth) q.v += '::' + data.depth;
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// fixes https://github.com/plone/volto/issues/2397
|
|
29
|
-
if (requestData?.sort_order !== null) {
|
|
30
|
-
if (typeof requestData.sort_order === 'boolean') {
|
|
31
|
-
requestData.sort_order = requestData.sort_order
|
|
32
|
-
? 'descending'
|
|
33
|
-
: 'ascending';
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const query = {
|
|
38
|
-
...requestData,
|
|
39
|
-
...(!requestData.b_size && {
|
|
40
|
-
b_size: settings.defaultPageSize,
|
|
41
|
-
}),
|
|
42
|
-
...(page && {
|
|
43
|
-
b_start: requestData.b_size
|
|
44
|
-
? data.b_size * (page - 1)
|
|
45
|
-
: settings.defaultPageSize * (page - 1),
|
|
46
|
-
}),
|
|
47
|
-
query: requestData?.query,
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
return {
|
|
51
|
-
type: GET_QUERYSTRING_RESULTS,
|
|
52
|
-
subrequest,
|
|
53
|
-
request: {
|
|
54
|
-
op: settings.querystringSearchGet ? 'get' : 'post',
|
|
55
|
-
path: `${path}/@querystring-search${
|
|
56
|
-
settings.querystringSearchGet
|
|
57
|
-
? `?query=${encodeURIComponent(JSON.stringify(query))}`
|
|
58
|
-
: ''
|
|
59
|
-
}`,
|
|
60
|
-
data: settings.querystringSearchGet ? null : query,
|
|
61
|
-
},
|
|
62
|
-
};
|
|
63
|
-
}
|