Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix rename dialog, await error #56

Merged
merged 1 commit into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 15 additions & 17 deletions src/extensions/savetoLaserfiche/SaveToLaserficheDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ import { SPComponentLoader } from '@microsoft/sp-loader';
import * as ReactDOM from 'react-dom';
import { BaseDialog } from '@microsoft/sp-dialog';
import { getRegion } from '../../Utils/Funcs';
import {
APIServerException,
Entry,
} from '@laserfiche/lf-repository-api-client';
import { Entry } from '@laserfiche/lf-repository-api-client';
import { RepositoryClientExInternal } from '../../repository-client/repository-client';
import { IRepositoryApiClientExInternal } from '../../repository-client/repository-client-types';
import { PathUtils } from '@laserfiche/lf-js-utils';
Expand Down Expand Up @@ -76,7 +73,8 @@ export default class SaveToLaserficheCustomDialog extends BaseDialog {
}
}

const ENTRY_WITH_SAME_NAME_EXISTS_IN_FOLDER_IF_CONTINUE_LF_WILL_RENAME = 'An entry with the same name already exists in the specified folder. If you continue, Laserfiche will automatically rename the new document.';
const ENTRY_WITH_SAME_NAME_EXISTS_IN_FOLDER_IF_CONTINUE_LF_WILL_RENAME =
'An entry with the same name already exists in the specified folder. If you continue, Laserfiche will automatically rename the new document.';
function SaveToLaserficheDialog(props: {
isSuccessfulLoggedIn: (success: boolean) => void;
closeClick: (success?: SavedToLaserficheDocumentData) => Promise<void>;
Expand Down Expand Up @@ -112,9 +110,9 @@ function SaveToLaserficheDialog(props: {

React.useEffect(() => {
const initializeComponentAsync: () => Promise<void> = async () => {
await SPComponentLoader.loadScript(ZONE_JS_URL);
await SPComponentLoader.loadScript(LF_UI_COMPONENTS_URL);
try {
await SPComponentLoader.loadScript(ZONE_JS_URL);
await SPComponentLoader.loadScript(LF_UI_COMPONENTS_URL);
if (loginComponent.current?.authorization_credentials) {
const validRepoClient = await tryGetValidRepositoryClientAsync();
const saveToLF = new SaveDocumentToLaserfiche(
Expand All @@ -129,13 +127,14 @@ function SaveToLaserficheDialog(props: {
repoId,
entryId: Number.parseInt(props.spFileMetadata.entryId, 10),
});
const entryWithPathExists = validRepoClient.entriesClient.getEntryByPath({
repoId,
fullPath: PathUtils.combinePaths(
entryInfo.fullPath,
props.spFileMetadata.fileName
),
});
const entryWithPathExists =
await validRepoClient.entriesClient.getEntryByPath({
repoId,
fullPath: PathUtils.combinePaths(
entryInfo.fullPath,
PathUtils.removeFileExtension(props.spFileMetadata.fileName)
),
});
if (entryWithPathExists) {
setShowSaveTo(false);
const confirmSave = await getConfirmation(
Expand All @@ -151,11 +150,10 @@ function SaveToLaserficheDialog(props: {
}
}
} catch (err) {
const docDoesNotAlreadyExists = (err as APIServerException).statusCode === 404;
const docDoesNotAlreadyExists = err.status === 404;
if (docDoesNotAlreadyExists) {
await continueSavingDocumentAsync(saveToLF);
}
else {
} else {
throw err;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ export default function LaserficheRepositoryAccessWebPart(
};

const initializeComponentAsync: () => Promise<void> = async () => {
await SPComponentLoader.loadScript(ZONE_JS_URL);
await SPComponentLoader.loadScript(LF_UI_COMPONENTS_URL);
SPComponentLoader.loadCss(LF_INDIGO_PINK_CSS_URL);
SPComponentLoader.loadCss(LF_MS_OFFICE_LITE_CSS_URL);
try {
await SPComponentLoader.loadScript(ZONE_JS_URL);
await SPComponentLoader.loadScript(LF_UI_COMPONENTS_URL);
SPComponentLoader.loadCss(LF_INDIGO_PINK_CSS_URL);
SPComponentLoader.loadCss(LF_MS_OFFICE_LITE_CSS_URL);
const loginCompleted: () => Promise<void> = async () => {
await getAndInitializeRepositoryClientAndServicesAsync();
setLoggedIn(true);
Expand Down Expand Up @@ -176,15 +176,15 @@ export default function LaserficheRepositoryAccessWebPart(
</button>
</div>
{messageErrorModal !== undefined && (
<div
className={styles.modal}
id='messageErrorModal'
data-backdrop='static'
data-keyboard='false'
>
{messageErrorModal}
</div>
)}
<div
className={styles.modal}
id='messageErrorModal'
data-backdrop='static'
data-keyboard='false'
>
{messageErrorModal}
</div>
)}
<RepositoryViewComponent
webClientUrl={webClientUrl}
repoClient={repoClient}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
PostEntryWithEdocMetadataRequest,
PutFieldValsRequest,
FileParameter,
APIServerException,
} from '@laserfiche/lf-repository-api-client';
import {
LfRepoTreeNodeService,
Expand Down Expand Up @@ -388,7 +387,8 @@ function RepositoryBrowserToolbar(props: {
);
}

const ENTRY_WITH_SAME_NAME_EXISTS_IN_FOLDER_IF_CONTINUE_LF_WILL_RENAME = 'An entry with the same name already exists in the specified folder. If you continue, Laserfiche will automatically rename the new document.';
const ENTRY_WITH_SAME_NAME_EXISTS_IN_FOLDER_IF_CONTINUE_LF_WILL_RENAME =
'An entry with the same name already exists in the specified folder. If you continue, Laserfiche will automatically rename the new document.';
function ImportFileModal(props: {
repoClient: IRepositoryApiClientExInternal;
loggedIn: boolean;
Expand Down Expand Up @@ -467,10 +467,11 @@ function ImportFileModal(props: {
const renamedFile = new File([fileData], fileName + extension);
const fileContainsBacklash = fileName.includes('\\');
try {
const entryWithPathExists = await props.repoClient.entriesClient.getEntryByPath({
repoId,
fullPath: PathUtils.combinePaths(props.parentItem.path, fileName),
});
const entryWithPathExists =
await props.repoClient.entriesClient.getEntryByPath({
repoId,
fullPath: PathUtils.combinePaths(props.parentItem.path, fileName),
});
if (entryWithPathExists) {
setShowImport(false);
const confirmUpload = await getConfirmation(
Expand All @@ -485,10 +486,10 @@ function ImportFileModal(props: {
}
}
} catch (err) {
if ((err as APIServerException).statusCode === 404) {
const docDoesNotAlreadyExists = err.status === 404;
if (docDoesNotAlreadyExists) {
// doesn't exist, good to go
}
else {
} else {
throw err;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ export default function LaserficheAdminConfiguration(

React.useEffect(() => {
const initializeComponentAsync: () => Promise<void> = async () => {
SPComponentLoader.loadCss(LF_INDIGO_PINK_CSS_URL);
SPComponentLoader.loadCss(LF_MS_OFFICE_LITE_CSS_URL);
await SPComponentLoader.loadScript(ZONE_JS_URL);
await SPComponentLoader.loadScript(LF_UI_COMPONENTS_URL);
try {
SPComponentLoader.loadCss(LF_INDIGO_PINK_CSS_URL);
SPComponentLoader.loadCss(LF_MS_OFFICE_LITE_CSS_URL);
await SPComponentLoader.loadScript(ZONE_JS_URL);
await SPComponentLoader.loadScript(LF_UI_COMPONENTS_URL);
const loginCompleted: () => Promise<void> = async () => {
await getAndInitializeRepositoryClientAndServicesAsync();
setLoggedIn(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,16 +136,16 @@ export default function SendToLaserficheLoginComponent(
};

const setUpLoginComponentAsync: () => Promise<void> = async () => {
try {
SPComponentLoader.loadCss(LF_INDIGO_PINK_CSS_URL);
SPComponentLoader.loadCss(LF_MS_OFFICE_LITE_CSS_URL);
loginComponent.current.addEventListener(
'logoutCompleted',
logoutCompletedInPopup
);
await SPComponentLoader.loadScript(ZONE_JS_URL);
await SPComponentLoader.loadScript(LF_UI_COMPONENTS_URL);
SPComponentLoader.loadCss(LF_INDIGO_PINK_CSS_URL);
SPComponentLoader.loadCss(LF_MS_OFFICE_LITE_CSS_URL);
loginComponent.current.addEventListener(
'logoutCompleted',
logoutCompletedInPopup
);
await SPComponentLoader.loadScript(ZONE_JS_URL);
await SPComponentLoader.loadScript(LF_UI_COMPONENTS_URL);

try {
if (window.location.href.includes('autologin')) {
document.body.style.display = 'none';
await handleLoginOrLogoutInPopupAsync();
Expand Down