Commit c481cb95 authored by Oleksii Savran's avatar Oleksii Savran

WIP: Navigation to tabs

parent 00dc5b43
......@@ -27,6 +27,7 @@ import PageTitle from '@gringlobal/client/ui/common/PageTitle';
import AuditDataDisplay from 'common/AuditDataDisplay';
import EditGroupDialog from 'inventorygroup/ui/c/EditGroupDialog';
import confirm from '@gringlobal/client/utilities/confirmAlert';
import navigateTo from '@gringlobal/client/action/navigation';
interface IDetailsPageProps extends React.ClassAttributes<any>, WithTranslation {
......@@ -34,6 +35,8 @@ interface IDetailsPageProps extends React.ClassAttributes<any>, WithTranslation
getInventoryGroupAction: (id: number) => void;
inventoryGroupCall: ApiCall<AccessionInvGroup>;
removeInventoryGroupAction: (id: number) => void;
location: any;
navigateTo: (path: string, query?: object) => void;
}
......@@ -93,7 +96,7 @@ class InventoryDetailsPage extends React.Component<IDetailsPageProps> {
}
public componentDidMount(): void {
const { groupId, inventoryGroupCall } = this.props;
const { groupId, inventoryGroupCall, navigateTo, location } = this.props;
if (groupId && !inventoryGroupCall || inventoryGroupCall.data.id !== +groupId) {
this.loadData(groupId);
} else {
......@@ -102,15 +105,26 @@ class InventoryDetailsPage extends React.Component<IDetailsPageProps> {
this.loadMoreMembers();
}
}
if (!location.hash) {
navigateTo(`${location.pathname}#${this.state.selectedTab}`);
}
}
public componentDidUpdate() {
const { inventoryGroupCall, groupId } = this.props;
public componentDidUpdate(prevProps: IDetailsPageProps, prevState: any) {
const { inventoryGroupCall, groupId, location } = this.props;
if (!inventoryGroupCall || !inventoryGroupCall.loading && (!inventoryGroupCall.error && groupId && +groupId !== inventoryGroupCall.data.id)) {
this.loadData(groupId);
// } else {
// console.log('component did update');
}
if (location.hash) {
const hashTab = location.hash.slice(1);
if (hashTab !== this.state.selectedTab && hashTab !== prevState.selectedTab) {
console.log('navigation back', location.hash.slice(1));
this.setState({ selectedTab: hashTab });
}
}
}
private loadData(groupId: number) {
......@@ -137,8 +151,11 @@ class InventoryDetailsPage extends React.Component<IDetailsPageProps> {
}
private selectTab = (event, newValue) => {
const { navigateTo, location } = this.props;
this.setState({
selectedTab: newValue,
}, () => {
navigateTo(`${location.pathname}#${newValue}`);
});
}
......@@ -255,6 +272,7 @@ const mapStateToProps = (state, ownProps) => ({
const mapDispatchToProps = (dispatch) => bindActionCreators({
getInventoryGroupAction,
removeInventoryGroupAction,
navigateTo,
}, dispatch);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment