@itwin/manage-versions-react
Advanced tools
Comparing version 1.4.0 to 2.0.0
@@ -11,3 +11,3 @@ import React from "react"; | ||
}; | ||
export declare const ConfigProvider: (props: ConfigProviderProps) => JSX.Element; | ||
export declare const ConfigProvider: (props: ConfigProviderProps) => React.JSX.Element; | ||
export declare const useConfig: () => { | ||
@@ -14,0 +14,0 @@ accessToken: string; |
@@ -1,2 +0,2 @@ | ||
/// <reference types="react" /> | ||
import React from "react"; | ||
export declare type MenuAction = { | ||
@@ -12,2 +12,2 @@ icon?: JSX.Element; | ||
} | ||
export declare const ContextMenu: ({ menuActions }: ContextMenuProps) => JSX.Element; | ||
export declare const ContextMenu: ({ menuActions }: ContextMenuProps) => React.JSX.Element; |
@@ -1,3 +0,3 @@ | ||
/// <reference types="react" /> | ||
import "./CreateVersionModal.scss"; | ||
import React from "react"; | ||
import { Changeset, NamedVersion } from "../../../models"; | ||
@@ -10,2 +10,2 @@ export declare type CreateVersionModalProps = { | ||
}; | ||
export declare const CreateVersionModal: (props: CreateVersionModalProps) => JSX.Element; | ||
export declare const CreateVersionModal: (props: CreateVersionModalProps) => React.JSX.Element; |
@@ -1,2 +0,2 @@ | ||
/// <reference types="react" /> | ||
import React from "react"; | ||
import { NamedVersion } from "../../../models"; | ||
@@ -8,2 +8,2 @@ export declare type UpdateVersionModalProps = { | ||
}; | ||
export declare const UpdateVersionModal: (props: UpdateVersionModalProps) => JSX.Element; | ||
export declare const UpdateVersionModal: (props: UpdateVersionModalProps) => React.JSX.Element; |
@@ -13,2 +13,2 @@ import "./VersionModal.scss"; | ||
}; | ||
export declare const VersionModal: (props: VersionModalProps) => JSX.Element; | ||
export declare const VersionModal: (props: VersionModalProps) => React.JSX.Element; |
@@ -10,2 +10,2 @@ import "./ChangesetInformationPanel.scss"; | ||
} | ||
export declare const ChangesetInformationPanel: (props: ChangesetInfoPanelProps) => JSX.Element; | ||
export declare const ChangesetInformationPanel: (props: ChangesetInfoPanelProps) => React.JSX.Element; |
@@ -1,3 +0,3 @@ | ||
/// <reference types="react" /> | ||
import "./ChangesTab.scss"; | ||
import React from "react"; | ||
import { Changeset, NamedVersion } from "../../../models"; | ||
@@ -12,3 +12,3 @@ import { RequestStatus } from "../types"; | ||
}; | ||
declare const ChangesTab: (props: ChangesTabProps) => JSX.Element; | ||
declare const ChangesTab: (props: ChangesTabProps) => React.JSX.Element; | ||
export default ChangesTab; |
@@ -1,2 +0,2 @@ | ||
/// <reference types="react" /> | ||
import React from "react"; | ||
import { NamedVersion } from "../../models"; | ||
@@ -29,2 +29,2 @@ import { ApiOverrides, LogFunc, ManageVersionsStringOverrides } from "./types"; | ||
} | ||
export declare const ManageVersions: (props: ManageVersionsProps) => JSX.Element; | ||
export declare const ManageVersions: (props: ManageVersionsProps) => React.JSX.Element; |
@@ -1,3 +0,3 @@ | ||
/// <reference types="react" /> | ||
import "./VersionsTab.scss"; | ||
import React from "react"; | ||
import { ChangesetClient } from "../../../clients/changesetClient"; | ||
@@ -15,3 +15,3 @@ import { Changeset, NamedVersion, VersionTableData } from "../../../models"; | ||
}; | ||
declare const VersionsTab: (props: VersionsTabProps) => JSX.Element; | ||
declare const VersionsTab: (props: VersionsTabProps) => React.JSX.Element; | ||
export default VersionsTab; |
@@ -1,1 +0,1 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@itwin/itwinui-react"),t=require("react"),a=require("@itwin/itwinui-icons-react");function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var s,i=n(t);!function(e){e.Authorization="Authorization",e.ContentType="Content-Type",e.Prefer="Prefer",e.Accept="Accept"}(s||(s={}));class r extends Error{constructor(e,t){super(e?.message),this.code=e?.code,this.statusCode=t}}const o={year:"numeric",month:"short",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!0};const l=e=>e.toLocaleDateString([...navigator.languages],o),d={title:"Change #",createdBy:"Created By",createdDate:"Date Created",application:"Application",connectionAttributes:"Connection Attributes",changedFiles:"Changed Files",noValue:"N/A"};class c{constructor(e,t){this._errorMessagePrefix="@itwin/manage-versions-react",this._defaultErrorMessage="HTTP error without a message.",this._token=e,this._log=t}async get(e,t){const a={method:"GET",url:e,headers:{...t?.headers},signal:t?.abortController?.signal};return this.makeRequest(a)}async post(e,t,a){const n={method:"POST",url:e,headers:{...a?.headers},body:t,signal:a?.abortController?.signal};return this.makeRequest(n)}async patch(e,t,a){const n={method:"PATCH",url:e,headers:{...a?.headers},body:t,signal:a?.abortController?.signal};return this.makeRequest(n)}async delete(e,t){const a={method:"DELETE",url:e,headers:{...t?.headers},signal:t?.abortController?.signal};return this.makeRequest(a)}async makeRequest(e){this.prepareHeaders(e);try{const t=await fetch(e.url,{method:e.method,headers:e.headers,body:e.body?JSON.stringify(e.body):void 0,signal:e?.signal}),a=await t.json();if(!t.ok)throw new r(a?.error,t.status);return a}catch(t){throw this.logError(t,e),t}}prepareHeaders(e){e.headers={[s.Authorization]:this._token,[s.Accept]:"application/vnd.bentley.itwin-platform.v2+json",[s.ContentType]:"application/json",...e.headers}}logError(e,t){this._log?.(`${this._errorMessagePrefix} - ${e.message||this._defaultErrorMessage}`,{request:this.getRequestToLog(t),error:e})}getRequestToLog(e){const t={...e.headers};return delete t[s.Authorization],{headers:t,url:e.url,method:e.method}}}class u{static getBaseUrl(e){return`https://${e?`${e}-`:""}api.bentley.com`}static buildVersionsUrl(e,t,a){return`${this.getBaseUrl(a)}/imodels/${e}/namedversions${t?`/${t}`:""}`}static buildChangesetUrl(e,t){return`${this.getBaseUrl(t)}/imodels/${e}/changesets`}static buildGetUsersUrl(e,t){return`${this.getBaseUrl(t)}/imodels/${e}/users`}}u.getQuery=e=>{const t=Object.entries(e).filter((([e,t])=>!!t)).map((([e,t])=>"lastIndex"===e?`${e}=${t}`:`$${e}=${t}`)).join("&");return t?`?${t}`:""};class m{constructor(e,t,a){this._http=new c(e,a),this._serverEnvironmentPrefix=t}async get(e,t={}){return this._http.get(`${u.buildChangesetUrl(e,this._serverEnvironmentPrefix)}${u.getQuery({orderBy:"index+desc",...t})}`,{headers:{[s.Prefer]:"return=representation",[s.Accept]:"application/vnd.bentley.itwin-platform.v2+json"}}).then((e=>e.changesets))}async getUsers(e){return this._http.get(`${u.buildGetUsersUrl(e,this._serverEnvironmentPrefix)}`,{headers:{[s.Prefer]:"return=representation",[s.Accept]:"application/vnd.bentley.itwin-platform.v2+json"}}).then((e=>e.users))}async getChangesetCheckpoint(e,t,a={}){const n=`${u.buildChangesetUrl(e,this._serverEnvironmentPrefix)}/${t}/checkpoint${u.getQuery(a)}`;return this._http.get(n,{headers:{[s.Accept]:"application/vnd.bentley.itwin-platform.v2+json"}}).then((e=>e.checkpoint))}}class g{constructor(e,t,a){this._http=new c(e,a),this._serverEnvironmentPrefix=t}async get(e,t={}){return this._http.get(`${u.buildVersionsUrl(e,void 0,this._serverEnvironmentPrefix)}${u.getQuery(t)}`,{headers:{[s.Prefer]:"return=representation",[s.Accept]:"application/vnd.bentley.itwin-platform.v2+json"}}).then((e=>e.namedVersions))}async create(e,t){return this._http.post(u.buildVersionsUrl(e,void 0,this._serverEnvironmentPrefix),t).then((e=>e.namedVersion))}async update(e,t,a){return this._http.patch(u.buildVersionsUrl(e,t,this._serverEnvironmentPrefix),a).then((e=>e.namedVersion))}}const f=i.default.createContext(void 0),h=e=>{const{children:t,...a}=e;return i.default.createElement(f.Provider,{value:a},t)},p=()=>{const e=i.default.useContext(f);if(void 0===e)throw new Error("useConfig must be used within a ConfigContext");return e};function v(e,t){void 0===t&&(t={});var a=t.insertAt;if(e&&"undefined"!=typeof document){var n=document.head||document.getElementsByTagName("head")[0],s=document.createElement("style");s.type="text/css","top"===a&&n.firstChild?n.insertBefore(s,n.firstChild):n.appendChild(s),s.styleSheet?s.styleSheet.cssText=e:s.appendChild(document.createTextNode(e))}}v(".iac-changes-table .iui-table-body .iui-table-cell{word-break:break-word}.iac-changes-table .iac-create-version-icon-hidden{visibility:hidden}.iac-changes-table .iac-changes-tab-actions{gap:var(--iui-size-2xs)}");v(".iac-additional-info{display:flex;justify-content:space-between;padding:var(--iui-size-s);background-color:var(--iui-color-background-backdrop)}.iac-additional-info span{flex-shrink:0}.iac-additional-info span:not(:last-child){margin-right:var(--iui-size-m)}.iac-additional-info .iac-cell-ellipsis{white-space:nowrap;overflow:hidden;text-overflow:ellipsis;flex-shrink:1}");v(".iac-version-modal .iui-modal-dialog{max-width:min(600px,50%)}.iac-version-modal-overlay{position:fixed;z-index:99999;height:100vh;width:100vw;top:0;left:0}.iac-version-modal .iui-input-container{margin-bottom:var(--iui-size-s)}");const C=t=>{const{initialVersion:a,isLoading:n,title:s,actionName:r,onClose:o,onActionClick:l,children:d}=t,{stringsOverrides:c}=p(),[u,m]=i.default.useState({name:a?.name??"",description:a?.description??""}),g=e=>{const t=e.target.name,a=e.target.value;m((e=>({...e,[t]:a??""})))},f=e=>e.length<=255;return i.default.createElement(i.default.Fragment,null,i.default.createElement(e.Modal,{title:s,isOpen:!0,onClose:o,className:"iac-version-modal"},i.default.createElement(e.LabeledInput,{setFocus:!0,name:"name",label:c.name,onChange:g,value:u.name,status:f(u.name)?void 0:"negative",message:f(u.name)?void 0:c.messageValueTooLong.replace("{{length}}",255..toString()),required:!0,autoComplete:"off"}),i.default.createElement(e.LabeledTextarea,{name:"description",label:c.description,onChange:g,value:u.description,status:f(u.description)?void 0:"negative",message:f(u.description)?void 0:c.messageValueTooLong.replace("{{length}}",255..toString()),rows:3,autoComplete:"off"}),d,i.default.createElement(e.ModalButtonBar,null,i.default.createElement(e.Button,{styleType:"high-visibility",onClick:()=>l(u.name,u.description),disabled:!(u.name&&(u.name!==a?.name||u.description!==a?.description)&&f(u.name)&&f(u.description))},r),i.default.createElement(e.Button,{onClick:o},c.cancel)),n&&i.default.createElement("div",{className:"iui-progress-indicator-overlay"},i.default.createElement(e.ProgressRadial,{indeterminate:!0}))),n&&i.default.createElement("div",{className:"iac-version-modal-overlay"}))},b=t=>{const{latestVersion:a,changeset:n,onClose:s,onCreate:r}=t,{accessToken:o,imodelId:d,apiOverrides:c,stringsOverrides:u,log:m}=p(),[f,h]=i.default.useState(!1),v=i.default.useMemo((()=>new g(o,c?.serverEnvironmentPrefix,m)),[o,c?.serverEnvironmentPrefix,m]);return i.default.createElement(C,{title:u.createNamedVersion,actionName:u.create,isLoading:f,onClose:s,onActionClick:(t,a)=>{h(!0),e.toaster.closeAll(),v.create(d,{name:t,description:a,changeSetId:n.id}).then((()=>{h(!1),r(),e.toaster.positive(u.messageVersionCreated.replace("{{name}}",t),{hasCloseButton:!0})})).catch((t=>{h(!1),e.toaster.negative((e=>{switch(e){case"NamedVersionExists":return u.messageVersionNameExists;case"InsufficientPermissions":return u.messageInsufficientPermissionsToCreateVersion;default:return u.messageCouldNotCreateVersion}})(t.code),{hasCloseButton:!0})}))}},i.default.createElement("div",{className:"iui-input-container"},i.default.createElement("div",{className:"iui-label"},"Latest included change"),i.default.createElement("div",{className:"iac-additional-info"},i.default.createElement("span",null,"#",n.index),i.default.createElement("span",null,l(new Date(n.pushDateTime))))),a&&i.default.createElement("div",{className:"iui-input-container"},i.default.createElement("div",{className:"iui-label"},"Latest Named Version"),i.default.createElement("div",{className:"iac-additional-info"},i.default.createElement("span",{className:"iac-cell-ellipsis"},a.name),i.default.createElement("span",null,l(new Date(a.createdDateTime))))))};v(".iac-info-panel{width:400px;min-width:400px}.iac-info-panel .iac-info-panel-body .iac-info-panel-container{padding:var(--iui-size-xs)}.iac-info-panel .iac-info-panel-body .iac-info-panel-container+div{border-top:1px solid var(--iui-color-border-subtle)}.iac-info-panel .iac-info-panel-body .iac-info-panel-details{padding:var(--iui-size-xs);display:flex;flex-direction:row;align-items:flex-start;justify-content:space-between}.iac-info-panel .iac-info-panel-body .iac-info-panel-details .iac-info-panel-data-value{flex:2;min-width:50%}.iac-info-panel .iac-info-panel-body .iac-info-panel-property{display:flex;flex:1;margin-right:var(--iui-size-m);justify-content:right;color:var(--iui-color-text-disabled)}");const E=t=>{const{changeset:a,onClose:n,stringOverrides:s=d}=t,r=a.synchronizationInfo?.changedFiles?a.synchronizationInfo.changedFiles:[s.noValue],o=l(new Date(a.pushDateTime)),c=(e,t)=>i.default.createElement("div",{className:"iac-info-panel-details"},i.default.createElement("span",{className:"iac-info-panel-property"},`${e}: `),i.default.createElement("span",{className:"iac-info-panel-data-value"},t));return i.default.createElement(e.InformationPanel,{className:"iac-info-panel",resizable:!1,isOpen:!0},i.default.createElement(e.InformationPanelHeader,{onClose:n},i.default.createElement(e.Text,{variant:"subheading"},s.title+a.index)),i.default.createElement(e.InformationPanelBody,null,i.default.createElement("div",{className:"iac-info-panel-body"},i.default.createElement(e.Text,{className:"iac-info-panel-container"},a.description),i.default.createElement("div",{className:"iac-info-panel-container"},c(s.createdBy,a.createdBy??""),c(s.createdDate,o??""),c(s.application,a.application.name??s.noValue)),i.default.createElement("div",{className:"iac-info-panel-container"},i.default.createElement(e.Text,{variant:"leading"},s.connectionAttributes),c(s.changedFiles,r.join(","))))))};var w;!function(e){e[e.NotStarted=0]="NotStarted",e[e.InProgress=1]="InProgress",e[e.Finished=2]="Finished",e[e.Failed=3]="Failed"}(w||(w={}));const y=t=>{const{changesets:n,status:s,loadMoreChanges:r,onVersionCreated:o,latestVersion:d}=t,{stringsOverrides:c}=p(),[u,m]=i.default.useState(!1),[g,f]=i.default.useState(void 0),[h,v]=i.default.useState(!1),C=i.default.useCallback((e=>!e._links.namedVersion),[]),y=i.default.useMemo((()=>[{Header:"Name",columns:[{id:"INDEX",Header:"#",accessor:"index",width:90},{id:"DESCRIPTION",Header:c.description,accessor:"description"},{id:"CREATOR",Header:c.user??"User",accessor:"createdBy",maxWidth:220,Cell:t=>""!==t.row.original.createdBy?i.default.createElement(e.Text,null,t.row.original.createdBy):i.default.createElement(e.Text,{isSkeleton:!0},"Loading user info")},{id:"CHANGED_FILES",Header:c.changedFiles,Cell:e=>{const t=e.row.original.synchronizationInfo?.changedFiles;return t?.length?t.join(", "):""}},{id:"PUSH_DATE",Header:c.time,accessor:"pushDateTime",maxWidth:220,Cell:e=>i.default.createElement("span",null,l(new Date(e.row.original.pushDateTime)))},{id:"changes-table-actions",width:100,cellClassName:"iac-changes-tab-actions",Cell:t=>{const n=t.data[t.row.index],s=C(n)?"":"iac-create-version-icon-hidden";return i.default.createElement(i.default.Fragment,null,i.default.createElement(e.IconButton,{onClick:()=>{f(n),m(!0)},title:c.createNamedVersion,styleType:"borderless",className:s,size:"small"},i.default.createElement(a.SvgNamedVersionAdd,null)),i.default.createElement(e.IconButton,{title:c.informationPanel??"Information Panel",styleType:"borderless",onClick:()=>(f(n),void v(!0)),size:"small"},i.default.createElement(a.SvgInfoCircular,null)))}}]}]),[c.description,c.user,c.changedFiles,c.time,c.createNamedVersion,c.informationPanel,C]),x=i.default.useMemo((()=>s===w.Failed?c.messageFailedGetChanges:c.messageNoChanges),[s,c.messageFailedGetChanges,c.messageNoChanges]);return i.default.createElement(i.default.Fragment,null,i.default.createElement(e.Table,{columns:y,data:n,isLoading:s===w.InProgress||s===w.NotStarted,emptyTableContent:x,onBottomReached:r,className:"iac-changes-table"}),u&&i.default.createElement(b,{changeset:g,onCreate:()=>{m(!1),o()},onClose:()=>m(!1),latestVersion:d}),h&&g&&i.default.createElement(E,{changeset:g,onClose:()=>v(!1),stringOverrides:c.informationPanelStringOverrides}))};v(".iac-versions-table .iui-table-body .iui-table-cell{word-break:break-word}");const x=({menuActions:n})=>{const{stringsOverrides:s}=p(),r=t.useCallback((t=>n.map(((a,n)=>i.default.createElement(e.MenuItem,{icon:a.icon,key:n,onClick:()=>{t(),a.onClick()},title:a.title,disabled:a.disabled},a.label)))),[n]);return i.default.createElement(e.DropdownMenu,{menuItems:r},i.default.createElement(e.IconButton,{onClick:e=>e.stopPropagation(),styleType:"borderless",size:"small",role:"button",label:s.More},i.default.createElement(a.SvgMore,null)))},N=t=>{const{version:a,onClose:n,onUpdate:s}=t,{accessToken:r,imodelId:o,apiOverrides:l,stringsOverrides:d,log:c}=p(),[u,m]=i.default.useState(!1),f=i.default.useMemo((()=>new g(r,l?.serverEnvironmentPrefix,c)),[r,l?.serverEnvironmentPrefix,c]);return i.default.createElement(C,{title:d.updateNamedVersion,actionName:d.update,initialVersion:a,isLoading:u,onClose:n,onActionClick:(t,n)=>{m(!0),e.toaster.closeAll(),f.update(o,a.id,{name:t,description:n}).then((()=>{m(!1),s(),e.toaster.positive(d.messageVersionUpdated.replace("{{name}}",t),{hasCloseButton:!0})})).catch((t=>{m(!1),e.toaster.negative((e=>{switch(e){case"NamedVersionExists":return d.messageVersionNameExists;case"InsufficientPermissions":return d.messageInsufficientPermissionsToUpdateVersion;default:return d.messageCouldNotUpdateVersion}})(t.code),{hasCloseButton:!0})}))}})},V=e=>"version"in e,T=n=>{const{status:s,onVersionUpdated:r,loadMoreVersions:o,onViewClick:d,tableData:c,changesetClient:u,setRelatedChangesets:m}=n,{stringsOverrides:g,imodelId:f}=p(),[h,v]=i.default.useState(void 0),[C,b]=i.default.useState(!1);const E=t.useCallback((async t=>{e.toaster.closeAll();try{const a=(await u.getChangesetCheckpoint(f,t))._links.download.href;window.open(a,"_blank","noopener,noreferrer"),e.toaster.informational(g.messageFileDownloadInProgress,{hasCloseButton:!0,duration:2e3})}catch(t){e.toaster.negative(g.messageCouldNotDownloadedFileSuccessfully,{hasCloseButton:!0})}}),[u,f,g.messageCouldNotDownloadedFileSuccessfully,g.messageFileDownloadInProgress]),y=i.default.useMemo((()=>t=>{if(V(t))return i.default.createElement(e.Text,null,l(new Date(t.version.createdDateTime)));return""!==t.pushDateTime?i.default.createElement(e.Text,null,l(new Date(t.pushDateTime))):i.default.createElement(e.Text,{isSkeleton:!0},"Loading Date")}),[]),T=i.default.useMemo((()=>(t,a)=>{if(["createdDateTime","pushDateTime"].includes(a))return y(t);if(V(t))return i.default.createElement(e.Text,null,t.version[a]);{const n=t[a];return""!==n?i.default.createElement(e.Text,null,n):i.default.createElement(e.Text,{isSkeleton:!0},"Loading")}}),[y]),k=t.useCallback((e=>[{title:g.updateNamedVersion,label:g.updateNamedVersion,icon:i.default.createElement(a.SvgEdit,null),disabled:!1,onClick:()=>{v(e.row.original.version),b(!0)}},{title:g.download??"Download",label:g.download??"Download",icon:i.default.createElement(a.SvgDownload,null),disabled:!1,onClick:async()=>{const{changesetIndex:t}=e.row.original.version;await E(t)}}]),[E,g.download,g.updateNamedVersion]),P=i.default.useMemo((()=>{const t=[{Header:"Name",columns:[{id:"NAME",Header:g.name,accessor:"name",Cell:e=>{const t=V(e.row.original)?"name":"displayName";return T(e.row.original,t)}},{id:"DESCRIPTION",Header:g.description,accessor:"description",Cell:e=>T(e.row.original,"description")},{id:"CREATOR",Header:g.user??"User",accessor:"createdBy",maxWidth:220,Cell:t=>{const a=V(t.row.original)?t.row.original.version.createdBy:t.row.original.createdBy;return""!==a?i.default.createElement(e.Text,null,a):i.default.createElement(e.Text,{isSkeleton:!0},"Loading user info")}},{id:"CREATED_DATE",Header:g.time,accessor:"createdDateTime",maxWidth:220,Cell:e=>{const t=V(e.row.original)?"createdDateTime":"pushDateTime";return T(e.row.original,t)}},{id:"versions-table-actions",width:62,Cell:e=>i.default.createElement(i.default.Fragment,null,V(e.row.original)?i.default.createElement(x,{menuActions:k(e)}):i.default.createElement(i.default.Fragment,null))}]}];return d&&t[0].columns.splice(4,0,{id:"versions-table-view",width:100,Cell:e=>V(e.row.original)?i.default.createElement("span",{className:"iui-anchor",onClick:()=>d(e.row.original.version)},g.view):i.default.createElement(i.default.Fragment,null)}),t}),[g.name,g.description,g.user,g.time,g.view,d,T,k]),I=i.default.useMemo((()=>s===w.Failed?g.messageFailedGetNamedVersions:g.messageNoNamedVersions),[s,g.messageFailedGetNamedVersions,g.messageNoNamedVersions]);return i.default.createElement(i.default.Fragment,null,i.default.createElement(e.Table,{columns:P,data:c,isLoading:s===w.InProgress||s===w.NotStarted,emptyTableContent:I,onBottomReached:o,className:"iac-versions-table",onExpand:e=>{e?.forEach((e=>{e.subRowsLoaded||async function(e){try{return await u.get(f,{top:10,lastIndex:e})}catch(e){throw e}}(e.version.changesetIndex).then((t=>{const a=[];if(void 0!==t)for(const n of t)if(n.index===e.version.changesetIndex&&null!==n._links.namedVersion||n.index<e.version.changesetIndex&&null===n._links.namedVersion)a.push(n);else if(n.index<e.version.changesetIndex&&null!==n._links.namedVersion)break;m(e.version.id??"",a)})).catch((()=>{console.error("Failed to get Changesets")}))}))},autoResetExpanded:!1}),C&&i.default.createElement(N,{version:h,onUpdate:()=>{b(!1),r()},onClose:()=>b(!1)}))},k={namedVersions:"Named Versions",changes:"Changes",name:"Name",description:"Description",time:"Time",changedFiles:"Changed Files",createNamedVersion:"Create a Named Version",user:"User",informationPanel:"Information Panel",cancel:"Cancel",create:"Create",updateNamedVersion:"Update a Named Version",update:"Update",download:"Download",More:"More",view:"View",messageFailedGetNamedVersions:"Could not get Named Versions. Please try again later.",messageNoNamedVersions:"There are no Named Versions created. To create first go to Changes.",messageFailedGetChanges:"Could not get changes. Please try again later.",messageNoChanges:"There are no changes synchronized.",messageVersionCreated:'Named Version "{{name}}" was successfully created.',messageVersionNameExists:"Named Version with the same name already exists.",messageInsufficientPermissionsToCreateVersion:"You do not have the required permissions to create a Named Version.",messageCouldNotCreateVersion:"Could not create a Named Version. Please try again later.",messageVersionUpdated:'Named Version "{{name}}" was successfully updated.',messageFileDownloadInProgress:"Downloading file...",messageCouldNotDownloadedFileSuccessfully:"Unable to download file.",messageInsufficientPermissionsToUpdateVersion:"You do not have the required permissions to update a Named Version.",messageCouldNotUpdateVersion:"Could not update a Named Version. Please try again later.",messageValueTooLong:"The value exceeds allowed {{length}} characters.",informationPanelStringOverrides:d};var P;exports.ManageVersionsTabs=void 0,(P=exports.ManageVersionsTabs||(exports.ManageVersionsTabs={}))[P.Versions=0]="Versions",P[P.Changes=1]="Changes";const I={id:"",index:0,displayName:"",description:"",pushDateTime:"",synchronizationInfo:{changedFiles:[]},_links:{},creatorId:"",createdBy:"",application:{id:"",name:""}},D=(e,t,a)=>(e??[]).map(((e,n)=>{const s=t?.[n];return{version:e,subRows:a?[I]:s?.subRows??[I],subRowsLoaded:!a&&(s?.subRowsLoaded??!1)}})),S=(e,t)=>{if(e.length)return e.map((e=>{const a=e._links.creator.href.substring(e._links.creator.href.lastIndexOf("/")+1);return{...e,createdBy:t?.[a]??""}}))},F=(e,t)=>{if(e.length)return e.map((e=>({...e,createdBy:t?.[e.creatorId]??""})))};exports.ManageVersions=t=>{const{accessToken:a,apiOverrides:n,imodelId:s,stringsOverrides:r=k,log:o,onViewClick:l,currentTab:d=exports.ManageVersionsTabs.Versions,onTabChange:c}=t,u=i.default.useMemo((()=>new g(a,n?.serverEnvironmentPrefix,o)),[a,n?.serverEnvironmentPrefix,o]),f=i.default.useMemo((()=>new m(a,n?.serverEnvironmentPrefix,o)),[a,n?.serverEnvironmentPrefix,o]),[p,v]=i.default.useState(d),C=i.default.useRef(void 0),b=i.default.useCallback((async()=>{const e=(await f.getUsers(s)).reduce(((e,t)=>{const a=[t.givenName,t.surname].filter(Boolean);return e[t.id]=a.length?a.join(" "):t.displayName,e}),{});C.current=e}),[f,s]);i.default.useEffect((()=>{v(d)}),[d]);const[E,x]=i.default.useState(),[N,V]=i.default.useState(w.NotStarted),[P,I]=i.default.useState(),[M,_]=i.default.useState(w.NotStarted),B=i.default.useCallback((e=>{v(e),c?.(e)}),[c]),U=i.default.useCallback(((e,t)=>{V(w.InProgress),u.get(s,{top:100,skip:e}).then((e=>{e.sort(((e,t)=>t.changesetIndex-e.changesetIndex));const a=S(e,C.current);x((e=>[...D(a??[],e,t)])),V(w.Finished)})).catch((()=>V(w.Failed)))}),[s,u]),A=i.default.useCallback((()=>{E&&E.length%100!=0||U(E?.length)}),[U,E]),O=i.default.useCallback((()=>{P&&P.length%100!=0||(_(w.InProgress),f.get(s,{top:100,skip:P?.length}).then((e=>{I([...P??[],...F(e,C.current)??[]]),_(w.Finished)})).catch((()=>_(w.Failed))))}),[P,f,s]),R=i.default.useCallback((e=>{U(void 0,e)}),[U]);i.default.useEffect((()=>{C.current||(async()=>{await b()})().then((()=>{const e=E?.map((e=>{const t=S([e.version]??[],C.current);return{...e,version:t?t[0]:e.version}}));x(e),I((e=>[...F(P??[],C.current)??e??[]]))})).catch((()=>{console.error("Unable to fetch users data")}))}),[P,b,E]),i.default.useEffect((()=>{p===exports.ManageVersionsTabs.Versions&&N===w.NotStarted&&U()}),[p,U,N]),i.default.useEffect((()=>{p===exports.ManageVersionsTabs.Changes&&M===w.NotStarted&&O()}),[M,p,O]);const $=i.default.useCallback((()=>{B(exports.ManageVersionsTabs.Versions),R(!0),I(void 0),_(w.NotStarted)}),[B,R]),L=i.default.useMemo((()=>[...E??[]].sort(((e,t)=>new Date(e.version.createdDateTime).valueOf()<new Date(t.version.createdDateTime).valueOf()?1:-1))[0]),[E]);return i.default.createElement(e.ThemeProvider,{theme:"inherit"},i.default.createElement(h,{accessToken:a,imodelId:s,apiOverrides:n,stringsOverrides:r,log:o},i.default.createElement("div",null,i.default.createElement(e.HorizontalTabs,{labels:[r.namedVersions,r.changes],activeIndex:p,onTabSelected:e=>B(e),type:"borderless"}),p===exports.ManageVersionsTabs.Versions&&i.default.createElement(T,{status:N,onVersionUpdated:R,loadMoreVersions:A,onViewClick:l,tableData:E??[],changesetClient:f,setRelatedChangesets:(e,t)=>{const a=F(t,C.current)??[];x((t=>{const n=t?.map((t=>t.version.id===e?{...t,subRows:a,subRowsLoaded:!0}:t));return n??t}))}}),p===exports.ManageVersionsTabs.Changes&&i.default.createElement(y,{changesets:P??[],status:M,loadMoreChanges:O,onVersionCreated:$,latestVersion:L?.version}))))}; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@itwin/itwinui-react"),t=require("react"),a=require("@itwin/itwinui-icons-react");function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var s,i=n(t);!function(e){e.Authorization="Authorization",e.ContentType="Content-Type",e.Prefer="Prefer",e.Accept="Accept"}(s||(s={}));class r extends Error{constructor(e,t){super(e?.message),this.code=e?.code,this.statusCode=t}}const o={year:"numeric",month:"short",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!0};const l=e=>e.toLocaleDateString([...navigator.languages],o),d={title:"Change #",createdBy:"Created By",createdDate:"Date Created",application:"Application",connectionAttributes:"Connection Attributes",changedFiles:"Changed Files",noValue:"N/A"};class c{constructor(e,t){this._errorMessagePrefix="@itwin/manage-versions-react",this._defaultErrorMessage="HTTP error without a message.",this._token=e,this._log=t}async get(e,t){const a={method:"GET",url:e,headers:{...t?.headers},signal:t?.abortController?.signal};return this.makeRequest(a)}async post(e,t,a){const n={method:"POST",url:e,headers:{...a?.headers},body:t,signal:a?.abortController?.signal};return this.makeRequest(n)}async patch(e,t,a){const n={method:"PATCH",url:e,headers:{...a?.headers},body:t,signal:a?.abortController?.signal};return this.makeRequest(n)}async delete(e,t){const a={method:"DELETE",url:e,headers:{...t?.headers},signal:t?.abortController?.signal};return this.makeRequest(a)}async makeRequest(e){this.prepareHeaders(e);try{const t=await fetch(e.url,{method:e.method,headers:e.headers,body:e.body?JSON.stringify(e.body):void 0,signal:e?.signal}),a=await t.json();if(!t.ok)throw new r(a?.error,t.status);return a}catch(t){throw this.logError(t,e),t}}prepareHeaders(e){e.headers={[s.Authorization]:this._token,[s.Accept]:"application/vnd.bentley.itwin-platform.v2+json",[s.ContentType]:"application/json",...e.headers}}logError(e,t){this._log?.(`${this._errorMessagePrefix} - ${e.message||this._defaultErrorMessage}`,{request:this.getRequestToLog(t),error:e})}getRequestToLog(e){const t={...e.headers};return delete t[s.Authorization],{headers:t,url:e.url,method:e.method}}}class u{static getBaseUrl(e){return`https://${e?`${e}-`:""}api.bentley.com`}static buildVersionsUrl(e,t,a){return`${this.getBaseUrl(a)}/imodels/${e}/namedversions${t?`/${t}`:""}`}static buildChangesetUrl(e,t){return`${this.getBaseUrl(t)}/imodels/${e}/changesets`}static buildGetUsersUrl(e,t){return`${this.getBaseUrl(t)}/imodels/${e}/users`}}u.getQuery=e=>{const t=Object.entries(e).filter((([e,t])=>!!t)).map((([e,t])=>"lastIndex"===e?`${e}=${t}`:`$${e}=${t}`)).join("&");return t?`?${t}`:""};class m{constructor(e,t,a){this._http=new c(e,a),this._serverEnvironmentPrefix=t}async get(e,t={}){return this._http.get(`${u.buildChangesetUrl(e,this._serverEnvironmentPrefix)}${u.getQuery({orderBy:"index+desc",...t})}`,{headers:{[s.Prefer]:"return=representation",[s.Accept]:"application/vnd.bentley.itwin-platform.v2+json"}}).then((e=>e.changesets))}async getUsers(e){return this._http.get(`${u.buildGetUsersUrl(e,this._serverEnvironmentPrefix)}`,{headers:{[s.Prefer]:"return=representation",[s.Accept]:"application/vnd.bentley.itwin-platform.v2+json"}}).then((e=>e.users))}async getChangesetCheckpoint(e,t,a={}){const n=`${u.buildChangesetUrl(e,this._serverEnvironmentPrefix)}/${t}/checkpoint${u.getQuery(a)}`;return this._http.get(n,{headers:{[s.Accept]:"application/vnd.bentley.itwin-platform.v2+json"}}).then((e=>e.checkpoint))}}class g{constructor(e,t,a){this._http=new c(e,a),this._serverEnvironmentPrefix=t}async get(e,t={}){return this._http.get(`${u.buildVersionsUrl(e,void 0,this._serverEnvironmentPrefix)}${u.getQuery(t)}`,{headers:{[s.Prefer]:"return=representation",[s.Accept]:"application/vnd.bentley.itwin-platform.v2+json"}}).then((e=>e.namedVersions))}async create(e,t){return this._http.post(u.buildVersionsUrl(e,void 0,this._serverEnvironmentPrefix),t).then((e=>e.namedVersion))}async update(e,t,a){return this._http.patch(u.buildVersionsUrl(e,t,this._serverEnvironmentPrefix),a).then((e=>e.namedVersion))}}const f=i.default.createContext(void 0),h=e=>{const{children:t,...a}=e;return i.default.createElement(f.Provider,{value:a},t)},p=()=>{const e=i.default.useContext(f);if(void 0===e)throw new Error("useConfig must be used within a ConfigContext");return e};function v(e,t){void 0===t&&(t={});var a=t.insertAt;if(e&&"undefined"!=typeof document){var n=document.head||document.getElementsByTagName("head")[0],s=document.createElement("style");s.type="text/css","top"===a&&n.firstChild?n.insertBefore(s,n.firstChild):n.appendChild(s),s.styleSheet?s.styleSheet.cssText=e:s.appendChild(document.createTextNode(e))}}v(".iac-changes-table .iui-table-body .iui-table-cell{word-break:break-word}.iac-changes-table .iac-create-version-icon-hidden{visibility:hidden}.iac-changes-table .iac-changes-tab-actions{gap:var(--iui-size-2xs)}");v(".iac-additional-info{display:flex;justify-content:space-between;padding:var(--iui-size-s);background-color:var(--iui-color-background-backdrop)}.iac-additional-info span{flex-shrink:0}.iac-additional-info span:not(:last-child){margin-right:var(--iui-size-m)}.iac-additional-info .iac-cell-ellipsis{white-space:nowrap;overflow:hidden;text-overflow:ellipsis;flex-shrink:1}");v(".iac-version-modal .iui-modal-dialog{max-width:min(600px,50%)}.iac-version-modal-overlay{position:fixed;z-index:99999;height:100vh;width:100vw;top:0;left:0}.iac-version-modal .iui-input-container{margin-bottom:var(--iui-size-s)}");const C=t=>{const{initialVersion:a,isLoading:n,title:s,actionName:r,onClose:o,onActionClick:l,children:d}=t,{stringsOverrides:c}=p(),[u,m]=i.default.useState({name:a?.name??"",description:a?.description??""}),g=e=>{const t=e.target.name,a=e.target.value;m((e=>({...e,[t]:a??""})))},f=e=>e.length<=255;return i.default.createElement(i.default.Fragment,null,i.default.createElement(e.Modal,{title:s,isOpen:!0,onClose:o,className:"iac-version-modal"},i.default.createElement(e.LabeledInput,{setFocus:!0,name:"name",label:c.name,onChange:g,value:u.name,status:f(u.name)?void 0:"negative",message:f(u.name)?void 0:c.messageValueTooLong.replace("{{length}}",255..toString()),required:!0,autoComplete:"off"}),i.default.createElement(e.LabeledTextarea,{name:"description",label:c.description,onChange:g,value:u.description,status:f(u.description)?void 0:"negative",message:f(u.description)?void 0:c.messageValueTooLong.replace("{{length}}",255..toString()),rows:3,autoComplete:"off"}),d,i.default.createElement(e.ModalButtonBar,null,i.default.createElement(e.Button,{styleType:"high-visibility",onClick:()=>l(u.name,u.description),disabled:!(u.name&&(u.name!==a?.name||u.description!==a?.description)&&f(u.name)&&f(u.description))},r),i.default.createElement(e.Button,{onClick:o},c.cancel)),n&&i.default.createElement("div",{className:"iui-progress-indicator-overlay"},i.default.createElement(e.ProgressRadial,{indeterminate:!0}))),n&&i.default.createElement("div",{className:"iac-version-modal-overlay"}))},b=t=>{const{latestVersion:a,changeset:n,onClose:s,onCreate:r}=t,{accessToken:o,imodelId:d,apiOverrides:c,stringsOverrides:u,log:m}=p(),[f,h]=i.default.useState(!1),v=i.default.useMemo((()=>new g(o,c?.serverEnvironmentPrefix,m)),[o,c?.serverEnvironmentPrefix,m]);return i.default.createElement(C,{title:u.createNamedVersion,actionName:u.create,isLoading:f,onClose:s,onActionClick:(t,a)=>{h(!0),e.toaster.closeAll(),v.create(d,{name:t,description:a,changeSetId:n.id}).then((()=>{h(!1),r(),e.toaster.positive(u.messageVersionCreated.replace("{{name}}",t),{hasCloseButton:!0})})).catch((t=>{h(!1),e.toaster.negative((e=>{switch(e){case"NamedVersionExists":return u.messageVersionNameExists;case"InsufficientPermissions":return u.messageInsufficientPermissionsToCreateVersion;default:return u.messageCouldNotCreateVersion}})(t.code),{hasCloseButton:!0})}))}},i.default.createElement("div",{className:"iui-input-container"},i.default.createElement("div",{className:"iui-label"},"Latest included change"),i.default.createElement("div",{className:"iac-additional-info"},i.default.createElement("span",null,"#",n.index),i.default.createElement("span",null,l(new Date(n.pushDateTime))))),a&&i.default.createElement("div",{className:"iui-input-container"},i.default.createElement("div",{className:"iui-label"},"Latest Named Version"),i.default.createElement("div",{className:"iac-additional-info"},i.default.createElement("span",{className:"iac-cell-ellipsis"},a.name),i.default.createElement("span",null,l(new Date(a.createdDateTime))))))};v(".iac-info-panel{width:400px;min-width:400px}.iac-info-panel .iac-info-panel-body .iac-info-panel-container{padding:var(--iui-size-xs)}.iac-info-panel .iac-info-panel-body .iac-info-panel-container+div{border-top:1px solid var(--iui-color-border-subtle)}.iac-info-panel .iac-info-panel-body .iac-info-panel-details{padding:var(--iui-size-xs);display:flex;flex-direction:row;align-items:flex-start;justify-content:space-between}.iac-info-panel .iac-info-panel-body .iac-info-panel-details .iac-info-panel-data-value{flex:2;min-width:50%}.iac-info-panel .iac-info-panel-body .iac-info-panel-property{display:flex;flex:1;margin-right:var(--iui-size-m);justify-content:right;color:var(--iui-color-text-disabled)}");const E=t=>{const{changeset:a,onClose:n,stringOverrides:s=d}=t,r=a.synchronizationInfo?.changedFiles?a.synchronizationInfo.changedFiles:[s.noValue],o=l(new Date(a.pushDateTime)),c=(e,t)=>i.default.createElement("div",{className:"iac-info-panel-details"},i.default.createElement("span",{className:"iac-info-panel-property"},`${e}: `),i.default.createElement("span",{className:"iac-info-panel-data-value"},t));return i.default.createElement(e.InformationPanel,{className:"iac-info-panel",resizable:!1,isOpen:!0},i.default.createElement(e.InformationPanelHeader,{onClose:n},i.default.createElement(e.Text,{variant:"subheading"},s.title+a.index)),i.default.createElement(e.InformationPanelBody,null,i.default.createElement("div",{className:"iac-info-panel-body"},i.default.createElement(e.Text,{className:"iac-info-panel-container"},a.description),i.default.createElement("div",{className:"iac-info-panel-container"},c(s.createdBy,a.createdBy??""),c(s.createdDate,o??""),c(s.application,a.application.name??s.noValue)),i.default.createElement("div",{className:"iac-info-panel-container"},i.default.createElement(e.Text,{variant:"leading"},s.connectionAttributes),c(s.changedFiles,r.join(","))))))};var w;!function(e){e[e.NotStarted=0]="NotStarted",e[e.InProgress=1]="InProgress",e[e.Finished=2]="Finished",e[e.Failed=3]="Failed"}(w||(w={}));const y=t=>{const{changesets:n,status:s,loadMoreChanges:r,onVersionCreated:o,latestVersion:d}=t,{stringsOverrides:c}=p(),[u,m]=i.default.useState(!1),[g,f]=i.default.useState(void 0),[h,v]=i.default.useState(!1),C=i.default.useCallback((e=>!e._links.namedVersion),[]),y=i.default.useMemo((()=>[{Header:"Name",columns:[{id:"INDEX",Header:"#",accessor:"index",width:90},{id:"DESCRIPTION",Header:c.description,accessor:"description"},{id:"CREATOR",Header:c.user??"User",accessor:"createdBy",maxWidth:220,Cell:t=>""!==t.row.original.createdBy?i.default.createElement(e.Text,null,t.row.original.createdBy):i.default.createElement(e.Text,{isSkeleton:!0},"Loading user info")},{id:"CHANGED_FILES",Header:c.changedFiles,Cell:e=>{const t=e.row.original.synchronizationInfo?.changedFiles;return t?.length?t.join(", "):""}},{id:"PUSH_DATE",Header:c.time,accessor:"pushDateTime",maxWidth:220,Cell:e=>i.default.createElement("span",null,l(new Date(e.row.original.pushDateTime)))},{id:"changes-table-actions",width:100,cellClassName:"iac-changes-tab-actions",Cell:t=>{const n=t.data[t.row.index],s=C(n)?"":"iac-create-version-icon-hidden";return i.default.createElement(i.default.Fragment,null,i.default.createElement(e.IconButton,{onClick:()=>{f(n),m(!0)},title:c.createNamedVersion,styleType:"borderless",className:s,size:"small"},i.default.createElement(a.SvgNamedVersionAdd,null)),i.default.createElement(e.IconButton,{title:c.informationPanel??"Information Panel",styleType:"borderless",onClick:()=>(f(n),void v(!0)),size:"small"},i.default.createElement(a.SvgInfoCircular,null)))}}]}]),[c.description,c.user,c.changedFiles,c.time,c.createNamedVersion,c.informationPanel,C]),x=i.default.useMemo((()=>s===w.Failed?c.messageFailedGetChanges:c.messageNoChanges),[s,c.messageFailedGetChanges,c.messageNoChanges]);return i.default.createElement(i.default.Fragment,null,i.default.createElement(e.Table,{columns:y,data:n,isLoading:s===w.InProgress||s===w.NotStarted,emptyTableContent:x,onBottomReached:r,className:"iac-changes-table"}),u&&i.default.createElement(b,{changeset:g,onCreate:()=>{m(!1),o()},onClose:()=>m(!1),latestVersion:d}),h&&g&&i.default.createElement(E,{changeset:g,onClose:()=>v(!1),stringOverrides:c.informationPanelStringOverrides}))};v(".iac-versions-table .iui-table-body .iui-table-cell{word-break:break-word}");const x=({menuActions:n})=>{const{stringsOverrides:s}=p(),r=t.useCallback((t=>n.map(((a,n)=>i.default.createElement(e.MenuItem,{icon:a.icon,key:n,onClick:()=>{t(),a.onClick()},title:a.title,disabled:a.disabled},a.label)))),[n]);return i.default.createElement(e.DropdownMenu,{menuItems:r},i.default.createElement(e.IconButton,{onClick:e=>e.stopPropagation(),styleType:"borderless",size:"small",role:"button",label:s.More},i.default.createElement(a.SvgMore,null)))},N=t=>{const{version:a,onClose:n,onUpdate:s}=t,{accessToken:r,imodelId:o,apiOverrides:l,stringsOverrides:d,log:c}=p(),[u,m]=i.default.useState(!1),f=i.default.useMemo((()=>new g(r,l?.serverEnvironmentPrefix,c)),[r,l?.serverEnvironmentPrefix,c]);return i.default.createElement(C,{title:d.updateNamedVersion,actionName:d.update,initialVersion:a,isLoading:u,onClose:n,onActionClick:(t,n)=>{m(!0),e.toaster.closeAll(),f.update(o,a.id,{name:t,description:n}).then((()=>{m(!1),s(),e.toaster.positive(d.messageVersionUpdated.replace("{{name}}",t),{hasCloseButton:!0})})).catch((t=>{m(!1),e.toaster.negative((e=>{switch(e){case"NamedVersionExists":return d.messageVersionNameExists;case"InsufficientPermissions":return d.messageInsufficientPermissionsToUpdateVersion;default:return d.messageCouldNotUpdateVersion}})(t.code),{hasCloseButton:!0})}))}})},V=e=>"version"in e,T=n=>{const{status:s,onVersionUpdated:r,loadMoreVersions:o,onViewClick:d,tableData:c,changesetClient:u,setRelatedChangesets:m}=n,{stringsOverrides:g,imodelId:f}=p(),[h,v]=i.default.useState(void 0),[C,b]=i.default.useState(!1);const E=t.useCallback((async t=>{e.toaster.closeAll();try{const a=(await u.getChangesetCheckpoint(f,t))._links.download.href;window.open(a,"_blank","noopener,noreferrer"),e.toaster.informational(g.messageFileDownloadInProgress,{hasCloseButton:!0,duration:2e3})}catch(t){e.toaster.negative(g.messageCouldNotDownloadedFileSuccessfully,{hasCloseButton:!0})}}),[u,f,g.messageCouldNotDownloadedFileSuccessfully,g.messageFileDownloadInProgress]),y=i.default.useMemo((()=>t=>{if(V(t))return i.default.createElement(e.Text,null,l(new Date(t.version.createdDateTime)));return""!==t.pushDateTime?i.default.createElement(e.Text,null,l(new Date(t.pushDateTime))):i.default.createElement(e.Text,{isSkeleton:!0},"Loading Date")}),[]),T=i.default.useMemo((()=>(t,a)=>{if(["createdDateTime","pushDateTime"].includes(a))return y(t);if(V(t)){const n=t.version[a];return i.default.createElement(e.Text,null,n)}{const n=t[a];return""!==n?i.default.createElement(e.Text,null,n):i.default.createElement(e.Text,{isSkeleton:!0},"Loading")}}),[y]),k=t.useCallback((e=>[{title:g.updateNamedVersion,label:g.updateNamedVersion,icon:i.default.createElement(a.SvgEdit,null),disabled:!1,onClick:()=>{v(e.row.original.version),b(!0)}},{title:g.download??"Download",label:g.download??"Download",icon:i.default.createElement(a.SvgDownload,null),disabled:!1,onClick:async()=>{const{changesetIndex:t}=e.row.original.version;await E(t)}}]),[E,g.download,g.updateNamedVersion]),P=i.default.useMemo((()=>{const t=[{Header:"Name",columns:[{id:"NAME",Header:g.name,accessor:"name",Cell:e=>{const t=V(e.row.original)?"name":"displayName";return T(e.row.original,t)}},{id:"DESCRIPTION",Header:g.description,accessor:"description",Cell:e=>T(e.row.original,"description")},{id:"CREATOR",Header:g.user??"User",accessor:"createdBy",maxWidth:220,Cell:t=>{const a=V(t.row.original)?t.row.original.version.createdBy:t.row.original.createdBy;return""!==a?i.default.createElement(e.Text,null,a):i.default.createElement(e.Text,{isSkeleton:!0},"Loading user info")}},{id:"CREATED_DATE",Header:g.time,accessor:"createdDateTime",maxWidth:220,Cell:e=>{const t=V(e.row.original)?"createdDateTime":"pushDateTime";return T(e.row.original,t)}},{id:"versions-table-actions",width:62,Cell:e=>i.default.createElement(i.default.Fragment,null,V(e.row.original)?i.default.createElement(x,{menuActions:k(e)}):i.default.createElement(i.default.Fragment,null))}]}];return d&&t[0].columns.splice(4,0,{id:"versions-table-view",width:100,Cell:e=>V(e.row.original)?i.default.createElement("span",{className:"iui-anchor",onClick:()=>d(e.row.original.version)},g.view):i.default.createElement(i.default.Fragment,null)}),t}),[g.name,g.description,g.user,g.time,g.view,d,T,k]),I=i.default.useMemo((()=>s===w.Failed?g.messageFailedGetNamedVersions:g.messageNoNamedVersions),[s,g.messageFailedGetNamedVersions,g.messageNoNamedVersions]);return i.default.createElement(i.default.Fragment,null,i.default.createElement(e.Table,{columns:P,data:c,isLoading:s===w.InProgress||s===w.NotStarted,emptyTableContent:I,onBottomReached:o,className:"iac-versions-table",onExpand:e=>{e?.forEach((e=>{e.subRowsLoaded||async function(e){try{return await u.get(f,{top:10,lastIndex:e})}catch(e){throw e}}(e.version.changesetIndex).then((t=>{const a=[];if(void 0!==t)for(const n of t)if(n.index===e.version.changesetIndex&&null!==n._links.namedVersion||n.index<e.version.changesetIndex&&null===n._links.namedVersion)a.push(n);else if(n.index<e.version.changesetIndex&&null!==n._links.namedVersion)break;m(e.version.id??"",a)})).catch((()=>{console.error("Failed to get Changesets")}))}))},autoResetExpanded:!1}),C&&i.default.createElement(N,{version:h,onUpdate:()=>{b(!1),r()},onClose:()=>b(!1)}))},k={namedVersions:"Named Versions",changes:"Changes",name:"Name",description:"Description",time:"Time",changedFiles:"Changed Files",createNamedVersion:"Create a Named Version",user:"User",informationPanel:"Information Panel",cancel:"Cancel",create:"Create",updateNamedVersion:"Update a Named Version",update:"Update",download:"Download",More:"More",view:"View",messageFailedGetNamedVersions:"Could not get Named Versions. Please try again later.",messageNoNamedVersions:"There are no Named Versions created. To create first go to Changes.",messageFailedGetChanges:"Could not get changes. Please try again later.",messageNoChanges:"There are no changes synchronized.",messageVersionCreated:'Named Version "{{name}}" was successfully created.',messageVersionNameExists:"Named Version with the same name already exists.",messageInsufficientPermissionsToCreateVersion:"You do not have the required permissions to create a Named Version.",messageCouldNotCreateVersion:"Could not create a Named Version. Please try again later.",messageVersionUpdated:'Named Version "{{name}}" was successfully updated.',messageFileDownloadInProgress:"Downloading file...",messageCouldNotDownloadedFileSuccessfully:"Unable to download file.",messageInsufficientPermissionsToUpdateVersion:"You do not have the required permissions to update a Named Version.",messageCouldNotUpdateVersion:"Could not update a Named Version. Please try again later.",messageValueTooLong:"The value exceeds allowed {{length}} characters.",informationPanelStringOverrides:d};var P;exports.ManageVersionsTabs=void 0,(P=exports.ManageVersionsTabs||(exports.ManageVersionsTabs={}))[P.Versions=0]="Versions",P[P.Changes=1]="Changes";const I={id:"",index:0,displayName:"",description:"",pushDateTime:"",synchronizationInfo:{changedFiles:[]},_links:{},creatorId:"",createdBy:"",application:{id:"",name:""}},D=(e,t,a)=>(e??[]).map(((e,n)=>{const s=t?.[n];return{version:e,subRows:a?[I]:s?.subRows??[I],subRowsLoaded:!a&&(s?.subRowsLoaded??!1)}})),S=(e,t)=>{if(e.length)return e.map((e=>{const a=e._links.creator.href.substring(e._links.creator.href.lastIndexOf("/")+1);return{...e,createdBy:t?.[a]??""}}))},F=(e,t)=>{if(e.length)return e.map((e=>({...e,createdBy:t?.[e.creatorId]??""})))};exports.ManageVersions=t=>{const{accessToken:a,apiOverrides:n,imodelId:s,stringsOverrides:r=k,log:o,onViewClick:l,currentTab:d=exports.ManageVersionsTabs.Versions,onTabChange:c}=t,u=i.default.useMemo((()=>new g(a,n?.serverEnvironmentPrefix,o)),[a,n?.serverEnvironmentPrefix,o]),f=i.default.useMemo((()=>new m(a,n?.serverEnvironmentPrefix,o)),[a,n?.serverEnvironmentPrefix,o]),[p,v]=i.default.useState(d),C=i.default.useRef(void 0),b=i.default.useCallback((async()=>{const e=(await f.getUsers(s)).reduce(((e,t)=>{const a=[t.givenName,t.surname].filter(Boolean);return e[t.id]=a.length?a.join(" "):t.displayName,e}),{});C.current=e}),[f,s]);i.default.useEffect((()=>{v(d)}),[d]);const[E,x]=i.default.useState(),[N,V]=i.default.useState(w.NotStarted),[P,I]=i.default.useState(),[M,_]=i.default.useState(w.NotStarted),B=i.default.useCallback((e=>{v(e),c?.(e)}),[c]),U=i.default.useCallback(((e,t)=>{V(w.InProgress),u.get(s,{top:100,skip:e}).then((e=>{e.sort(((e,t)=>t.changesetIndex-e.changesetIndex));const a=S(e,C.current);x((e=>[...D(a??[],e,t)])),V(w.Finished)})).catch((()=>V(w.Failed)))}),[s,u]),A=i.default.useCallback((()=>{E&&E.length%100!=0||U(E?.length)}),[U,E]),O=i.default.useCallback((()=>{P&&P.length%100!=0||(_(w.InProgress),f.get(s,{top:100,skip:P?.length}).then((e=>{I([...P??[],...F(e,C.current)??[]]),_(w.Finished)})).catch((()=>_(w.Failed))))}),[P,f,s]),R=i.default.useCallback((e=>{U(void 0,e)}),[U]);i.default.useEffect((()=>{C.current||(async()=>{await b()})().then((()=>{const e=E?.map((e=>{const t=S([e.version]??[],C.current);return{...e,version:t?t[0]:e.version}}));e&&x(e),I((e=>[...F(P??[],C.current)??e??[]]))})).catch((()=>{console.error("Unable to fetch users data")}))}),[P,b,E]),i.default.useEffect((()=>{p===exports.ManageVersionsTabs.Versions&&N===w.NotStarted&&U()}),[p,U,N]),i.default.useEffect((()=>{p===exports.ManageVersionsTabs.Changes&&M===w.NotStarted&&O()}),[M,p,O]);const $=i.default.useCallback((()=>{B(exports.ManageVersionsTabs.Versions),R(!0),I(void 0),_(w.NotStarted)}),[B,R]),L=i.default.useMemo((()=>[...E??[]].sort(((e,t)=>new Date(e.version.createdDateTime).valueOf()<new Date(t.version.createdDateTime).valueOf()?1:-1))[0]),[E]);return i.default.createElement(e.ThemeProvider,{theme:"inherit"},i.default.createElement(h,{accessToken:a,imodelId:s,apiOverrides:n,stringsOverrides:r,log:o},i.default.createElement("div",null,i.default.createElement(e.HorizontalTabs,{labels:[r.namedVersions,r.changes],activeIndex:p,onTabSelected:e=>B(e),type:"borderless"}),p===exports.ManageVersionsTabs.Versions&&i.default.createElement(T,{status:N,onVersionUpdated:R,loadMoreVersions:A,onViewClick:l,tableData:E??[],changesetClient:f,setRelatedChangesets:(e,t)=>{const a=F(t,C.current)??[];x((t=>{const n=t?.map((t=>t.version.id===e?{...t,subRows:a,subRowsLoaded:!0}:t));return n??t}))}}),p===exports.ManageVersionsTabs.Changes&&i.default.createElement(y,{changesets:P??[],status:M,loadMoreChanges:O,onVersionCreated:$,latestVersion:L?.version}))))}; |
@@ -11,3 +11,3 @@ import React from "react"; | ||
}; | ||
export declare const ConfigProvider: (props: ConfigProviderProps) => JSX.Element; | ||
export declare const ConfigProvider: (props: ConfigProviderProps) => React.JSX.Element; | ||
export declare const useConfig: () => { | ||
@@ -14,0 +14,0 @@ accessToken: string; |
@@ -1,2 +0,2 @@ | ||
/// <reference types="react" /> | ||
import React from "react"; | ||
export declare type MenuAction = { | ||
@@ -12,2 +12,2 @@ icon?: JSX.Element; | ||
} | ||
export declare const ContextMenu: ({ menuActions }: ContextMenuProps) => JSX.Element; | ||
export declare const ContextMenu: ({ menuActions }: ContextMenuProps) => React.JSX.Element; |
@@ -1,3 +0,3 @@ | ||
/// <reference types="react" /> | ||
import "./CreateVersionModal.scss"; | ||
import React from "react"; | ||
import { Changeset, NamedVersion } from "../../../models"; | ||
@@ -10,2 +10,2 @@ export declare type CreateVersionModalProps = { | ||
}; | ||
export declare const CreateVersionModal: (props: CreateVersionModalProps) => JSX.Element; | ||
export declare const CreateVersionModal: (props: CreateVersionModalProps) => React.JSX.Element; |
@@ -1,2 +0,2 @@ | ||
/// <reference types="react" /> | ||
import React from "react"; | ||
import { NamedVersion } from "../../../models"; | ||
@@ -8,2 +8,2 @@ export declare type UpdateVersionModalProps = { | ||
}; | ||
export declare const UpdateVersionModal: (props: UpdateVersionModalProps) => JSX.Element; | ||
export declare const UpdateVersionModal: (props: UpdateVersionModalProps) => React.JSX.Element; |
@@ -13,2 +13,2 @@ import "./VersionModal.scss"; | ||
}; | ||
export declare const VersionModal: (props: VersionModalProps) => JSX.Element; | ||
export declare const VersionModal: (props: VersionModalProps) => React.JSX.Element; |
@@ -10,2 +10,2 @@ import "./ChangesetInformationPanel.scss"; | ||
} | ||
export declare const ChangesetInformationPanel: (props: ChangesetInfoPanelProps) => JSX.Element; | ||
export declare const ChangesetInformationPanel: (props: ChangesetInfoPanelProps) => React.JSX.Element; |
@@ -1,3 +0,3 @@ | ||
/// <reference types="react" /> | ||
import "./ChangesTab.scss"; | ||
import React from "react"; | ||
import { Changeset, NamedVersion } from "../../../models"; | ||
@@ -12,3 +12,3 @@ import { RequestStatus } from "../types"; | ||
}; | ||
declare const ChangesTab: (props: ChangesTabProps) => JSX.Element; | ||
declare const ChangesTab: (props: ChangesTabProps) => React.JSX.Element; | ||
export default ChangesTab; |
@@ -1,2 +0,2 @@ | ||
/// <reference types="react" /> | ||
import React from "react"; | ||
import { NamedVersion } from "../../models"; | ||
@@ -29,2 +29,2 @@ import { ApiOverrides, LogFunc, ManageVersionsStringOverrides } from "./types"; | ||
} | ||
export declare const ManageVersions: (props: ManageVersionsProps) => JSX.Element; | ||
export declare const ManageVersions: (props: ManageVersionsProps) => React.JSX.Element; |
@@ -1,3 +0,3 @@ | ||
/// <reference types="react" /> | ||
import "./VersionsTab.scss"; | ||
import React from "react"; | ||
import { ChangesetClient } from "../../../clients/changesetClient"; | ||
@@ -15,3 +15,3 @@ import { Changeset, NamedVersion, VersionTableData } from "../../../models"; | ||
}; | ||
declare const VersionsTab: (props: VersionsTabProps) => JSX.Element; | ||
declare const VersionsTab: (props: VersionsTabProps) => React.JSX.Element; | ||
export default VersionsTab; |
@@ -1,1 +0,1 @@ | ||
import{Modal as e,LabeledInput as t,LabeledTextarea as n,ModalButtonBar as a,Button as s,ProgressRadial as i,toaster as r,InformationPanel as o,InformationPanelHeader as l,Text as c,InformationPanelBody as d,IconButton as m,Table as u,MenuItem as g,DropdownMenu as h,ThemeProvider as p,HorizontalTabs as v}from"@itwin/itwinui-react";import f,{useCallback as C}from"react";import{SvgNamedVersionAdd as E,SvgInfoCircular as w,SvgMore as b,SvgEdit as y,SvgDownload as N}from"@itwin/itwinui-icons-react";var V;!function(e){e.Authorization="Authorization",e.ContentType="Content-Type",e.Prefer="Prefer",e.Accept="Accept"}(V||(V={}));class x extends Error{constructor(e,t){super(e?.message),this.code=e?.code,this.statusCode=t}}const k={year:"numeric",month:"short",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!0};const T=e=>e.toLocaleDateString([...navigator.languages],k),P={title:"Change #",createdBy:"Created By",createdDate:"Date Created",application:"Application",connectionAttributes:"Connection Attributes",changedFiles:"Changed Files",noValue:"N/A"};class D{constructor(e,t){this._errorMessagePrefix="@itwin/manage-versions-react",this._defaultErrorMessage="HTTP error without a message.",this._token=e,this._log=t}async get(e,t){const n={method:"GET",url:e,headers:{...t?.headers},signal:t?.abortController?.signal};return this.makeRequest(n)}async post(e,t,n){const a={method:"POST",url:e,headers:{...n?.headers},body:t,signal:n?.abortController?.signal};return this.makeRequest(a)}async patch(e,t,n){const a={method:"PATCH",url:e,headers:{...n?.headers},body:t,signal:n?.abortController?.signal};return this.makeRequest(a)}async delete(e,t){const n={method:"DELETE",url:e,headers:{...t?.headers},signal:t?.abortController?.signal};return this.makeRequest(n)}async makeRequest(e){this.prepareHeaders(e);try{const t=await fetch(e.url,{method:e.method,headers:e.headers,body:e.body?JSON.stringify(e.body):void 0,signal:e?.signal}),n=await t.json();if(!t.ok)throw new x(n?.error,t.status);return n}catch(t){throw this.logError(t,e),t}}prepareHeaders(e){e.headers={[V.Authorization]:this._token,[V.Accept]:"application/vnd.bentley.itwin-platform.v2+json",[V.ContentType]:"application/json",...e.headers}}logError(e,t){this._log?.(`${this._errorMessagePrefix} - ${e.message||this._defaultErrorMessage}`,{request:this.getRequestToLog(t),error:e})}getRequestToLog(e){const t={...e.headers};return delete t[V.Authorization],{headers:t,url:e.url,method:e.method}}}class I{static getBaseUrl(e){return`https://${e?`${e}-`:""}api.bentley.com`}static buildVersionsUrl(e,t,n){return`${this.getBaseUrl(n)}/imodels/${e}/namedversions${t?`/${t}`:""}`}static buildChangesetUrl(e,t){return`${this.getBaseUrl(t)}/imodels/${e}/changesets`}static buildGetUsersUrl(e,t){return`${this.getBaseUrl(t)}/imodels/${e}/users`}}I.getQuery=e=>{const t=Object.entries(e).filter((([e,t])=>!!t)).map((([e,t])=>"lastIndex"===e?`${e}=${t}`:`$${e}=${t}`)).join("&");return t?`?${t}`:""};class S{constructor(e,t,n){this._http=new D(e,n),this._serverEnvironmentPrefix=t}async get(e,t={}){return this._http.get(`${I.buildChangesetUrl(e,this._serverEnvironmentPrefix)}${I.getQuery({orderBy:"index+desc",...t})}`,{headers:{[V.Prefer]:"return=representation",[V.Accept]:"application/vnd.bentley.itwin-platform.v2+json"}}).then((e=>e.changesets))}async getUsers(e){return this._http.get(`${I.buildGetUsersUrl(e,this._serverEnvironmentPrefix)}`,{headers:{[V.Prefer]:"return=representation",[V.Accept]:"application/vnd.bentley.itwin-platform.v2+json"}}).then((e=>e.users))}async getChangesetCheckpoint(e,t,n={}){const a=`${I.buildChangesetUrl(e,this._serverEnvironmentPrefix)}/${t}/checkpoint${I.getQuery(n)}`;return this._http.get(a,{headers:{[V.Accept]:"application/vnd.bentley.itwin-platform.v2+json"}}).then((e=>e.checkpoint))}}class F{constructor(e,t,n){this._http=new D(e,n),this._serverEnvironmentPrefix=t}async get(e,t={}){return this._http.get(`${I.buildVersionsUrl(e,void 0,this._serverEnvironmentPrefix)}${I.getQuery(t)}`,{headers:{[V.Prefer]:"return=representation",[V.Accept]:"application/vnd.bentley.itwin-platform.v2+json"}}).then((e=>e.namedVersions))}async create(e,t){return this._http.post(I.buildVersionsUrl(e,void 0,this._serverEnvironmentPrefix),t).then((e=>e.namedVersion))}async update(e,t,n){return this._http.patch(I.buildVersionsUrl(e,t,this._serverEnvironmentPrefix),n).then((e=>e.namedVersion))}}const _=f.createContext(void 0),U=e=>{const{children:t,...n}=e;return f.createElement(_.Provider,{value:n},t)},A=()=>{const e=f.useContext(_);if(void 0===e)throw new Error("useConfig must be used within a ConfigContext");return e};function B(e,t){void 0===t&&(t={});var n=t.insertAt;if(e&&"undefined"!=typeof document){var a=document.head||document.getElementsByTagName("head")[0],s=document.createElement("style");s.type="text/css","top"===n&&a.firstChild?a.insertBefore(s,a.firstChild):a.appendChild(s),s.styleSheet?s.styleSheet.cssText=e:s.appendChild(document.createTextNode(e))}}B(".iac-changes-table .iui-table-body .iui-table-cell{word-break:break-word}.iac-changes-table .iac-create-version-icon-hidden{visibility:hidden}.iac-changes-table .iac-changes-tab-actions{gap:var(--iui-size-2xs)}");B(".iac-additional-info{display:flex;justify-content:space-between;padding:var(--iui-size-s);background-color:var(--iui-color-background-backdrop)}.iac-additional-info span{flex-shrink:0}.iac-additional-info span:not(:last-child){margin-right:var(--iui-size-m)}.iac-additional-info .iac-cell-ellipsis{white-space:nowrap;overflow:hidden;text-overflow:ellipsis;flex-shrink:1}");B(".iac-version-modal .iui-modal-dialog{max-width:min(600px,50%)}.iac-version-modal-overlay{position:fixed;z-index:99999;height:100vh;width:100vw;top:0;left:0}.iac-version-modal .iui-input-container{margin-bottom:var(--iui-size-s)}");const O=r=>{const{initialVersion:o,isLoading:l,title:c,actionName:d,onClose:m,onActionClick:u,children:g}=r,{stringsOverrides:h}=A(),[p,v]=f.useState({name:o?.name??"",description:o?.description??""}),C=e=>{const t=e.target.name,n=e.target.value;v((e=>({...e,[t]:n??""})))},E=e=>e.length<=255;return f.createElement(f.Fragment,null,f.createElement(e,{title:c,isOpen:!0,onClose:m,className:"iac-version-modal"},f.createElement(t,{setFocus:!0,name:"name",label:h.name,onChange:C,value:p.name,status:E(p.name)?void 0:"negative",message:E(p.name)?void 0:h.messageValueTooLong.replace("{{length}}",255..toString()),required:!0,autoComplete:"off"}),f.createElement(n,{name:"description",label:h.description,onChange:C,value:p.description,status:E(p.description)?void 0:"negative",message:E(p.description)?void 0:h.messageValueTooLong.replace("{{length}}",255..toString()),rows:3,autoComplete:"off"}),g,f.createElement(a,null,f.createElement(s,{styleType:"high-visibility",onClick:()=>u(p.name,p.description),disabled:!(p.name&&(p.name!==o?.name||p.description!==o?.description)&&E(p.name)&&E(p.description))},d),f.createElement(s,{onClick:m},h.cancel)),l&&f.createElement("div",{className:"iui-progress-indicator-overlay"},f.createElement(i,{indeterminate:!0}))),l&&f.createElement("div",{className:"iac-version-modal-overlay"}))},R=e=>{const{latestVersion:t,changeset:n,onClose:a,onCreate:s}=e,{accessToken:i,imodelId:o,apiOverrides:l,stringsOverrides:c,log:d}=A(),[m,u]=f.useState(!1),g=f.useMemo((()=>new F(i,l?.serverEnvironmentPrefix,d)),[i,l?.serverEnvironmentPrefix,d]);return f.createElement(O,{title:c.createNamedVersion,actionName:c.create,isLoading:m,onClose:a,onActionClick:(e,t)=>{u(!0),r.closeAll(),g.create(o,{name:e,description:t,changeSetId:n.id}).then((()=>{u(!1),s(),r.positive(c.messageVersionCreated.replace("{{name}}",e),{hasCloseButton:!0})})).catch((e=>{u(!1),r.negative((e=>{switch(e){case"NamedVersionExists":return c.messageVersionNameExists;case"InsufficientPermissions":return c.messageInsufficientPermissionsToCreateVersion;default:return c.messageCouldNotCreateVersion}})(e.code),{hasCloseButton:!0})}))}},f.createElement("div",{className:"iui-input-container"},f.createElement("div",{className:"iui-label"},"Latest included change"),f.createElement("div",{className:"iac-additional-info"},f.createElement("span",null,"#",n.index),f.createElement("span",null,T(new Date(n.pushDateTime))))),t&&f.createElement("div",{className:"iui-input-container"},f.createElement("div",{className:"iui-label"},"Latest Named Version"),f.createElement("div",{className:"iac-additional-info"},f.createElement("span",{className:"iac-cell-ellipsis"},t.name),f.createElement("span",null,T(new Date(t.createdDateTime))))))};B(".iac-info-panel{width:400px;min-width:400px}.iac-info-panel .iac-info-panel-body .iac-info-panel-container{padding:var(--iui-size-xs)}.iac-info-panel .iac-info-panel-body .iac-info-panel-container+div{border-top:1px solid var(--iui-color-border-subtle)}.iac-info-panel .iac-info-panel-body .iac-info-panel-details{padding:var(--iui-size-xs);display:flex;flex-direction:row;align-items:flex-start;justify-content:space-between}.iac-info-panel .iac-info-panel-body .iac-info-panel-details .iac-info-panel-data-value{flex:2;min-width:50%}.iac-info-panel .iac-info-panel-body .iac-info-panel-property{display:flex;flex:1;margin-right:var(--iui-size-m);justify-content:right;color:var(--iui-color-text-disabled)}");const $=e=>{const{changeset:t,onClose:n,stringOverrides:a=P}=e,s=t.synchronizationInfo?.changedFiles?t.synchronizationInfo.changedFiles:[a.noValue],i=T(new Date(t.pushDateTime)),r=(e,t)=>f.createElement("div",{className:"iac-info-panel-details"},f.createElement("span",{className:"iac-info-panel-property"},`${e}: `),f.createElement("span",{className:"iac-info-panel-data-value"},t));return f.createElement(o,{className:"iac-info-panel",resizable:!1,isOpen:!0},f.createElement(l,{onClose:n},f.createElement(c,{variant:"subheading"},a.title+t.index)),f.createElement(d,null,f.createElement("div",{className:"iac-info-panel-body"},f.createElement(c,{className:"iac-info-panel-container"},t.description),f.createElement("div",{className:"iac-info-panel-container"},r(a.createdBy,t.createdBy??""),r(a.createdDate,i??""),r(a.application,t.application.name??a.noValue)),f.createElement("div",{className:"iac-info-panel-container"},f.createElement(c,{variant:"leading"},a.connectionAttributes),r(a.changedFiles,s.join(","))))))};var L;!function(e){e[e.NotStarted=0]="NotStarted",e[e.InProgress=1]="InProgress",e[e.Finished=2]="Finished",e[e.Failed=3]="Failed"}(L||(L={}));const M=e=>{const{changesets:t,status:n,loadMoreChanges:a,onVersionCreated:s,latestVersion:i}=e,{stringsOverrides:r}=A(),[o,l]=f.useState(!1),[d,g]=f.useState(void 0),[h,p]=f.useState(!1),v=f.useCallback((e=>!e._links.namedVersion),[]),C=f.useMemo((()=>[{Header:"Name",columns:[{id:"INDEX",Header:"#",accessor:"index",width:90},{id:"DESCRIPTION",Header:r.description,accessor:"description"},{id:"CREATOR",Header:r.user??"User",accessor:"createdBy",maxWidth:220,Cell:e=>""!==e.row.original.createdBy?f.createElement(c,null,e.row.original.createdBy):f.createElement(c,{isSkeleton:!0},"Loading user info")},{id:"CHANGED_FILES",Header:r.changedFiles,Cell:e=>{const t=e.row.original.synchronizationInfo?.changedFiles;return t?.length?t.join(", "):""}},{id:"PUSH_DATE",Header:r.time,accessor:"pushDateTime",maxWidth:220,Cell:e=>f.createElement("span",null,T(new Date(e.row.original.pushDateTime)))},{id:"changes-table-actions",width:100,cellClassName:"iac-changes-tab-actions",Cell:e=>{const t=e.data[e.row.index],n=v(t)?"":"iac-create-version-icon-hidden";return f.createElement(f.Fragment,null,f.createElement(m,{onClick:()=>{g(t),l(!0)},title:r.createNamedVersion,styleType:"borderless",className:n,size:"small"},f.createElement(E,null)),f.createElement(m,{title:r.informationPanel??"Information Panel",styleType:"borderless",onClick:()=>(g(t),void p(!0)),size:"small"},f.createElement(w,null)))}}]}]),[r.description,r.user,r.changedFiles,r.time,r.createNamedVersion,r.informationPanel,v]),b=f.useMemo((()=>n===L.Failed?r.messageFailedGetChanges:r.messageNoChanges),[n,r.messageFailedGetChanges,r.messageNoChanges]);return f.createElement(f.Fragment,null,f.createElement(u,{columns:C,data:t,isLoading:n===L.InProgress||n===L.NotStarted,emptyTableContent:b,onBottomReached:a,className:"iac-changes-table"}),o&&f.createElement(R,{changeset:d,onCreate:()=>{l(!1),s()},onClose:()=>l(!1),latestVersion:i}),h&&d&&f.createElement($,{changeset:d,onClose:()=>p(!1),stringOverrides:r.informationPanelStringOverrides}))};B(".iac-versions-table .iui-table-body .iui-table-cell{word-break:break-word}");const z=({menuActions:e})=>{const{stringsOverrides:t}=A(),n=C((t=>e.map(((e,n)=>f.createElement(g,{icon:e.icon,key:n,onClick:()=>{t(),e.onClick()},title:e.title,disabled:e.disabled},e.label)))),[e]);return f.createElement(h,{menuItems:n},f.createElement(m,{onClick:e=>e.stopPropagation(),styleType:"borderless",size:"small",role:"button",label:t.More},f.createElement(b,null)))},H=e=>{const{version:t,onClose:n,onUpdate:a}=e,{accessToken:s,imodelId:i,apiOverrides:o,stringsOverrides:l,log:c}=A(),[d,m]=f.useState(!1),u=f.useMemo((()=>new F(s,o?.serverEnvironmentPrefix,c)),[s,o?.serverEnvironmentPrefix,c]);return f.createElement(O,{title:l.updateNamedVersion,actionName:l.update,initialVersion:t,isLoading:d,onClose:n,onActionClick:(e,n)=>{m(!0),r.closeAll(),u.update(i,t.id,{name:e,description:n}).then((()=>{m(!1),a(),r.positive(l.messageVersionUpdated.replace("{{name}}",e),{hasCloseButton:!0})})).catch((e=>{m(!1),r.negative((e=>{switch(e){case"NamedVersionExists":return l.messageVersionNameExists;case"InsufficientPermissions":return l.messageInsufficientPermissionsToUpdateVersion;default:return l.messageCouldNotUpdateVersion}})(e.code),{hasCloseButton:!0})}))}})},j=e=>"version"in e,q=e=>{const{status:t,onVersionUpdated:n,loadMoreVersions:a,onViewClick:s,tableData:i,changesetClient:o,setRelatedChangesets:l}=e,{stringsOverrides:d,imodelId:m}=A(),[g,h]=f.useState(void 0),[p,v]=f.useState(!1);const E=C((async e=>{r.closeAll();try{const t=(await o.getChangesetCheckpoint(m,e))._links.download.href;window.open(t,"_blank","noopener,noreferrer"),r.informational(d.messageFileDownloadInProgress,{hasCloseButton:!0,duration:2e3})}catch(e){r.negative(d.messageCouldNotDownloadedFileSuccessfully,{hasCloseButton:!0})}}),[o,m,d.messageCouldNotDownloadedFileSuccessfully,d.messageFileDownloadInProgress]),w=f.useMemo((()=>e=>{if(j(e))return f.createElement(c,null,T(new Date(e.version.createdDateTime)));return""!==e.pushDateTime?f.createElement(c,null,T(new Date(e.pushDateTime))):f.createElement(c,{isSkeleton:!0},"Loading Date")}),[]),b=f.useMemo((()=>(e,t)=>{if(["createdDateTime","pushDateTime"].includes(t))return w(e);if(j(e))return f.createElement(c,null,e.version[t]);{const n=e[t];return""!==n?f.createElement(c,null,n):f.createElement(c,{isSkeleton:!0},"Loading")}}),[w]),V=C((e=>[{title:d.updateNamedVersion,label:d.updateNamedVersion,icon:f.createElement(y,null),disabled:!1,onClick:()=>{h(e.row.original.version),v(!0)}},{title:d.download??"Download",label:d.download??"Download",icon:f.createElement(N,null),disabled:!1,onClick:async()=>{const{changesetIndex:t}=e.row.original.version;await E(t)}}]),[E,d.download,d.updateNamedVersion]),x=f.useMemo((()=>{const e=[{Header:"Name",columns:[{id:"NAME",Header:d.name,accessor:"name",Cell:e=>{const t=j(e.row.original)?"name":"displayName";return b(e.row.original,t)}},{id:"DESCRIPTION",Header:d.description,accessor:"description",Cell:e=>b(e.row.original,"description")},{id:"CREATOR",Header:d.user??"User",accessor:"createdBy",maxWidth:220,Cell:e=>{const t=j(e.row.original)?e.row.original.version.createdBy:e.row.original.createdBy;return""!==t?f.createElement(c,null,t):f.createElement(c,{isSkeleton:!0},"Loading user info")}},{id:"CREATED_DATE",Header:d.time,accessor:"createdDateTime",maxWidth:220,Cell:e=>{const t=j(e.row.original)?"createdDateTime":"pushDateTime";return b(e.row.original,t)}},{id:"versions-table-actions",width:62,Cell:e=>f.createElement(f.Fragment,null,j(e.row.original)?f.createElement(z,{menuActions:V(e)}):f.createElement(f.Fragment,null))}]}];return s&&e[0].columns.splice(4,0,{id:"versions-table-view",width:100,Cell:e=>j(e.row.original)?f.createElement("span",{className:"iui-anchor",onClick:()=>s(e.row.original.version)},d.view):f.createElement(f.Fragment,null)}),e}),[d.name,d.description,d.user,d.time,d.view,s,b,V]),k=f.useMemo((()=>t===L.Failed?d.messageFailedGetNamedVersions:d.messageNoNamedVersions),[t,d.messageFailedGetNamedVersions,d.messageNoNamedVersions]);return f.createElement(f.Fragment,null,f.createElement(u,{columns:x,data:i,isLoading:t===L.InProgress||t===L.NotStarted,emptyTableContent:k,onBottomReached:a,className:"iac-versions-table",onExpand:e=>{e?.forEach((e=>{e.subRowsLoaded||async function(e){try{return await o.get(m,{top:10,lastIndex:e})}catch(e){throw e}}(e.version.changesetIndex).then((t=>{const n=[];if(void 0!==t)for(const a of t)if(a.index===e.version.changesetIndex&&null!==a._links.namedVersion||a.index<e.version.changesetIndex&&null===a._links.namedVersion)n.push(a);else if(a.index<e.version.changesetIndex&&null!==a._links.namedVersion)break;l(e.version.id??"",n)})).catch((()=>{console.error("Failed to get Changesets")}))}))},autoResetExpanded:!1}),p&&f.createElement(H,{version:g,onUpdate:()=>{v(!1),n()},onClose:()=>v(!1)}))},G={namedVersions:"Named Versions",changes:"Changes",name:"Name",description:"Description",time:"Time",changedFiles:"Changed Files",createNamedVersion:"Create a Named Version",user:"User",informationPanel:"Information Panel",cancel:"Cancel",create:"Create",updateNamedVersion:"Update a Named Version",update:"Update",download:"Download",More:"More",view:"View",messageFailedGetNamedVersions:"Could not get Named Versions. Please try again later.",messageNoNamedVersions:"There are no Named Versions created. To create first go to Changes.",messageFailedGetChanges:"Could not get changes. Please try again later.",messageNoChanges:"There are no changes synchronized.",messageVersionCreated:'Named Version "{{name}}" was successfully created.',messageVersionNameExists:"Named Version with the same name already exists.",messageInsufficientPermissionsToCreateVersion:"You do not have the required permissions to create a Named Version.",messageCouldNotCreateVersion:"Could not create a Named Version. Please try again later.",messageVersionUpdated:'Named Version "{{name}}" was successfully updated.',messageFileDownloadInProgress:"Downloading file...",messageCouldNotDownloadedFileSuccessfully:"Unable to download file.",messageInsufficientPermissionsToUpdateVersion:"You do not have the required permissions to update a Named Version.",messageCouldNotUpdateVersion:"Could not update a Named Version. Please try again later.",messageValueTooLong:"The value exceeds allowed {{length}} characters.",informationPanelStringOverrides:P};var Q;!function(e){e[e.Versions=0]="Versions",e[e.Changes=1]="Changes"}(Q||(Q={}));const W={id:"",index:0,displayName:"",description:"",pushDateTime:"",synchronizationInfo:{changedFiles:[]},_links:{},creatorId:"",createdBy:"",application:{id:"",name:""}},Y=(e,t,n)=>(e??[]).map(((e,a)=>{const s=t?.[a];return{version:e,subRows:n?[W]:s?.subRows??[W],subRowsLoaded:!n&&(s?.subRowsLoaded??!1)}})),J=(e,t)=>{if(e.length)return e.map((e=>{const n=e._links.creator.href.substring(e._links.creator.href.lastIndexOf("/")+1);return{...e,createdBy:t?.[n]??""}}))},X=(e,t)=>{if(e.length)return e.map((e=>({...e,createdBy:t?.[e.creatorId]??""})))},K=e=>{const{accessToken:t,apiOverrides:n,imodelId:a,stringsOverrides:s=G,log:i,onViewClick:r,currentTab:o=Q.Versions,onTabChange:l}=e,c=f.useMemo((()=>new F(t,n?.serverEnvironmentPrefix,i)),[t,n?.serverEnvironmentPrefix,i]),d=f.useMemo((()=>new S(t,n?.serverEnvironmentPrefix,i)),[t,n?.serverEnvironmentPrefix,i]),[m,u]=f.useState(o),g=f.useRef(void 0),h=f.useCallback((async()=>{const e=(await d.getUsers(a)).reduce(((e,t)=>{const n=[t.givenName,t.surname].filter(Boolean);return e[t.id]=n.length?n.join(" "):t.displayName,e}),{});g.current=e}),[d,a]);f.useEffect((()=>{u(o)}),[o]);const[C,E]=f.useState(),[w,b]=f.useState(L.NotStarted),[y,N]=f.useState(),[V,x]=f.useState(L.NotStarted),k=f.useCallback((e=>{u(e),l?.(e)}),[l]),T=f.useCallback(((e,t)=>{b(L.InProgress),c.get(a,{top:100,skip:e}).then((e=>{e.sort(((e,t)=>t.changesetIndex-e.changesetIndex));const n=J(e,g.current);E((e=>[...Y(n??[],e,t)])),b(L.Finished)})).catch((()=>b(L.Failed)))}),[a,c]),P=f.useCallback((()=>{C&&C.length%100!=0||T(C?.length)}),[T,C]),D=f.useCallback((()=>{y&&y.length%100!=0||(x(L.InProgress),d.get(a,{top:100,skip:y?.length}).then((e=>{N([...y??[],...X(e,g.current)??[]]),x(L.Finished)})).catch((()=>x(L.Failed))))}),[y,d,a]),I=f.useCallback((e=>{T(void 0,e)}),[T]);f.useEffect((()=>{g.current||(async()=>{await h()})().then((()=>{const e=C?.map((e=>{const t=J([e.version]??[],g.current);return{...e,version:t?t[0]:e.version}}));E(e),N((e=>[...X(y??[],g.current)??e??[]]))})).catch((()=>{console.error("Unable to fetch users data")}))}),[y,h,C]),f.useEffect((()=>{m===Q.Versions&&w===L.NotStarted&&T()}),[m,T,w]),f.useEffect((()=>{m===Q.Changes&&V===L.NotStarted&&D()}),[V,m,D]);const _=f.useCallback((()=>{k(Q.Versions),I(!0),N(void 0),x(L.NotStarted)}),[k,I]),A=f.useMemo((()=>[...C??[]].sort(((e,t)=>new Date(e.version.createdDateTime).valueOf()<new Date(t.version.createdDateTime).valueOf()?1:-1))[0]),[C]);return f.createElement(p,{theme:"inherit"},f.createElement(U,{accessToken:t,imodelId:a,apiOverrides:n,stringsOverrides:s,log:i},f.createElement("div",null,f.createElement(v,{labels:[s.namedVersions,s.changes],activeIndex:m,onTabSelected:e=>k(e),type:"borderless"}),m===Q.Versions&&f.createElement(q,{status:w,onVersionUpdated:I,loadMoreVersions:P,onViewClick:r,tableData:C??[],changesetClient:d,setRelatedChangesets:(e,t)=>{const n=X(t,g.current)??[];E((t=>{const a=t?.map((t=>t.version.id===e?{...t,subRows:n,subRowsLoaded:!0}:t));return a??t}))}}),m===Q.Changes&&f.createElement(M,{changesets:y??[],status:V,loadMoreChanges:D,onVersionCreated:_,latestVersion:A?.version}))))};export{K as ManageVersions,Q as ManageVersionsTabs}; | ||
import{Modal as e,LabeledInput as t,LabeledTextarea as n,ModalButtonBar as a,Button as s,ProgressRadial as i,toaster as r,InformationPanel as o,InformationPanelHeader as l,Text as c,InformationPanelBody as d,IconButton as m,Table as u,MenuItem as g,DropdownMenu as h,ThemeProvider as p,HorizontalTabs as v}from"@itwin/itwinui-react";import f,{useCallback as C}from"react";import{SvgNamedVersionAdd as E,SvgInfoCircular as w,SvgMore as b,SvgEdit as y,SvgDownload as N}from"@itwin/itwinui-icons-react";var V;!function(e){e.Authorization="Authorization",e.ContentType="Content-Type",e.Prefer="Prefer",e.Accept="Accept"}(V||(V={}));class x extends Error{constructor(e,t){super(e?.message),this.code=e?.code,this.statusCode=t}}const k={year:"numeric",month:"short",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!0};const T=e=>e.toLocaleDateString([...navigator.languages],k),P={title:"Change #",createdBy:"Created By",createdDate:"Date Created",application:"Application",connectionAttributes:"Connection Attributes",changedFiles:"Changed Files",noValue:"N/A"};class D{constructor(e,t){this._errorMessagePrefix="@itwin/manage-versions-react",this._defaultErrorMessage="HTTP error without a message.",this._token=e,this._log=t}async get(e,t){const n={method:"GET",url:e,headers:{...t?.headers},signal:t?.abortController?.signal};return this.makeRequest(n)}async post(e,t,n){const a={method:"POST",url:e,headers:{...n?.headers},body:t,signal:n?.abortController?.signal};return this.makeRequest(a)}async patch(e,t,n){const a={method:"PATCH",url:e,headers:{...n?.headers},body:t,signal:n?.abortController?.signal};return this.makeRequest(a)}async delete(e,t){const n={method:"DELETE",url:e,headers:{...t?.headers},signal:t?.abortController?.signal};return this.makeRequest(n)}async makeRequest(e){this.prepareHeaders(e);try{const t=await fetch(e.url,{method:e.method,headers:e.headers,body:e.body?JSON.stringify(e.body):void 0,signal:e?.signal}),n=await t.json();if(!t.ok)throw new x(n?.error,t.status);return n}catch(t){throw this.logError(t,e),t}}prepareHeaders(e){e.headers={[V.Authorization]:this._token,[V.Accept]:"application/vnd.bentley.itwin-platform.v2+json",[V.ContentType]:"application/json",...e.headers}}logError(e,t){this._log?.(`${this._errorMessagePrefix} - ${e.message||this._defaultErrorMessage}`,{request:this.getRequestToLog(t),error:e})}getRequestToLog(e){const t={...e.headers};return delete t[V.Authorization],{headers:t,url:e.url,method:e.method}}}class I{static getBaseUrl(e){return`https://${e?`${e}-`:""}api.bentley.com`}static buildVersionsUrl(e,t,n){return`${this.getBaseUrl(n)}/imodels/${e}/namedversions${t?`/${t}`:""}`}static buildChangesetUrl(e,t){return`${this.getBaseUrl(t)}/imodels/${e}/changesets`}static buildGetUsersUrl(e,t){return`${this.getBaseUrl(t)}/imodels/${e}/users`}}I.getQuery=e=>{const t=Object.entries(e).filter((([e,t])=>!!t)).map((([e,t])=>"lastIndex"===e?`${e}=${t}`:`$${e}=${t}`)).join("&");return t?`?${t}`:""};class S{constructor(e,t,n){this._http=new D(e,n),this._serverEnvironmentPrefix=t}async get(e,t={}){return this._http.get(`${I.buildChangesetUrl(e,this._serverEnvironmentPrefix)}${I.getQuery({orderBy:"index+desc",...t})}`,{headers:{[V.Prefer]:"return=representation",[V.Accept]:"application/vnd.bentley.itwin-platform.v2+json"}}).then((e=>e.changesets))}async getUsers(e){return this._http.get(`${I.buildGetUsersUrl(e,this._serverEnvironmentPrefix)}`,{headers:{[V.Prefer]:"return=representation",[V.Accept]:"application/vnd.bentley.itwin-platform.v2+json"}}).then((e=>e.users))}async getChangesetCheckpoint(e,t,n={}){const a=`${I.buildChangesetUrl(e,this._serverEnvironmentPrefix)}/${t}/checkpoint${I.getQuery(n)}`;return this._http.get(a,{headers:{[V.Accept]:"application/vnd.bentley.itwin-platform.v2+json"}}).then((e=>e.checkpoint))}}class F{constructor(e,t,n){this._http=new D(e,n),this._serverEnvironmentPrefix=t}async get(e,t={}){return this._http.get(`${I.buildVersionsUrl(e,void 0,this._serverEnvironmentPrefix)}${I.getQuery(t)}`,{headers:{[V.Prefer]:"return=representation",[V.Accept]:"application/vnd.bentley.itwin-platform.v2+json"}}).then((e=>e.namedVersions))}async create(e,t){return this._http.post(I.buildVersionsUrl(e,void 0,this._serverEnvironmentPrefix),t).then((e=>e.namedVersion))}async update(e,t,n){return this._http.patch(I.buildVersionsUrl(e,t,this._serverEnvironmentPrefix),n).then((e=>e.namedVersion))}}const _=f.createContext(void 0),U=e=>{const{children:t,...n}=e;return f.createElement(_.Provider,{value:n},t)},A=()=>{const e=f.useContext(_);if(void 0===e)throw new Error("useConfig must be used within a ConfigContext");return e};function B(e,t){void 0===t&&(t={});var n=t.insertAt;if(e&&"undefined"!=typeof document){var a=document.head||document.getElementsByTagName("head")[0],s=document.createElement("style");s.type="text/css","top"===n&&a.firstChild?a.insertBefore(s,a.firstChild):a.appendChild(s),s.styleSheet?s.styleSheet.cssText=e:s.appendChild(document.createTextNode(e))}}B(".iac-changes-table .iui-table-body .iui-table-cell{word-break:break-word}.iac-changes-table .iac-create-version-icon-hidden{visibility:hidden}.iac-changes-table .iac-changes-tab-actions{gap:var(--iui-size-2xs)}");B(".iac-additional-info{display:flex;justify-content:space-between;padding:var(--iui-size-s);background-color:var(--iui-color-background-backdrop)}.iac-additional-info span{flex-shrink:0}.iac-additional-info span:not(:last-child){margin-right:var(--iui-size-m)}.iac-additional-info .iac-cell-ellipsis{white-space:nowrap;overflow:hidden;text-overflow:ellipsis;flex-shrink:1}");B(".iac-version-modal .iui-modal-dialog{max-width:min(600px,50%)}.iac-version-modal-overlay{position:fixed;z-index:99999;height:100vh;width:100vw;top:0;left:0}.iac-version-modal .iui-input-container{margin-bottom:var(--iui-size-s)}");const O=r=>{const{initialVersion:o,isLoading:l,title:c,actionName:d,onClose:m,onActionClick:u,children:g}=r,{stringsOverrides:h}=A(),[p,v]=f.useState({name:o?.name??"",description:o?.description??""}),C=e=>{const t=e.target.name,n=e.target.value;v((e=>({...e,[t]:n??""})))},E=e=>e.length<=255;return f.createElement(f.Fragment,null,f.createElement(e,{title:c,isOpen:!0,onClose:m,className:"iac-version-modal"},f.createElement(t,{setFocus:!0,name:"name",label:h.name,onChange:C,value:p.name,status:E(p.name)?void 0:"negative",message:E(p.name)?void 0:h.messageValueTooLong.replace("{{length}}",255..toString()),required:!0,autoComplete:"off"}),f.createElement(n,{name:"description",label:h.description,onChange:C,value:p.description,status:E(p.description)?void 0:"negative",message:E(p.description)?void 0:h.messageValueTooLong.replace("{{length}}",255..toString()),rows:3,autoComplete:"off"}),g,f.createElement(a,null,f.createElement(s,{styleType:"high-visibility",onClick:()=>u(p.name,p.description),disabled:!(p.name&&(p.name!==o?.name||p.description!==o?.description)&&E(p.name)&&E(p.description))},d),f.createElement(s,{onClick:m},h.cancel)),l&&f.createElement("div",{className:"iui-progress-indicator-overlay"},f.createElement(i,{indeterminate:!0}))),l&&f.createElement("div",{className:"iac-version-modal-overlay"}))},R=e=>{const{latestVersion:t,changeset:n,onClose:a,onCreate:s}=e,{accessToken:i,imodelId:o,apiOverrides:l,stringsOverrides:c,log:d}=A(),[m,u]=f.useState(!1),g=f.useMemo((()=>new F(i,l?.serverEnvironmentPrefix,d)),[i,l?.serverEnvironmentPrefix,d]);return f.createElement(O,{title:c.createNamedVersion,actionName:c.create,isLoading:m,onClose:a,onActionClick:(e,t)=>{u(!0),r.closeAll(),g.create(o,{name:e,description:t,changeSetId:n.id}).then((()=>{u(!1),s(),r.positive(c.messageVersionCreated.replace("{{name}}",e),{hasCloseButton:!0})})).catch((e=>{u(!1),r.negative((e=>{switch(e){case"NamedVersionExists":return c.messageVersionNameExists;case"InsufficientPermissions":return c.messageInsufficientPermissionsToCreateVersion;default:return c.messageCouldNotCreateVersion}})(e.code),{hasCloseButton:!0})}))}},f.createElement("div",{className:"iui-input-container"},f.createElement("div",{className:"iui-label"},"Latest included change"),f.createElement("div",{className:"iac-additional-info"},f.createElement("span",null,"#",n.index),f.createElement("span",null,T(new Date(n.pushDateTime))))),t&&f.createElement("div",{className:"iui-input-container"},f.createElement("div",{className:"iui-label"},"Latest Named Version"),f.createElement("div",{className:"iac-additional-info"},f.createElement("span",{className:"iac-cell-ellipsis"},t.name),f.createElement("span",null,T(new Date(t.createdDateTime))))))};B(".iac-info-panel{width:400px;min-width:400px}.iac-info-panel .iac-info-panel-body .iac-info-panel-container{padding:var(--iui-size-xs)}.iac-info-panel .iac-info-panel-body .iac-info-panel-container+div{border-top:1px solid var(--iui-color-border-subtle)}.iac-info-panel .iac-info-panel-body .iac-info-panel-details{padding:var(--iui-size-xs);display:flex;flex-direction:row;align-items:flex-start;justify-content:space-between}.iac-info-panel .iac-info-panel-body .iac-info-panel-details .iac-info-panel-data-value{flex:2;min-width:50%}.iac-info-panel .iac-info-panel-body .iac-info-panel-property{display:flex;flex:1;margin-right:var(--iui-size-m);justify-content:right;color:var(--iui-color-text-disabled)}");const $=e=>{const{changeset:t,onClose:n,stringOverrides:a=P}=e,s=t.synchronizationInfo?.changedFiles?t.synchronizationInfo.changedFiles:[a.noValue],i=T(new Date(t.pushDateTime)),r=(e,t)=>f.createElement("div",{className:"iac-info-panel-details"},f.createElement("span",{className:"iac-info-panel-property"},`${e}: `),f.createElement("span",{className:"iac-info-panel-data-value"},t));return f.createElement(o,{className:"iac-info-panel",resizable:!1,isOpen:!0},f.createElement(l,{onClose:n},f.createElement(c,{variant:"subheading"},a.title+t.index)),f.createElement(d,null,f.createElement("div",{className:"iac-info-panel-body"},f.createElement(c,{className:"iac-info-panel-container"},t.description),f.createElement("div",{className:"iac-info-panel-container"},r(a.createdBy,t.createdBy??""),r(a.createdDate,i??""),r(a.application,t.application.name??a.noValue)),f.createElement("div",{className:"iac-info-panel-container"},f.createElement(c,{variant:"leading"},a.connectionAttributes),r(a.changedFiles,s.join(","))))))};var L;!function(e){e[e.NotStarted=0]="NotStarted",e[e.InProgress=1]="InProgress",e[e.Finished=2]="Finished",e[e.Failed=3]="Failed"}(L||(L={}));const M=e=>{const{changesets:t,status:n,loadMoreChanges:a,onVersionCreated:s,latestVersion:i}=e,{stringsOverrides:r}=A(),[o,l]=f.useState(!1),[d,g]=f.useState(void 0),[h,p]=f.useState(!1),v=f.useCallback((e=>!e._links.namedVersion),[]),C=f.useMemo((()=>[{Header:"Name",columns:[{id:"INDEX",Header:"#",accessor:"index",width:90},{id:"DESCRIPTION",Header:r.description,accessor:"description"},{id:"CREATOR",Header:r.user??"User",accessor:"createdBy",maxWidth:220,Cell:e=>""!==e.row.original.createdBy?f.createElement(c,null,e.row.original.createdBy):f.createElement(c,{isSkeleton:!0},"Loading user info")},{id:"CHANGED_FILES",Header:r.changedFiles,Cell:e=>{const t=e.row.original.synchronizationInfo?.changedFiles;return t?.length?t.join(", "):""}},{id:"PUSH_DATE",Header:r.time,accessor:"pushDateTime",maxWidth:220,Cell:e=>f.createElement("span",null,T(new Date(e.row.original.pushDateTime)))},{id:"changes-table-actions",width:100,cellClassName:"iac-changes-tab-actions",Cell:e=>{const t=e.data[e.row.index],n=v(t)?"":"iac-create-version-icon-hidden";return f.createElement(f.Fragment,null,f.createElement(m,{onClick:()=>{g(t),l(!0)},title:r.createNamedVersion,styleType:"borderless",className:n,size:"small"},f.createElement(E,null)),f.createElement(m,{title:r.informationPanel??"Information Panel",styleType:"borderless",onClick:()=>(g(t),void p(!0)),size:"small"},f.createElement(w,null)))}}]}]),[r.description,r.user,r.changedFiles,r.time,r.createNamedVersion,r.informationPanel,v]),b=f.useMemo((()=>n===L.Failed?r.messageFailedGetChanges:r.messageNoChanges),[n,r.messageFailedGetChanges,r.messageNoChanges]);return f.createElement(f.Fragment,null,f.createElement(u,{columns:C,data:t,isLoading:n===L.InProgress||n===L.NotStarted,emptyTableContent:b,onBottomReached:a,className:"iac-changes-table"}),o&&f.createElement(R,{changeset:d,onCreate:()=>{l(!1),s()},onClose:()=>l(!1),latestVersion:i}),h&&d&&f.createElement($,{changeset:d,onClose:()=>p(!1),stringOverrides:r.informationPanelStringOverrides}))};B(".iac-versions-table .iui-table-body .iui-table-cell{word-break:break-word}");const z=({menuActions:e})=>{const{stringsOverrides:t}=A(),n=C((t=>e.map(((e,n)=>f.createElement(g,{icon:e.icon,key:n,onClick:()=>{t(),e.onClick()},title:e.title,disabled:e.disabled},e.label)))),[e]);return f.createElement(h,{menuItems:n},f.createElement(m,{onClick:e=>e.stopPropagation(),styleType:"borderless",size:"small",role:"button",label:t.More},f.createElement(b,null)))},H=e=>{const{version:t,onClose:n,onUpdate:a}=e,{accessToken:s,imodelId:i,apiOverrides:o,stringsOverrides:l,log:c}=A(),[d,m]=f.useState(!1),u=f.useMemo((()=>new F(s,o?.serverEnvironmentPrefix,c)),[s,o?.serverEnvironmentPrefix,c]);return f.createElement(O,{title:l.updateNamedVersion,actionName:l.update,initialVersion:t,isLoading:d,onClose:n,onActionClick:(e,n)=>{m(!0),r.closeAll(),u.update(i,t.id,{name:e,description:n}).then((()=>{m(!1),a(),r.positive(l.messageVersionUpdated.replace("{{name}}",e),{hasCloseButton:!0})})).catch((e=>{m(!1),r.negative((e=>{switch(e){case"NamedVersionExists":return l.messageVersionNameExists;case"InsufficientPermissions":return l.messageInsufficientPermissionsToUpdateVersion;default:return l.messageCouldNotUpdateVersion}})(e.code),{hasCloseButton:!0})}))}})},j=e=>"version"in e,q=e=>{const{status:t,onVersionUpdated:n,loadMoreVersions:a,onViewClick:s,tableData:i,changesetClient:o,setRelatedChangesets:l}=e,{stringsOverrides:d,imodelId:m}=A(),[g,h]=f.useState(void 0),[p,v]=f.useState(!1);const E=C((async e=>{r.closeAll();try{const t=(await o.getChangesetCheckpoint(m,e))._links.download.href;window.open(t,"_blank","noopener,noreferrer"),r.informational(d.messageFileDownloadInProgress,{hasCloseButton:!0,duration:2e3})}catch(e){r.negative(d.messageCouldNotDownloadedFileSuccessfully,{hasCloseButton:!0})}}),[o,m,d.messageCouldNotDownloadedFileSuccessfully,d.messageFileDownloadInProgress]),w=f.useMemo((()=>e=>{if(j(e))return f.createElement(c,null,T(new Date(e.version.createdDateTime)));return""!==e.pushDateTime?f.createElement(c,null,T(new Date(e.pushDateTime))):f.createElement(c,{isSkeleton:!0},"Loading Date")}),[]),b=f.useMemo((()=>(e,t)=>{if(["createdDateTime","pushDateTime"].includes(t))return w(e);if(j(e)){const n=e.version[t];return f.createElement(c,null,n)}{const n=e[t];return""!==n?f.createElement(c,null,n):f.createElement(c,{isSkeleton:!0},"Loading")}}),[w]),V=C((e=>[{title:d.updateNamedVersion,label:d.updateNamedVersion,icon:f.createElement(y,null),disabled:!1,onClick:()=>{h(e.row.original.version),v(!0)}},{title:d.download??"Download",label:d.download??"Download",icon:f.createElement(N,null),disabled:!1,onClick:async()=>{const{changesetIndex:t}=e.row.original.version;await E(t)}}]),[E,d.download,d.updateNamedVersion]),x=f.useMemo((()=>{const e=[{Header:"Name",columns:[{id:"NAME",Header:d.name,accessor:"name",Cell:e=>{const t=j(e.row.original)?"name":"displayName";return b(e.row.original,t)}},{id:"DESCRIPTION",Header:d.description,accessor:"description",Cell:e=>b(e.row.original,"description")},{id:"CREATOR",Header:d.user??"User",accessor:"createdBy",maxWidth:220,Cell:e=>{const t=j(e.row.original)?e.row.original.version.createdBy:e.row.original.createdBy;return""!==t?f.createElement(c,null,t):f.createElement(c,{isSkeleton:!0},"Loading user info")}},{id:"CREATED_DATE",Header:d.time,accessor:"createdDateTime",maxWidth:220,Cell:e=>{const t=j(e.row.original)?"createdDateTime":"pushDateTime";return b(e.row.original,t)}},{id:"versions-table-actions",width:62,Cell:e=>f.createElement(f.Fragment,null,j(e.row.original)?f.createElement(z,{menuActions:V(e)}):f.createElement(f.Fragment,null))}]}];return s&&e[0].columns.splice(4,0,{id:"versions-table-view",width:100,Cell:e=>j(e.row.original)?f.createElement("span",{className:"iui-anchor",onClick:()=>s(e.row.original.version)},d.view):f.createElement(f.Fragment,null)}),e}),[d.name,d.description,d.user,d.time,d.view,s,b,V]),k=f.useMemo((()=>t===L.Failed?d.messageFailedGetNamedVersions:d.messageNoNamedVersions),[t,d.messageFailedGetNamedVersions,d.messageNoNamedVersions]);return f.createElement(f.Fragment,null,f.createElement(u,{columns:x,data:i,isLoading:t===L.InProgress||t===L.NotStarted,emptyTableContent:k,onBottomReached:a,className:"iac-versions-table",onExpand:e=>{e?.forEach((e=>{e.subRowsLoaded||async function(e){try{return await o.get(m,{top:10,lastIndex:e})}catch(e){throw e}}(e.version.changesetIndex).then((t=>{const n=[];if(void 0!==t)for(const a of t)if(a.index===e.version.changesetIndex&&null!==a._links.namedVersion||a.index<e.version.changesetIndex&&null===a._links.namedVersion)n.push(a);else if(a.index<e.version.changesetIndex&&null!==a._links.namedVersion)break;l(e.version.id??"",n)})).catch((()=>{console.error("Failed to get Changesets")}))}))},autoResetExpanded:!1}),p&&f.createElement(H,{version:g,onUpdate:()=>{v(!1),n()},onClose:()=>v(!1)}))},G={namedVersions:"Named Versions",changes:"Changes",name:"Name",description:"Description",time:"Time",changedFiles:"Changed Files",createNamedVersion:"Create a Named Version",user:"User",informationPanel:"Information Panel",cancel:"Cancel",create:"Create",updateNamedVersion:"Update a Named Version",update:"Update",download:"Download",More:"More",view:"View",messageFailedGetNamedVersions:"Could not get Named Versions. Please try again later.",messageNoNamedVersions:"There are no Named Versions created. To create first go to Changes.",messageFailedGetChanges:"Could not get changes. Please try again later.",messageNoChanges:"There are no changes synchronized.",messageVersionCreated:'Named Version "{{name}}" was successfully created.',messageVersionNameExists:"Named Version with the same name already exists.",messageInsufficientPermissionsToCreateVersion:"You do not have the required permissions to create a Named Version.",messageCouldNotCreateVersion:"Could not create a Named Version. Please try again later.",messageVersionUpdated:'Named Version "{{name}}" was successfully updated.',messageFileDownloadInProgress:"Downloading file...",messageCouldNotDownloadedFileSuccessfully:"Unable to download file.",messageInsufficientPermissionsToUpdateVersion:"You do not have the required permissions to update a Named Version.",messageCouldNotUpdateVersion:"Could not update a Named Version. Please try again later.",messageValueTooLong:"The value exceeds allowed {{length}} characters.",informationPanelStringOverrides:P};var Q;!function(e){e[e.Versions=0]="Versions",e[e.Changes=1]="Changes"}(Q||(Q={}));const W={id:"",index:0,displayName:"",description:"",pushDateTime:"",synchronizationInfo:{changedFiles:[]},_links:{},creatorId:"",createdBy:"",application:{id:"",name:""}},Y=(e,t,n)=>(e??[]).map(((e,a)=>{const s=t?.[a];return{version:e,subRows:n?[W]:s?.subRows??[W],subRowsLoaded:!n&&(s?.subRowsLoaded??!1)}})),J=(e,t)=>{if(e.length)return e.map((e=>{const n=e._links.creator.href.substring(e._links.creator.href.lastIndexOf("/")+1);return{...e,createdBy:t?.[n]??""}}))},X=(e,t)=>{if(e.length)return e.map((e=>({...e,createdBy:t?.[e.creatorId]??""})))},K=e=>{const{accessToken:t,apiOverrides:n,imodelId:a,stringsOverrides:s=G,log:i,onViewClick:r,currentTab:o=Q.Versions,onTabChange:l}=e,c=f.useMemo((()=>new F(t,n?.serverEnvironmentPrefix,i)),[t,n?.serverEnvironmentPrefix,i]),d=f.useMemo((()=>new S(t,n?.serverEnvironmentPrefix,i)),[t,n?.serverEnvironmentPrefix,i]),[m,u]=f.useState(o),g=f.useRef(void 0),h=f.useCallback((async()=>{const e=(await d.getUsers(a)).reduce(((e,t)=>{const n=[t.givenName,t.surname].filter(Boolean);return e[t.id]=n.length?n.join(" "):t.displayName,e}),{});g.current=e}),[d,a]);f.useEffect((()=>{u(o)}),[o]);const[C,E]=f.useState(),[w,b]=f.useState(L.NotStarted),[y,N]=f.useState(),[V,x]=f.useState(L.NotStarted),k=f.useCallback((e=>{u(e),l?.(e)}),[l]),T=f.useCallback(((e,t)=>{b(L.InProgress),c.get(a,{top:100,skip:e}).then((e=>{e.sort(((e,t)=>t.changesetIndex-e.changesetIndex));const n=J(e,g.current);E((e=>[...Y(n??[],e,t)])),b(L.Finished)})).catch((()=>b(L.Failed)))}),[a,c]),P=f.useCallback((()=>{C&&C.length%100!=0||T(C?.length)}),[T,C]),D=f.useCallback((()=>{y&&y.length%100!=0||(x(L.InProgress),d.get(a,{top:100,skip:y?.length}).then((e=>{N([...y??[],...X(e,g.current)??[]]),x(L.Finished)})).catch((()=>x(L.Failed))))}),[y,d,a]),I=f.useCallback((e=>{T(void 0,e)}),[T]);f.useEffect((()=>{g.current||(async()=>{await h()})().then((()=>{const e=C?.map((e=>{const t=J([e.version]??[],g.current);return{...e,version:t?t[0]:e.version}}));e&&E(e),N((e=>[...X(y??[],g.current)??e??[]]))})).catch((()=>{console.error("Unable to fetch users data")}))}),[y,h,C]),f.useEffect((()=>{m===Q.Versions&&w===L.NotStarted&&T()}),[m,T,w]),f.useEffect((()=>{m===Q.Changes&&V===L.NotStarted&&D()}),[V,m,D]);const _=f.useCallback((()=>{k(Q.Versions),I(!0),N(void 0),x(L.NotStarted)}),[k,I]),A=f.useMemo((()=>[...C??[]].sort(((e,t)=>new Date(e.version.createdDateTime).valueOf()<new Date(t.version.createdDateTime).valueOf()?1:-1))[0]),[C]);return f.createElement(p,{theme:"inherit"},f.createElement(U,{accessToken:t,imodelId:a,apiOverrides:n,stringsOverrides:s,log:i},f.createElement("div",null,f.createElement(v,{labels:[s.namedVersions,s.changes],activeIndex:m,onTabSelected:e=>k(e),type:"borderless"}),m===Q.Versions&&f.createElement(q,{status:w,onVersionUpdated:I,loadMoreVersions:P,onViewClick:r,tableData:C??[],changesetClient:d,setRelatedChangesets:(e,t)=>{const n=X(t,g.current)??[];E((t=>{const a=t?.map((t=>t.version.id===e?{...t,subRows:n,subRowsLoaded:!0}:t));return a??t}))}}),m===Q.Changes&&f.createElement(M,{changesets:y??[],status:V,loadMoreChanges:D,onVersionCreated:_,latestVersion:A?.version}))))};export{K as ManageVersions,Q as ManageVersionsTabs}; |
@@ -5,3 +5,3 @@ { | ||
"repository": "https://github.com/iTwin/admin-components-react/tree/main/packages/modules/manage-versions", | ||
"version": "1.4.0", | ||
"version": "2.0.0", | ||
"main": "cjs/index.js", | ||
@@ -44,4 +44,4 @@ "module": "esm/index.js", | ||
"@types/jest": "^27.5.1", | ||
"@types/react": "^17.0.37", | ||
"@types/react-dom": "^17.0.0", | ||
"@types/react": "^18.3.5", | ||
"@types/react-dom": "^18.3.0", | ||
"@types/react-table": "~7.7.14", | ||
@@ -65,4 +65,4 @@ "@typescript-eslint/eslint-plugin": "^5.62.0", | ||
"prettier": "^2.0.5", | ||
"react": "^17.0.2", | ||
"react-dom": "^17.0.2", | ||
"react": "^18.3.1", | ||
"react-dom": "^18.3.1", | ||
"rimraf": "^3.0.2", | ||
@@ -79,5 +79,5 @@ "rollup-plugin-peer-deps-external": "^2.2.4", | ||
"peerDependencies": { | ||
"react": "^16.13.0 || ^17.0.2", | ||
"react-dom": "^16.13.0 || ^17.0.2" | ||
"react": "^17.0.2 || ^18.3.1", | ||
"react-dom": "^17.0.2 || ^18.3.1" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
82806