Skip to content

Commit

Permalink
Fleet: Add Enable Polling checkbox
Browse files Browse the repository at this point in the history
Signed-off-by: Francesco Torchia <[email protected]>
  • Loading branch information
torchiaf committed Feb 12, 2025
1 parent 899d4af commit 7725e8a
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 2 deletions.
1 change: 1 addition & 0 deletions shell/assets/translations/en-us.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2467,6 +2467,7 @@ fleet:
correctDriftTooltip: When enabled, Fleet will ensure that the cluster resources are kept in sync with the git repository. All resource changes made on the cluster will be lost.
polling:
label: Polling
enable: Enable Polling
pollingInterval:
label: Polling Interval
tooltip: Polling Interval is the time between a push to the Repository and Fleet reacting to it.
Expand Down
32 changes: 32 additions & 0 deletions shell/edit/__tests__/fleet.cattle.io.gitrepo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,38 @@ describe('view: fleet.cattle.io.gitrepo should', () => {
expect(correctDriftCheckbox.props().value).toBeTruthy();
});

it.each([
['show Polling Interval', 'enabled', undefined, true],
['show Polling Interval', 'enabled', false, true],
['hide Polling Interval', 'disabled', true, false],
])('show Enable Polling checkbox and %p if %p, with spec.disablePolling: %p', (
showPollingIntervalMessage,
enabledMessage,
disablePolling,
enabled
) => {
const wrapper = mount(GitRepo, {
props: {
value: {
...values,
spec: {
disablePolling,
pollingInterval: 60
}
},
mode: _EDIT
},
global: { mocks },
});

const pollingCheckbox = wrapper.findComponent('[data-testid="GitRepo-enablePolling-checkbox"]') as any;
const pollingIntervalInput = wrapper.find('[data-testid="GitRepo-pollingInterval-input"]');

expect(pollingCheckbox.exists()).toBeTruthy();
expect(pollingCheckbox.vm.value).toBe(enabled);
expect(pollingIntervalInput.exists()).toBe(enabled);
});

it.each([
['null', 'default 60 seconds', null, '60'],
['0', 'default 60 seconds', 0, '60'],
Expand Down
33 changes: 31 additions & 2 deletions shell/edit/fleet.cattle.io.gitrepo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export default {
},
data() {
const isPollingEnabled = !this.value.spec.disablePolling;
const pollingInterval = this.value.spec.pollingInterval || DEFAULT_POLLING_INTERVAL;
const targetInfo = this.value.targetInfo;
const targetCluster = targetInfo.cluster;
Expand Down Expand Up @@ -150,6 +151,7 @@ export default {
correctDriftEnabled: false,
targetAdvancedErrors: null,
matchingClusters: null,
isPollingEnabled,
pollingInterval,
ref,
refValue,
Expand Down Expand Up @@ -519,6 +521,14 @@ export default {
}
},
enablePolling(value) {
if (value) {
delete this.value.spec.disablePolling;
} else {
this.value.spec.disablePolling = true;
}
},
updatePollingInterval(value) {
let interval = (value || DEFAULT_POLLING_INTERVAL).toString();
Expand Down Expand Up @@ -726,8 +736,22 @@ export default {
<div class="spacer" />
<h2 v-t="'fleet.gitRepo.polling.label'" />
<div class="row">
<div class="row polling">
<div class="col span-6">
<Checkbox
v-model:value="isPollingEnabled"
data-testid="GitRepo-enablePolling-checkbox"
class="check"
type="checkbox"
label-key="fleet.gitRepo.polling.enable"
:mode="mode"
@update:value="enablePolling"
/>
</div>
<div
v-if="isPollingEnabled"
class="col span-6"
>
<Banner
v-if="showPollingIntervalWarning"
color="warning"
Expand Down Expand Up @@ -826,6 +850,11 @@ export default {
.resource-handling {
display: flex;
flex-direction: column;
gap: 5px
gap: 5px;
}
.polling {
display: flex;
flex-direction: column;
gap: 5px;
}
</style>

0 comments on commit 7725e8a

Please sign in to comment.