Skip to content

Commit

Permalink
Merge pull request #2 from forumone/FOIA22-118
Browse files Browse the repository at this point in the history
[FOIA22-118] Add support for a State/Local flow
  • Loading branch information
mrclay authored Aug 11, 2023
2 parents 265a7c5 + 5194d72 commit cef64f1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
13 changes: 13 additions & 0 deletions js/models/wizard_summaries.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { summary } from '../util/wizard_helpers';

/**
* Default summary that shows user their query plus resources found by the model.
*/
export const defaultSummary = summary();

/**
* Summary if the intent model returns stateOrLocalFlow.
*/
export const stateLocalSummary = summary('m49');

export const stateOrLocalFlow = 'State or Local';
17 changes: 13 additions & 4 deletions js/stores/wizard_store.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { fetchWizardInitData, fetchWizardPredictions } from '../util/wizard_api'
import { convertSomeLinksToCards, normalizeScore, urlParams } from '../util/wizard_helpers';
import allTopics from '../models/wizard_topics';
import extraMessages from '../models/wizard_extra_messages';
import { defaultSummary, stateLocalSummary, stateOrLocalFlow } from '../models/wizard_summaries';

const DEFAULT_CONFIDENCE_THRESHOLD = Number(
urlParams().get('confidence-threshold') || 0.5,
Expand Down Expand Up @@ -215,6 +216,7 @@ const useRawWizardStore = create((
let recommendedAgencies = [];
let recommendedLinks = [];
let effectiveTopic = topic;
let isStateOrLocal = false;

if (query && !effectiveTopic) {
nudgeLoading(1);
Expand All @@ -224,9 +226,13 @@ const useRawWizardStore = create((
// the links and agencies anyway.
const { flow } = data.model_output.predefined_flow || {};
if (typeof flow === 'string') {
effectiveTopic = allTopics.find(
(el) => el.title.toUpperCase() === flow.toUpperCase(),
);
if (flow === stateOrLocalFlow) {
isStateOrLocal = true;
} else {
effectiveTopic = allTopics.find(
(el) => el.title.toUpperCase() === flow.toUpperCase(),
);
}
}

// Used to avoid agency duplicates.
Expand Down Expand Up @@ -281,8 +287,11 @@ const useRawWizardStore = create((
nudgeLoading(-1);
}

// We use this if no topic is selected/predicted.
const summary = isStateOrLocal ? stateLocalSummary : defaultSummary;

set(withCapturedHistory({
activity: effectiveTopic ? effectiveTopic.journey : { type: 'summary' },
activity: effectiveTopic ? effectiveTopic.journey : summary,
displayedTopic: effectiveTopic ? effectiveTopic.title : '',
query,
recommendedLinks,
Expand Down
2 changes: 1 addition & 1 deletion js/util/wizard_helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export function continueStep(titleMid, next) {
}

/**
* @param {string | undefined} titleMid
* @param {string=} titleMid
* @returns {WizardSummary}
*/
export function summary(titleMid) {
Expand Down

0 comments on commit cef64f1

Please sign in to comment.