Skip to content

Commit

Permalink
v0.6.5
Browse files Browse the repository at this point in the history
Use hash router to prevent 404 pages in Tomcat
  • Loading branch information
ekuiter committed Mar 25, 2019
1 parent f91255d commit ca24786
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
4 changes: 3 additions & 1 deletion client/src/components/CommandBarContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ const CommandBarContainer = (props: StateDerivedProps & RouteProps) => (
...props.collaborativeSessions!.length > 1
? [{
key: 'collaborativeSessions',
text: artifactPathToString(props.currentArtifactPath!),
text: props.currentArtifactPath
? artifactPathToString(props.currentArtifactPath!)
: i18n.t('commandPalette.switch'),
subMenuProps: {
items: props.collaborativeSessions!
.map(collaborativeSession => {
Expand Down
4 changes: 2 additions & 2 deletions client/src/components/FeatureDiagramRouteContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, {CSSProperties} from 'react';
import {StateDerivedProps, State} from '../store/types';
import {getArtifactPathFromPath} from '../router';
import {getArtifactPathFromLocation} from '../router';
import {isArtifactPathEqual, RouteProps} from '../types';
import SplitView from './SplitView';
import ConstraintsView, {enableConstraintsView} from './constraintsView/ConstraintsView';
Expand All @@ -26,7 +26,7 @@ class FeatureDiagramRoute extends React.Component<FeatureDiagramRouteProps> {
}

onRouteChanged() {
const artifactPath = getArtifactPathFromPath();
const artifactPath = getArtifactPathFromLocation();
if (artifactPath && !this.props.collaborativeSessions!.find(collaborativeSession =>
isArtifactPathEqual(collaborativeSession.artifactPath, artifactPath))) {
this.props.onJoinRequest!({artifactPath}); // TODO: error handling
Expand Down
3 changes: 2 additions & 1 deletion client/src/components/overlays/FeatureComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ export default ({doUpdate = false} = {}) =>
window.clearInterval(this.interval);
}

getFeature = () => this.props.featureID && this.props.featureModel.getFeature(this.props.featureID!);
getFeature = () => this.props.featureID && this.props.featureModel &&
this.props.featureModel.getFeature(this.props.featureID!);

renderIfFeature(_feature: Feature): JSX.Element | null {
throw new Error('abstract method not implemented');
Expand Down
15 changes: 8 additions & 7 deletions client/src/router.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import {ArtifactPath, isArtifactPathEqual} from './types';
import {createBrowserHistory} from 'history';
import {createHashHistory} from 'history';
import {CollaborativeSession} from './store/types';

export const history = createBrowserHistory();
export const history = createHashHistory();
(window as any).h = history;

export function getArtifactPathFromPath(): ArtifactPath | undefined {
export function getArtifactPathFromLocation(): ArtifactPath | undefined {
let path = history.location.pathname.substr(1);
if (!path)
return;
Expand All @@ -15,23 +16,23 @@ export function getArtifactPathFromPath(): ArtifactPath | undefined {
}

export function getCurrentArtifactPath(collaborativeSessions: CollaborativeSession[]): ArtifactPath | undefined {
const artifactPath = getArtifactPathFromPath();
const artifactPath = getArtifactPathFromLocation();
return collaborativeSessions.find(collaborativeSession =>
isArtifactPathEqual(collaborativeSession.artifactPath, artifactPath))
? artifactPath
: undefined;
}

function getPathFromArtifactPath(artifactPath?: ArtifactPath) {
function getLocationFromArtifactPath(artifactPath?: ArtifactPath) {
if (!artifactPath)
return '/';
return `/${artifactPath.project}/${artifactPath.artifact}`;
}

export function getShareableURL(artifactPath: ArtifactPath) {
return `${window.location.protocol}//${window.location.host}${getPathFromArtifactPath(artifactPath)}`;
return `${window.location.protocol}//${window.location.host}/#${getLocationFromArtifactPath(artifactPath)}`;
}

export function redirectToArtifactPath(artifactPath?: ArtifactPath) {
history.push(getPathFromArtifactPath(artifactPath));
history.push(getLocationFromArtifactPath(artifactPath));
}

0 comments on commit ca24786

Please sign in to comment.