@sensinum/strapi-plugin-xecp 5.0.0-beta.1

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/LICENSE.md ADDED
@@ -0,0 +1,7 @@
1
+ # End User License Agreement (EULA)
2
+
3
+ ## Strapi Content Promotion Plugin (XECP)
4
+
5
+ *All rights reserved. Copyright (c) [Sensinum Sp. z o.o.](https://sensinum.com/)*
6
+
7
+ Full content of the EULA is available - [here](https://www.sensinum.com/eula-strapi-cross-environment-content-promotion-plugin)
package/README.md ADDED
@@ -0,0 +1,195 @@
1
+ <div align="center" width="150px">
2
+ <img style="width: 150px; height: auto;" src="https://www.sensinum.com/img/open-source/strapi-plugin-xecp/logo.png" alt="Logo - Strapi Plugin XECP" />
3
+ </div>
4
+ <div align="center">
5
+ <h1>Strapi - Content Promotion Plugin (XECP)</h1>
6
+ <p>One Content. Many Environments. Zero Surprises.
7
+ </p>
8
+ <a href="https://www.npmjs.org/package/@sensinum/strapi-plugin-xecp">
9
+ <img alt="GitHub package.json version" src="https://img.shields.io/npm/v/@sensinum/strapi-plugin-xecp">
10
+ </a>
11
+ <a href="https://www.npmjs.org/package/@sensinum/strapi-plugin-xecp">
12
+ <img src="https://img.shields.io/npm/dm/@sensinum/strapi-plugin-xecp.svg" alt="Monthly download on NPM" />
13
+ </a>
14
+ <a href="https://dl.circleci.com/status-badge/redirect/gh/Sensinum/strapi-plugin-xecp/tree/main">
15
+ <img src="https://dl.circleci.com/status-badge/img/gh/Sensinum/strapi-plugin-xecp/tree/main.svg?style=shield&circle-token=CCIPRJ_2J5QBQ4HXi1waBrAU9Lhje_aa6fbb9e2232e9101e5447c9b2585a663cad99d3" alt="CircleCI" />
16
+ </a>
17
+ </div>
18
+
19
+ ---
20
+
21
+ This plugin brings Cross Environment Content Promotion (XECP) to Strapi: move selected content from a source environment to a target with schema checks and snapshot-based comparison.
22
+
23
+ > โœ… **GET THE LICENSE**: To obtain the license we encourage you to [**visit the plugin commercial website**](https://www.sensinum.com/strapi-cross-environment-content-promotion-plugin), select the appropriate plan, and reach out to your preferred reseller or directly contact the plugin authors via [**this form**](http://sensinum.com/contact).
24
+
25
+ > โš ๏ธ **This plugin is licensed by Sensinum Sp. z o.o. under the [End User License Agreement (EULA)](https://www.sensinum.com/eula-strapi-cross-environment-content-promotion-plugin).**
26
+ > Unauthorized use, including usage without a valid license key or modification of the code in a way that breaches the integrity of the software, is strictly prohibited and will be treated as a violation of the [EULA](https://www.sensinum.com/eula-strapi-cross-environment-content-promotion-plugin), with all associated legal consequences.
27
+
28
+ ### Table of Contents
29
+
30
+ 1. [โœจ Features](#-features)
31
+ 2. [๐ŸŽจ Admin Panel Features](#-admin-panel-features)
32
+ 3. [โš™๏ธ How it works](#%EF%B8%8F-how-it-works)
33
+ 4. [โš ๏ธ Important Considerations](#%EF%B8%8F-important-considerations)
34
+ 5. [๐Ÿ”ง Configuration](#-configuration)
35
+ 6. [๐Ÿ” Permissions](#-permissions)
36
+ 7. [๐Ÿงช Testing](#-testing)
37
+ 8. [๐Ÿ“ License](#-license)
38
+
39
+ ## โœจ Features
40
+
41
+ - **Schema Comparison**: Catch content-type mismatches before promotion.
42
+ - **Environment Snapshots**: Store target content hashes locally so comparison can detect changes without re-fetching the remote every time.
43
+ - **Selective Content Promotion**: Choose exactly what moves to the target.
44
+ - **Sync Job Control**: Start, monitor, cancel, and resume snapshot syncs (extra requests queue while one is running).
45
+ - **Configurable Scope**: Include or exclude content types from the promotion graph.
46
+ - **Media-Aware Promotion**: Transfer media only when opted in (uploads, replaces, removes, reorders, alt changes).
47
+
48
+ ## ๐ŸŽจ Admin Panel Features
49
+
50
+ - **Comparison Workspace**: Review local vs snapshot differences and choose what to promote.
51
+ - **Snapshot Controls**: Request a new snapshot and track sync progress (start, cancel, resume).
52
+ - **Target Setup**: Configure the remote environment, API token, and which content types are in scope.
53
+
54
+ ## โš™๏ธ How it works
55
+
56
+ XECP links a Strapi application (the source) to another Strapi instance (the target) configured with a URL and API token. The plugin also uses a configured set of content types as the promotion scope.
57
+
58
+ Before content can be promoted, XECP compares the schemas of those configured content types (and the components they use) between source and target. If they do not match, promotion and snapshot actions stay blocked until the environments are aligned. Unconfigured content types are ignored by this check.
59
+
60
+ Entity comparison requires a local snapshot of the target. XECP syncs target entities into that snapshot so comparison does not fetch from the remote on every review. The snapshot must be refreshed manually after changes on the target; it is not updated automatically.
61
+
62
+ Snapshot syncs use a **shared queue**: only one sync job runs at a time on the instance. If a snapshot is requested while another sync is already running, the new job is queued (FIFO) and starts automatically when the active job finishes. A content type cannot have more than one running or queued sync at once.
63
+
64
+ On the home page, operators pick a content type, review differences between local entries and the snapshot, select what to promote (including related content when applicable), and optionally opt in to media updates. XECP then pushes the selected content to the target.
65
+
66
+ ## โš ๏ธ Important Considerations
67
+
68
+ ### Schema compatibility
69
+
70
+ Promotion and meaningful entity comparison require compatible schemas between source and target. If schemas do not match, the home page shows a schema-mismatch alert and blocks promote / get-snapshot actions until the environments are aligned.
71
+
72
+ Schema comparison is **not** run for every content type in the app. It covers only content types configured under **Settings โ†’ Content Promotion โ†’ Configuration**, excluding UIDs listed in `excludedContentTypes` and `nonPromotableContentTypes` (and a small set of plugin-owned types). Components are compared only when they are used by that scoped set. If no content types are configured, the comparison scope is empty and is treated as a match.
73
+
74
+ ### Entity comparison depth
75
+
76
+ Under **Settings โ†’ Content Promotion โ†’ Configuration**, **Entity comparison depth** controls how many levels of nested relations and components are inspected during entity comparison (and related sync/promote traversal). The default is **3**.
77
+
78
+ If the graph is deeper than this limit, the home page can warn that max depth was exceeded: promotion can still proceed, but some nested relations may be omitted from comparison. Values above **6** may slow snapshot sync and comparison because of deep relation traversal.
79
+
80
+ ### Target API compatibility
81
+
82
+ XECP uses Strapi's default Content API endpoints to retrieve, create, and update content on the target environment. All default endpoints used by XECP must remain available, and their standard response structures must not be modified. Replacing these endpoints or changing their responses may prevent snapshot synchronization, comparison, or content promotion from working correctly.
83
+
84
+ ### Target environment credentials
85
+
86
+ The target API token is stored encrypted using the plugin `encryptionKey`. Use a dedicated **Custom** API token with at least:
87
+
88
+ | Scope | Actions | Why |
89
+ | --------------------------------------------------- | ------------------------------------- | ------------------------------------------------------------------------------- |
90
+ | Each **promotable** and **related** collection type | `find`, `findOne`, `create`, `update` | Snapshot sync (list), lookups, create, and update / locale writes |
91
+ | Each **promotable** and **related** single type | `find`, `update` | Read and update |
92
+ | **Content-Type Builder** | `getContentTypes`, `getComponents` | Schema comparison |
93
+ | **Upload** | `find`, `upload` | Media match (`GET /api/upload/files`) and upload / replace (`POST /api/upload`) |
94
+
95
+ Grant these for every content type in Configuration that can be promoted or appears as related content. Do not grant delete unless required for other reasons โ€” XECP does not delete remote entries.
96
+
97
+ ### Media uploads
98
+
99
+ When promoting media, the plugin uses Strapiโ€™s **Upload API**. Uploaded files are stored in the **API Uploads** folder. This destination is fixed by Strapiโ€™s upload pipeline and **cannot be changed** by the plugin.
100
+
101
+ **Media fields are updated only when the โ€œUpdate mediaโ€ checkbox is selected** for the promoted entries. That includes not only uploading or replacing files, but also:
102
+
103
+ - removing media from entity fields
104
+ - reordering media
105
+ - changing media metadata
106
+
107
+ Without โ€œUpdate mediaโ€ selected, those field changes are not applied on the target.
108
+
109
+ Replacing images that already exist on the target environment causes them to **lose folder info** and appear in the **root** Media Library folder, while the folder file count is **not updated**. This is a **Strapi bug**, not XECP behaviour.
110
+
111
+ ## ๐Ÿ”ง Configuration
112
+
113
+ To configure the plugin, create a `plugins.js` (or `plugins.ts`) file in the Strapi project's `config` directory.
114
+
115
+ File: `config/plugins.js`
116
+
117
+ ```javascript
118
+ module.exports = {
119
+ 'content-promotion': {
120
+ enabled: true,
121
+ config: {
122
+ /**
123
+ * Required. Exactly 32 characters.
124
+ * Used to encrypt the target environment API key at rest.
125
+ */
126
+ encryptionKey: '12345678901234567890123456789012',
127
+ /**
128
+ * Optional. Max time (ms) a sync job may run before being treated as stale.
129
+ * Default value: 6 * 60 * 1000 (6 minutes)
130
+ */
131
+ staleSyncLockMs: 6 * 60 * 1000,
132
+ /**
133
+ * Optional. Content types excluded from the promotion graph and remote push,
134
+ * but still configurable as related types in settings.
135
+ */
136
+ nonPromotableContentTypes: [],
137
+ /**
138
+ * Optional. Content types fully ignored by XECP
139
+ * (not in settings, comparison, or promotion).
140
+ */
141
+ excludedContentTypes: [],
142
+ },
143
+ },
144
+ };
145
+ ```
146
+
147
+ Then configure the target environment and promotable content types under **Settings โ†’ Content Promotion โ†’ Configuration**.
148
+
149
+ ### Configuration options
150
+
151
+ - `encryptionKey` (string, **required**): Exactly 32 characters. Encrypts the target environment API key.
152
+ - `staleSyncLockMs` (number, optional): Maximum duration for a running sync job before it is considered stale.
153
+ - `nonPromotableContentTypes` (string[], optional): UIDs excluded from promotion / remote push / content hashes, but allowed as related types in settings.
154
+ - `excludedContentTypes` (string[], optional): UIDs fully ignored by XECP.
155
+
156
+ ### Environment variables
157
+
158
+ | Variable | Description |
159
+ | --------------------- | ------------------ |
160
+ | `XECP_LICENSE_KEY` | Licence key |
161
+ | `XECP_LICENSE_SERVER` | Licence server URL |
162
+
163
+ ## ๐Ÿ” Permissions
164
+
165
+ Four admin actions:
166
+
167
+ | Action | Typical use |
168
+ | ------------------- | ------------------------------------------------ |
169
+ | `settings.read` | View Configuration / About; settings links |
170
+ | `settings.update` | Save configuration; test target connection |
171
+ | `promotion.read` | Plugin menu, home page, comparison / sync status |
172
+ | `promotion.execute` | Promote content; start / cancel / resume sync |
173
+
174
+ ## ๐Ÿงช Testing
175
+
176
+ From the plugin directory:
177
+
178
+ ```bash
179
+ yarn test:unit
180
+ # or
181
+ npm run test:unit
182
+ ```
183
+
184
+ Typecheck:
185
+
186
+ ```bash
187
+ yarn test:ts:front
188
+ yarn test:ts:back
189
+ ```
190
+
191
+ Watch mode: `yarn test:unit:watch` / `npm run test:unit:watch`.
192
+
193
+ ## ๐Ÿ“ License
194
+
195
+ All rights reserved. Copyright (c) [Sensinum Sp. z o.o.](https://sensinum.com/)
@@ -0,0 +1,30 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),f=require("@strapi/strapi/admin"),K=require("react-router-dom"),i=require("./index-CjbN24vV.js"),J=require("./queryKeys-B_GC_f73.js"),s=require("@strapi/design-system"),Z=require("@strapi/icons"),j=require("react"),T=require("react-intl"),Ge=require("zod"),S=require("./TruncatedTypography-72wp11m4.js"),I=require("@tanstack/react-query"),He=require("styled-components"),Ce=e=>e&&e.__esModule?e:{default:e},G=Ce(Ge),me=Ce(He),Ve=120*1e3,Ye=()=>{const{get:e}=f.useFetchClient();return I.useQuery({queryKey:[J.LICENSE_QUERY_KEY,"status"],staleTime:Ve,queryFn:async()=>{const{data:n}=await e(`/${i.URL_PREFIX}/license/status`);return n}})},je=(e,n)=>n?e.find(o=>o.value===n)?.label??"":"",Xe=({name:e,onClear:n,onChange:o,options:a,value:r,placeholder:l,disabled:d})=>{const[c,u]=j.useState(()=>je(a,r));return j.useEffect(()=>{u(je(a,r))},[r,a]),t.jsx(s.Combobox,{name:e,autocomplete:"list",onClear:n,onChange:o,placeholder:l,onTextValueChange:u,value:r,textValue:c,disabled:d,width:"100%",children:a.map(({key:g,label:h,value:y})=>t.jsx(s.ComboboxOption,{value:y,children:h},g))})},Je="90vh",W=({open:e,onClose:n,title:o,children:a,isConfirmButtonLoading:r=!1,confirmButtonText:l,isConfirmButtonDisabled:d=!1,onSubmit:c,cancelButtonText:u,showConfirmButton:g=!0,fillMaxHeight:h=!1})=>{const{formatMessage:y}=T.useIntl();return t.jsx(s.Modal.Root,{open:e,onOpenChange:()=>n(),children:t.jsxs(s.Modal.Content,{style:h?{height:Je}:void 0,children:[t.jsx(s.Modal.Header,{children:t.jsx(s.Modal.Title,{children:o})}),t.jsx(s.Modal.Body,{children:a}),t.jsx(s.Modal.Footer,{style:g?void 0:{justifyContent:"flex-end"},children:g?t.jsxs(t.Fragment,{children:[t.jsx(s.Modal.Close,{children:t.jsx(s.Button,{variant:"tertiary",onClick:n,children:u||y({id:i.getTranslation("common.button.close")})})}),t.jsx(s.Button,{loading:r,disabled:d,onClick:c,children:l||y({id:i.getTranslation("common.button.submit")})})]}):t.jsx(s.Modal.Close,{children:t.jsx(s.Button,{variant:"tertiary",onClick:n,children:u||y({id:i.getTranslation("common.button.close")})})})})]})})},Ie=e=>/^[\w]+(?:\.[\w]+)+$/.test(e),Ze=e=>{if(typeof e!="object"||e===null)return;const n=e.response?.data?.error?.message;if(typeof n=="string")return n;const o=e.message;return typeof o=="string"?o:void 0},z=(e,n)=>{const o=Ze(e);return o&&Ie(o)?n({id:i.getTranslation(o)}):n({id:i.getTranslation("homePage.error")})},We=(e,n)=>e&&Ie(e)?n({id:i.getTranslation(e)}):null,O={all:["sync"],lists:()=>[...O.all,"list"],list:e=>[...O.lists(),{uid:e}]},be="entities-comparison",ze=({uid:e,page:n=1,pageSize:o=10,enabled:a=!0})=>{const{get:r}=f.useFetchClient();return I.useQuery({queryKey:[be,{uid:e,page:n,pageSize:o}],queryFn:async()=>{const{data:l}=await r(`/${i.URL_PREFIX}/entity-comparison/${e}?page=${n}&pageSize=${o}`);return l},enabled:!!e&&a})},Ee=e=>{e.invalidateQueries({queryKey:[be]})},ee=(e,n)=>{e.invalidateQueries({queryKey:n?O.list(n):O.lists()}),Ee(e)},et=()=>{const{post:e}=f.useFetchClient(),n=I.useQueryClient();return I.useMutation({mutationFn:async o=>await e(`/${i.URL_PREFIX}/snapshot/${o}/sync`),onSuccess:(o,a)=>{ee(n,a)}})},we=({open:e,onClose:n,contentTypeUid:o})=>{const{formatMessage:a}=T.useIntl(),{mutate:r,isPending:l,error:d,reset:c}=et(),u=()=>{n(),c()},g=()=>{r(o,{onSuccess:n})};return t.jsx(W,{open:e,onClose:u,onSubmit:g,title:a({id:i.getTranslation("homePage.modal.getNewSnapshot.title")}),confirmButtonText:a({id:i.getTranslation("homePage.modal.getNewSnapshot.confirmButtonText")}),isConfirmButtonDisabled:l||!o,isConfirmButtonLoading:l,children:t.jsxs(s.Flex,{direction:"column",gap:4,alignItems:"stretch",children:[t.jsx(s.Typography,{variant:"omega",children:a({id:i.getTranslation("homePage.modal.getNewSnapshot.description")})}),d&&t.jsx(s.Typography,{variant:"omega",textColor:"danger500",children:z(d,a)})]})})},tt=({contentTypeUid:e,selectedPromotionsLength:n,syncedAt:o,isGetSnapshotDisabled:a=!1,hasSnapshot:r,clearSelectedPromotions:l,canExecute:d})=>{const{formatMessage:c}=T.useIntl(),[u,g]=j.useState(!1);return t.jsxs(s.Flex,{direction:"row",justifyContent:"space-between",alignItems:"center",marginBottom:1,marginTop:1,children:[e&&r?t.jsxs(s.Flex,{direction:"row",gap:3,alignItems:"center",children:[t.jsx(s.Typography,{variant:"omega",children:c({id:i.getTranslation("homePage.selectedEntities")},{count:n})}),n>0&&d?t.jsx(s.Button,{variant:"secondary",onClick:l,children:c({id:i.getTranslation("homePage.clearSelectedEntities")})}):null]}):null,o?t.jsxs(s.Flex,{direction:"row",gap:3,alignItems:"center",children:[t.jsx(s.Typography,{variant:"omega",textColor:"neutral600",children:c({id:i.getTranslation("homePage.lastSync")},{lastSync:new Date(o).toLocaleString()})}),d?t.jsx(s.Button,{variant:"secondary",onClick:()=>g(!0),disabled:a,children:c({id:i.getTranslation("homePage.getNewSnapshot")})}):null]}):null,d?t.jsx(we,{open:u,onClose:()=>g(!1),contentTypeUid:e}):null]})},nt=({canReadSettings:e})=>{const{formatMessage:n}=T.useIntl();return t.jsx(S.Alert,{title:n({id:i.getTranslation("homePage.alert.invalidLicense.title")}),variant:"danger",description:n({id:i.getTranslation(e?"homePage.alert.invalidLicense.description":"homePage.alert.invalidLicense.readOnlyDescription")}),action:e?t.jsx(s.Flex,{children:t.jsx(s.Link,{tag:K.Link,to:"/settings/xecp/about",children:n({id:i.getTranslation("homePage.alert.invalidLicense.linkText")})})}):void 0})},ot=({compareSchemasData:e,errorCompareSchemas:n})=>{const{formatMessage:o}=T.useIntl(),a=e&&!e?.isMatch,r=()=>o(a?{id:i.getTranslation("homePage.alert.schemaMismatch.title")}:{id:i.getTranslation("homePage.error")}),l=()=>{switch(!0){case a:return o({id:i.getTranslation("homePage.alert.schemaMismatch.description")});case!!n:return n;default:return o({id:i.getTranslation("homePage.somethingWentWrong")})}};return t.jsx(S.Alert,{title:r(),variant:"danger",children:l()})},st=({contentTypeUid:e,hasExistingSnapshot:n,unconfiguredRelationsError:o,isGetSnapshotDisabled:a=!1,canExecute:r,canReadSettings:l})=>{const{formatMessage:d}=T.useIntl(),[c,u]=j.useState(!1);return!n&&!o?t.jsxs(t.Fragment,{children:[t.jsx(s.EmptyStateLayout,{content:d({id:i.getTranslation(r?"homePage.alert.noSync.description":"homePage.alert.noSync.readOnlyDescription")}),action:r?t.jsx(s.Button,{onClick:()=>u(!0),disabled:a,children:d({id:i.getTranslation("homePage.alert.noSync.linkText")})}):void 0}),r?t.jsx(we,{open:c,onClose:()=>u(!1),contentTypeUid:e}):null]}):t.jsxs(t.Fragment,{children:[o?t.jsx(S.Alert,{title:d({id:i.getTranslation("homePage.alert.unconfiguredRelations.title")}),variant:"danger",action:l?t.jsx(s.Link,{tag:K.Link,to:"/settings/xecp/configuration",children:d({id:i.getTranslation("homePage.alert.unconfiguredRelations.linkText")})}):void 0,description:d({id:i.getTranslation(l?"homePage.alert.unconfiguredRelations.description":"homePage.alert.unconfiguredRelations.readOnlyDescription")},{relations:o.unconfiguredRelations.join(", ")})}):null,t.jsx(s.EmptyStateLayout,{content:d({id:i.getTranslation("homePage.emptyState")})})]})},he=e=>[e,...e.localizations??[]],ve=e=>(e??[]).flatMap(he),at=(e,n)=>{const o=n?.find(a=>a.documentId===e);return o?he(o):[]},rt=e=>{const n=e[0];return n?{...n,localizations:e.slice(1)}:null},te=(e,n)=>{if(!n)return e.uniqueKeyValue;const o=e?.[n];return typeof o=="string"||typeof o=="number"?String(o):e.uniqueKeyValue},H=e=>({documentId:e.documentId,locale:e.locale??"default"}),Q=(e,n)=>e.documentId===n.documentId&&e.locale===n.locale,V=(e,n)=>n.some(o=>Q(o,H(e))),it=e=>[...new Set(e.map(n=>n.documentId))],lt=(e,n)=>{if(e.length===0)return!1;const o=e.filter(a=>n.has(a)).length;return o===0?!1:o===e.length?!0:"indeterminate"},ct=(e,n)=>{const o=new Set(n);return new Set([...e].filter(a=>o.has(a)))},dt="homePage.missingUniqueKey",Y={single:"homePage.hint.missingUniqueKey.single",allLocales:"homePage.hint.missingUniqueKey.allLocales",someLocales:"homePage.hint.missingUniqueKey.someLocales"},B=(e,n)=>e!=="up_to_date"&&n!=="missing_unique_key",ut=e=>{switch(!0){case e.every(n=>n.warning==="missing_unique_key"):return"allLocales";case e.some(n=>n.warning==="missing_unique_key"):return"someLocales";default:return null}},ke=(e,n,o)=>{if(!e)return"homePage.tooltip.noExecutePermission";switch(!0){case n==="up_to_date":return"homePage.tooltip.upToDate";case o==="missing_unique_key":return Y.single;default:return null}},Me=(e,n)=>{if(!e)return"homePage.tooltip.noExecutePermission";switch(!0){case n.some(o=>B(o.status,o.warning)):return null;case n.every(o=>o.status==="up_to_date"):return"homePage.tooltip.allEntitiesUpToDate";case n.every(o=>o.warning==="missing_unique_key"):return Y.allLocales;default:return Y.someLocales}},ge=({checked:e,onCheckedChange:n,disable:o=!1,tooltipLabel:a=""})=>t.jsx("div",{onClick:r=>r.stopPropagation(),children:t.jsx(s.Tooltip,{label:o?a:"",align:"start",children:t.jsx(s.Checkbox,{checked:e,onCheckedChange:n,disabled:o})})}),ne=({locale:e})=>{const{formatMessage:n}=T.useIntl();return e==="default"?t.jsx(s.Badge,{variant:"neutral",children:n({id:i.getTranslation("homePage.promotionResults.locale.nonLocalized")})}):t.jsx(s.Badge,{variant:"neutral",children:e})},gt=e=>{switch(e){case"new":return"homePage.table.status.new";case"changed":return"homePage.table.status.changed";case"up_to_date":return"homePage.table.status.upToDate";default:return"homePage.table.status.new"}},mt=e=>{switch(e){case"new":return"success";case"changed":return"danger";case"up_to_date":return"neutral";default:return"success"}},Re=({status:e})=>{const{formatMessage:n}=T.useIntl();return t.jsx(s.Badge,{variant:mt(e),children:n({id:i.getTranslation(gt(e))})})},ht=({shouldShow:e,message:n,tooltipLabel:o})=>e?t.jsx(s.Tooltip,{label:o,align:"start",children:t.jsxs(s.Flex,{direction:"row",gap:1,alignItems:"center",children:[t.jsx(Z.WarningCircle,{fill:"warning500",width:20,height:20}),t.jsx(s.Typography,{variant:"pi",textColor:"warning500",children:n})]})}):null,oe=({uniqueKey:e,missingUniqueKeyScope:n,maxCharacters:o=40})=>{const{formatMessage:a}=T.useIntl();if(!n)return t.jsx(S.TruncatedTypography,{maxCharacters:o,text:e||"N/A",variant:"pi",textColor:"neutral600"});const r=a({id:i.getTranslation(dt)}),l=a({id:i.getTranslation(Y[n])}),d=t.jsx(ht,{shouldShow:!0,tooltipLabel:l,message:r});return n==="someLocales"&&e?t.jsxs(s.Flex,{direction:"row",gap:2,alignItems:"center",children:[t.jsx(S.TruncatedTypography,{maxCharacters:o,text:e,variant:"pi",textColor:"neutral600"}),d]}):d},Fe=({entryTitle:e,uniqueKey:n,missingUniqueKeyScope:o,locale:a,titleMaxCharacters:r=60,checked:l,onCheckedChange:d,checkboxDisabled:c=!1,checkboxTooltipLabel:u,status:g})=>{const h=t.jsx(S.TruncatedTypography,{maxCharacters:r,text:e,variant:"omega",fontWeight:"semiBold"});return t.jsxs(t.Fragment,{children:[t.jsxs(s.Flex,{direction:"row",gap:4,alignItems:"center",children:[t.jsx(ge,{checked:l,onCheckedChange:d,disable:c,tooltipLabel:u}),a?t.jsxs(s.Flex,{direction:"row",gap:2,alignItems:"center",children:[t.jsx(ne,{locale:a}),h]}):h,t.jsx(oe,{uniqueKey:n,missingUniqueKeyScope:o})]}),t.jsx(Re,{status:g})]})},pt=({entryTitle:e,uniqueKey:n,status:o,warning:a,locale:r,isChecked:l,onCheckItemChange:d,canExecute:c})=>{const{formatMessage:u}=T.useIntl(),g=!c||!B(o,a),h=ke(c,o,a);return t.jsx(s.Flex,{direction:"row",justifyContent:"space-between",alignItems:"center",background:"neutral0",style:{width:"100%",padding:"24px"},grow:1,gap:4,children:t.jsx(Fe,{entryTitle:e,uniqueKey:n,missingUniqueKeyScope:a==="missing_unique_key"?"single":null,locale:r,checked:l,onCheckedChange:d,checkboxDisabled:g,checkboxTooltipLabel:h?u({id:i.getTranslation(h)}):void 0,status:o})})},yt=({isAllCheckedInEntity:e,onCheckAllInEntity:n,entityWithLocalizations:o,selectedPromotions:a,onCheckItemChange:r,isIndeterminate:l,contentTypeMainField:d,canExecute:c})=>{const{formatMessage:u}=T.useIntl(),g=[{key:"checkbox"},{key:"locale",label:u({id:i.getTranslation("homePage.table.locale")})},{key:"entryTitle",label:u({id:i.getTranslation("homePage.table.entryTitle")})},{key:"key",label:u({id:i.getTranslation("homePage.table.key")})},{key:"status",label:u({id:i.getTranslation("homePage.table.status")})}],h=!o?.some(m=>B(m.status,m.warning)),y=Me(c,o??[]);return t.jsxs(s.Table,{colCount:g.length,rowCount:o?.length??0,children:[t.jsx(s.Thead,{children:t.jsx(s.Tr,{children:g.map(m=>t.jsx(s.Th,{children:m.key==="checkbox"?t.jsx(ge,{checked:l?"indeterminate":e,onCheckedChange:n,disable:h||!c,tooltipLabel:y?u({id:i.getTranslation(y)}):""}):t.jsx(s.Typography,{variant:"sigma",children:m.label})},m.key))})}),t.jsx(s.Tbody,{children:o?.map(m=>{const x=!c||!B(m.status,m.warning),p=ke(c,m.status,m.warning);return t.jsxs(s.Tr,{children:[t.jsx(s.Td,{children:t.jsx(ge,{checked:V(m,a),onCheckedChange:r(m),disable:x,tooltipLabel:p?u({id:i.getTranslation(p)}):""})}),t.jsx(s.Td,{children:m?.locale?t.jsx(ne,{locale:m.locale}):null}),t.jsx(s.Td,{children:t.jsx(S.TruncatedTypography,{maxCharacters:50,text:te(m,d)||""})}),t.jsx(s.Td,{children:t.jsx(oe,{uniqueKey:m?.uniqueKeyValue,missingUniqueKeyScope:m?.warning==="missing_unique_key"?"single":null})}),t.jsx(s.Td,{children:t.jsx(Re,{status:m?.status})})]},`${m.documentId}-${m.locale}`)})})]})},xt=me.default(s.Accordion.Trigger)`
2
+ width: 100%;
3
+ & > span:first-child {
4
+ width: 100%;
5
+ display: flex;
6
+ justify-content: space-between;
7
+ & > span {
8
+ width: 100%;
9
+ }
10
+ }
11
+ `,ft=({uniqueKey:e,entityWithLocalizations:n,entryTitle:o,selectedPromotions:a,setSelectedPromotions:r,onCheckItemChange:l,contentTypeMainField:d,onRememberEntityGroup:c,canExecute:u})=>{const{formatMessage:g}=T.useIntl(),h=n.filter(C=>B(C.status,C.warning)),y=C=>{r(P=>{const q=h.map(E=>H(E)),_=E=>n.some(F=>Q(E,H(F)));return C?(c?.(n),[...P.filter(F=>!_(F)),...q]):P.filter(E=>!_(E))})},m=n?.some(C=>V(C,a)),x=h.length>0&&h.every(C=>V(C,a)),p=h.length===0,v=Me(u,n),k=ut(n),R=(()=>{switch(!0){case n?.some(C=>C?.status==="new"):return"new";case n?.some(C=>C?.status==="changed"):return"changed";default:return"up_to_date"}})(),w=m&&!x;return t.jsx(s.Accordion.Root,{style:{width:"100%"},size:"M",children:t.jsxs(s.Accordion.Item,{value:`${o}-${e}`,children:[t.jsx(s.Accordion.Header,{children:t.jsx(xt,{caretPosition:"right",children:t.jsx(s.Flex,{direction:"row",justifyContent:"space-between",alignItems:"center",style:{width:"100%"},grow:1,gap:4,children:t.jsx(Fe,{entryTitle:o,uniqueKey:e,missingUniqueKeyScope:k,checked:w?"indeterminate":x,onCheckedChange:y,checkboxDisabled:p||!u,checkboxTooltipLabel:v?g({id:i.getTranslation(v)}):void 0,status:R})})})}),t.jsx(s.Accordion.Content,{children:t.jsx(yt,{isAllCheckedInEntity:x,onCheckAllInEntity:y,entityWithLocalizations:n,selectedPromotions:a,onCheckItemChange:l,isIndeterminate:w,contentTypeMainField:d,canExecute:u})})]})})},Tt=({entities:e,contentTypeMainField:n,selectedPromotions:o,setSelectedPromotions:a,onRememberEntityGroup:r,canExecute:l})=>{const d=u=>g=>h=>{const y=H(g);a(m=>h?m.some(x=>Q(x,y))?m:(r?.(u),[...m,y]):m.filter(x=>!Q(x,y)))},c=(u,g)=>{const h=te(u,n),y=u?.uniqueKeyValue||"";return g.length>1?t.jsx(ft,{uniqueKey:y,contentTypeMainField:n,entityWithLocalizations:g,entryTitle:h||"",selectedPromotions:o,setSelectedPromotions:a,onCheckItemChange:d(g),onRememberEntityGroup:r,canExecute:l}):t.jsx(pt,{entryTitle:h||"",uniqueKey:y,status:u?.status,warning:u?.warning,locale:u?.locale,isChecked:V(u,o),onCheckItemChange:d(g)(u),canExecute:l})};return t.jsx("div",{children:e?.map((u,g)=>{const h=he(u);return t.jsxs(j.Fragment,{children:[c(u,h),e?.length-1>g&&t.jsx(s.Divider,{})]},u?.documentId)})})},jt=()=>{const{get:e}=f.useFetchClient();return I.useQuery({queryKey:["content-types"],queryFn:async()=>{const{data:n}=await e("/content-type-builder/content-types");return n.data}})},Pt=(e,n)=>{const{get:o}=f.useFetchClient();return I.useQuery({queryKey:[J.SETTINGS_QUERY_KEY,"related-content-types",e],queryFn:async()=>{const{data:a}=await o(`/${i.URL_PREFIX}/promotion/related-content-types`,{params:{contentTypeUid:e}});return a},enabled:!!e&&n})},St=()=>{const{post:e}=f.useFetchClient(),n=I.useQueryClient();return I.useMutation({mutationFn:async o=>{const{data:a}=await e(`/${i.URL_PREFIX}/promotion`,o);return a},onSuccess:()=>{Ee(n)}})},Ct=(e,n)=>e.includes(n)?[n,...e.filter(o=>o!==n).sort()]:e.sort(),It=e=>e.filter(n=>B(n.status,n.warning)).map(n=>n.locale??"default"),bt=(e,n)=>e.length>0&&e.every(o=>n.includes(o)),Et=(e,n,o)=>{const a=new Map;for(const c of n??[])a.set(c.documentId,c);const r=ve(n),l=new Map;for(const c of e){const u=l.get(c.documentId)??[];u.push(c),l.set(c.documentId,u)}return[...new Set(e.map(c=>c.documentId))].map(c=>{const u=l.get(c)??[],g=a.get(c)??r.find(p=>p.documentId===c),h=g?.locale??"default",y=g??r.find(p=>u.some(v=>Q(v,{documentId:p.documentId,locale:p.locale??"default"}))),m=Ct(u.map(p=>p.locale),h),x=It(at(c,n));return{documentId:c,title:y?te(y,o)??c:c,locales:m,allLocalesSelected:bt(x,m),uniqueKey:y?.uniqueKeyValue??null}})},X=(e,n)=>n?.find(o=>o.uid===e)?.schema.displayName??e,wt=e=>{const n=[e.summary,...e.dependencyResults.map(r=>r.summary)],o=n.reduce((r,l)=>r+l.failed,0),a=n.reduce((r,l)=>r+l.total,0);return o===0?"success":o>=a?"failure":"partial"},vt=["en","default"],kt=e=>{for(const n of vt){const o=e.find(a=>a.locale===n);if(o?.uniqueKey!=null&&o.uniqueKey.length>0)return o.uniqueKey}return e.find(n=>n.uniqueKey!=null&&n.uniqueKey.length>0)?.uniqueKey??null},Mt=(e,n,o)=>{if(e.uniqueKey!=null&&e.uniqueKey.length>0)return e.uniqueKey;const a=e.documentId??e.documentKey,r=ve(n).find(l=>l.documentId===a);if(r){const l=te(r,o);if(l!=null&&String(l).length>0)return String(l)}return a},Rt=e=>{if(e.documentId!=null&&e.documentId.length>0)return e.documentId;const n=e.steps.find(a=>a.push.remoteDocumentId!=null&&a.push.remoteDocumentId.length>0)?.push.remoteDocumentId;if(n!=null&&n.length>0)return n;if(e.uniqueKey!=null&&e.uniqueKey.length>0)return e.uniqueKey;const o=e.groupKey.lastIndexOf("::");return o===-1?e.groupKey:e.groupKey.slice(0,o)},Ft={create:"created",update:"updated"},Le=e=>e.push.ok?e.push.skipped||e.action==="skip"?"skipped":Ft[e.action]:"failed",Lt=e=>{const n=e[0];return n?Le(n):"skipped"},qt=e=>{switch(e){case"failed":return"danger";case"skipped":return"neutral";case"updated":return"secondary";case"created":return"success";default:return"success"}},se=e=>{const n=new Map;for(const o of e){const a=o.snapshotKey,r=n.get(a)??[];r.push(o),n.set(a,r)}return Array.from(n.entries()).map(([o,a])=>{const r=a.some(d=>!d.push.ok),l=a[a.length-1];return{groupKey:o,documentId:l.documentId,locale:l.locale,uniqueKey:l.uniqueKey,outcome:r?"failed":Lt(a),steps:a,hasFailure:r}})},qe=e=>{const n=se(e),o=new Map;for(const a of n){const r=Rt(a),l=o.get(r)??[];l.push(a),o.set(r,l)}return Array.from(o.entries()).map(([a,r])=>{const l=r.sort((d,c)=>d.locale.localeCompare(c.locale));return{documentKey:a,documentId:l[0]?.documentId,uniqueKey:kt(l),localeEntries:l}})},_t=(e,n)=>qe(e).map(o=>({id:o.documentKey,title:Mt(o,n?.comparedEntities,n?.contentTypeMainField),entries:o.localeEntries.flatMap(a=>a.steps)})),Pe=e=>{const n=se(e);return{entityCount:n.length,created:n.filter(o=>o.outcome==="created").length,updated:n.filter(o=>o.outcome==="updated").length,skipped:n.filter(o=>o.outcome==="skipped").length,failed:n.filter(o=>o.outcome==="failed").length,locales:[...new Set(n.map(o=>o.locale))].sort()}},At=e=>{const n={total:0,created:0,updated:0,skipped:0,failed:0},o=se(e);for(const a of o){const r=a.steps[0];r&&(n.total+=1,n[Le(r)]+=1)}return n},Kt=(e,n)=>{const o=qe(e.entries),a=Pe(e.entries),r=[...new Set(e.selections.map(u=>u.locale))].sort(),l=e.dependencyResults.map(u=>{const g=Pe(u.entries);return{contentTypeUid:u.contentTypeUid,displayName:X(u.contentTypeUid,n),...g}}),d=a.entityCount+l.reduce((u,g)=>u+g.entityCount,0),c=a.failed+l.reduce((u,g)=>u+g.failed,0);return{outcome:wt(e),primaryDisplayName:X(e.contentTypeUid,n),primaryEntityCount:o.length,dependencySummaries:l,totalEntityCount:d,totalFailed:c,selectionLocales:r,dependencyContentTypeCount:e.dependencyResults.length,mediaSummary:e.mediaSummary}},_e=({entries:e,showFailuresOnly:n=!1})=>{const{formatMessage:o}=T.useIntl(),a=j.useMemo(()=>{const r=se(e);return n?r.filter(l=>l.hasFailure):r},[e,n]);return a.length===0?t.jsx(s.Typography,{variant:"omega",textColor:"neutral600",children:o({id:i.getTranslation(n?"homePage.promotionResults.noFailures":"homePage.promotionResults.noEntries")})}):t.jsxs(s.Table,{colCount:3,rowCount:a.length,children:[t.jsx(s.Thead,{children:t.jsxs(s.Tr,{children:[t.jsx(s.Th,{children:t.jsx(s.Typography,{variant:"sigma",children:o({id:i.getTranslation("homePage.table.locale")})})}),t.jsx(s.Th,{children:t.jsx(s.Typography,{variant:"sigma",children:o({id:i.getTranslation("homePage.table.key")})})}),t.jsx(s.Th,{children:t.jsx(s.Typography,{variant:"sigma",children:o({id:i.getTranslation("homePage.promotionResults.table.outcome")})})})]})}),t.jsx(s.Tbody,{children:a.map(r=>t.jsxs(s.Tr,{children:[t.jsx(s.Td,{children:t.jsx(ne,{locale:r.locale})}),t.jsx(s.Td,{children:t.jsx(oe,{uniqueKey:r.uniqueKey,maxCharacters:35})}),t.jsx(s.Td,{children:t.jsx(s.Badge,{variant:qt(r.outcome),children:o({id:i.getTranslation(`homePage.promotionResults.outcome.${r.outcome}`)})})})]},r.groupKey))})]})},Bt=({summary:e})=>{const{formatMessage:n}=T.useIntl(),o=[{key:"created",label:n({id:i.getTranslation("homePage.promotionResults.summary.created")}),value:e.created,variant:"success"},{key:"updated",label:n({id:i.getTranslation("homePage.promotionResults.summary.updated")}),value:e.updated,variant:"secondary"},...e.skipped>0?[{key:"skipped",label:n({id:i.getTranslation("homePage.promotionResults.summary.skipped")}),value:e.skipped,variant:"neutral"}]:[],...e.failed>0?[{key:"failed",label:n({id:i.getTranslation("homePage.promotionResults.summary.failed")}),value:e.failed,variant:"danger"}]:[]];return t.jsx(s.Flex,{gap:2,wrap:"wrap",children:o.map(a=>t.jsxs(s.Badge,{variant:a.variant,children:[a.label,": ",a.value]},a.key))})},Dt=me.default(s.Accordion.Trigger)`
12
+ width: 100%;
13
+ font-weight: ${({theme:e})=>e.fontWeights.regular};
14
+
15
+ & > span:first-child {
16
+ width: 100%;
17
+ display: flex;
18
+ justify-content: space-between;
19
+ font-weight: inherit;
20
+ & > span {
21
+ width: 100%;
22
+ font-weight: inherit;
23
+ }
24
+ }
25
+ `,Se=({items:e})=>t.jsx(s.Accordion.Root,{style:{width:"100%"},size:"S",children:e.map(n=>t.jsxs(s.Accordion.Item,{value:n.id,children:[t.jsx(s.Accordion.Header,{children:t.jsx(Dt,{caretPosition:"right",children:t.jsxs(s.Flex,{justifyContent:"space-between",alignItems:"center",width:"100%",gap:2,children:[t.jsx(S.TruncatedTypography,{maxCharacters:40,text:n.title,fontWeight:"regular"}),t.jsx(s.Box,{style:{flexShrink:0},children:t.jsx(Bt,{summary:At(n.entries)})})]})})}),t.jsx(s.Accordion.Content,{children:t.jsx(_e,{entries:n.entries})})]},n.id))}),Nt=({overview:e})=>{const{formatMessage:n}=T.useIntl(),o=e.dependencySummaries.map(a=>a.displayName);return t.jsxs(s.Flex,{direction:"column",alignItems:"stretch",gap:2,children:[t.jsx(s.Typography,{variant:"omega",children:n({id:i.getTranslation("homePage.promotionResults.header.summary")},{primaryCount:e.primaryEntityCount,dependencyCount:e.dependencyContentTypeCount,entityCount:e.totalEntityCount,failedCount:e.totalFailed})}),o.length>0&&t.jsx(s.Typography,{variant:"pi",textColor:"neutral600",children:n({id:i.getTranslation("homePage.promotionResults.header.dependencies")},{contentTypes:o.join(", ")})}),e.mediaSummary&&t.jsx(s.Typography,{variant:"pi",textColor:"neutral600",children:n({id:i.getTranslation("homePage.promotionResults.media.summary")},{uploaded:e.mediaSummary.uploaded,replaced:e.mediaSummary.replaced,failed:e.mediaSummary.failed})})]})},Ut=({result:e,contentTypes:n,comparedEntities:o,contentTypeMainField:a})=>{const{formatMessage:r}=T.useIntl(),l=Kt(e,n),d=l.outcome,c=[...e.entries,...e.dependencyResults.flatMap(p=>p.entries)],u=X(e.contentTypeUid,n),g=l.totalFailed>0,h=e.dependencyResults.length>0,y=_t(e.entries,{comparedEntities:o,contentTypeMainField:a}),m=e.dependencyResults.map(p=>({id:p.contentTypeUid,title:X(p.contentTypeUid,n),entries:p.entries})),x=()=>{switch(d){case"success":return t.jsx(S.Alert,{variant:"success",title:r({id:i.getTranslation("homePage.promotionResults.success.title")}),description:r({id:i.getTranslation("homePage.promotionResults.success.description")},{primaryCount:l.primaryEntityCount})});case"partial":return t.jsx(S.Alert,{variant:"warning",title:r({id:i.getTranslation("homePage.promotionResults.partialFailure.title")}),description:r({id:i.getTranslation("homePage.promotionResults.partialFailure.description")})});case"failure":return t.jsx(S.Alert,{variant:"danger",title:r({id:i.getTranslation("homePage.promotionResults.failure.title")}),description:r({id:i.getTranslation("homePage.promotionResults.failure.description")})})}};return t.jsxs(s.Flex,{direction:"column",alignItems:"stretch",gap:4,children:[x(),t.jsx(Nt,{overview:l}),g&&t.jsxs(s.Flex,{direction:"column",alignItems:"stretch",gap:2,children:[t.jsx(s.Typography,{variant:"delta",children:r({id:i.getTranslation("homePage.promotionResults.failures.title")})}),t.jsx(_e,{entries:c,showFailuresOnly:!0})]}),t.jsxs(s.Flex,{direction:"column",alignItems:"stretch",gap:2,children:[t.jsxs(s.Typography,{variant:"delta",children:[u,":"]}),t.jsx(Se,{items:y})]}),h&&t.jsxs(s.Flex,{direction:"column",alignItems:"stretch",gap:2,children:[t.jsx(s.Typography,{variant:"delta",children:r({id:i.getTranslation("homePage.promotionResults.dependencies.title")})}),t.jsx(Se,{items:m})]})]})},Ot=({previews:e,mediaDocumentIds:n,onToggleMediaDocument:o})=>{const{formatMessage:a}=T.useIntl();return e.length===0?null:t.jsxs(s.Table,{colCount:4,rowCount:e.length,children:[t.jsx(s.Thead,{children:t.jsxs(s.Tr,{children:[t.jsxs(s.Th,{children:[t.jsx(s.Typography,{variant:"sigma",children:a({id:i.getTranslation("homePage.modal.confirmPromotion.includeMedia")})}),t.jsx(s.Tooltip,{label:a({id:i.getTranslation("homePage.modal.confirmPromotion.tooltip")}),children:t.jsx(Z.Information,{style:{marginLeft:"4px"}})})]}),t.jsx(s.Th,{children:t.jsx(s.Typography,{variant:"sigma",children:a({id:i.getTranslation("homePage.table.entryTitle")})})}),t.jsx(s.Th,{children:t.jsx(s.Typography,{variant:"sigma",children:a({id:i.getTranslation("homePage.table.locale")})})}),t.jsx(s.Th,{children:t.jsx(s.Typography,{variant:"sigma",children:a({id:i.getTranslation("homePage.table.key")})})})]})}),t.jsx(s.Tbody,{children:e.map(r=>t.jsxs(s.Tr,{children:[t.jsx(s.Td,{children:t.jsx(s.Checkbox,{checked:n.has(r.documentId),onCheckedChange:l=>o(r.documentId,l===!0),"aria-label":a({id:i.getTranslation("homePage.modal.confirmPromotion.includeMediaForDocument")},{title:r.title})})}),t.jsx(s.Td,{children:t.jsx(S.TruncatedTypography,{maxCharacters:50,text:r.title})}),t.jsx(s.Td,{children:r.allLocalesSelected?t.jsx(s.Typography,{variant:"pi",children:a({id:i.getTranslation("homePage.modal.confirmPromotion.allLocalesSelected")})}):t.jsx(s.Flex,{gap:2,wrap:"wrap",children:r.locales.map(l=>t.jsx(ne,{locale:l},`${r.documentId}-${l}`))})}),t.jsx(s.Td,{children:t.jsx(oe,{uniqueKey:r.uniqueKey,maxCharacters:35})})]},r.documentId))})]})},Qt=({open:e,onClose:n,selectedPromotions:o,contentTypeUid:a,contentTypeMainField:r,comparedEntities:l,onPromoteComplete:d})=>{const{formatMessage:c}=T.useIntl(),{data:u}=jt(),{data:g}=Pt(a,e),[h,y]=j.useState(null),[m,x]=j.useState(()=>new Set),p=it(o),v=lt(p,m),k=m.size>0,{mutate:D,isPending:R,error:w,reset:C}=St(),P=()=>{y(null),x(new Set),C()};j.useEffect(()=>{x(b=>ct(b,p))},[p]);const q=g?.contentTypes.map(b=>b.displayName)??[],_=Et(o,l,r),E=()=>{P(),n()},F=b=>{x(b?new Set(p):new Set)},A=(b,re)=>{x(ie=>{const L=new Set(ie);return re?L.add(b):L.delete(b),L})},ae=()=>{D({selections:o,contentTypeUid:a,mediaDocumentIds:[...m]},{onSuccess:b=>{y(b),d?.(b)}})},N=h!=null;return t.jsx(W,{open:e,onClose:E,onSubmit:ae,title:c({id:i.getTranslation(N?"homePage.modal.promotionResults.title":"homePage.modal.confirmPromotion.title")}),confirmButtonText:c({id:i.getTranslation("homePage.modal.confirmPromotion.confirmButtonText")}),isConfirmButtonDisabled:R||!a||o.length===0,isConfirmButtonLoading:R,showConfirmButton:!N,fillMaxHeight:!0,children:N?t.jsx(Ut,{result:h,contentTypes:u,comparedEntities:l,contentTypeMainField:r}):t.jsxs(s.Flex,{direction:"column",gap:4,alignItems:"stretch",children:[t.jsx(s.Typography,{variant:"omega",children:c({id:i.getTranslation("homePage.modal.confirmPromotion.description")},{count:o.length})}),t.jsx(s.Checkbox,{checked:v,onCheckedChange:b=>F(b===!0),children:c({id:i.getTranslation("homePage.modal.confirmPromotion.includeMediaAll")})}),t.jsx(Ot,{previews:_,mediaDocumentIds:m,onToggleMediaDocument:A}),t.jsx(S.Alert,{variant:"default",title:c({id:i.getTranslation("homePage.promotionResults.scope.title")}),description:c({id:i.getTranslation("homePage.modal.confirmPromotion.localeScopeHint")})}),k&&t.jsx(S.Alert,{variant:"default",title:c({id:i.getTranslation("homePage.modal.confirmPromotion.mediaScopeHint.title")}),description:c({id:i.getTranslation("homePage.modal.confirmPromotion.mediaScopeHint.description")})}),q.length>0&&t.jsx(S.Alert,{variant:"warning",title:c({id:i.getTranslation("homePage.modal.confirmPromotion.relatedWarning.title")}),description:c({id:i.getTranslation("homePage.modal.confirmPromotion.relatedWarning.description")},{contentTypes:q.join(", ")})}),w&&t.jsx(s.Typography,{variant:"omega",textColor:"danger500",children:z(w,c)})]})})},$t=2500,Gt=5e3,Ht=e=>e==="running"?$t:e==="queued"?Gt:!1,Ae=(e,n=!0)=>{const{get:o}=f.useFetchClient(),a=I.useQueryClient(),r=j.useRef(void 0),l=I.useQuery({queryKey:O.list(e),queryFn:async()=>{const{data:d}=await o(`/${i.URL_PREFIX}/snapshot/sync/${e}/status`);return d},enabled:!!e&&n,refetchInterval:d=>Ht(d.state.data?.status),refetchOnWindowFocus:!0});return j.useEffect(()=>{if(!e)return;const d=r.current,c=l.data?.status;(d==="running"&&c!=="running"||d==="queued"&&c==="running")&&ee(a,e),r.current=c},[l.data?.status,e,a]),l},Vt=({syncStatus:e,isSyncInProgressFromComparison:n})=>{const o=e?.status;switch(!0){case(o==="running"||n):return"in_progress";case o==="queued":return"queued";case o==="cancelled":return"cancelled";case o==="failed":return"failed";default:return"none"}},Yt=me.default(s.ProgressBar)`
26
+ background-color: ${({theme:e})=>e.colors.neutral600};
27
+ & > div {
28
+ background-color: ${({theme:e})=>e.colors.neutral150};
29
+ }
30
+ `,ue=({lastProcessedPage:e,totalPages:n})=>{const{formatMessage:o}=T.useIntl(),a=(r,l)=>Math.round(Number(r)/Number(l)*100);return t.jsxs(s.Flex,{direction:"row",gap:2,alignItems:"center",children:[t.jsx(s.Typography,{variant:"omega",children:o({id:i.getTranslation("homePage.alert.syncInProgress.progress")},{currentPage:e,totalPages:n})}),t.jsx(Yt,{value:a(e,n)})]})},Xt=({view:e,syncStatus:n,onRefresh:o,onCancel:a,onResume:r,canExecute:l})=>{const{formatMessage:d}=T.useIntl();if(e==="none")return null;const c=We(n?.error,d),g=(()=>{switch(e){case"queued":return{title:d({id:i.getTranslation("homePage.alert.syncQueued.title")}),description:t.jsxs(s.Flex,{direction:"column",gap:2,alignItems:"flex-start",children:[t.jsx(s.Typography,{variant:"omega",children:d({id:i.getTranslation("homePage.alert.syncQueued.description")})}),n?.queuePosition!=null?t.jsx(s.Typography,{variant:"omega",textColor:"neutral600",children:d({id:i.getTranslation("homePage.alert.syncQueued.position")},{position:n.queuePosition})}):null,n?.queuedAt?t.jsx(s.Typography,{variant:"omega",textColor:"neutral600",children:d({id:i.getTranslation("homePage.alert.syncQueued.queuedAt")},{queuedAt:new Date(n.queuedAt).toLocaleString()})}):null]}),action:t.jsx(s.Button,{onClick:o,variant:"secondary",children:d({id:i.getTranslation("homePage.alert.syncQueued.linkText")})}),variant:"default"};case"in_progress":return{title:d({id:i.getTranslation("homePage.alert.syncInProgress.title")}),description:t.jsxs(s.Flex,{direction:"column",gap:2,alignItems:"flex-start",children:[t.jsx(s.Typography,{variant:"omega",children:d({id:i.getTranslation("homePage.alert.syncInProgress.description")})}),t.jsx(ue,{lastProcessedPage:n?.lastProcessedPage??0,totalPages:n?.totalPages??1})]}),action:t.jsxs(s.Flex,{direction:"row",gap:2,alignItems:"center",children:[t.jsx(s.Button,{onClick:o,variant:"secondary",children:d({id:i.getTranslation("homePage.alert.syncInProgress.linkText")})}),l?t.jsx(s.Button,{variant:"danger-light",onClick:a,children:d({id:i.getTranslation("common.button.cancel")})}):null]}),variant:"default"};case"cancelled":return{title:d({id:i.getTranslation("homePage.alert.resumeSync.title")}),description:t.jsxs(s.Flex,{direction:"column",gap:2,alignItems:"flex-start",children:[t.jsx(s.Typography,{variant:"omega",children:d({id:i.getTranslation("homePage.alert.resumeSync.description")})}),t.jsx(ue,{lastProcessedPage:n?.lastProcessedPage??0,totalPages:n?.totalPages??1})]}),action:l?t.jsx(s.Button,{onClick:r,variant:"secondary",children:d({id:i.getTranslation("homePage.alert.resumeSync.linkText")})}):void 0,variant:"warning"};case"failed":return{title:d({id:i.getTranslation("homePage.alert.syncFailed.title")}),description:t.jsxs(s.Flex,{direction:"column",gap:2,alignItems:"flex-start",children:[t.jsx(s.Typography,{variant:"omega",children:d({id:i.getTranslation("homePage.alert.syncFailed.description")})}),c?t.jsx(s.Typography,{variant:"omega",textColor:"danger500",children:c}):null,t.jsx(ue,{lastProcessedPage:n?.lastProcessedPage??0,totalPages:n?.totalPages??1})]}),action:l?t.jsx(s.Button,{onClick:r,variant:"secondary",children:d({id:i.getTranslation("homePage.alert.syncFailed.linkText")})}):void 0,variant:"danger"};default:return e}})();return t.jsx(S.Alert,{title:g?.title,description:g?.description,action:g?.action,variant:g?.variant})},Jt=()=>{const{post:e}=f.useFetchClient(),n=I.useQueryClient();return I.useMutation({mutationFn:async()=>await e(`/${i.URL_PREFIX}/snapshot/sync/cancel`),onSuccess:()=>{ee(n)}})},Zt=({open:e,onClose:n})=>{const{formatMessage:o}=T.useIntl(),{mutate:a,isPending:r,error:l,reset:d}=Jt(),c=()=>{n(),d()};return t.jsx(W,{open:e,onClose:c,onSubmit:()=>a(void 0,{onSuccess:c}),title:t.jsxs(s.Flex,{direction:"row",gap:2,alignItems:"center",children:[t.jsx(Z.WarningCircle,{fill:"danger500",width:20,height:20}),o({id:i.getTranslation("homePage.modal.cancelSync.title")})]}),confirmButtonText:o({id:i.getTranslation("homePage.modal.cancelSync.confirmButtonText")}),isConfirmButtonLoading:r,children:t.jsxs(s.Flex,{direction:"column",gap:4,alignItems:"stretch",children:[t.jsx(s.Typography,{variant:"omega",children:o({id:i.getTranslation("homePage.modal.cancelSync.description")})}),l&&t.jsx(s.Typography,{variant:"omega",textColor:"danger500",children:z(l,o)})]})})},Wt=()=>{const{post:e}=f.useFetchClient(),n=I.useQueryClient();return I.useMutation({mutationFn:async o=>await e(`/${i.URL_PREFIX}/snapshot/sync/${o}/resume`),onSuccess:()=>{ee(n)}})},zt=({open:e,onClose:n,jobDocumentId:o})=>{const{formatMessage:a}=T.useIntl(),{mutate:r,isPending:l,error:d,reset:c}=Wt(),u=()=>{n(),c()};return t.jsx(W,{open:e,onClose:u,onSubmit:()=>r(o,{onSuccess:u}),title:a({id:i.getTranslation("homePage.modal.resumeSync.title")}),confirmButtonText:a({id:i.getTranslation("homePage.modal.resumeSync.confirmButtonText")}),isConfirmButtonDisabled:!o,isConfirmButtonLoading:l,children:t.jsxs(s.Flex,{direction:"column",gap:4,alignItems:"stretch",children:[t.jsx(s.Typography,{variant:"omega",children:a({id:i.getTranslation("homePage.modal.resumeSync.description")})}),d&&t.jsx(s.Typography,{variant:"omega",textColor:"danger500",children:z(d,a)})]})})},en=({contentTypeUid:e,isSyncInProgressFromComparison:n,canExecute:o})=>{const[a,r]=j.useState(!1),[l,d]=j.useState(!1),{data:c,refetch:u}=Ae(e),g=Vt({syncStatus:c,isSyncInProgressFromComparison:n}),h=c?.jobDocumentId??"";return t.jsxs(t.Fragment,{children:[t.jsx(Xt,{view:g,syncStatus:c,onRefresh:()=>u(),onCancel:()=>r(!0),onResume:()=>d(!0),canExecute:o}),o?t.jsxs(t.Fragment,{children:[t.jsx(Zt,{open:a,onClose:()=>r(!1)}),t.jsx(zt,{open:l,onClose:()=>d(!1),jobDocumentId:h})]}):null]})},tn=e=>{const{get:n}=f.useFetchClient();return I.useQuery({queryKey:["compare-schemas"],queryFn:async()=>{const{data:o}=await n(`/${i.URL_PREFIX}/compare-schemas`);return o},enabled:e})},nn=(e=!0)=>{const{get:n}=f.useFetchClient();return I.useQuery({queryKey:[J.PROMOTABLE_CONTENT_TYPES_QUERY_KEY],enabled:e,queryFn:async()=>{const{data:o}=await n(`/${i.URL_PREFIX}/promotion/promotable-content-types`);return o.contentTypes}})},on=(e,n)=>{const o=new Set((e??[]).map(r=>r.documentId)),a=[...n.entries()].filter(([r])=>!o.has(r)).map(([,r])=>rt(r)).filter(r=>r!=null);return[...e??[],...a]},sn=(e,n)=>{const o=new Set(n.map(r=>r.documentId)),a=new Map;for(const[r,l]of e)o.has(r)&&a.set(r,l);return a},an=(e,n)=>{const o=n[0]?.documentId;if(!o)return e;const a=new Map(e);return a.set(o,n),a},rn=e=>{const[n,o]=j.useState([]),[a,r]=j.useState(()=>new Map),l=j.useCallback(()=>{o([]),r(new Map)},[]);j.useEffect(()=>{r(u=>sn(u,n))},[n]);const d=j.useCallback(u=>{r(g=>an(g,u))},[]),c=j.useMemo(()=>on(e,a),[e,a]);return{selectedPromotions:n,setSelectedPromotions:o,clear:l,rememberEntityGroup:d,entitiesForPreview:c}},ln=()=>{const{formatMessage:e}=T.useIntl(),{isLoading:n,allowedActions:{canExecute:o=!1,canRead:a=!1}}=f.useRBAC([...i.PERMISSIONS.promotionExecute,...i.PERMISSIONS.settingsRead]),[{query:r},l]=f.useQueryParams(),d=j.useRef(!1),c=G.default.object({page:G.default.coerce.number().optional().default(1),pageSize:G.default.coerce.number().optional().default(10),uid:G.default.string().optional()}).parse(r),[u,g]=j.useState(!1),{data:h,isLoading:y,isError:m}=Ye(),x=!y&&!m&&!!h?.active,p=!y&&(m||!h?.active),{data:v}=Ae(c.uid??"",x),{data:k,isSuccess:D,isLoading:R}=nn(x),w=D&&(k?.length??0)>0,C=k?.map(M=>({key:M.uid,value:M.uid,label:M.displayName}))??[],{data:P,isLoading:q,error:_}=ze({uid:c.uid,page:c.page,pageSize:c.pageSize,enabled:x}),{selectedPromotions:E,setSelectedPromotions:F,clear:A,rememberEntityGroup:ae,entitiesForPreview:N}=rn(P?.results),b=M=>{d.current=!1,l({...r,page:1,pageSize:10,uid:M}),A()},re=()=>{d.current=!0,l({...r,page:1,pageSize:10,uid:void 0}),A()},ie=()=>{g(!1),A()},{data:L,isLoading:U,error:pe}=tn(x&&w),ye=P?.mainField,Ke=P?.maxDepthReached,le=P?.errors,Be=le?.type==="unconfigured_relations"?le:void 0,ce=le?.type==="sync_in_progress",de=ce||v?.status==="running",$=!p&&!U&&(!!pe||!!L&&!L?.isMatch),xe=!o||y||p||U||$||ce||v?.status==="running"||v?.status==="queued",De=!!c.uid&&q,Ne=()=>{switch(!0){case(R||De):return t.jsx(s.Loader,{});case(D&&!w):return t.jsx(S.Alert,{title:e({id:i.getTranslation("homePage.alert.configurationNeeded.title")}),description:e({id:i.getTranslation(a?"homePage.alert.configurationNeeded.description":"homePage.alert.configurationNeeded.readOnlyDescription")}),action:a?t.jsx(s.Link,{tag:K.Link,to:"/settings/xecp/configuration",children:e({id:i.getTranslation("homePage.alert.configurationNeeded.linkText")})}):void 0,variant:"danger"});case de:return t.jsx(s.EmptyStateLayout,{content:e({id:i.getTranslation("homePage.alert.syncInProgress.contentUnavailable")})});case(P?.results&&P?.results?.length>0):return t.jsxs(t.Fragment,{children:[Ke&&t.jsx(S.Alert,{title:e({id:i.getTranslation("homePage.alert.maxDepthExceeded.title")}),variant:"warning",description:e({id:i.getTranslation("homePage.alert.maxDepthExceeded.description")})}),t.jsx(Tt,{entities:P?.results,contentTypeMainField:ye,selectedPromotions:E,setSelectedPromotions:F,onRememberEntityGroup:ae,canExecute:o&&!p})]});case!!_:return t.jsx(s.EmptyStateLayout,{icon:t.jsx(Z.WarningCircle,{width:24,height:24}),content:e({id:i.getTranslation("homePage.errorLoadingEntities")})});case(P?.results&&P?.results?.length===0):return t.jsx(st,{contentTypeUid:c.uid??"",hasExistingSnapshot:P?.snapshot?.exists??!1,unconfiguredRelationsError:Be,isGetSnapshotDisabled:xe,canExecute:o&&!p,canReadSettings:a});default:return t.jsx(s.EmptyStateLayout,{content:e({id:i.getTranslation("homePage.youNeedToSelectAContentTypeToSeeTheEntities")})})}},fe=P?.snapshot?.exists??!1,Ue=!de&&fe&&P?.pagination&&P?.pagination?.pageCount>0,Oe=!o||y||p||U||!w||$||!c.uid||E.length===0||de,Qe=R||y||U||p||$||!w,$e=()=>{switch(!0){case y:return t.jsxs(s.Flex,{gap:2,alignItems:"center",children:[t.jsx(s.Loader,{small:!0}),t.jsx(s.Typography,{variant:"omega",children:e({id:i.getTranslation("homePage.verifyingLicense")})})]});case p:return t.jsx(nt,{canReadSettings:a});case U:return t.jsxs(s.Flex,{gap:2,alignItems:"center",children:[t.jsx(s.Loader,{small:!0}),t.jsx(s.Typography,{variant:"omega",children:e({id:i.getTranslation("homePage.verifyingSchemas")})})]});case $:return t.jsx(ot,{compareSchemasData:L,errorCompareSchemas:pe?.message});default:return null}},Te=d.current||!!c.uid||!w;return j.useEffect(()=>{if(Te)return;const M=k?.[0]?.uid;M&&l({...r,uid:M,page:1,pageSize:10})},[Te,k,r,l]),n?t.jsx(f.Page.Loading,{}):t.jsxs(t.Fragment,{children:[t.jsx(f.Page.Title,{children:e({id:i.getTranslation("homePage.title")})}),t.jsxs(f.Page.Main,{children:[t.jsx(f.Layouts.Header,{title:e({id:i.getTranslation("homePage.title")}),primaryAction:o?t.jsx(s.Button,{disabled:Oe,onClick:()=>g(!0),children:e({id:i.getTranslation("homePage.promoteContent")})}):null}),t.jsx(f.Layouts.Content,{children:t.jsxs(s.Flex,{direction:"column",alignItems:"stretch",gap:4,children:[$e(),t.jsx(s.Flex,{children:t.jsx(Xe,{name:"contentType",placeholder:e({id:i.getTranslation("homePage.selectContentType")}),onClear:re,onChange:b,options:C,value:c.uid,disabled:Qe})}),c?.uid&&!p?t.jsxs(t.Fragment,{children:[t.jsx(en,{contentTypeUid:c.uid,isSyncInProgressFromComparison:ce,canExecute:o&&!p}),t.jsx(tt,{contentTypeUid:c.uid,selectedPromotionsLength:E.length,syncedAt:P?.snapshot?.syncedAt??null,isGetSnapshotDisabled:xe,hasSnapshot:fe,clearSelectedPromotions:A,canExecute:o&&!p})]}):null,p?null:Ne(),Ue&&!p?t.jsxs(f.Pagination.Root,{total:P?.pagination?.total||0,pageCount:P?.pagination?.pageCount||0,children:[t.jsx(f.Pagination.PageSize,{}),t.jsx(f.Pagination.Links,{})]}):null]})})]}),o&&!p&&u?t.jsx(Qt,{open:u,onClose:ie,selectedPromotions:E,contentTypeUid:c.uid??"",contentTypeMainField:ye,comparedEntities:N}):null]})},cn=()=>t.jsx(f.Page.Protect,{permissions:[...i.PERMISSIONS.promotionRead],children:t.jsx(ln,{})}),dn=()=>t.jsx(J.QueryProvider,{children:t.jsxs(K.Routes,{children:[t.jsx(K.Route,{index:!0,element:t.jsx(cn,{})}),t.jsx(K.Route,{path:"*",element:t.jsx(f.Page.Error,{})})]})});exports.default=dn;