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: hash_on field and limitation #2034

Merged
merged 5 commits into from
Aug 8, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,14 @@ context('Create and Delete Upstream With Custom CHash Key', () => {
cy.get(selector.upstreamType).within(() => {
cy.contains('CHash').click();
});
cy.get('[title="Key"]').should('exist');
// Key is hidden when Hasn on select consumer
cy.get(selector.varSelect).click();
cy.get(selector.hashPosition).within(() => {
cy.contains('consumer').click();
});
cy.get('[title="Key"]').should('not.exist');
cy.get('#hash_on').click({ force: true });
cy.get(selector.hashPosition).within(() => {
cy.contains('cookie').click();
});
Expand Down
46 changes: 24 additions & 22 deletions web/src/components/Upstream/components/Type.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type Props = {
form: FormInstance;
};

const CHash: React.FC<Pick<Props, 'readonly'>> = ({ readonly }) => {
const CHash: React.FC<Props> = ({ form, readonly }) => {
const { formatMessage } = useIntl();
const [keySearchWord, setKeySearchWord] = useState('');

Expand All @@ -50,26 +50,28 @@ const CHash: React.FC<Pick<Props, 'readonly'>> = ({ readonly }) => {
))}
</Select>
</Form.Item>
<Form.Item
name="key"
rules={[{ required: true }]}
label={formatMessage({ id: 'component.upstream.fields.key' })}
tooltip={formatMessage({ id: 'component.upstream.fields.key.tooltip' })}
initialValue="remote_addr"
>
<AutoComplete disabled={readonly} onSearch={handleSearch}>
{Object.entries(CommonHashKeyEnum)
.filter(
([label, value]) =>
label.startsWith(keySearchWord) || value.startsWith(keySearchWord),
)
.map(([label, value]) => (
<Select.Option value={value} key={value}>
{label}
</Select.Option>
))}
</AutoComplete>
</Form.Item>
{form.getFieldValue('hash_on') !== 'consumer' && (
<Form.Item
name="key"
rules={[{ required: true }]}
label={formatMessage({ id: 'component.upstream.fields.key' })}
tooltip={formatMessage({ id: 'component.upstream.fields.key.tooltip' })}
initialValue="remote_addr"
>
<AutoComplete disabled={readonly} onSearch={handleSearch}>
{Object.entries(CommonHashKeyEnum)
.filter(
([label, value]) =>
label.startsWith(keySearchWord) || value.startsWith(keySearchWord),
)
.map(([label, value]) => (
<Select.Option value={value} key={value}>
{label}
</Select.Option>
))}
</AutoComplete>
</Form.Item>
)}
</React.Fragment>
);
};
Expand Down Expand Up @@ -98,7 +100,7 @@ const Component: React.FC<Props> = ({ readonly, form }) => {
<Form.Item shouldUpdate noStyle>
{() => {
if (form.getFieldValue('type') === 'chash') {
return <CHash readonly={readonly} />;
return <CHash form={form} readonly={readonly} />;
}
return null;
}}
Expand Down
2 changes: 2 additions & 0 deletions web/src/components/Upstream/locales/en-US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ export default {
'component.upstream.fields.checks.active.http_path': 'HTTP Path',
'component.upstream.fields.checks.active.http_path.tooltip':
'The path that should be used when issuing the HTTP GET request to the target. The default value is /.',
'component.upstream.fields.checks.active.http_path.placeholder':
'Please enter the HTTP request path',

'component.upstream.fields.checks.active.https_verify_certificate': 'Verify HTTPs Certificate',
'component.upstream.fields.checks.active.https_verify_certificate.tooltip':
Expand Down