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

Fleet Resource Handling - Replace warning banners with tooltips #13082

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
14 changes: 12 additions & 2 deletions pkg/rancher-components/src/components/Form/Checkbox/Checkbox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,14 @@ export default defineComponent({
*/
isChecked(): boolean {
return this.isMulti(this.value) ? this.findTrueValues(this.value) : this.value === this.valueWhenTrue;
}
},

/**
* Determines if the Labeled Input should display a tooltip.
*/
hasTooltip(): boolean {
return !!this.tooltip || !!this.tooltipKey;
},
},

methods: {
Expand Down Expand Up @@ -214,6 +221,9 @@ export default defineComponent({
<div
class="checkbox-outer-container"
data-checkbox-ctrl
:class="{
'v-popper--has-tooltip': hasTooltip,
}"
>
<label
class="checkbox-container"
Expand Down Expand Up @@ -241,7 +251,7 @@ export default defineComponent({
role="checkbox"
/>
<span
v-if="$slots.label || label || labelKey || tooltipKey || tooltip"
v-if="$slots.label || label || labelKey || hasTooltip"
class="checkbox-label"
:class="{ 'checkbox-primary': primary }"
>
Expand Down
15 changes: 12 additions & 3 deletions shell/edit/__tests__/fleet.cattle.io.gitrepo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,21 @@ describe('view: fleet.cattle.io.gitrepo should', () => {
global: { mocks }
});

it('should have self-healing checkbox and banner', () => {
it('should have self-healing checkbox and tooltip', () => {
const correctDriftCheckbox = wrapper.find('[data-testid="GitRepo-correctDrift-checkbox"]');
const correctDriftBanner = wrapper.find('[data-testid="GitRepo-correctDrift-banner"]');
const tooltip = wrapper.findAll('[data-testid="GitRepo-correctDrift-checkbox"] .v-popper--has-tooltip');

expect(tooltip).toHaveLength(1);
expect(correctDriftCheckbox.exists()).toBeTruthy();
expect(correctDriftCheckbox.attributes().value).toBeFalsy();
});

it('should have keep-resources checkbox and tooltip', () => {
const correctDriftCheckbox = wrapper.find('[data-testid="GitRepo-keepResources-checkbox"]');
const tooltip = wrapper.findAll('[data-testid="GitRepo-keepResources-checkbox"] .v-popper--has-tooltip');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it should not use classes as an identifier.
You could set the data-testid on the span directly or pass it as prop to achieve this. Otherwise use HTML tags, but CSS classes are a cause of issues.


expect(tooltip).toHaveLength(1);
expect(correctDriftCheckbox.exists()).toBeTruthy();
expect(correctDriftBanner.exists()).toBeTruthy();
expect(correctDriftCheckbox.attributes().value).toBeFalsy();
});

Expand Down
39 changes: 19 additions & 20 deletions shell/edit/fleet.cattle.io.gitrepo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -646,35 +646,26 @@ export default {
</template>
<div class="spacer" />
<h2 v-t="'fleet.gitRepo.resources.label'" />
<div>
<div class="resource-handling">
<Checkbox
v-model:value="value.spec.correctDrift.enabled"
:tooltip="t('fleet.gitRepo.resources.correctDriftBanner')"
data-testid="GitRepo-correctDrift-checkbox"
class="check"
type="checkbox"
label-key="fleet.gitRepo.resources.correctDrift"
:mode="mode"
/>
<Banner
data-testid="GitRepo-correctDrift-banner"
color="info"
>
{{ t('fleet.gitRepo.resources.correctDriftBanner') }}
</Banner>
<Checkbox
v-model:value="value.spec.keepResources"
:tooltip="t('fleet.gitRepo.resources.keepResourcesBanner')"
data-testid="GitRepo-keepResources-checkbox"
class="check"
type="checkbox"
label-key="fleet.gitRepo.resources.keepResources"
:mode="mode"
/>
</div>

<Checkbox
v-model:value="value.spec.keepResources"
class="check"
type="checkbox"
label-key="fleet.gitRepo.resources.keepResources"
:mode="mode"
/>
<Banner
color="info"
>
{{ t('fleet.gitRepo.resources.keepResourcesBanner') }}
</Banner>
<div class="spacer" />
<h2 v-t="'fleet.gitRepo.paths.label'" />
<ArrayList
Expand Down Expand Up @@ -764,3 +755,11 @@ export default {
</template>
</CruResource>
</template>

<style lang="scss" scoped>
.resource-handling {
display: flex;
flex-direction: column;
gap: 5px
}
</style>
Loading