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

Revert "Remove deprecated disabledWhen" #19672

Merged
merged 1 commit into from
Jul 22, 2021
Merged
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
6 changes: 6 additions & 0 deletions packages/@ember/-internals/glimmer/lib/components/-link-to.ts
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,12 @@ const LinkComponent = EmberComponent.extend({
loadingHref: '#',

didReceiveAttrs() {
let { disabledWhen } = this;

if (disabledWhen !== undefined) {
this.set('disabled', disabledWhen);
}

let { params } = this;

if (!params || params.length === 0) {
Expand Down
64 changes: 64 additions & 0 deletions packages/@ember/-internals/glimmer/lib/components/link-to.ts
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,70 @@ if (EMBER_MODERNIZED_BUILT_IN_COMPONENTS) {
});
}

// @disabledWhen
{
let superIsSupportedArgument = prototype['isSupportedArgument'];

Object.defineProperty(prototype, 'isSupportedArgument', {
configurable: true,
enumerable: false,
value: function isSupportedArgument(this: LinkTo, name: string): boolean {
if (this.modernized) {
if (name === 'disabledWhen') {
deprecate(
'Passing the `@disabledWhen` argument to <LinkTo> is deprecated. ' +
'Use the `@disabled` argument instead.',
false,
{
id: 'ember.link-to.disabled-when',
for: 'ember-source',
since: {},
until: '4.0.0',
}
);

return true;
}
}

return superIsSupportedArgument.call(this, name);
},
});

let superDescriptor = descriptorFor(prototype, 'isDisabled');

assert(
`[BUG] expecting isDisabled to be a getter on <LinkTo>`,
superDescriptor && typeof superDescriptor.get === 'function'
);

let superGetter = superDescriptor.get as (this: LinkTo) => boolean;

Object.defineProperty(prototype, 'isDisabled', {
configurable: true,
enumerable: false,
get: function isDisabled(this: LinkTo): boolean {
if ('disabledWhen' in this.args.named) {
deprecate(
'Passing the `@disabledWhen` argument to <LinkTo> is deprecated. ' +
'Use the `@disabled` argument instead.',
false,
{
id: 'ember.link-to.disabled-when',
for: 'ember-source',
since: {},
until: '4.0.0',
}
);

return Boolean(this.named('disabledWhen'));
}

return superGetter.call(this);
},
});
}

// QP
{
let superModelsDescriptor = descriptorFor(prototype, 'models');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,64 @@ moduleFor(
assert.strictEqual(this.$('#about-link').attr('href'), null, 'there is no href attribute');
}

async [`@test [DEPRECATED] it applies a 'disabled' class when disabledWhen`](assert) {
this.addTemplate(
'index',
`
<LinkTo id="about-link-static" @route="about" @disabledWhen="truthy">About</LinkTo>
<LinkTo id="about-link-dynamic" @route="about" @disabledWhen={{this.dynamicDisabledWhen}}>About</LinkTo>
`
);

let controller;

this.add(
'controller:index',
class extends Controller {
constructor(...args) {
super(...args);
controller = this;
}

dynamicDisabledWhen = true;
}
);

await expectDeprecationAsync(
() => this.visit('/'),
'Passing the `@disabledWhen` argument to <LinkTo> is deprecated. Use the `@disabled` argument instead.',
EMBER_MODERNIZED_BUILT_IN_COMPONENTS
);

assert.equal(
this.$('#about-link-static.disabled').length,
1,
'The static link is disabled when its disabledWhen is true'
);
assert.equal(
this.$('#about-link-dynamic.disabled').length,
1,
'The dynamic link is disabled when its disabledWhen is true'
);

expectDeprecation(
() => runTask(() => controller.set('dynamicDisabledWhen', false)),
'Passing the `@disabledWhen` argument to <LinkTo> is deprecated. Use the `@disabled` argument instead.',
EMBER_MODERNIZED_BUILT_IN_COMPONENTS
);

assert.equal(
this.$('#about-link-static.disabled').length,
1,
'The static link is disabled when its disabledWhen is true'
);
assert.strictEqual(
this.$('#about-link-dynamic.disabled').length,
0,
'The dynamic link is re-enabled when its disabledWhen becomes false'
);
}

async [`@test it applies a 'disabled' class when disabled`](assert) {
this.addTemplate(
'index',
Expand Down Expand Up @@ -326,6 +384,27 @@ moduleFor(
);
}

async [`@test [DEPRECATED] it does not respond to clicks when disabledWhen`](assert) {
this.addTemplate(
'index',
`<LinkTo id="about-link" @route="about" @disabledWhen={{true}}>About</LinkTo>`
);

await expectDeprecationAsync(
() => this.visit('/'),
'Passing the `@disabledWhen` argument to <LinkTo> is deprecated. Use the `@disabled` argument instead.',
EMBER_MODERNIZED_BUILT_IN_COMPONENTS
);

await expectDeprecationAsync(
() => this.click('#about-link'),
'Passing the `@disabledWhen` argument to <LinkTo> is deprecated. Use the `@disabled` argument instead.',
EMBER_MODERNIZED_BUILT_IN_COMPONENTS
);

assert.strictEqual(this.$('h3.about').length, 0, 'Transitioning did not occur');
}

async [`@test it does not respond to clicks when disabled`](assert) {
this.addTemplate(
'index',
Expand Down Expand Up @@ -372,7 +451,7 @@ moduleFor(
assert.equal(
this.$('h3.about').length,
1,
'Transitioning did occur when disabled became false'
'Transitioning did occur when disabledWhen became false'
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,64 @@ moduleFor(
);
}

async [`@test [DEPRECATED] it applies a 'disabled' class when disabledWhen`](assert) {
this.addTemplate(
'index',
`
<div id="about-link-static">{{#link-to route="about" disabledWhen="truthy"}}About{{/link-to}}</div>
<div id="about-link-dynamic">{{#link-to route="about" disabledWhen=this.dynamicDisabledWhen}}About{{/link-to}}</div>
`
);

let controller;

this.add(
'controller:index',
class extends Controller {
constructor(...args) {
super(...args);
controller = this;
}

dynamicDisabledWhen = true;
}
);

await expectDeprecationAsync(
() => this.visit('/'),
'Passing the `@disabledWhen` argument to <LinkTo> is deprecated. Use the `@disabled` argument instead.',
EMBER_MODERNIZED_BUILT_IN_COMPONENTS
);

assert.equal(
this.$('#about-link-static > a.disabled').length,
1,
'The static link is disabled when its disabledWhen is true'
);
assert.equal(
this.$('#about-link-dynamic > a.disabled').length,
1,
'The dynamic link is disabled when its disabledWhen is true'
);

expectDeprecation(
() => runTask(() => controller.set('dynamicDisabledWhen', false)),
'Passing the `@disabledWhen` argument to <LinkTo> is deprecated. Use the `@disabled` argument instead.',
EMBER_MODERNIZED_BUILT_IN_COMPONENTS
);

assert.equal(
this.$('#about-link-static > a.disabled').length,
1,
'The static link is disabled when its disabledWhen is true'
);
assert.strictEqual(
this.$('#about-link-dynamic > a.disabled').length,
0,
'The dynamic link is re-enabled when its disabledWhen becomes false'
);
}

async [`@test it applies a 'disabled' class when disabled`](assert) {
this.addTemplate(
'index',
Expand Down Expand Up @@ -193,7 +251,7 @@ moduleFor(
assert.equal(
this.$('#about-link-static > a.disabled').length,
1,
'The static link is disabled when its disabled is true'
'The static link is disabled when its disabledWhen is true'
);
assert.strictEqual(
this.$('#about-link-dynamic > a.disabled').length,
Expand Down Expand Up @@ -338,6 +396,27 @@ moduleFor(
);
}

async [`@test [DEPRECATED] it does not respond to clicks when disabledWhen`](assert) {
this.addTemplate(
'index',
`<div id="about-link">{{#link-to route="about" disabledWhen=true}}About{{/link-to}}</div>`
);

await expectDeprecationAsync(
() => this.visit('/'),
'Passing the `@disabledWhen` argument to <LinkTo> is deprecated. Use the `@disabled` argument instead.',
EMBER_MODERNIZED_BUILT_IN_COMPONENTS
);

await expectDeprecationAsync(
() => this.click('#about-link > a'),
'Passing the `@disabledWhen` argument to <LinkTo> is deprecated. Use the `@disabled` argument instead.',
EMBER_MODERNIZED_BUILT_IN_COMPONENTS
);

assert.strictEqual(this.$('h3.about').length, 0, 'Transitioning did not occur');
}

async [`@test it does not respond to clicks when disabled`](assert) {
this.addTemplate(
'index',
Expand Down Expand Up @@ -384,7 +463,7 @@ moduleFor(
assert.equal(
this.$('h3.about').length,
1,
'Transitioning did occur when disabled became false'
'Transitioning did occur when disabledWhen became false'
);
}

Expand Down