Skip to content

Commit

Permalink
fix: check correct platfrom version and show error
Browse files Browse the repository at this point in the history
  • Loading branch information
stepan662 committed Dec 7, 2023
1 parent 7cf05d3 commit 0b2f038
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 35 deletions.
8 changes: 5 additions & 3 deletions packages/web/src/ui/KeyDialog/KeyForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ const ScRestriction = styled('div')`
`;

const ScError = styled('div')`
padding-top: 16px;
color: red;
`;

Expand Down Expand Up @@ -177,9 +178,10 @@ export const KeyForm = () => {
)}

{formDisabled && ready && (
<ScRestriction>{`Modification is restricted due to missing ${
keyData?.keyId !== undefined ? 'translations.edit' : 'keys.edit'
} scope in current api key settings.`}</ScRestriction>
<ScRestriction>
Modification is restricted due to missing edit permissions in current
api key settings.
</ScRestriction>
)}

{error && <ScError>{error}</ScError>}
Expand Down
45 changes: 21 additions & 24 deletions packages/web/src/ui/KeyDialog/dialogContext/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,16 @@ import {
setPreferredLanguages,
isAuthorizedTo,
} from './tools';
import { getApiKeyType } from '../../../tools/decodeApiKey';
import { useGallery } from './useGallery';
import { requirePlatformVersion } from '../../tools/requirePlatformVersion';
import { checkPlatformVersion } from '../../tools/checkPlatformVersion';
import { limitSurroundingKeys } from '../../tools/limitSurroundingKeys';
import {
StateInType,
STATES_FOR_UPDATE,
StateType,
} from '../State/translationStates';

const PLATFORM_SUPPORTING_BIG_META = 'v3.20.0';
const MINIMAL_PLATFORM_VERSION = 'v3.39.0';

type FormTranslations = {
[key: string]: {
Expand Down Expand Up @@ -116,6 +115,11 @@ export const [DialogProvider, useDialogActions, useDialogContext] =
},
});

const versionError = checkPlatformVersion(
MINIMAL_PLATFORM_VERSION,
languagesLoadable.data?._internal?.version
);

const createKey = useApiMutation({
url: '/v2/projects/keys/create',
method: 'post',
Expand Down Expand Up @@ -265,28 +269,20 @@ export const [DialogProvider, useDialogActions, useDialogContext] =
path: { id: keyData.keyId! },
}));

const version = result._internal?.version;

if (
version &&
(version === '??' ||
requirePlatformVersion(PLATFORM_SUPPORTING_BIG_META, version))
) {
const surroundingKeys = limitSurroundingKeys(
props.uiProps.findPositions(),
{ keyName: props.keyName, keyNamespace: selectedNs }
);
await updateMetadata.mutateAsync({
content: {
'application/json': {
relatedKeysInOrder: surroundingKeys.map((val) => ({
keyName: val.keyName,
namespace: val.keyNamespace || undefined,
})),
},
const surroundingKeys = limitSurroundingKeys(
props.uiProps.findPositions(),
{ keyName: props.keyName, keyNamespace: selectedNs }
);
await updateMetadata.mutateAsync({
content: {
'application/json': {
relatedKeysInOrder: surroundingKeys.map((val) => ({
keyName: val.keyName,
namespace: val.keyNamespace || undefined,
})),
},
});
}
},
});

changeInTolgeeCache(
props.keyName,
Expand Down Expand Up @@ -414,6 +410,7 @@ export const [DialogProvider, useDialogActions, useDialogContext] =
(translationsLoadable.isLoading && !translationsLoadable.data) ||
scopesLoadable.isFetching;
const error =
versionError ||
languagesLoadable.error ||
translationsLoadable.error ||
scopesLoadable.error ||
Expand Down
17 changes: 17 additions & 0 deletions packages/web/src/ui/tools/checkPlatformVersion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export const checkPlatformVersion = (
requiredV: string,
currentV: string | undefined
) => {
if (!currentV || currentV === '??') {
return undefined;
}
const result = requiredV.localeCompare(currentV, 'en', {
numeric: true,
sensitivity: 'base',
});

if (result > 0) {
return `Requires platform version ${requiredV} (got ${currentV})`;
}
return undefined;
};
8 changes: 0 additions & 8 deletions packages/web/src/ui/tools/requirePlatformVersion.ts

This file was deleted.

0 comments on commit 0b2f038

Please sign in to comment.