Skip to content

Commit

Permalink
fix(llm): dont render IntroducedTextPassage if prompt is unpublished
Browse files Browse the repository at this point in the history
  • Loading branch information
nsantacruz committed Feb 26, 2024
1 parent d8257d5 commit efd6637
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 22 deletions.
29 changes: 9 additions & 20 deletions static/js/Story.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -167,15 +167,6 @@ const useReviewState = (topic, text) => {
return [reviewState, markReviewed]
}

const VisibilityWrapper = ({children, text}) => {
let lang = Sefaria.interfaceLang === "english" ? 'en' : 'he';
const isPromptPublished = text.descriptions?.[lang]?.published;
if (isPromptPublished === true || Sefaria.is_moderator) {
return children;
}
return null;
}

const IntroducedTextPassage = ({text, topic, afterSave, toggleSignUpModal, bodyTextIsLink=false}) => {
if (!text.ref) { return null; }
const versions = text.versions || {}
Expand All @@ -191,17 +182,15 @@ const IntroducedTextPassage = ({text, topic, afterSave, toggleSignUpModal, bodyT

return (
<StoryFrame cls="introducedTextPassageStory">
<VisibilityWrapper text={text}>
<div className={"headerWithAdminButtonsContainer"}>
<CategoryHeader type="sources" data={[topic, text]} toggleButtonIDs={["edit"]}>
<StoryTitleBlock en={text.descriptions?.en?.title} he={text.descriptions?.he?.title}/>
</CategoryHeader>
<ReviewStateIndicator reviewState={state} onClick={markReviewed}/>
</div>
<div className={"systemText learningPrompt"}>
<InterfaceText text={{"en": text.descriptions?.en?.prompt, "he": text.descriptions?.he?.prompt}} />
</div>
</VisibilityWrapper>
<div className={"headerWithAdminButtonsContainer"}>
<CategoryHeader type="sources" data={[topic, text]} toggleButtonIDs={["edit"]}>
<StoryTitleBlock en={text.descriptions?.en?.title} he={text.descriptions?.he?.title}/>
</CategoryHeader>
<ReviewStateIndicator reviewState={state} onClick={markReviewed}/>
</div>
<div className={"systemText learningPrompt"}>
<InterfaceText text={{"en": text.descriptions?.en?.prompt, "he": text.descriptions?.he?.prompt}} />
</div>
<SaveLine
dref={text.ref}
versions={versions}
Expand Down
11 changes: 9 additions & 2 deletions static/js/TopicPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,14 @@ const sheetSort = (currSortOption, a, b) => {
}
};

const hasPrompts = (description) => {
/**
* returns true if description has a title
* If description is explicitly marked as not published, only return true if user is a moderator
*/
return description?.title?.length && (Sefaria.is_moderator || description?.published !== false);
}

const refRenderWrapper = (toggleSignUpModal, topicData, topicTestVersion) => item => {
const text = item[1];
const topicTitle = topicData && topicData.primaryTitle;
Expand All @@ -166,11 +174,10 @@ const refRenderWrapper = (toggleSignUpModal, topicData, topicTestVersion) => ite
</ToolTipped>
);

const hasPrompts = text.descriptions && text.descriptions[langKey] && text.descriptions[langKey].title;

// When running a test, topicTestVersion is respected.
// const Passage = (topicTestVersion && hasPrompts) ? IntroducedTextPassage : TextPassage;
const Passage = hasPrompts ? IntroducedTextPassage : TextPassage;
const Passage = hasPrompts(text?.descriptions?.[langKey]) ? IntroducedTextPassage : TextPassage;
return (
<Passage
key={item[0]}
Expand Down

0 comments on commit efd6637

Please sign in to comment.