Skip to content

Commit

Permalink
Disable format button without Prettier applied
Browse files Browse the repository at this point in the history
  • Loading branch information
wmarques committed Sep 15, 2022
1 parent c5f4e02 commit 641f1a0
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,10 @@ export default defineComponent({
operationInProgress.value = false;
};

const isApplied = (moduleId: string): boolean => {
return landscapeValue().isApplied(new ModuleSlug(moduleId));
};

return {
levels,
isFeature,
Expand Down Expand Up @@ -397,6 +401,7 @@ export default defineComponent({
applyNewModules,
operationStarted,
operationEnded,
isApplied,
};
},
});
7 changes: 6 additions & 1 deletion src/main/webapp/app/module/primary/landscape/Landscape.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@
/>
</div>
<div class="jhlite-vertical-space--slot">
<ProjectActionsVue :folderPath="folderPath" @operationStarted="operationStarted()" @operationEnded="operationEnded()">
<ProjectActionsVue
:folderPath="folderPath"
:isPrettierButtonEnabled="isApplied('prettier')"
@operationStarted="operationStarted()"
@operationEnded="operationEnded()"
>
<div class="jhlite-vertical-space--slot">
<button
class="jhlite-button -block"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@
@propertyDeleted="deleteProperty"
/>

<ProjectActionsVue :folderPath="folderPath" @operationStarted="operationStarted()" @operationEnded="operationEnded()" />
<ProjectActionsVue
:folderPath="folderPath"
:isPrettierButtonEnabled="true"
@operationStarted="operationStarted()"
@operationEnded="operationEnded()"
/>
</aside>

<div class="jhipster-modules-list">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ export default defineComponent({
type: String,
required: true,
},
isPrettierButtonEnabled: {
type: Boolean,
required: true,
},
},
emits: ['operationStarted', 'operationEnded'],
setup(props, { emit }) {
Expand All @@ -27,6 +31,10 @@ export default defineComponent({
return operationInProgress.value || empty(props.folderPath);
};

const disabledPrettier = (): boolean => {
return disabledActions() || !props.isPrettierButtonEnabled;
};

const formatProject = (): void => {
startOperation();

Expand Down Expand Up @@ -85,6 +93,7 @@ export default defineComponent({

return {
disabledActions,
disabledPrettier,
formatProject,
downloadProject,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
tabindex="5"
class="jhlite-button -block"
@click="formatProject()"
:disabled="disabledActions()"
:disabled="disabledPrettier()"
data-selector="format-button"
>
<IconVue name="code" aria-label="Icon code" />
Expand Down
2 changes: 1 addition & 1 deletion src/test/javascript/spec/module/domain/Modules.fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export const defaultProjectHistory = (): ProjectHistory => ({
});

export const projectHistoryWithInit = (): ProjectHistory => ({
modules: [moduleSlug('init')],
modules: [moduleSlug('init'), moduleSlug('prettier')],
properties: appliedModuleProperties(),
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const defaultLandscape = (): Landscape =>
elements: [
initialModule('infinitest', 'Add infinitest filters', [applicationBaseNamePropertyDefinition()], []),
initialModule('init', 'Add some initial tools', [applicationBaseNamePropertyDefinition()], []),
initialModule('prettier', 'Add prettier', [applicationBaseNamePropertyDefinition()], []),
],
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ describe('Landscape', () => {

assertSelectedConnectorsCount(wrapper, 1);
expect(wrapper.find(wrappedElement('modules-apply-new-button')).text()).toContain('(1)');
expect(wrapper.find(wrappedElement('modules-apply-all-button')).text()).toContain('(2)');
expect(wrapper.find(wrappedElement('modules-apply-all-button')).text()).toContain('(3)');
});

it('Should not select not selectable module', async () => {
Expand Down Expand Up @@ -370,7 +370,9 @@ describe('Landscape', () => {
const [appliedModules] = modules.applyAll.lastCall.args as ModulesToApply[];
expect(appliedModules.modules.map(slug => slug.get())).toEqual(['vue']);
expect(wrapper.find(wrappedElement('modules-apply-new-button')).attributes('disabled')).toBeDefined();

const component: any = wrapper.vm;
expect(component.isApplied('vue')).toBeTruthy();
expect(component.isApplied('angular')).toBeFalsy();
const [message] = alertBus.success.lastCall.args;
expect(message).toBe('Modules applied');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,25 @@ import sinon from 'sinon';

interface WrapperOptions {
folderPath: string;
isPrettierButtonEnabled: boolean;
modules: ModulesRepository;
}

const alertBus = stubAlertBus();
const windowStub = stubWindow();

const wrap = (options?: Partial<WrapperOptions>): VueWrapper => {
const { modules, folderPath }: WrapperOptions = {
const { modules, folderPath, isPrettierButtonEnabled }: WrapperOptions = {
folderPath: '/dummy',
modules: stubModulesRepository(),
isPrettierButtonEnabled: true,
...options,
};

return shallowMount(ProjectActionsVue, {
props: {
folderPath,
isPrettierButtonEnabled,
},
global: { provide: { modules, alertBus, globalWindow: windowStub } },
});
Expand All @@ -45,6 +48,18 @@ describe('Project actions', () => {

expect(wrapper.find(wrappedElement('format-button')).attributes('disabled')).toBeDefined();
});

it('should disable format button according to prop', async () => {
const wrapper = wrap({ isPrettierButtonEnabled: false });

expect(wrapper.find(wrappedElement('format-button')).attributes('disabled')).toBeDefined();
});

it('should enable format button according to prop', async () => {
const wrapper = wrap({ isPrettierButtonEnabled: true });

expect(wrapper.find(wrappedElement('format-button')).attributes('disabled')).toBeUndefined();
});
});

it('Should format file using repository', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ const restLandscape = (): RestLandscape => ({
elements: [
landscapeModule('infinitest', 'Add infinitest filters', applicationBaseNameProperties()),
landscapeModule('init', 'Add some initial tools', applicationBaseNameProperties()),
landscapeModule('prettier', 'Add prettier', applicationBaseNameProperties()),
],
},
{
Expand Down

0 comments on commit 641f1a0

Please sign in to comment.