Skip to content

Commit

Permalink
Add simple version stamp to flex to use in persisted state, so redux …
Browse files Browse the repository at this point in the history
…in localStorage is invalidated on upgrade / rollback
  • Loading branch information
stephenhand committed Dec 13, 2023
1 parent 9ae4355 commit 73e45e0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
11 changes: 11 additions & 0 deletions .github/actions/main-action/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,15 @@ runs:
TWILIO_ACCOUNT_SID: ${{ inputs.account-sid }}
with:
filename: ./plugin-hrm-form/public/appConfig.js
# Get latest tag for this version
- name: Get latest tag
uses: oprypin/find-latest-tag@v1
with:
repository: ${{ inputs.repository }}
# releases-only: false
regex: "^v\d+\.\d+\.\d+.*$"
id: latest_matching_tag
continue-on-error: true
- name: Create secret.js
run: |
touch ./src/private/secret.js
Expand All @@ -95,6 +104,8 @@ runs:
export const datadogAccessToken = '$DATADOG_ACCESS_TOKEN';
export const datadogApplicationID = '$DATADOG_APP_ID';
export const fullStoryId = '$FULLSTORY_ID';
export const versionId = '${{ steps.latest_matching_tag.outputs.tag }}'
export const githubSha = '{{ github.sha }}';
EOT
working-directory: ./plugin-hrm-form
shell: bash
Expand Down
3 changes: 3 additions & 0 deletions plugin-hrm-form/src/hrmConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { buildFormDefinitionsBaseUrlGetter, inferConfiguredFormDefinitionsBaseUr
import { ConfigFlags, FeatureFlags } from './types/types';
import type { RootState } from './states';
import { namespace } from './states/storeNamespaces';
import { githubSha, versionId } from './private/secret';

const featureFlagEnvVarPrefix = 'REACT_APP_FF_';
type ContactSaveFrequency = 'onTabChange' | 'onFinalSaveAndTransfer';
Expand Down Expand Up @@ -167,3 +168,5 @@ export const getAseloFeatureFlags = (): FeatureFlags => cachedConfig.featureFlag
export const getDefinitionVersions = () => {
return (Flex.Manager.getInstance().store.getState() as RootState)[namespace].configuration;
};

export const pluginVersionDescription = `${versionId}${githubSha ? `#${githubSha}` : ''}`;
14 changes: 9 additions & 5 deletions plugin-hrm-form/src/states/persistState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import _ from 'lodash';

import { RootState } from '.';
import { namespace } from './storeNamespaces';
import { getAseloFeatureFlags } from '../hrmConfig';
import { getAseloFeatureFlags, pluginVersionDescription } from '../hrmConfig';

// Quick & dirty module to persist redux state to localStorage via subscriptions since we can't add middleware like redux-persist to do it for us
export const activateStatePersistence = () => {
Expand All @@ -29,17 +29,21 @@ export const activateStatePersistence = () => {
const {
[namespace]: { configuration, ...persistableState },
} = Manager.getInstance().store.getState() as RootState;
localStorage.setItem('redux-state/plugin-hrm-form', JSON.stringify(persistableState));
localStorage.setItem(
'redux-state/plugin-hrm-form',
JSON.stringify({ [pluginVersionDescription]: persistableState }),
);
}, 1000);
Manager.getInstance().store.subscribe(debouncedWrite);
}
};

export const readPersistedState = (): RootState[typeof namespace] | null => {
if (getAseloFeatureFlags().enable_local_redux_persist) {
const persistedState = localStorage.getItem('redux-state/plugin-hrm-form');
if (persistedState) {
return JSON.parse(persistedState);
const persistedStateJson = localStorage.getItem('redux-state/plugin-hrm-form');
if (persistedStateJson) {
const persistedState = JSON.parse(persistedStateJson);
return persistedState[pluginVersionDescription];
}
}
return undefined;
Expand Down

0 comments on commit 73e45e0

Please sign in to comment.