Compare commits

...

3 Commits

Author SHA1 Message Date
Tom Moor d2a6e3970a Merge branch 'develop' into feat/issue-1310 2020-11-01 10:36:28 -08:00
Tom Moor dfcbaa9aa0 wip 2020-09-07 18:59:03 -07:00
Tom Moor b93e4c61d6 Migration, model 2020-09-07 15:34:46 -07:00
5 changed files with 51 additions and 2 deletions
+20
View File
@@ -13,8 +13,16 @@ import HelpText from "components/HelpText";
import IconPicker, { icons } from "components/IconPicker";
import Input from "components/Input";
import InputRich from "components/InputRich";
import InputSelect from "components/InputSelect";
import Switch from "components/Switch";
const SORT_OPTIONS = [
{ label: "Newest", value: "createdAt,DESC" },
{ label: "Oldest", value: "createdAt,ASC" },
{ label: "Recently updated", value: "updatedAt,DESC" },
{ label: "Least recently updated", value: "updatedAt,ASC" },
];
type Props = {
history: RouterHistory,
ui: UiStore,
@@ -28,6 +36,7 @@ class CollectionNew extends React.Component<Props> {
@observable description: string = "";
@observable icon: string = "";
@observable color: string = "#4E5C6E";
@observable defaultSort: string = "updatedAt,DESC";
@observable private: boolean = false;
@observable isSaving: boolean;
hasOpenedIconPicker: boolean = false;
@@ -39,6 +48,7 @@ class CollectionNew extends React.Component<Props> {
{
name: this.name,
description: this.description,
defaultSort: this.defaultSort,
icon: this.icon,
color: this.color,
private: this.private,
@@ -92,6 +102,10 @@ class CollectionNew extends React.Component<Props> {
this.private = ev.target.checked;
};
handleSortChange = (ev) => {
this.defaultSort = ev.target.value;
};
handleChange = (color: string, icon: string) => {
this.color = color;
this.icon = icon;
@@ -131,6 +145,12 @@ class CollectionNew extends React.Component<Props> {
minHeight={68}
maxHeight={200}
/>
<InputSelect
label="Sort"
onChange={this.handleSortChange}
options={SORT_OPTIONS}
value={this.defaultSort}
/>
<Switch
id="private"
label="Private collection"
+5 -2
View File
@@ -30,7 +30,7 @@ const { authorize } = policy;
const router = new Router();
router.post("collections.create", auth(), async (ctx) => {
const { name, color, description, icon } = ctx.body;
const { name, color, defaultSort, description, icon } = ctx.body;
const isPrivate = ctx.body.private;
ctx.assertPresent(name, "name is required");
@@ -46,6 +46,7 @@ router.post("collections.create", auth(), async (ctx) => {
description,
icon,
color,
defaultSort,
teamId: user.teamId,
creatorId: user.id,
private: isPrivate,
@@ -445,7 +446,7 @@ router.post("collections.export_all", auth(), async (ctx) => {
});
router.post("collections.update", auth(), async (ctx) => {
const { id, name, description, icon, color } = ctx.body;
const { id, name, description, defaultSort, icon, color } = ctx.body;
const isPrivate = ctx.body.private;
ctx.assertPresent(name, "name is required");
@@ -484,6 +485,8 @@ router.post("collections.update", auth(), async (ctx) => {
collection.color = color;
collection.private = isPrivate;
if (defaultSort) collection.defaultSort = defaultSort;
await collection.save();
await Event.create({
@@ -0,0 +1,14 @@
'use strict';
module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.addColumn('collections', 'defaultSort', {
type: Sequelize.STRING,
defaultValue: "updatedAt,DESC"
});
},
down: async (queryInterface, Sequelize) => {
await queryInterface.removeColumn('collections', 'defaultSort');
}
};
+11
View File
@@ -21,6 +21,17 @@ const Collection = sequelize.define(
description: DataTypes.STRING,
icon: DataTypes.STRING,
color: DataTypes.STRING,
defaultSort: {
type: DataTypes.STRING,
validate: {
isEven(value) {
const direction = value.split(",")[1];
if (!["ASC", "DESC"].includes(direction)) {
throw new Error("Invalid sort direction");
}
},
},
},
private: DataTypes.BOOLEAN,
maintainerApprovalRequired: DataTypes.BOOLEAN,
documentStructure: DataTypes.JSONB,
+1
View File
@@ -27,6 +27,7 @@ export default function present(collection: Collection) {
icon: collection.icon,
color: collection.color || "#4E5C6E",
private: collection.private,
defaultSort: collection.defaultSort,
createdAt: collection.createdAt,
updatedAt: collection.updatedAt,
deletedAt: collection.deletedAt,