Skip to content

Commit

Permalink
Merge pull request #202 from instedd/feature/217-dehardcode-bot-index
Browse files Browse the repository at this point in the history
De-hardcode bot index
  • Loading branch information
NEKRON authored Aug 16, 2018
2 parents db63431 + 15aa773 commit 484c3b9
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 4 deletions.
5 changes: 4 additions & 1 deletion app/controllers/api/bots_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,11 @@ def bot_api_json(bot)
id: bot.id,
name: bot.name,
published: bot.published?,
channel_setup: bot.channels.first.setup?,
channel_setup: bot.channels.any?{|c| c.setup? },
uuid: bot.uuid,
channels: bot.channels.select{|c| c.setup? }.map{|c| c.name.capitalize },
updated_at: bot.updated_at,
active_users: bot.published? ? GatherBotStats.run(bot, 'this_month')[:active_users] : 0,
permissions: bot_permissions(bot),
collaborator_id: bot.collaborators.find { |c| c.user_id == current_user.id }.try(:id)
}
Expand Down
15 changes: 12 additions & 3 deletions app/javascript/components/BotIndex.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,23 @@ export class BotIndexComponent extends Component {
)
} else {
const title = botList.length == 1 ? '1 bot' : `${botList.length} bots`

const commaSeparatedChannels = channels => (
channels.sort().map((channel, ix) => (
ix > 0 ? `, ${channel}` : channel
))
)

const dateOptions = { year: 'numeric', month: 'long', day: 'numeric' }

content = (
<MainWhite>
<Listing items={botList} title={title}
onItemClick={b => botClicked(b)}>
<Column title="Name" render={b => b.name} />
<Column title="Type" render={b => "Facebook"} />
<Column title="Uses" render={b => null} />
<Column title="Last activity date" render={d => null} />
<Column title="Type" render={b => commaSeparatedChannels(b.channels)} />
<Column title="Uses" render={b => b.active_users} />
<Column title="Last activity date" render={b => new Date(b.updated_at).toLocaleDateString('en-US', dateOptions)} />
</Listing>
</MainWhite>
)
Expand Down
3 changes: 3 additions & 0 deletions app/javascript/utils/types-generated-decl.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ export type Bot = {
name: string;
published: boolean;
channel_setup: boolean;
channels?: Array<string>;
uuid?: string | null;
updated_at?: string;
active_users?: number;
permissions: Permissions;
collaborator_id?: number | null;
};
Expand Down
8 changes: 8 additions & 0 deletions app/schemas/types.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,20 @@
"name": { "type": "string" },
"published": { "type": "boolean" },
"channel_setup": { "type": "boolean" },
"channels": {
"type": "array",
"items": {
"type": "string"
}
},
"uuid": {
"oneOf": [
{ "type": "string" },
{ "type": "null" }
]
},
"updated_at": { "type": "string" },
"active_users": {"type": "integer" },
"permissions": { "$ref": "#/definitions/permissions" },
"collaborator_id": {
"oneOf": [
Expand Down
2 changes: 2 additions & 0 deletions spec/controllers/api/bots_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

describe "index" do
it "returns a list of bots" do
allow(GatherBotStats).to receive(:run) { { :active_users => 0 } }
get :index

expect(response).to be_success
Expand All @@ -20,6 +21,7 @@
it "lists only the user accessible bots" do
shared_bot = create(:bot, shared_with: user)

allow(GatherBotStats).to receive(:run) { { :active_users => 0 } }
get :index

bot_ids = json_pluck(json_body, :id)
Expand Down

0 comments on commit 484c3b9

Please sign in to comment.