feat(import): complete OpenAPI onboarding and verify delivery
This commit is contained in:
1 parent
bb3e376767
commit
e93de7015a
244 files changed
+57020
-5139
No files matched your search
@@ -1,6 +1,8 @@
|
||||
var wizardOperationLoadGeneration = 0;
|
||||
var wizardLifecycleActionBusy = false;
|
||||
var wizardTestConfirmationToken = null;
|
||||
var wizardSavedDraftPayload = null;
|
||||
var wizardPinnedVersionStale = false;
|
||||
|
||||
function operationErrorCode(error) {
|
||||
return error && error.payload && error.payload.error
|
||||
@@ -130,12 +132,33 @@ async function saveOperation(stayOnPage) {
|
||||
async function loadOperationForEdit() {
|
||||
if (!wizardWorkspaceId || !wizardEditId) return;
|
||||
var generation = ++wizardOperationLoadGeneration;
|
||||
wizardCurrentOperation = null;
|
||||
wizardCurrentVersion = null;
|
||||
wizardSavedDraftPayload = null;
|
||||
wizardPinnedVersionStale = false;
|
||||
var pinnedVersionValue = new URLSearchParams(window.location.search).get('operationVersion');
|
||||
var pinnedVersion = null;
|
||||
if (pinnedVersionValue !== null) {
|
||||
pinnedVersion = Number(pinnedVersionValue);
|
||||
if (!/^[0-9]{1,10}$/.test(pinnedVersionValue) || !Number.isSafeInteger(pinnedVersion) || pinnedVersion < 1) {
|
||||
wizardPinnedVersionStale = true;
|
||||
showWizardLiveStatus(tKey('wizard.stale.title'), tKey('wizard.stale.body'), true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
var requestedWorkspaceId = wizardWorkspaceId;
|
||||
var requestedOperationId = wizardEditId;
|
||||
var detail = await window.CrankApi.getOperation(requestedWorkspaceId, requestedOperationId);
|
||||
if (generation !== wizardOperationLoadGeneration
|
||||
|| requestedWorkspaceId !== wizardWorkspaceId
|
||||
|| requestedOperationId !== wizardEditId) return;
|
||||
var detailDraftVersion = Number(detail.draft_version_ref && detail.draft_version_ref.version
|
||||
|| detail.current_draft_version);
|
||||
if (pinnedVersion !== null && detailDraftVersion !== pinnedVersion) {
|
||||
wizardPinnedVersionStale = true;
|
||||
showWizardLiveStatus(tKey('wizard.stale.title'), tKey('wizard.stale.body'), true);
|
||||
return;
|
||||
}
|
||||
wizardProtocol = detail.protocol || 'rest';
|
||||
await loadWizardPanels([3]);
|
||||
var draftVersion = await window.CrankApi.getOperationVersion(
|
||||
@@ -146,9 +169,24 @@ async function loadOperationForEdit() {
|
||||
if (generation !== wizardOperationLoadGeneration
|
||||
|| requestedWorkspaceId !== wizardWorkspaceId
|
||||
|| requestedOperationId !== wizardEditId) return;
|
||||
if (pinnedVersion !== null) {
|
||||
var currentDetail = await window.CrankApi.getOperation(requestedWorkspaceId, requestedOperationId);
|
||||
if (generation !== wizardOperationLoadGeneration
|
||||
|| requestedWorkspaceId !== wizardWorkspaceId
|
||||
|| requestedOperationId !== wizardEditId) return;
|
||||
var currentDraftVersion = Number(currentDetail.draft_version_ref && currentDetail.draft_version_ref.version
|
||||
|| currentDetail.current_draft_version);
|
||||
if (currentDraftVersion !== pinnedVersion) {
|
||||
wizardPinnedVersionStale = true;
|
||||
showWizardLiveStatus(tKey('wizard.stale.title'), tKey('wizard.stale.body'), true);
|
||||
return;
|
||||
}
|
||||
detail = currentDetail;
|
||||
}
|
||||
wizardCurrentOperation = detail;
|
||||
wizardCurrentVersion = draftVersion;
|
||||
prefillWizardFromEdit(detail, draftVersion);
|
||||
wizardSavedDraftPayload = updateOperationPayload(collectWizardPayload());
|
||||
renderAgentFacingPreview();
|
||||
renderImportQualityFindings(draftVersion);
|
||||
}
|
||||
@@ -375,6 +413,27 @@ function updateOperationPayload(payload) {
|
||||
};
|
||||
}
|
||||
|
||||
function canonicalDraftPayload(payload) {
|
||||
var editablePayload = updateOperationPayload(payload);
|
||||
delete editablePayload.category;
|
||||
|
||||
function sortKeys(value) {
|
||||
if (Array.isArray(value)) return value.map(sortKeys);
|
||||
if (!value || typeof value !== 'object') return value;
|
||||
return Object.keys(value).sort().reduce(function(sorted, key) {
|
||||
sorted[key] = sortKeys(value[key]);
|
||||
return sorted;
|
||||
}, {});
|
||||
}
|
||||
|
||||
return JSON.stringify(sortKeys(editablePayload));
|
||||
}
|
||||
|
||||
function draftPayloadMatchesBaseline(payload) {
|
||||
return wizardSavedDraftPayload !== null
|
||||
&& canonicalDraftPayload(payload) === canonicalDraftPayload(wizardSavedDraftPayload);
|
||||
}
|
||||
|
||||
async function refreshCurrentOperationState() {
|
||||
if (!wizardWorkspaceId || !wizardEditId) return null;
|
||||
var detail = await window.CrankApi.getOperation(wizardWorkspaceId, wizardEditId);
|
||||
@@ -396,6 +455,9 @@ async function refreshCurrentOperationState() {
|
||||
}
|
||||
|
||||
async function persistCurrentDraft(stayOnPage) {
|
||||
if (wizardPinnedVersionStale) {
|
||||
throw new Error(tKey('wizard.stale.body'));
|
||||
}
|
||||
if (!wizardWorkspaceId) {
|
||||
throw new Error(tKey('wizard.error.no_workspace'));
|
||||
}
|
||||
@@ -405,14 +467,33 @@ async function persistCurrentDraft(stayOnPage) {
|
||||
var createdNow = false;
|
||||
|
||||
if (wizardMode === 'edit' && wizardEditId) {
|
||||
if (draftPayloadMatchesBaseline(payload)) {
|
||||
if (stayOnPage) {
|
||||
var unchangedSaveDraftBtn = document.querySelector('.btn-save-draft');
|
||||
if (unchangedSaveDraftBtn) {
|
||||
var unchangedLabel = unchangedSaveDraftBtn.textContent;
|
||||
unchangedSaveDraftBtn.textContent = tKey('wizard.save.saved');
|
||||
setTimeout(function() {
|
||||
unchangedSaveDraftBtn.textContent = unchangedLabel;
|
||||
}, 1400);
|
||||
}
|
||||
}
|
||||
return {
|
||||
operation_id: wizardEditId,
|
||||
version: currentDraftVersion(),
|
||||
status: 'draft',
|
||||
};
|
||||
}
|
||||
response = await window.CrankApi.updateOperation(
|
||||
wizardWorkspaceId,
|
||||
wizardEditId,
|
||||
updateOperationPayload(payload)
|
||||
);
|
||||
wizardSavedDraftPayload = updateOperationPayload(payload);
|
||||
} else {
|
||||
response = await window.CrankApi.createOperation(wizardWorkspaceId, payload);
|
||||
createdNow = true;
|
||||
wizardSavedDraftPayload = updateOperationPayload(payload);
|
||||
wizardEditId = response.operation_id;
|
||||
wizardMode = 'edit';
|
||||
history.replaceState(
|
||||
|
||||
Reference in new issue
Block a user