Skip to content
This repository has been archived by the owner on Oct 8, 2022. It is now read-only.

Commit

Permalink
Add sort option for slack
Browse files Browse the repository at this point in the history
  • Loading branch information
hverlin committed May 12, 2020
1 parent b4fb1b1 commit cf666b1
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 14 deletions.
33 changes: 23 additions & 10 deletions src/components/configuration-form.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import { FormGroup, InputGroup, NumericInput, Switch } from "@blueprintjs/core";
import { FormGroup, HTMLSelect, InputGroup, NumericInput, Switch } from "@blueprintjs/core";
import { useStateLink } from "@hookstate/core";
import _ from "lodash";
import configurationSchema from "../configuration-schema.json";
Expand Down Expand Up @@ -29,14 +29,25 @@ export default function ConfigurationForm({ configuration, fields = [], isForm =
/>
);
} else if (fieldSchema.type === "string") {
return (
<InputGroup
id={inputId}
placeholder={placeholder}
value={state.nested[fieldId].get() || ""}
onChange={(e) => state.nested[fieldId].set(e.target.value)}
/>
);
if (fieldSchema.enum) {
return (
<HTMLSelect
id="theme-selector"
value={state.nested[fieldId].get() || fieldSchema.default}
options={fieldSchema["x-enum-mapping"]}
onChange={(e) => state.nested[fieldId].set(e.target.value)}
/>
);
} else {
return (
<InputGroup
id={inputId}
placeholder={placeholder}
value={state.nested[fieldId].get() || ""}
onChange={(e) => state.nested[fieldId].set(e.target.value)}
/>
);
}
} else if (fieldSchema.type === "integer") {
return (
<NumericInput
Expand Down Expand Up @@ -77,7 +88,9 @@ export default function ConfigurationForm({ configuration, fields = [], isForm =
key={fieldId}
label={fieldSchema.title}
labelFor={inputId}
labelInfo={_.includes(required, fieldId) ? "(required)" : undefined}
labelInfo={
_.includes(required, fieldId) && !fieldSchema.enum ? "(required)" : undefined
}
>
{getInputForType(fieldId, inputId, fieldSchema)}
</FormGroup>
Expand Down
12 changes: 11 additions & 1 deletion src/configuration-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@
},
{
"type": "object",
"required": ["moduleType", "enabled", "id", "name", "token"],
"required": ["moduleType", "enabled", "id", "name", "token", "sortBy"],
"additionalProperties": false,
"properties": {
"moduleType": {
Expand Down Expand Up @@ -402,6 +402,16 @@
"default": 5,
"minimum": 1,
"maximum": 50
},
"sortBy": {
"title": "Sort results by",
"type": "string",
"default": "score",
"enum": ["score", "timestamp"],
"x-enum-mapping": [
{ "value": "score", "label": "Most relevant" },
{ "value": "timestamp", "label": "Most recent" }
]
}
}
},
Expand Down
6 changes: 4 additions & 2 deletions src/modules/slack/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ function SlackDetail({ item, users, emojis }) {

async function fetchMessages(
key,
{ input, queryObj, userId, token, pageSize, owner, dateFilter },
{ input, queryObj, sortBy = "score", userId, token, pageSize, owner, dateFilter },
offset = 1
) {
const query = [input];
Expand All @@ -171,6 +171,7 @@ async function fetchMessages(
token,
query: query.join(" "),
offset,
sort: sortBy,
});

const res = await fetch(`https://slack.com/api/search.messages?${searchParams}`, {
Expand Down Expand Up @@ -200,7 +201,7 @@ const slackResultsRenderer = (users, emojis) => ({ pages }) => {
};

export default function SlackSearchResults({ configuration, searchViewState }) {
const { token, pageSize, userId } = configuration.get();
const { token, pageSize, userId, sortBy } = configuration.get();
const searchData = searchViewState.get();

const [users, setUsers] = React.useState([]);
Expand All @@ -225,6 +226,7 @@ export default function SlackSearchResults({ configuration, searchViewState }) {
{
input: searchData.input,
queryObj: searchData.queryObj,
sortBy,
token,
pageSize,
userId,
Expand Down
2 changes: 1 addition & 1 deletion src/modules/slack/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export default function SlackSettings({ configurationState }) {
<form>
<ConfigurationForm
configuration={config}
fields={["clientId", "clientSecret", "pageSize"]}
fields={["clientId", "clientSecret", "pageSize", "sortBy"]}
isForm={false}
/>
<FormGroup>
Expand Down

0 comments on commit cf666b1

Please sign in to comment.