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

715 defence successfully configured message should not disappear after a delay #778

Conversation

dhinrichs-scottlogic
Copy link
Contributor

@dhinrichs-scottlogic dhinrichs-scottlogic commented Jan 16, 2024

Description

Previously, when a user changed or reset the text or number inputs of the defence and model configurations, a message would pop up for 3 seconds to indicate to the user that the change has been made. This can easily be missed, which is why I moved this message to the chat, where the user already gets updates when defences get toggled on/off.
Additionally, I added an info message for the GPT model selection and the model sliders

Screenshots

Before:

image

After:

image

Notes

  • changed two key/value pairs of the enum DEFENCE_ID: FILTER_USER_INPUT to INPUT_FILTERING and FILTER_BOT_OUTPUT to OUTPUT_FILTERING
  • added the info messages to the chatHistory
  • removed the old pop up info messages

Concerns

  • Due to the naming of the Information Defence, "defence" is repeated in the chat, there is already a ticket to address this.
  • There is currently no error messages for the user if the backend fails while we are changing a configuration. There's a separate ticket to address this.
  • The defence.name and the DEFENCE_ID are slightly different q/a LLM versus qa LLM. I couldn't change the enum to include the "/" in the enum key (which is what's being used in the function to update the config) and I didn't want to create a special conditional to change the output to the UI. Personally I think the difference between q/a and qa is acceptable for now. There is a general question about how useful the DEFENCE_ID enum is given that the defence names and the enum is almost identical, so this could become a bigger refactor.

Checklist

Have you done the following?

  • Linked the relevant Issue
  • Added tests
  • Ensured the workflow steps are passing

@dhinrichs-scottlogic dhinrichs-scottlogic changed the title DRAFT 715 defence successfully configured message should not disappear after a delay 715 defence successfully configured message should not disappear after a delay Jan 17, 2024
@dhinrichs-scottlogic dhinrichs-scottlogic marked this pull request as ready for review January 17, 2024 10:20
@pmarsh-scottlogic
Copy link
Contributor

pmarsh-scottlogic commented Jan 19, 2024

this change interacts amusingly with this bug #742
Not something to block this PR, but we should prioritise the bug once this is in

image

Copy link
Contributor

@pmarsh-scottlogic pmarsh-scottlogic left a comment

Choose a reason for hiding this comment

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

I've not looked at the code yet, but this is a great change!

First thing I notice is that on refresh, or changing level then back again, these lovely new messages vanish! That's because when we add an info message to the messages state object, we must also update the chatHistory in the backend. See addInfoMessage defined in MainComponent.tsx.
Almost the same problem as #741

I'll do a proper review next week

Edit: Turns out it's only the model selection and configuration messages that disappear. I've found that addInfoMessage in MainComponenet.tsx will add the message to the front and as well as the backend history. So the fix is to use addInfoMessage rather than addChatMessage.

Copy link
Contributor

@pmarsh-scottlogic pmarsh-scottlogic left a comment

Choose a reason for hiding this comment

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

Super sleek!

Only some minor things from me

backend/src/models/defence.ts Show resolved Hide resolved
}

async function setConfigurationValue(
defence: Defence,
configId: string,
value: string
) {
const configIsValid = validateDefence(defence.id, configId, value);
Copy link
Contributor

Choose a reason for hiding this comment

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

I notice you've removed the validation. Do you plan to add it back in (here or in a fresh ticket) or do you think we don't need validation? It means that, for instance, you can configure things like this:

image

I went through and put invalid configurations and none of them actually stop the site from working, and the backend even comes back with somewhat sensible responses. If we decided to remove validation, then we should also remove validateDefence from defenceService.ts

Copy link
Member

Choose a reason for hiding this comment

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

Yep I think that was a mistake when @dhinrichs-scottlogic pulled out the disappearing messages. We want to keep validation, and only call setDefenceConfiguration if we have a valid value.

That then leaves the question of what to show when the value is not valid; we would want an error message that persists beneath the input until the value is changed to a valid one, probably with error styling / validation state on the input to match.

That is not trivial, because we don't currently have validation on our themed inputs - ThemedNumberInput and ThemedTextArea.

Doro, I suggest you move the validation check into DefenceConfiguration, so we can have input-specific validation errors. We can put it in setDefenceConfigurationValueIfDifferent, and only call setDefenceConfiguration if the value is valid. We will want some local state to store whether the config input is valid or not, and will display some generic error-styled message underneath the DefenceConfigurationInput component when invalid.

As I anticipate some accessibility concerns, you could add a new issue to add accessible validation states to our themed inputs, unless you want to tackle that in this issue; in that case, you could do that part in a subsequent PR.

}) {
const [value, setValue] = useState<number>(config.value);
const [showInfo, setShowInfo] = useState<boolean>(false);

async function handleValueChange(_: Event, value: number | number[]) {
const val = Array.isArray(value) ? value[0] : value;
setValue(val);
addChatMessage({
Copy link
Contributor

Choose a reason for hiding this comment

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

You should import and use addInfoMessage instead. That'll sort out the refresh problem

Comment on lines +32 to +35
addChatMessage({
type: CHAT_MESSAGE_TYPE.INFO,
message: `GPT model changed to: ${currentSelectedModel}`,
});
Copy link
Contributor

Choose a reason for hiding this comment

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

You should import and use addInfoMessage instead. That'll sort out the refresh problem

Copy link
Member

@chriswilty chriswilty left a comment

Choose a reason for hiding this comment

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

One primary concern echoing @pmarsh-scottlogic's comment about validation, but all else good.

I assume there are no tests covering these components? If you want to learn some Testing Library style component tests, you might consider adding some for one of the simpler components, or some around the proposed validation changes. Doesn't need to be in this PR though.

}

async function setConfigurationValue(
defence: Defence,
configId: string,
value: string
) {
const configIsValid = validateDefence(defence.id, configId, value);
Copy link
Member

Choose a reason for hiding this comment

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

Yep I think that was a mistake when @dhinrichs-scottlogic pulled out the disappearing messages. We want to keep validation, and only call setDefenceConfiguration if we have a valid value.

That then leaves the question of what to show when the value is not valid; we would want an error message that persists beneath the input until the value is changed to a valid one, probably with error styling / validation state on the input to match.

That is not trivial, because we don't currently have validation on our themed inputs - ThemedNumberInput and ThemedTextArea.

Doro, I suggest you move the validation check into DefenceConfiguration, so we can have input-specific validation errors. We can put it in setDefenceConfigurationValueIfDifferent, and only call setDefenceConfiguration if the value is valid. We will want some local state to store whether the config input is valid or not, and will display some generic error-styled message underneath the DefenceConfigurationInput component when invalid.

As I anticipate some accessibility concerns, you could add a new issue to add accessible validation states to our themed inputs, unless you want to tackle that in this issue; in that case, you could do that part in a subsequent PR.

@@ -184,6 +184,9 @@ function MainComponent({
return defence;
});
setDefencesToShow(newDefences);
// add info message to chat
const displayedDefenceId = defenceId.replace(/_/g, ' ').toLowerCase();
addInfoMessage(`${displayedDefenceId} defence reset`);
Copy link
Member

Choose a reason for hiding this comment

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

You have these two lines duplicated now; may as well pull out into a separate function, which takes param 'reset' or 'configured' for the message to add.

@dhinrichs-scottlogic
Copy link
Contributor Author

This all turned out much more complicated than anticipated, so after some discussion decided to approach it slightly differently and started again from scratch.
New PR: #802

@chriswilty chriswilty deleted the 715-defence-successfully-configured-message-should-not-disappear-after-a-delay branch February 13, 2024 13:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"Defence successfully configured" message should not disappear after a delay
3 participants