2022-05-07 20:08:51 +05:30
|
|
|
import produce from 'immer';
|
|
|
|
|
|
|
|
export const hasErrors = ({ errors = [] }) => errors?.length;
|
|
|
|
|
|
|
|
export function addAgentTokenToStore(store, clusterAgentTokenCreate, query, variables) {
|
|
|
|
if (!hasErrors(clusterAgentTokenCreate)) {
|
|
|
|
const { token } = clusterAgentTokenCreate;
|
|
|
|
const sourceData = store.readQuery({
|
|
|
|
query,
|
|
|
|
variables,
|
|
|
|
});
|
|
|
|
|
|
|
|
const data = produce(sourceData, (draftData) => {
|
|
|
|
draftData.project.clusterAgent.tokens.nodes.unshift(token);
|
|
|
|
draftData.project.clusterAgent.tokens.count += 1;
|
|
|
|
});
|
|
|
|
|
|
|
|
store.writeQuery({
|
|
|
|
query,
|
|
|
|
variables,
|
|
|
|
data,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2022-07-16 23:28:13 +05:30
|
|
|
|
|
|
|
export function removeTokenFromStore(store, revokeToken, query, variables) {
|
|
|
|
if (!hasErrors(revokeToken)) {
|
|
|
|
const sourceData = store.readQuery({
|
|
|
|
query,
|
|
|
|
variables,
|
|
|
|
});
|
|
|
|
|
|
|
|
const data = produce(sourceData, (draftData) => {
|
|
|
|
draftData.project.clusterAgent.tokens.nodes = draftData.project.clusterAgent.tokens.nodes.filter(
|
|
|
|
({ id }) => id !== revokeToken.id,
|
|
|
|
);
|
|
|
|
draftData.project.clusterAgent.tokens.count -= 1;
|
|
|
|
});
|
|
|
|
|
|
|
|
store.writeQuery({
|
|
|
|
query,
|
|
|
|
variables,
|
|
|
|
data,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|