Fix server state not being updated correctly when adding/removing allocation; closes #2680

This commit is contained in:
Dane Everitt 2020-11-08 17:12:07 -08:00
parent 74e90e087f
commit 6795bae335
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
3 changed files with 12 additions and 2 deletions

View file

@ -6,6 +6,7 @@ This project follows [Semantic Versioning](http://semver.org) guidelines.
## v1.1.1 ## v1.1.1
### Fixed ### Fixed
* Fixes allocation permissions checking on the frontend checking the wrong permission therefore leading to the item never showing up. * Fixes allocation permissions checking on the frontend checking the wrong permission therefore leading to the item never showing up.
* Fixes allocations not updating correctly when added or deleted and switching between pages.
## v1.1.0 ## v1.1.0
This release **requires** `Wings@1.1.0` in order to work properly due to breaking internal API changes. This release **requires** `Wings@1.1.0` in order to work properly due to breaking internal API changes.

View file

@ -13,8 +13,11 @@ interface Props {
} }
const DeleteAllocationButton = ({ allocation }: Props) => { const DeleteAllocationButton = ({ allocation }: Props) => {
const uuid = ServerContext.useStoreState(state => state.server.data!.uuid);
const [ confirm, setConfirm ] = useState(false); const [ confirm, setConfirm ] = useState(false);
const uuid = ServerContext.useStoreState(state => state.server.data!.uuid);
const setServerFromState = ServerContext.useStoreActions(actions => actions.server.setServerFromState);
const { mutate } = getServerAllocations(); const { mutate } = getServerAllocations();
const { clearFlashes, clearAndAddHttpError } = useFlash(); const { clearFlashes, clearAndAddHttpError } = useFlash();
@ -22,6 +25,8 @@ const DeleteAllocationButton = ({ allocation }: Props) => {
clearFlashes('server:network'); clearFlashes('server:network');
mutate(data => data?.filter(a => a.id !== allocation), false); mutate(data => data?.filter(a => a.id !== allocation), false);
setServerFromState(s => ({ ...s, allocations: s.allocations.filter(a => a.id !== allocation) }));
deleteServerAllocation(uuid, allocation) deleteServerAllocation(uuid, allocation)
.catch(error => clearAndAddHttpError({ key: 'server:network', error })); .catch(error => clearAndAddHttpError({ key: 'server:network', error }));
}; };

View file

@ -19,6 +19,7 @@ const NetworkContainer = () => {
const allocationLimit = ServerContext.useStoreState(state => state.server.data!.featureLimits.allocations); const allocationLimit = ServerContext.useStoreState(state => state.server.data!.featureLimits.allocations);
// @ts-ignore // @ts-ignore
const allocations: Allocation[] = ServerContext.useStoreState(state => state.server.data!.allocations, isEqual); const allocations: Allocation[] = ServerContext.useStoreState(state => state.server.data!.allocations, isEqual);
const setServerFromState = ServerContext.useStoreActions(actions => actions.server.setServerFromState);
const { clearFlashes, clearAndAddHttpError } = useFlash(); const { clearFlashes, clearAndAddHttpError } = useFlash();
const { data, error, mutate } = getServerAllocations(); const { data, error, mutate } = getServerAllocations();
@ -38,7 +39,10 @@ const NetworkContainer = () => {
setLoading(true); setLoading(true);
createServerAllocation(uuid) createServerAllocation(uuid)
.then(allocation => mutate(data?.concat(allocation), false)) .then(allocation => {
setServerFromState(s => ({ ...s, allocations: s.allocations.concat(allocation) }));
return mutate(data?.concat(allocation), false);
})
.catch(error => clearAndAddHttpError({ key: 'server:network', error })) .catch(error => clearAndAddHttpError({ key: 'server:network', error }))
.then(() => setLoading(false)); .then(() => setLoading(false));
}; };