Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/promptid selectors #48

Merged
merged 6 commits into from
Jan 12, 2024
Merged

Fix/promptid selectors #48

merged 6 commits into from
Jan 12, 2024

Conversation

jthrilly
Copy link
Member

@jthrilly jthrilly commented Jan 11, 2024

This fixes bugs related to the lack of a promptId in certain contexts.

The issue was caused by faulty selectors that assumed promptIndex (note: not the same as prompt ID!) was being passed into the stage component as a prop. I removed this during refactoring as it would cause the stage to re-render when the prompt changed (so was incorrect).

The new implementation gets the promptId from the session, via the promptIndex. This is implemented within the getPromptIndex session selector.

Ultimately, the issue was manifesting in the getPromptNodeModelData selector, which is used to determine the metadata that nodes should have when they are created or added to a given stage/prompt combination. However it was also causing several other selectors to return incorrect data.

This fixes bugs related to the lack of a promptId in certain contexts.

The issue was caused by faulty selectors that assumed promptIndex (not
ID!) was being passed into the stage component as a prop. I removed this
during refactoring as it would cause the stage to re-render when the
prompt changed (so was incorrect).

The new implementation gets the promptId from the session, via the
promptIndex. This is implemented within the `getPromptIndex` session
selector.
Copy link

vercel bot commented Jan 11, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
fresco ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 12, 2024 7:30am

@jthrilly jthrilly requested a review from buckhalt January 11, 2024 12:25
Comment on lines 121 to 126
export const getPromptId = createSelector(
getPrompts,
getPromptIndex,
(prompts, promptIndex) => prompts[promptIndex].id,
)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New selector, which fetches the prompt ID via the promptIndex property in the session state.

export const getNetworkNodesForPrompt = createSelector(
getNetworkNodesForType,
getPropPromptId,
getPromptId,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace the old selector with the new one - this selector was previously also failing without us realizing.

@@ -133,7 +140,7 @@ export const makeNetworkNodesForPrompt = () => getNetworkNodesForPrompt;
*/

export const getNetworkNodesForOtherPrompts = createSelector(
getNetworkNodesForType, getPropPromptId,
getNetworkNodesForType, getPromptId,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above, update to use the session state selector rather than looking for prompt ID in props.

Comment on lines +27 to +37
const getIDs = createSelector(
propStageId,
getPromptId,
(stageId, promptId) => {
return {
stageId,
promptId,
};
},
)

Copy link
Member Author

@jthrilly jthrilly Jan 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A "helper" selector that just gets the stage and prompt ID and returns them in an object.

This replaces the one I removed from the props selectors file, and puts it in a more appropriate location given that it now depends on state rather than props. I could also have put this in the interfaces selector file, and may do so if it turns out other interfaces use it.

This is in effect what fixes this issue.

Comment on lines +40 to +47
getIDs,
({ type }, { stageId, promptId }) => {
return {
type,
stageId,
promptId,
};
},
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the actual "fix" (although the real fix is in the new implementation of the getIDs selector, so as not to use props).

I also changed the style a little to remove the spread operator, which is something I want us to do more broadly. Spread operators can make it difficult to debug problems because it isn't clear which data they contain.

@@ -22,7 +22,6 @@ export const getAdditionalAttributes = (stage, prompt) => {
export const propStage = (_, props) => props?.stage ?? null;
export const propPrompt = (_, props) => props?.prompt ?? null;
export const propStageId = (_, props) => props?.stage?.id ?? null;
export const getPropPromptId = (_, props) => props?.prompt?.id ?? null;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed this entirely because (1) it is broken now that prompt isn't consistently passed to props, and (2) I wanted to force myself to find other instances where this broken selector was used and fix them.

Comment on lines -45 to -49
// Returns current stage and prompt ID
export const getIds = createSelector(
propStageId, getPropPromptId,
(stageId, promptId) => ({ stageId, promptId }),
);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This selector was replaced above, with a new implementation that uses session state.

Comment on lines -142 to -149
it('makeGetIds()', () => {
const selected = Interface.makeGetIds();
expect(selected(mockState, mockProps)).toEqual({
stageId: mockStage.id,
promptId: mockPrompt.id,
});
});

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed this test because I also deleted the underlying selector. See below.

@jthrilly jthrilly requested a review from mrkarimoff January 11, 2024 12:51
buckhalt
buckhalt previously approved these changes Jan 11, 2024
@jthrilly jthrilly merged commit 90b3060 into main Jan 12, 2024
3 checks passed
stageId,
promptId,
};
},
)

export const makeGetPromptNodeModelData = () => getPromptModelData;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't understand the purpose of this function because it's not being called in anywhere

Copy link
Contributor

@mrkarimoff mrkarimoff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, this is a really interesting approach. I admit I haven't thought about getting the promptId via promptIndex from the session state

@jthrilly jthrilly deleted the fix/promptid-selectors branch April 5, 2024 10:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants