Skip to content

Commit

Permalink
updated the UI to no longer break when encountering disabled artifacts.
Browse files Browse the repository at this point in the history
Fixes #788 (#853)
  • Loading branch information
EricWittmann authored Sep 20, 2020
1 parent 93b9d21 commit 8cebce0
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
import io.apicurio.registry.storage.RegistryStorage;
import io.apicurio.registry.storage.RuleConfigurationDto;
import io.apicurio.registry.storage.StoredArtifact;
import io.apicurio.registry.storage.VersionNotFoundException;
import io.apicurio.registry.types.ArtifactMediaTypes;
import io.apicurio.registry.types.ArtifactState;
import io.apicurio.registry.types.ArtifactType;
Expand Down Expand Up @@ -351,7 +352,7 @@ public CompletionStage<ArtifactMetaData> createArtifact(ArtifactType xRegistryAr
@Override
public Response getLatestArtifact(String artifactId) {
ArtifactMetaDataDto metaData = storage.getArtifactMetaData(artifactId);
if(ArtifactState.DISABLED.equals(metaData.getState())) {
if (ArtifactState.DISABLED.equals(metaData.getState())) {
throw new ArtifactNotFoundException(artifactId);
}
StoredArtifact artifact = storage.getArtifact(artifactId);
Expand Down Expand Up @@ -446,9 +447,9 @@ public CompletionStage<VersionMetaData> createArtifactVersion(String artifactId,
*/
@Override
public Response getArtifactVersion(Integer version, String artifactId) {
ArtifactMetaDataDto metaData = storage.getArtifactMetaData(artifactId);
if(ArtifactState.DISABLED.equals(metaData.getState())) {
throw new ArtifactNotFoundException(artifactId);
ArtifactVersionMetaDataDto metaData = storage.getArtifactVersionMetaData(artifactId, version);
if (ArtifactState.DISABLED.equals(metaData.getState())) {
throw new VersionNotFoundException(artifactId, version);
}
StoredArtifact artifact = storage.getArtifactVersion(artifactId, version);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,20 @@ export interface ArtifactVersionPageState extends PageState {
invalidContentError: any | null;
}

function is404(e: any) {
if (typeof e === "string") {
try {
const eo: any = JSON.parse(e);
if (eo && eo.error_code && eo.error_code === 404) {
return true;
}
} catch (e) {
// Do nothing
}
}
return false;
}

/**
* The artifacts page.
*/
Expand Down Expand Up @@ -198,7 +212,17 @@ export class ArtifactVersionPage extends PageComponent<ArtifactVersionPageProps,
Services.getLoggerService().info("Loading data for artifact: ", artifactId);
return [
Services.getArtifactsService().getArtifactMetaData(artifactId, this.version()).then(md => this.setSingleState("artifact", md)),
Services.getArtifactsService().getArtifactContent(artifactId, this.version()).then(content => this.setSingleState("artifactContent", content)),
Services.getArtifactsService().getArtifactContent(artifactId, this.version())
.then(content => this.setSingleState("artifactContent", content))
.catch(e => {
Services.getLoggerService().warn("Failed to get artifact content: ", e);
if (is404(e)) {
this.setSingleState("artifactContent", "Artifact version content not available (404 Not Found).");
} else {
throw e;
}
}
),
Services.getArtifactsService().getArtifactRules(artifactId).then(rules => this.setSingleState("rules", rules)),
Services.getArtifactsService().getArtifactVersions(artifactId).then(versions => this.setSingleState("versions", versions.reverse()))
];
Expand All @@ -222,7 +246,7 @@ export class ArtifactVersionPage extends PageComponent<ArtifactVersionPageProps,

private showDocumentationTab(): boolean {
if (this.state.artifact) {
return this.state.artifact.type === "OPENAPI";
return this.state.artifact.type === "OPENAPI" && this.state.artifact.state !== "DISABLED";
} else {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
content: ')';
}

.artifact-list .artifact-list-item .content-cell .artifact-title .status-badge {
margin-left: 10px;
border: 1px solid #ccc;
}

.artifact-list .artifact-list-item .content-cell .artifact-description {
font-size: 13px;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ import {
DataListAction,
DataListCell,
DataListItemCells,
DataListItemRow
DataListItemRow,
Label
} from '@patternfly/react-core';
import {SearchedArtifact} from "@apicurio/registry-models";
import {Link} from "react-router-dom";
import {ArtifactTypeIcon, PureComponent, PureComponentProps, PureComponentState} from "../../../../components";
import {Services} from "@apicurio/registry-services";
import {ArtifactName} from "./artifactName";

/**
Expand Down Expand Up @@ -68,6 +68,11 @@ export class ArtifactList extends PureComponent<ArtifactListProps, ArtifactListS
<DataListCell key="main content" className="content-cell">
<div className="artifact-title">
<ArtifactName id={artifact.id} name={artifact.name} />
{
this.statuses(artifact).map( status =>
<Badge className="status-badge" key={status} isRead={true}>{status}</Badge>
)
}
</div>
<div className="artifact-description">{this.description(artifact)}</div>
<div className="artifact-tags">
Expand Down Expand Up @@ -102,6 +107,17 @@ export class ArtifactList extends PureComponent<ArtifactListProps, ArtifactListS
return artifact.labels ? artifact.labels : [];
}

private statuses(artifact: SearchedArtifact): string[] {
const rval: string[] = [];
if (artifact.state === "DISABLED") {
rval.push("Disabled");
}
if (artifact.state === "DEPRECATED") {
rval.push("Deprecated");
}
return rval;
}

private artifactLink(artifact: SearchedArtifact): string {
const link: string = `/artifacts/${ encodeURIComponent(artifact.id) }`;
return link;
Expand Down

0 comments on commit 8cebce0

Please sign in to comment.