--- /dev/null
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import { AxiosInstance } from "axios";
+import { ApiActions } from "~/services/api/api-actions";
+import { AccountToLink } from "~/models/link-account";
+
+export const USER_LINK_ACCOUNT_KEY = 'accountToLink';
+
+export class LinkAccountService {
+
+ constructor(
+ protected apiClient: AxiosInstance,
+ protected actions: ApiActions) { }
+
+ public saveLinkAccount(account: AccountToLink) {
+ sessionStorage.setItem(USER_LINK_ACCOUNT_KEY, JSON.stringify(account));
+ }
+
+ public removeLinkAccount() {
+ sessionStorage.removeItem(USER_LINK_ACCOUNT_KEY);
+ }
+
+ public getLinkAccount() {
+ const data = sessionStorage.getItem(USER_LINK_ACCOUNT_KEY);
+ return data ? JSON.parse(data) as AccountToLink : undefined;
+ }
+}
\ No newline at end of file
import { VocabularyService } from '~/services/vocabulary-service/vocabulary-service';
import { NodeService } from '~/services/node-service/node-service';
import { FileViewersConfigService } from '~/services/file-viewers-config-service/file-viewers-config-service';
+import { LinkAccountService } from "./link-account-service/link-account-service";
export type ServiceRepository = ReturnType<typeof createServices>;
const userService = new UserService(apiClient, actions);
const virtualMachineService = new VirtualMachinesService(apiClient, actions);
const workflowService = new WorkflowService(apiClient, actions);
+ const linkAccountService = new LinkAccountService(apiClient, actions);
const ancestorsService = new AncestorService(groupsService, userService);
const authService = new AuthService(apiClient, config.rootUrl, actions);
webdavClient,
workflowService,
vocabularyService,
+ linkAccountService
};
};
import { setBreadcrumbs } from "~/store/breadcrumbs/breadcrumbs-actions";
import { LinkAccountType, AccountToLink } from "~/models/link-account";
import { logout } from "~/store/auth/auth-action";
+import { unionize, ofType, UnionOf } from '~/common/unionize';
+
+export const linkAccountPanelActions = unionize({
+ LOAD_LINKING: ofType<AccountToLink>()
+});
+
+export type LinkAccountPanelAction = UnionOf<typeof linkAccountPanelActions>;
export const loadLinkAccountPanel = () =>
- (dispatch: Dispatch<any>) => {
- dispatch(setBreadcrumbs([{ label: 'Link account'}]));
+ (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
+ dispatch(setBreadcrumbs([{ label: 'Link account'}]));
+
+ const linkAccountData = services.linkAccountService.getLinkAccount();
+ if (linkAccountData) {
+ dispatch(linkAccountPanelActions.LOAD_LINKING(linkAccountData));
+ }
};
export const saveAccountLinkData = (t: LinkAccountType) =>
(dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
const accountToLink = {type: t, userToken: services.authService.getApiToken()} as AccountToLink;
- sessionStorage.setItem("accountToLink", JSON.stringify(accountToLink));
+ services.linkAccountService.saveLinkAccount(accountToLink);
dispatch(logout());
+ };
+
+export const getAccountLinkData = () =>
+ (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
+ return services.linkAccountService.getLinkAccount();
};
\ No newline at end of file
--- /dev/null
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import { linkAccountPanelActions, LinkAccountPanelAction } from "~/store/link-account-panel/link-account-panel-actions";
+import { AccountToLink } from "~/models/link-account";
+
+export interface LinkAccountPanelState {
+ accountToLink: AccountToLink | undefined;
+}
+
+const initialState = {
+ accountToLink: undefined
+};
+
+export const linkAccountPanelReducer = (state: LinkAccountPanelState = initialState, action: LinkAccountPanelAction) =>
+ linkAccountPanelActions.match(action, {
+ default: () => state,
+ LOAD_LINKING: (accountToLink) => ({ ...state, accountToLink }),
+ });
\ No newline at end of file
import { PublicFavoritesMiddlewareService } from '~/store/public-favorites-panel/public-favorites-middleware-service';
import { PUBLIC_FAVORITE_PANEL_ID } from '~/store/public-favorites-panel/public-favorites-action';
import { publicFavoritesReducer } from '~/store/public-favorites/public-favorites-reducer';
+import { linkAccountPanelReducer } from './link-account-panel/link-account-panel-reducer';
const composeEnhancers =
(process.env.NODE_ENV === 'development' &&
searchBar: searchBarReducer,
virtualMachines: virtualMachinesReducer,
repositories: repositoriesReducer,
- keepServices: keepServicesReducer
+ keepServices: keepServicesReducer,
+ linkAccountPanel: linkAccountPanelReducer
});
} from '@material-ui/core';
import { ArvadosTheme } from '~/common/custom-theme';
import { User } from "~/models/user";
-import { LinkAccountType } from "~/models/link-account";
+import { LinkAccountType, AccountToLink } from "~/models/link-account";
import { formatDate }from "~/common/formatters";
type CssRules = 'root';// | 'gridItem' | 'label' | 'title' | 'actions';
export interface LinkAccountPanelRootDataProps {
user?: User;
+ accountToLink?: AccountToLink;
}
export interface LinkAccountPanelRootActionProps {
const mapStateToProps = (state: RootState): LinkAccountPanelRootDataProps => {
return {
- user: state.auth.user
+ user: state.auth.user,
+ accountToLink: state.linkAccountPanel.accountToLink
};
};