fix recent process models, at least after they visit process model show page

This commit is contained in:
burnettk 2022-11-09 22:24:16 -05:00
parent 1a060cb213
commit 27c5db2339
3 changed files with 23 additions and 23 deletions

View File

@ -6,7 +6,7 @@ export interface Secret {
} }
export interface RecentProcessModel { export interface RecentProcessModel {
processGroupIdentifier: string; processGroupIdentifier?: string;
processModelIdentifier: string; processModelIdentifier: string;
processModelDisplayName: string; processModelDisplayName: string;
} }

View File

@ -158,13 +158,18 @@ export default function HomePage() {
); );
}; };
const tasksWaitingForMe = tasksWaitingForMeComponent();
const relevantProcessModelSection = const relevantProcessModelSection =
recentProcessModels.length > 0 && buildRecentProcessModelSection(); (recentProcessModels.length > 0 && buildRecentProcessModelSection()) ||
null;
if (pagination) { if (pagination) {
if (tasksWaitingForMe === null && relevantProcessModelSection === null) {
return <p>No tasks are waiting for you.</p>;
}
return ( return (
<> <>
{tasksWaitingForMeComponent()} {tasksWaitingForMe}
{relevantProcessModelSection} {relevantProcessModelSection}
</> </>
); );

View File

@ -35,15 +35,8 @@ import { ProcessFile, ProcessModel, RecentProcessModel } from '../interfaces';
import ButtonWithConfirmation from '../components/ButtonWithConfirmation'; import ButtonWithConfirmation from '../components/ButtonWithConfirmation';
const storeRecentProcessModelInLocalStorage = ( const storeRecentProcessModelInLocalStorage = (
processModelForStorage: any, processModelForStorage: ProcessModel
params: any
) => { ) => {
if (
params.process_group_id === undefined ||
params.process_model_id === undefined
) {
return;
}
// All values stored in localStorage are strings. // All values stored in localStorage are strings.
// Grab our recentProcessModels string from localStorage. // Grab our recentProcessModels string from localStorage.
const stringFromLocalStorage = window.localStorage.getItem( const stringFromLocalStorage = window.localStorage.getItem(
@ -60,16 +53,16 @@ const storeRecentProcessModelInLocalStorage = (
// Here's the value we want to add // Here's the value we want to add
const value = { const value = {
processGroupIdentifier: processModelForStorage.process_group_id,
processModelIdentifier: processModelForStorage.id, processModelIdentifier: processModelForStorage.id,
processModelDisplayName: processModelForStorage.display_name, processModelDisplayName: processModelForStorage.display_name,
}; };
// anything with a processGroupIdentifier is old and busted. leave it behind.
array = array.filter((item) => item.processGroupIdentifier === undefined);
// If our parsed/empty array doesn't already have this value in it... // If our parsed/empty array doesn't already have this value in it...
const matchingItem = array.find( const matchingItem = array.find(
(item) => (item) => item.processModelIdentifier === value.processModelIdentifier
item.processGroupIdentifier === value.processGroupIdentifier &&
item.processModelIdentifier === value.processModelIdentifier
); );
if (matchingItem === undefined) { if (matchingItem === undefined) {
// add the value to the beginning of the array // add the value to the beginning of the array
@ -79,13 +72,15 @@ const storeRecentProcessModelInLocalStorage = (
if (array.length > 3) { if (array.length > 3) {
array.pop(); array.pop();
} }
// turn the array WITH THE NEW VALUE IN IT into a string to prepare it to be stored in localStorage
const stringRepresentingArray = JSON.stringify(array);
// and store it in localStorage as "recentProcessModels"
window.localStorage.setItem('recentProcessModels', stringRepresentingArray);
} }
// once the old and busted serializations are gone, we can put these two statements inside the above if statement
// turn the array WITH THE NEW VALUE IN IT into a string to prepare it to be stored in localStorage
const stringRepresentingArray = JSON.stringify(array);
// and store it in localStorage as "recentProcessModels"
window.localStorage.setItem('recentProcessModels', stringRepresentingArray);
}; };
export default function ProcessModelShow() { export default function ProcessModelShow() {
@ -108,13 +103,13 @@ export default function ProcessModelShow() {
const processResult = (result: ProcessModel) => { const processResult = (result: ProcessModel) => {
setProcessModel(result); setProcessModel(result);
setReloadModel(false); setReloadModel(false);
storeRecentProcessModelInLocalStorage(result, params); storeRecentProcessModelInLocalStorage(result);
}; };
HttpService.makeCallToBackend({ HttpService.makeCallToBackend({
path: `/process-models/${modifiedProcessModelId}`, path: `/process-models/${modifiedProcessModelId}`,
successCallback: processResult, successCallback: processResult,
}); });
}, [params, reloadModel, modifiedProcessModelId]); }, [reloadModel, modifiedProcessModelId]);
const processModelRun = (processInstance: any) => { const processModelRun = (processInstance: any) => {
setErrorMessage(null); setErrorMessage(null);