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

Use NPM SimpleSchema rather than Meteor #3331

Merged
merged 30 commits into from
Mar 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
0b390ed
Use NPM SimpleSchema rather than Meteor
aldeed Nov 20, 2017
49dd908
WIP Latest changes
aldeed Dec 11, 2017
b6a52ad
Fix apps dashboard display issue
aldeed Dec 11, 2017
8946110
Fix form generation issue
aldeed Dec 11, 2017
982f9c1
Fix more simpl-schema bugs
aldeed Dec 20, 2017
4407bb6
Fix tests
aldeed Dec 30, 2017
8eb329b
Remove link
aldeed Dec 30, 2017
f5f2150
Address some of @zenweasel PR review
aldeed Jan 8, 2018
9338d34
Fix settings forms validation
aldeed Jan 9, 2018
3d52a34
Update method-update AutoForm methods
aldeed Jan 14, 2018
7617203
Fix address validation errors
aldeed Jan 17, 2018
35d1688
Clean up shop/createShop method
aldeed Jan 17, 2018
51b20a8
Merge branch 'master' into aldeed-npm-simple-schema
aldeed Jan 17, 2018
274ada3
Fix shop settings form submit errors
aldeed Jan 19, 2018
19da09e
Fix shippo errors during checkout
aldeed Jan 20, 2018
e8b1ffe
Merge branch 'master' into aldeed-npm-simple-schema
aldeed Jan 23, 2018
4194592
fix: Correct schema validation for search settings form
aldeed Jan 24, 2018
2952116
Merge branch 'master' into aldeed-npm-simple-schema
aldeed Jan 24, 2018
441869e
fix: Authnet id/key should not have min characters
aldeed Jan 26, 2018
6fb403a
fix: Fix some shipping schema issues
aldeed Jan 30, 2018
146c240
fix: Add migration for invalid shipmentMethod
aldeed Jan 30, 2018
6b0f931
Merge branch 'master' into aldeed-npm-simple-schema
aldeed Jan 30, 2018
4ca56d0
Merge branch 'release-1.8.0' into aldeed-npm-simple-schema
aldeed Feb 5, 2018
3bb3308
Merge branch 'master' into aldeed-npm-simple-schema
aldeed Feb 23, 2018
0a1863f
chore: Switch to collection2 pkg
aldeed Feb 23, 2018
7ccbe9c
Merge branch 'master' into aldeed-npm-simple-schema
aldeed Mar 6, 2018
35d98ba
tests: Fix test so that the real error is seen rather than timeout
aldeed Mar 6, 2018
91b3a66
fix: Use latest schema-index to avoid loading collection2 twice
aldeed Mar 6, 2018
dcb5926
Merge branch 'release-1.9.0' into aldeed-npm-simple-schema
aldeed Mar 7, 2018
ba46dd2
chore: Resolve lint issues
aldeed Mar 7, 2018
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: 3 additions & 3 deletions .meteor/packages
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ [email protected]

# Community Packages
alanning:roles
aldeed:autoform
aldeed:collection2
aldeed:schema-index
aldeed:autoform@6.2.0
aldeed:collection2@3.0.0
aldeed:schema-index@3.0.0
aldeed:template-extension
bozhao:accounts-instagram
cfs:filesystem
Expand Down
24 changes: 7 additions & 17 deletions client/modules/core/helpers/apps.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import { Meteor } from "meteor/meteor";
import { Roles } from "meteor/alanning:roles";
import { Reaction } from "/client/api";
import { Packages, Shops } from "/lib/collections";
import { Registry } from "/lib/collections/schemas/registry";


/**
*
Expand Down Expand Up @@ -149,23 +147,17 @@ export function Apps(optionHash) {
return false;
}

const filterKeys = Object.keys(itemFilter);
// Loop through all keys in the itemFilter
// each filter item should match exactly with the property in the registry or
// should be included in the array if that property is an array
return filterKeys.every((property) => {
// Check to see if the schema for this property is an array
// if so, we want to make sure that this item is included in the array
if (Array.isArray(Registry._schema[property].type())) {
// Check to see if the registry entry is an array.
// Legacy registry entries could exist that use a string even when the schema requires an array.
if (Array.isArray(item[property])) {
return item[property].includes(itemFilter[property]);
}
}
return Object.keys(itemFilter).every((property) => {
const filterVal = itemFilter[property];
const itemVal = item[property];

// Check to see if the registry entry is an array.
// Legacy registry entries could exist that use a string even when the schema requires an array.
// If it's not an array, the filter should match exactly
return item[property] === itemFilter[property];
return Array.isArray(itemVal) ? itemVal.includes(filterVal) : itemVal === filterVal;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was checking the schema to see if it should be an array, but it actually makes more sense to just check if the value is an array.

});
});

Expand All @@ -175,9 +167,7 @@ export function Apps(optionHash) {
});

// Sort apps by priority (registry.priority)
const sortedApps = reactionApps.sort((a, b) => a.priority - b.priority).slice();

return sortedApps;
return reactionApps.sort((a, b) => a.priority - b.priority).slice();
}

// Register global template helper
Expand Down
9 changes: 4 additions & 5 deletions client/modules/core/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ import { Router } from "/client/modules/router";
// This is placed outside the main object to make it a private variable.
// access using `Reaction.state`
const reactionState = new ReactiveDict();

export const userPrefs = new ReactiveVar(undefined, (val, newVal) => JSON.stringify(val) === JSON.stringify(newVal));

const deps = new Map();
/**
* Reaction namespace
Expand Down Expand Up @@ -536,13 +539,9 @@ export default {
},

allowGuestCheckout() {
let allowGuest = false;
const settings = this.getShopSettings();
// we can disable in admin, let's check.
if (settings.public && settings.public.allowGuestCheckout) {
allowGuest = settings.public.allowGuestCheckout;
}
return allowGuest;
return !!(settings.public && settings.public.allowGuestCheckout);
},
/**
* canInviteToGroup - client (similar to server/api canInviteToGroup)
Expand Down
14 changes: 12 additions & 2 deletions client/modules/core/startup.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Accounts as AccountsCollection } from "/lib/collections";
import { Accounts } from "meteor/accounts-base";

import { Reaction, Logger } from "/client/api";

import { userPrefs } from "./main";

const cookieName = "_RcFallbackLoginToken";

Expand All @@ -16,8 +16,9 @@ const cookieName = "_RcFallbackLoginToken";
Meteor.startup(() => {
// init the core
Reaction.init();

// initialize anonymous guest users
return Tracker.autorun(() => {
Tracker.autorun(() => {
const userId = Meteor.userId();

// Load data from Accounts collection into the localStorage
Expand Down Expand Up @@ -73,6 +74,15 @@ Meteor.startup(() => {
}
}
});

// Set up an autorun to get fine-grained reactivity on only the
// user preferences
Tracker.autorun(() => {
const userId = Meteor.userId();
if (!userId) return;
const user = Meteor.users.findOne(userId, { fields: { profile: 1 } });
userPrefs.set((user && user.profile && user.profile.preferences) || undefined);
});
});

function isLocalStorageAvailable() {
Expand Down
36 changes: 16 additions & 20 deletions client/modules/i18n/main.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import i18next from "i18next";
import { values } from "lodash";
import SimpleSchema from "simpl-schema";
import { Meteor } from "meteor/meteor";
import { Tracker } from "meteor/tracker";
import { SimpleSchema } from "meteor/aldeed:simple-schema";
import { Reaction } from "/client/api";

/**
Expand Down Expand Up @@ -39,25 +40,22 @@ export function getBrowserLanguage() {
* @return {Object} return schema label object
*/
export function getLabelsFor(schema, name) {
const titleCaseName = name.charAt(0).toLowerCase() + name.slice(1);
const labels = {};
// loop through all the rendered form fields and generate i18n keys
for (const fieldName of schema._schemaKeys) {
const i18nKey = `${name.charAt(0).toLowerCase() + name.slice(1)}.${
fieldName
.split(".$").join("")}`;
Object.keys(schema.mergedSchema()).forEach((fieldName) => {
const i18nKey = `${titleCaseName}.${fieldName.split(".$").join("")}`;
// translate autoform label
const t = i18next.t(i18nKey);
if (new RegExp("string").test(t) !== true && t !== i18nKey) {
if (t) {
labels[fieldName] = t;
}
if (t && new RegExp("string").test(t) !== true && t !== i18nKey) {
labels[fieldName] = t;
}
}
});
return labels;
}

/**
* @name getMessagesFor
* @name getValidationErrorMessages
* @method
* @memberof i18n
* @summary Get i18n messages for autoform messages. Currently using a globalMessage namespace only.
Expand All @@ -67,17 +65,15 @@ export function getLabelsFor(schema, name) {
* @todo Implement messaging hierarchy from simple-schema
* @return {Object} returns i18n translated message for schema labels
*/
export function getMessagesFor() {
export function getValidationErrorMessages() {
const messages = {};
for (const message in SimpleSchema._globalMessages) {
if ({}.hasOwnProperty.call(SimpleSchema._globalMessages, message)) {
const i18nKey = `globalMessages.${message}`;
const t = i18next.t(i18nKey);
if (new RegExp("string").test(t) !== true && t !== i18nKey) {
messages[message] = t;
}
values(SimpleSchema.ErrorTypes).forEach((errorType) => {
const i18nKey = `globalMessages.${errorType}`;
const message = i18next.t(i18nKey);
if (new RegExp("string").test(message) !== true && message !== i18nKey) {
messages[errorType] = message;
}
}
});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just tweaked for the changed SS API

return messages;
}

Expand Down
Loading