Skip to content

Commit

Permalink
feat: disable revert tokens functionality in core-registry mode
Browse files Browse the repository at this point in the history
fix: untokenized data unavailable on tokenization success
  • Loading branch information
wwills2 committed Sep 17, 2024
1 parent e652049 commit 0bd02ce
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 31 deletions.
19 changes: 16 additions & 3 deletions src/renderer/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { IntlProvider } from 'react-intl';
import { loadLocaleData } from '@/translations';
import '@/App.css';
import { AppNavigator } from '@/routes';
import { resetApiHost, setConfigFileLoaded, setHost, setLocale } from '@/store/slices/app';
import { resetApiHost, setConfigFileLoaded, setCoreRegistryMode, setHost, setLocale } from '@/store/slices/app';
import { ComponentCenteredSpinner } from '@/components';
import { useGetThemeColorsQuery, useGetUiConfigQuery } from '@/api';
import { useGetHealthQuery, useGetThemeColorsQuery, useGetUiConfigQuery } from '@/api';

/**
* @returns app react component to be rendered by electron as the UI
Expand All @@ -18,6 +18,19 @@ function App() {
const [appLoading, setAppLoading] = useState(true);
const { data: fetchedConfig, isLoading: configFileLoading } = useGetUiConfigQuery();
const { data: fetchedThemeColors, isLoading: themeColorsFileLoading } = useGetThemeColorsQuery();
const { data: healthData } = useGetHealthQuery(
{
apiHost: appStore?.apiHost,
apiKey: appStore?.apiKey,
},
{ skip: !appStore?.apiHost },
);

useEffect(() => {
if (Boolean(healthData?.coreRegistryMode) != appStore.coreRegistryMode) {
dispatch(setCoreRegistryMode(Boolean(healthData?.coreRegistryMode)));
}
}, [appStore.coreRegistryMode, dispatch, healthData?.coreRegistryMode]);

useEffect(() => {
if (appStore.locale) {
Expand Down Expand Up @@ -57,7 +70,7 @@ function App() {
if (!configFileLoading) setTimeout(() => setAppLoading(false), 400);
}, [configFileLoading]);

if (!translationTokens || configFileLoading || themeColorsFileLoading || appLoading) {
if (!translationTokens || configFileLoading || themeColorsFileLoading || !healthData || appLoading) {
return <ComponentCenteredSpinner />;
}

Expand Down
6 changes: 4 additions & 2 deletions src/renderer/api/tokenization-engine/system.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ interface GetHealthParams {
interface ServerHealth {
isHealthy: boolean;
readOnly: boolean;
coreRegistryMode: boolean;
}

export interface Config {
Expand All @@ -32,8 +33,9 @@ const systemApi = tokenizationEngineApi.injectEndpoints({
}),
transformResponse: (response: BaseQueryResult<Health>, meta): ServerHealth => {
const isHealthy = response?.message === 'OK';
const readOnly = meta?.response?.headers.get('cw-readonly') === 'true';
return { isHealthy, readOnly };
const readOnly = meta?.response?.headers.get('cw-read-only') === 'true';
const coreRegistryMode = meta?.response?.headers.get('x-core-registry-mode') === 'true';
return { isHealthy, readOnly, coreRegistryMode };
},
keepUnusedDataFor: 0,
}),
Expand Down
11 changes: 1 addition & 10 deletions src/renderer/api/tokenization-engine/units.api.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
import {
projectsByIdsTag,
projectsTag,
RECORDS_PER_PAGE,
tokenizationEngineApi,
tokenizedUnitsTag,
untokenizedUnitsTag,
} from './index';
import { RECORDS_PER_PAGE, tokenizationEngineApi, tokenizedUnitsTag, untokenizedUnitsTag } from './index';
import { Unit } from '@/schemas/Unit.schema';

interface GetUnitsParams {
Expand Down Expand Up @@ -123,7 +116,6 @@ const unitsApi = tokenizationEngineApi.injectEndpoints({
headers: { 'Content-Type': 'application/json' },
body: tokenizeParams,
}),
invalidatesTags: [untokenizedUnitsTag, tokenizedUnitsTag, projectsTag, projectsByIdsTag],
}),

parseDetokenizationFile: builder.mutation<DetokenizationData, string>({
Expand All @@ -142,7 +134,6 @@ const unitsApi = tokenizationEngineApi.injectEndpoints({
headers: { 'Content-Type': 'application/json' },
body: detokenizationData,
}),
invalidatesTags: [untokenizedUnitsTag, tokenizedUnitsTag, projectsTag, projectsByIdsTag],
}),
}),
});
Expand Down
43 changes: 32 additions & 11 deletions src/renderer/components/blocks/layout/LeftNav.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { useCallback } from 'react';
import { useLocation, useNavigate } from 'react-router-dom';
import { FormattedMessage } from 'react-intl';
import { Card, NoHomeOrgModal, Sidebar } from '@/components';
import { Card, NoHomeOrgModal, Sidebar, Tooltip } from '@/components';
import ROUTES from '@/routes/route-constants';
import { RiTokenSwapLine } from 'react-icons/ri';
import { useSelector } from 'react-redux';
import { RootState } from '@/store';

const LeftNav = () => {
const navigate = useNavigate();
const location = useLocation();
const isActive = useCallback((path: string) => location.pathname === path, [location]);

const coreRegistryMode: boolean = useSelector((state: RootState) => state.app.coreRegistryMode);
return (
<div className="h-full relative bg-white dark:bg-gray-800">
<div className="h-full hidden md:block">
Expand All @@ -33,15 +35,34 @@ const LeftNav = () => {
<FormattedMessage id="create-tokens" />
</p>
</Sidebar.Item>
<Sidebar.Item
style={{ cursor: 'pointer' }}
active={isActive(ROUTES.REVERT_TOKENS)}
onClick={() => navigate(ROUTES.REVERT_TOKENS)}
>
<p className="capitalize">
<FormattedMessage id="revert-tokens" />
</p>
</Sidebar.Item>
{coreRegistryMode ? (
<div className="cursor-not-allowed line-through decoration-leftNavText flex items-center justify-center rounded-lg p-2 font-normal text-leftNavText dark:text-gray-400">
<Tooltip
content={
<p className="sentence-case">
<FormattedMessage id="not-available-in-core-registry-mode" />
</p>
}
placement="bottom"
>
<div className="">
<p className="capitalize w-full">
<FormattedMessage id="revert-tokens" />
</p>
</div>
</Tooltip>
</div>
) : (
<Sidebar.Item
style={{ cursor: 'pointer' }}
active={isActive(ROUTES.REVERT_TOKENS)}
onClick={() => navigate(ROUTES.REVERT_TOKENS)}
>
<p className="capitalize">
<FormattedMessage id="revert-tokens" />
</p>
</Sidebar.Item>
)}
</Sidebar.ItemGroup>
</Sidebar.Items>
</Sidebar>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ const SubmitDetokenizationFileModal: React.FC<SubimitDetokenizationFileModalProp
values.password,
);

console.log(unzipResult);

if (!unzipResult.success && unzipResult?.badPassword) {
setFailureAlertMessageToken(ZIP_BAD_PASSWORD_TOKEN);
return;
Expand Down
5 changes: 4 additions & 1 deletion src/renderer/routes/AppNavigator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ import { BrowserRouter as Router, Navigate, redirect, Route, Routes } from 'reac
import ROUTES from '@/routes/route-constants';
import * as Pages from '@/pages';
import { Template } from '@/components';
import { useSelector } from 'react-redux';
import { RootState } from '@/store';

const AppNavigator: React.FC = () => {
const coreRegistryMode: boolean = useSelector((state: RootState) => state.app.coreRegistryMode);
return (
<>
<Router>
Expand All @@ -16,7 +19,7 @@ const AppNavigator: React.FC = () => {
<Route path="" element={<Template />}>
<Route path="/" element={<Navigate to={ROUTES.CREATE_TOKENS} />} />
<Route path={ROUTES.CREATE_TOKENS} element={<Pages.TokensPage />} />
<Route path={ROUTES.REVERT_TOKENS} element={<Pages.RevertTokensPage />} />
{!coreRegistryMode && <Route path={ROUTES.REVERT_TOKENS} element={<Pages.RevertTokensPage />} />}
<Route path="*" element={<Navigate replace to={ROUTES.CREATE_TOKENS} />} />
</Route>
</Routes>
Expand Down
2 changes: 2 additions & 0 deletions src/renderer/store/slices/app/app.initialstate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export interface AppState {
locale?: string | null;
apiHost: string;
apiKey?: string | null;
coreRegistryMode: boolean;
configFileLoaded: boolean;
isDarkTheme: boolean;
}
Expand All @@ -10,6 +11,7 @@ const initialState: AppState = {
locale: null,
apiHost: 'http://localhost:31311',
apiKey: null,
coreRegistryMode: false,
configFileLoaded: false,
isDarkTheme: false,
};
Expand Down
6 changes: 5 additions & 1 deletion src/renderer/store/slices/app/app.slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,14 @@ export const appSlice = createSlice({
toggleThemeMode: (state) => {
state.isDarkTheme = !state.isDarkTheme;
},
setCoreRegistryMode: (state, { payload }: { payload: boolean }) => {
state.coreRegistryMode = payload;
},
},
});

export const { setLocale, setHost, resetApiHost, setConfigFileLoaded, toggleThemeMode } = appSlice.actions;
export const { setLocale, setHost, resetApiHost, setConfigFileLoaded, toggleThemeMode, setCoreRegistryMode } =
appSlice.actions;

export const selectCurrentHost = (state) => state.app.host;

Expand Down
3 changes: 2 additions & 1 deletion src/renderer/translations/tokens/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,6 @@
"crediting-period-end-date": "crediting period end date",
"unit-quantity": "unit quantity",
"failed-to-detokenize-unit": "failed to detokenize unit",
"submit-detokenization-file": "submit detokenization file"
"submit-detokenization-file": "submit detokenization file",
"not-available-in-core-registry-mode": "not available in core registry mode"
}

0 comments on commit 0bd02ce

Please sign in to comment.