-
Notifications
You must be signed in to change notification settings - Fork 543
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
feat: Adding a Loading state to buttons #2630
Changes from 10 commits
b4a9a55
2d69cdb
420861e
59ebb8e
73233ed
4d99636
9d86b19
10f4af0
2a40b32
e0e284b
15e683d
9d4edfe
95cb478
c4b2bbf
5925816
f2d7467
478e4f0
e4b47b4
f2e3aa2
4570580
c489c23
27d3cf9
fd8796e
96bc692
997d5e6
61de3c6
d97b68a
4aa28bf
f8e901b
d7e2bf1
f1e0ae6
4b0cb0a
4cfbc70
269ae88
1a27211
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,7 +72,7 @@ context('Create Route Both use uri and uris', () => { | |
cy.contains('Route').click(); | ||
cy.get(selector.empty).should('be.visible'); | ||
cy.contains('Create').click(); | ||
cy.contains('Next').click().click(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The two clicks here are to ensure that the rendering of the page is finished, and this is a point that can be optimized. |
||
cy.contains('Next').click(); | ||
cy.get(selector.name).type(data.name); | ||
cy.get(selector.description).type(data.description); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,7 +70,7 @@ context('Create Route with advanced matching conditions', () => { | |
it('should create route with advanced matching conditions', function () { | ||
cy.visit('/routes/list'); | ||
cy.contains('Create').click(); | ||
cy.contains('Next').click().click(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
cy.contains('Next').click(); | ||
cy.get(selector.name).type(data.routeName); | ||
|
||
// All Of Operational Character Should Exist And Can be Created | ||
|
@@ -162,7 +162,9 @@ context('Create Route with advanced matching conditions', () => { | |
cy.contains('Next').click(); | ||
cy.get(selector.nodes_0_port).focus(); | ||
cy.contains('Next').click(); | ||
cy.wait(2000); | ||
cy.contains('Next').click(); | ||
cy.wait(2000); | ||
cy.contains('Submit').click(); | ||
cy.contains(data.submitSuccess); | ||
cy.contains('Goto List').click(); | ||
|
@@ -185,7 +187,9 @@ context('Create Route with advanced matching conditions', () => { | |
cy.contains('Next').click(); | ||
cy.get(selector.nodes_0_port).focus(); | ||
cy.contains('Next').click(); | ||
cy.wait(2000); | ||
cy.contains('Next').click(); | ||
cy.wait(2000); | ||
cy.contains('Submit').click(); | ||
cy.contains(data.submitSuccess); | ||
cy.contains('Goto List').click(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I think so. Just use the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
So I remove custom hooks and add ahooks? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes. |
||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
import { useRef } from 'react'; | ||
|
||
function useLatest<T>(value: T) { | ||
const ref = useRef(value); | ||
ref.current = value; | ||
|
||
return ref; | ||
} | ||
export default useLatest; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
import { useCallback, useState } from 'react'; | ||
|
||
export default function useRequest<T, Y extends any[]>(requestFn: any) { | ||
const [loading, setLoading] = useState(false); | ||
|
||
const [data, setData] = useState<T>(); | ||
|
||
const [err, setErr] = useState(); | ||
|
||
const fn = useCallback(async (...params: Y) => { | ||
setLoading(true); | ||
let res; | ||
try { | ||
res = await requestFn(...params); | ||
setData(res); | ||
} catch (error) { | ||
// @ts-ignore | ||
setErr(error); | ||
} | ||
setLoading(false); | ||
return res; | ||
}, []); | ||
|
||
return { | ||
fn, | ||
data, | ||
err, | ||
loading, | ||
}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
import useLatest from '@/hooks/useLatest'; | ||
import { useMemo } from 'react'; | ||
import { throttle } from 'lodash'; | ||
import useUnmount from '@/hooks/useUnmount'; | ||
|
||
type useThrottleReturn = (...args: any) => any; | ||
|
||
interface ThrottleOptions { | ||
wait?: number; | ||
leading?: boolean; | ||
trailing?: boolean; | ||
} | ||
|
||
function useThrottle<T extends useThrottleReturn>(fn: T, options?: ThrottleOptions) { | ||
const fnRef = useLatest(fn); | ||
|
||
const wait = options?.wait ?? 1000; | ||
|
||
const throttled = useMemo( | ||
() => | ||
throttle( | ||
(...args: any[]): ReturnType<T> => { | ||
return fnRef.current(...args); | ||
}, | ||
wait, | ||
options, | ||
), | ||
[], | ||
); | ||
|
||
useUnmount(() => { | ||
throttled.cancel(); | ||
}); | ||
|
||
return { | ||
fn: throttled, | ||
cancel: throttled.cancel, | ||
flush: throttled.flush, | ||
}; | ||
} | ||
|
||
export default useThrottle; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
import useLatest from '@/hooks/useLatest'; | ||
import { useEffect } from 'react'; | ||
|
||
const useUnmount = (fn: () => void) => { | ||
const fnRef = useLatest(fn); | ||
|
||
useEffect( | ||
() => () => { | ||
fnRef.current(); | ||
}, | ||
[], | ||
); | ||
}; | ||
|
||
export default useUnmount; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why does it need to add force here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make click work