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

Extend and lock current GUI support to just YAML and JSON data files #360

Merged
merged 12 commits into from
May 3, 2017

Conversation

ashmaroli
Copy link
Member

improves GUI for data files and tests with all Jekyll-supported data files

Currently JSON data is also displayed with "yaml" mode in the Editor.
With this commit, JSON data will be displayed under "json" mode while
every other data file type (YAML, CSV, TSV) will have "yaml" as the mode.
@@ -38,7 +38,7 @@ export function fetchDataFile(filename) {
};
}

export function putDataFile(filename, data, source = "editor") {
export function putDataFile(filename, data, source = "editor", ext = "") {
Copy link
Member

Choose a reason for hiding this comment

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

Why not get the extension from the filename? We have a helper for that too.

@@ -51,8 +51,11 @@ export function putDataFile(filename, data, source = "editor") {
payload = { raw_content: data };
} else if (source == "gui") {
const metadata = getState().metadata.metadata;
const yaml_string = toYAML(metadata);
payload = { raw_content: yaml_string };
if (ext == ".yml" || ext == ".yaml") {
Copy link
Member

Choose a reason for hiding this comment

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

Let's use regex here to include uppercase ones as well.

const yaml = /yaml|yml/i.test(ext);

@@ -21,11 +22,12 @@ class Editor extends Component {
}

render() {
const { content } = this.props;
const { content, ext } = this.props;
Copy link
Member

Choose a reason for hiding this comment

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

let's make ext prop type without dot.

@@ -21,11 +22,12 @@ class Editor extends Component {
}

render() {
const { content } = this.props;
const { content, ext } = this.props;
const mode = (ext == ".json") ? "json" : "yaml";
Copy link
Member

Choose a reason for hiding this comment

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

Regex again.


// Prevent the default event from bubbling
preventDefault(e);

if (fieldChanged) {
putDataFile(params.data_file, null, 'gui');
putDataFile(params.data_file, null, 'gui', ext);
Copy link
Member

Choose a reason for hiding this comment

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

Again we can retrieve ext from params.data_file.

const filename = getFilenameFromPath(path);

const guiSupport = (ext == ".yml" || ext == ".yaml" || ext == ".json") ? true : false;
Copy link
Member

Choose a reason for hiding this comment

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

Regex again.

@@ -78,9 +79,9 @@ export class DataFileEdit extends Component {

renderAside() {
const { datafile, datafileChanged, onDataFileChanged, fieldChanged, updated } = this.props;
const { path } = datafile;
const { path, ext } = datafile;
Copy link
Member

Choose a reason for hiding this comment

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

Can be retrieved from datafile.

@@ -120,7 +124,7 @@ export class DataFileEdit extends Component {
return <h1>{getNotFoundMessage("data file")}</h1>;
}

const { path, raw_content, content } = datafile;
const { path, raw_content, content, ext } = datafile;
Copy link
Member

Choose a reason for hiding this comment

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

Already have filename below this line. For this and above comments, I think it would be better to have a getExtension helper.

<div className="content-body">
<Editor
editorChanged={datafileChanged}
onEditorChange={onDataFileChanged}
content={raw_content}
ext={ext}
Copy link
Member

Choose a reason for hiding this comment

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

type for this too.

@@ -0,0 +1,3 @@
name age sex location
Copy link
Member

Choose a reason for hiding this comment

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

I think csv will do the job. Let's remove this 😄

Copy link
Member Author

Choose a reason for hiding this comment

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

csv and tsv (supported by Jekyll 3.5 and beyond) have been included here for better futureproof

@ashmaroli
Copy link
Member Author

@mertkahyaoglu Thanks for the wonderful suggestions 👍

if (!path) return '';
return path.substring(path.lastIndexOf('.') + 1);
};

Copy link
Member

Choose a reason for hiding this comment

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

Could you add a test for this?

Copy link
Member Author

Choose a reason for hiding this comment

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

added in 1fcc613 .. changed the function a bit to account for paths that do not contain an extension

@ashmaroli
Copy link
Member Author

ashmaroli commented May 3, 2017

I'm not able to run coveralls or script/cibuild-node successfully locally on Windows. The run hangs at babel-node tools/testCi.js

Update: I'm able to run test:cover as expected though..

return path.substring(path.lastIndexOf('.') + 1);
const index = path.lastIndexOf('.');

if (index >= 0) {
Copy link
Member

Choose a reason for hiding this comment

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

Should it be =? I think last . at the beginning is not a valid path.

Copy link
Member Author

Choose a reason for hiding this comment

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

dotFiles are valid filepaths.. just not in current context.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah. Since we are checking the last . here, dotFiles with no extension will get into if statement. For example, .babelrc; it has no extension but index variable will be 0 and returned extension will be babelrc.

Copy link
Member

Choose a reason for hiding this comment

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

It would be good to add a test for dotFiles as well.

@mertkahyaoglu
Copy link
Member

Thanks @ashmaroli 👍

@mertkahyaoglu mertkahyaoglu merged commit 6e4c87b into jekyll:master May 3, 2017
@ashmaroli ashmaroli deleted the gui-plus branch May 12, 2017 11:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants