I'm pretty new to Kibana, and I'm trying to make my own visualization custom plugin (for kibana 6.1.1).
At that moment I just want to see something on the screen that says "hello world" or something.
Firstly, this is my folder structure:
.
├── package.json
├── public
| ├── mainTemplate.html
| ├── optionTemplate.html
| ├── mortaController.js
| └── morta.js
├── index.js
This is morta.js looks like:
import 'plugins/morta/mortaController';
//core methods
import {CATEGORY} from 'ui/vis/vis_category';
import {VisFactoryProvider} from 'ui/vis/vis_factory';
import {VisSchemasProvider} from 'ui/vis/editors/default/schemas';
import {VisTypesRegistryProvider} from 'ui/registry/vis_types';
//templates
import mainTemplate from 'plugins/morta/mainTemplate.html';
import optionTemplate from 'plugins/morta/optionTemplate.html';
VisTypesRegistryProvider.register(MortaProvider);
function MortaProvider(Private) {
const VisFactory = Private(VisFactoryProvider);
const Schemas = Private(VisSchemasProvider);
return VisFactory.createAngularVisualization({
name: "morta",
title: "Morta Vis",
icon: "fa-terminal",
description: "Morta visualization",
category: CATEGORY.BASIC,
visConfig: {
defaults: {},
template: mainTemplate
},
editorConfig: {
optionsTemplate: optionTemplate,
schemas: new Schemas([{
group: 'metrics',
name: 'test_metrics',
title: "Testing metrics",
min: 1,
max: 1,
aggFilter: ['count', 'avg', 'sum', 'min', 'max', 'cardinality', 'std_dev'],
defaults: [
{schema: 'metric', type: 'count'}
]
}])
}
});
}
export default MortaProvider;
This is my controller:
import { uiModules } from 'ui/modules';
const module = uiModules.get('morta', ['kibana']);
module.controller('MortaController', mortaController);
mortaController.$inject = ['$scope'];
function mortaController($scope){
let vm = this;
}
This is the mainTemplate:
<div data-ng-controller="MortaController as vm">
<h1>Morta Visualize View</h1>
</div>
This is the optionTemplate:
<p>Test Options</p>
I've got my kibana and elasticsearch servers up and running, then i'm trying to create a new visualization with my custom plugin but i'm getting an error saying :
"Visualize: cannot read property 'group' of undefined"
I'm not sure if I'm missing something or doing something wrong, let me know if you need more information that I can provide.
This can happen in the create visualization screen after changing the name and forcing a refresh.
name: 'test_metrics',
Exit out of the 'create visualization' screen e.g. click the 'visualize' tab, and the '+' create visualization button to get back to where you were
This worked for me (on version 6.3.2)
Related
I have some storage with pictures in src folder:
const pictures: Array<CarouselPicture> = [
{
index: '1',
url: '../../data/carousel/carousel1.png',
description: ''
}
export default pictures;
Urls are corect for this file, I can reach all my pictures without any problems. Also I have a component where this storage is used:
import pictures from './CarouselData'
export default class ImageContainer extends Component {
render() {
return (
<div className='carousel_image-container'>
{pictures.map((pic) => {
return (
<div key={pic.index}>
<img src={pic.url}></img>
</div>
)})}
</div>
)
}
}
For this component URL's are not correct and I can't reach my pictrures. How can I resolve this problem? I want to write URL's once in my storage and then use the storage in several different components in different folders in my project without changing URL's of my pictures. In other words I want to get pathes dynamically.
I understand that {pic.url} isn't correct, but I dont know how to programm this correctly.
PS: Accordingly some questions here, it would be better to store pictures in src folder, not in public, so I guess 'process.env.PUBLIC_URL' isn't solution (but who knows).
Due to webpack configurations url: '../../data/carousel/carousel1.png', or inline <img src="../../data/carousel/carousel1.png"/> often work for external links such as url: 'https://external/image/link.png'
In your case, you should try require('../../data/carousel/carousel1.png') or import carousel1 from '../../data/carousel/carousel1.png'
Your hunch with using process.env.PUBLIC_URL is correct when using the public/ folder. Assuming your images are in public/data/:
const pictures: Array<CarouselPicture> = [
{
index: '1',
url: `${process.env.PUBLIC_URL}/data/carousel/carousel1.png`,
description: ''
}
]
And as you said you can also do it differently and move your image to your src/ folder. Either one is fine.
These can be located anywhere in src/ and you import them using the normal import rules:
import carousel1 from './images/carousel1.png'
import carousel2 from './images/carousel2.png'
const pictures: Array<CarouselPicture> = [
{
index: '1',
url: carousel1,
description: ''
},
{
index: '1',
url: carousel2,
description: ''
}
]
Make a file which will export images as variable
like this.
for example-
imageExporter.js
export const imageA = {id:1, url:"./your correct relative path for image", description: 'some description'};
and in your component import these image as variable and use them as image source
import {imageA} from './ imageExporter.js path here'
and then
<img src={imageA.url} />
I am trying to implement OneSignal web push notifications with the next.js web app. I followed this article
to implement it. But it is not implementing properly as it shows an error. I have doubt that where should I place the window.OnseSignal code shown in step 7.
What I did?
I built a component name NewOneSignal instead of pasting it in App.js (because there is no App.js file in next.js) whose code is given below:
import React, { useEffect } from "react";
const NewOneSignal=()=>{
useEffect(()=>{
window.OneSignal = window.OneSignal || [];
const OneSignal = window.OneSignal;
},[]);
return (
OneSignal.push(()=> {
OneSignal.init(
{
appId: "i pasted my app id here", //STEP 9
promptOptions: {
slidedown: {
enabled: true,
actionMessage: "We'd like to show you notifications for the latest Jobs and updates about the following categories.",
acceptButtonText: "OMG YEEEEESS!",
cancelButtonText: "NAHHH",
categories: {
tags: [
{
tag: "governmentJobs",
label: "Government Jobs",
},
{
tag: "PrivateJobs",
label: "Private Jobs",
}
]
}
}
},
welcomeNotification: {
"title": "The website",
"message": "Thanks for subscribing!",
}
},
//Automatically subscribe to the new_app_version tag
OneSignal.sendTag("new_app_version", "new_app_version", tagsSent => {
// Callback called when tag has finished sending
console.log('new_app_version TAG SENT', tagsSent);
})
);
})
)
}
export default NewOneSignal;
And imported this component in the document.js file. According to this article, I have to put step 8 code in the useEffect but didn't work also, I have tried that also
I am very much sure that the problem is in this file. I paste the OneSignalsdk script in head section of the _document.js file.Also, i moved the two service worker files in a public folder as shown in the article. Please help me to make this code work
Good day! Can you help me please with my situation. I have a folder structure:
my-project
|----- node_modules.private
|----- src
│ |----- main
| |----- api.1
| |----- api.2
| |----- components
| |------ScreenLogin.js
In my project I have a hierarchical API structure. And I need to limit import of entities from ./node_modules.private and from ./src/main/api1 in ./src/main/components. That means I have to get the error in the case if import look like this if the current file being linted is ./src/main/components/ScreenLogin.js:
import { AccountService } from '../../../node-modules.private';
import { ChatService } from '../api.1';
And in my case the rule is set like this in .eslintrc.js:
'rules': {
'import/no-restricted-paths': [
'error',
{
'zones': [
{ 'target': './src/main/components', 'from': './node_modules.private' },
{ 'target': './src/main/components', 'from': './src/main/api.1' },
],
}
],
},
And interesting thing that the first zone is working and I get the error:
27:37 error Unexpected path "../../../node_modules.private/broker" imported in restricted zone import/no-restricted-paths
But it is not possible to get the error from the second zone. Can you recommend me please how can I do it? I have tried many variants, but nothing is working for me.
I'm developing a blog with Gatsby.js
Each post is a YAML file in which there is an array for the gallery like this:
gallery:
-'/uploads/image1.jpg'
-'/uploads/image2.jpg'
-'/uploads/image3.jpg'
-'/uploads/image4.jpg'
-'/uploads/image5.jpg'
in the post i have something like this:
const images = data.postData.frontmatter.gallery;
return (
{images.map((image, index) => {
return (
<img src={image}/>
)
}
)};
export const query = graphql`
query PostData($slug: String!) {
postData: markdownRemark(fields: {slug: {eq: $slug}}) {
frontmatter {
gallery
}
}
}
`;
But the images don't show up as they are not processed and put in the static folder at build time.
As I understand it, the plugin 'gatsby-plugin-sharp' is not transforming the images that are found in the array in the YAML file, but it does when it's just one image...
(in some of the post there is a field like this
main-image: 'path/to/the/image'
which then I can source with graphql like this:
main-image {
fluid {
src
}
}
}
and instead for the 'gallery' array the 'fluid' node doesn't get created.)
I hope this makes some sense, I realise I'm a bit confused about how some things, I hope you can help me understand some stuff.
Thanks,
M
EDIT
I went a bit forwards thanks to #Z. Zlatev.
I insert this in gatsby-node.js:
exports.createSchemaCustomization = ({ actions }) => {
const { createTypes } = actions;
const typeDefs = `
type MarkdownRemark
implements Node {
frontmatter: Frontmatter
}
type Frontmatter {
gallery: [File]
}
`;
createTypes(typeDefs);
};
and now nodes are created for each image in the gallery array.
However, querying the images I get null...
Here some details:
The YAML File:
---
date: 2019-11-06T13:47:07.000+00:00
title: Cool Project
main_picture: "/uploads/simon-matzinger-Gpck1WkgxIk-unsplash.jpg"
gallery:
- "/uploads/PROEGELHOEF.jpg"
- "/uploads/swapnil-dwivedi-N2IJ31xZ_ks-unsplash-1.jpg"
- "/uploads/swapnil-dwivedi-N2IJ31xZ_ks-unsplash.jpg"
- "/uploads/simon-matzinger-Gpck1WkgxIk-unsplash.jpg"
---
Here the GraphQl query:
query MyQuery {
allMarkdownRemark(filter: {id: {eq: "af697225-a842-545a-b5e1-4a4bcb0baf87"}}) {
edges {
node {
frontmatter {
title
gallery {
childImageSharp {
fluid {
src
}
}
}
}
}
}
}
}
Here the data response:
{
"data": {
"allMarkdownRemark": {
"edges": [
{
"node": {
"frontmatter": {
"title": "Cool Project",
"gallery": [
{
"childImageSharp": null
},
{
"childImageSharp": null
},
{
"childImageSharp": null
},
{
"childImageSharp": null
}
]
}
}
}
]
}
}
}
I guess I'm still missing something...
I will try to explain how this works in Gatsby. First of all, it's the gatsby-transformer-sharp plugin that's transforming your File nodes to ImageSharp nodes. gatsby-plugin-sharp is of course involved too as a low-level API.
The main issue you have is that Gatsby can't recognize(infer) your data as reference to files. Once it does a chain of transformation will automatically kick in. Gatsby actually tries to figure out if string is a file path but those paths must be relative to the file they are found in.
Consider the following example:
gatsby-project
├── content
│ ├── images
│ │ └── home.png
│ └── pages
│ └── home.yml
└── src
content/pages/home.yml
title: Homepage
url: /
image: ../images/home.png
The easiest solution would be to provide a correct relative paths in your yaml files. Sadly we know that's not always possible. An example of that are files created by NetlifyCMS. If this is your case too try some of the existing solutions like:
https://www.gatsbyjs.org/packages/gatsby-plugin-netlify-cms-paths/
Since Gatsby 2.2.0 the createSchemaCustomization API exists that allows us to handle such scenarios more gracefully by defining custom resolvers and field extensions but it may be daunting for people who are not familiar with GraphQL. Read more about it here.
I solved by installing this: https://www.npmjs.com/package/#forestryio/gatsby-remark-normalize-paths
Thanks for putting me in the right direction.
M
I am trying to use this library in my application to convert JSON data to CSV file format. I installed the lib into my project as it mentions https://www.npmjs.com/package/json2csv
npm install json2csv --save.
I also see the module in my node_module folder. Then in my component class i am calling it like so
import { json2csv } from 'json2csv';
But then I get this error
[ts] Module '"c:/dev/angularworkspace/tntzweb/node_modules/json2csv/index"' has no exported member 'json2csv'.
Can someone please help me!!
Change the import to:
import * as json2csv from 'json2csv';
Then implement as:
let fields = ['field1', 'field2', 'field3'];
let result = json2csv({ data:[{ field1: 'a', field2: 'b', field3: 'c' }], fields: fields });
console.log(result);
The other answers are now outdated. For json2csv version 5, first:
npm install --save json2csv #types/json2csv
Then at the top of your Angular component/service/etc:
import { parse } from 'json2csv';
Then to generate the csv in your method:
const csv = parse(json);
There are, of course, all kinds of options you can pass to parse() and json2csv exposes other classes and functions you can import and use as well. There are useful examples in the tests from #types/json2csv.
Here is a complete CSV download implementation:
<a [download]="csvFileName" [href]="getCSVDownloadLink()">CSV export</a>
import { Component } from '#angular/core';
import { DomSanitizer } from '#angular/platform-browser';
import * as json2csv from 'json2csv';
#Component({
selector: 'csv-download',
templateUrl: './csv-download.component.html',
styleUrls: ['./csv-download.component.scss']
})
export class CsvDownloadComponent {
public csvFileName = `test.csv`;
private SOME_DATA: any[] = [{id: 1, name: 'Peter'}, {id: 2, name: 'Sarah'}];
constructor(
private domSanitizer: DomSanitizer,
) { }
getCSVDownloadLink() {
return this.generateCSVDownloadLink({
filename: this.csvFileName,
data: this.SOME_DATA,
columns: [
'id',
'name',
],
});
}
// you can move this method to a service
public generateCSVDownloadLink(options: { filename: string, data: any[], columns: string[] }): SafeUrl {
const fields = options.columns;
const opts = { fields, output: options.filename };
const csv = json2csv.parse(options.data, opts);
return this.domSanitizer.bypassSecurityTrustUrl('data:text/csv,' + encodeURIComponent(csv));
}
}
You can use the angular 2 version of the library. The link to the same is: https://github.com/aqeel-legalinc/angular2-json2csv