Using breakParent to force a linebreak - prettier

I'm working on a prettier plugin and am struggling to understand the breakParent command.
From the command documentation:
Include this anywhere to force all parent groups to break.
The documentation is quite sparse, so maybe I've just completely misunderstood what it's supposed to do, but my expectation would be that it will line break parent groups in exactly the same way they would have if the line exceeded the maximum width.
I would therefore have expected the following commands
{
type: 'group',
contents: {
type: 'concat',
parts: [
'<div>',
{
type: 'indent',
contents: {
type: 'concat',
parts: [{ type: 'line', soft: true }, 'Text', { type: 'break-parent' }],
},
},
{ type: 'line', soft: true },
'</div>',
],
},
}
to print
<div>
Text
</div>
but instead I get
<div>Text</div>
How do I achieve what I thought breakParent would do, i.e. force the surrounding code to line break from inside the group?
And if that's not possible, what does breakParent actually do?
(Obviously, it can be done by turning the soft lines into hard lines, but that's not the solution I'm looking for because only the code generating "Text" in the example above knows if a line break is needed or not)

Related

Is there a way to exclude all files with 100% or at a threshold across the board from karma-coverage text reporter results?

This is very picky of me, I know, but I have a large Angular application where many files are covered at 100% or pretty darn close to it, and I want to exclude those results, so I can just deal with the ones I need to and don't have all the extra noise.
I don't want to exclude files by name because if they change they may go below the OK threshold.
My karma.conf.js (I'm aware I may not need some of the plugins, this is a shared file by the team):
// Karma configuration file, see link for more information
// https://karma-runner.github.io/1.0/config/configuration-file.html
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine', '#angular-devkit/build-angular'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage'),
require('#angular-devkit/build-angular/plugins/karma')
],
reporters: ['progress', 'coverage'],
coverageReporter: {
reporters: [
{type: 'text'},
{type: 'text-summary'},
]
},
browsers: ['ChromeHeadless'],
preprocessors: {'**/*.ts': ['coverage']},
restartOnFileChange: true,
});
};
and I'm gonna try to attach a screenshot here of my sample output in the type: 'text' coverageReporter:
I've tried searching SO and karma / karma-coverage documentation, but I only can find excluding files/paths specifically by name, or updating thresholds, but the latter seems to be only for determining what colors show up. Thank you~
EDIT: And since I only have one file per directory, would also be useful to not duplicate the numbers by printing them for the directory AND the one file under it. Thinking I may just have to dig into the weeds and create a pull request or something.
For this you can generate coverage reports in HTML format. There you will get option to sort files based on code-coverage.
To enable such reports you will have to do update coverageReporter property in your karma configurations -
coverageReporter: {
includeAllSources: true,
dir: 'coverage/',
reporters: [
{type: 'text'},
{type: 'text-summary'},
{type: 'html', subdir: 'html/'}
]
},
Reports will be generated within coverage/html folder.

Loopback 4 validation returns 422 unexepcted, plus how to require only one of three properties

My application accepts three different types of phone numbers for a model. I'd like to validate the numbers to match a certain pattern only if that number is not empty. I've tried this in declaring the properties, but it causes a 422 because it's trying to apply the validation even when a number isn't present. Is there a way to apply the pattern only when the property is not empty?
#property({
type: 'string',
jsonSchema: {
maxLength: 14,
pattern: "[(][0-9]{3}[)] [0-9]{3}-[0-9]{4}",
},
})
cell_phone: string;
I'd also like to make sure that at least one of them is not empty. It's not clear from the documentation (or I just completely missed it, which has happened) if this is possible outside of checking for at least one of them in the controller. Is there a way to declare this in the model?
I am assuming you are using getModelSchemaRef in your controller which means you could make the property optional by doing something like this
getModelSchemaRef(ModelClass, { optional: ["cell_phone"] })
Alrighty, maybe not the most pretty, but this works.
The phone number properties are defined as so:
type: 'string',
jsonSchema: {
oneOf: [
{pattern: "[(][0-9]{3}[)] [0-9]{3}-[0-9]{4}"},
{maxLength: 0},
],
},
})
home_phone?: string;
#property({
type: 'string',
jsonSchema: {
oneOf: [
{pattern: "[(][0-9]{3}[)] [0-9]{3}-[0-9]{4}"},
{maxLength: 0},
],
},
})
cell_phone: string;
#property({
type: 'string',
oneOf: [
{pattern: "[(][0-9]{3}[)] [0-9]{3}-[0-9]{4}"},
{maxLength: 0},
]
})
other_phone?: string;
Then I just check to make sure the correct phone number is set in the controller, like so:
if (application[primaryPhoneType] === '' || typeof application[primaryPhoneType] === 'undefined') {
throw new HttpErrors.UnprocessableEntity('The primary_phone_type is set to ' + application.primary_phone_type + ' but ' + primaryPhoneType + ' was empty.');
}

Define graphQLSchema properly in Node.js

Doing graphQL first time.I searched for resources but could not found a helpful one.
I have written the following schema, got some help from another stackoverflow post.
schema.js
function getDataFromUrl(){
return [
{
"EventCode": "ET00029280",
"EventType": "CT",
"EventTitle": "OYSTERS Beach Park",
"VenueName": "Newexcelsior",
"VenueRegion": "Mumbai"
},
{
"EventCode": "ET00030629",
"EventType": "CT",
"EventTitle": "Stand-Up Comedy: The Trial Room",
"VenueName": "Newexcelsior",
"VenueRegion": "Mumbai"
}
];
}
const eventType = new GraphQLObjectType({
name: 'Event',
fields: {
EventTitle: {
type: GraphQLString,
description: 'Event Title'
},
},
});
const eventListType = new GraphQLObjectType({
name: 'EventList',
fields: {
events: {
type: new GraphQLList(eventType),
description: 'List of items',
},
},
});
const schema = new GraphQLSchema({
query: new GraphQLObjectType({
name: 'Query',
fields: {
eventList: {
type: new GraphQLList(eventListType),
resolve: () => getDataFromUrl(),
}
}
})
});
module.exports = schema;
When I query
{
eventList {
events {
EventTitle
}
}
}
I get this response:
{
"data": {
"eventList": [
{
"events": null
},
{
"events": null
}
]
}
}
I am expecting some changes in my schema, however my desired response is
{
"data": [
{
"EventTitle": "OYSTERS Beach Park"
},
{
"EventTitle": "Stand-Up Comedy: The Trial Room"
}
]
}
Please also suggest some links where I learn basics.
It looks like what's tripping you up the most right now is how you're defining a list. There's no need to define a separate type called EventList -- when you specify GraphQLList(someOtherType) you are already telling GraphQL to expect an array of that particular type. Your current Schema is expecting an array of an array of types. Because the structure of the data you're passing in doesn't match your schema, GraphQL can't find a field called EventTitle to match against and so it's returning null.
The fix in this case is to just get rid of eventListType altogether and change the type of your eventList field to eventType instead.
The docs for GraphQL.js are probably going to be your best bet as far as learning the basics. The only problem is the examples they include are way too basic. Here is a list of projects on GitHub that you can checkout to see GraphQL in action.
If you are starting out, I would also highly recommend using Apollo's graphql-tools. Even if you don't use Apollo on the client-side, graphql-tools makes it ridiculously easy to set up the server. Your schema would be much more readable, since you would write it as string rather than an object like you do in vanilla GraphQL.js. And you can easily set up a GraphiQL endpoint in addition to your GraphQL one, which makes debugging much easier :)

Limit number of accepted groupings

A custom visual that I am creating for Power BI receives categories and values like this.
dataRoles: [
{
name: 'Category',
kind: VisualDataRoleKind.Grouping,
},
{
name: 'Values',
kind: VisualDataRoleKind.Measure,
}],
Now for the moment I only want to use one category grouping. I found the Tornado chart sample that supports this nicely in the UI. When a second group is dropped it will replace the first instead of being added.
I believe this is achieved by setting conditions in dataViewMappings but I couldn't figure out how. This seems to have no effect:
conditions: [
{ 'Category': { max: 1 }, 'Values': { min: 0 } }
],
Anyone can help?
Take a look at the Aster Plot capabilities. I think they do pretty much what you want. You might just need to set the min on 'Y' to 1 to match your scenario.

Ember observe nested array property

I want to observe a nested property. I have the following Ember Array:
specifications: [
{
title: "specification name",
filters: [
{
title: "example"
checked: false
},
{
title: "example 2",
checked: true
}
]
},
...
]
I want to create a computed property:
activeFilters: (->
Ember.computed.filterBy('specifications.#each.filters', 'checked', true),
).property('specifications.#each.filters')
The active filters property is not working, I tried several combinations of property methods, but none worked.
Is the property I am trying to create actually possible?
Yes, it is possible. The thing is that for it to work you can't use a JavaScript array, you need an Ember.ArrayProxy and then you can access its special properties: http://emberjs.com/api/classes/Ember.ArrayProxy.html
specifications: Ember.ArrayProxy.create({
content: [
{
title: "specification name",
},
]
});
So, you'll have something like:
oneSpecChangedCheck: function() {
// don't know which, but someone changed
var s = this.get('specs');
// loop and process
return s;
}.property('specs.#each.checked'),
http://emberjs.jsbin.com/zohuzo/2/edit?html,js,console,output