Skip to content

Commit 676261a

Browse files
committed
Merge branch 'master' of https://github.com/AvocadoHQ/avocado
2 parents 1379e44 + 99537b2 commit 676261a

File tree

11 files changed

+254
-9
lines changed

11 files changed

+254
-9
lines changed

Diff for: app/controllers/avo/resource_overview_controller.rb

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
require_dependency 'avo/application_controller'
2+
3+
module Avo
4+
class ResourceOverviewController < ApplicationController
5+
def index
6+
resources = App.get_resources.map do |resource|
7+
{
8+
name: resource.name,
9+
url: resource.url,
10+
count: resource.model.count,
11+
}
12+
end
13+
14+
render json: {
15+
resources: resources,
16+
hidden: Avo.configuration.hide_resource_overview_component,
17+
hide_docs: Avo.configuration.hide_documentation_link,
18+
}
19+
end
20+
end
21+
end

Diff for: app/frontend/js/components/Index/ItemControls.vue

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
viaResourceId: viaResourceId,
1313
}
1414
}"
15-
v-tooltip="`View ${this.resourceNameSingular}`"
15+
:title="`View ${this.resourceNameSingular}`"
1616
data-control="view"
1717
>
1818
<eye-icon :class="iconClasses"/>
@@ -29,22 +29,22 @@
2929
viaResourceId: viaResourceId,
3030
},
3131
}"
32-
v-tooltip="`Edit ${this.resourceNameSingular}`"
32+
:title="`Edit ${this.resourceNameSingular}`"
3333
data-control="edit"
3434
>
3535
<edit-icon :class="iconClasses"/>
3636
</router-link>
3737
<a href="javascript:void(0);"
3838
@click="openDetachModal"
39-
v-tooltip="`Detach ${this.resourceNameSingular}`"
39+
:title="`Detach ${this.resourceNameSingular}`"
4040
data-control="detach"
4141
v-if="relationship === 'has_and_belongs_to_many'"
4242
>
4343
<trash-icon :class="iconClasses"/>
4444
</a>
4545
<a href="javascript:void(0);"
4646
@click="openDeleteModal"
47-
v-tooltip="`Delete ${this.resourceNameSingular}`"
47+
:title="`Delete ${this.resourceNameSingular}`"
4848
data-control="delete"
4949
v-else
5050
>

Diff for: app/frontend/js/components/LoadingOverlay.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<div class="absolute flex items-center justify-center h-full w-full bg-white bg-opacity-75 z-20">
2+
<div class="absolute flex items-center justify-center h-full w-full bg-white bg-opacity-75 z-20 rounded-xl">
33
<loading-component class="bg-white rounded bg-opacity-75"/>
44
</div>
55
</template>

Diff for: app/frontend/js/components/Pane.vue

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<template>
2+
<div class="relative bg-white rounded-xl shadow-xl mb-8">
3+
<slot />
4+
</div>
5+
</template>

Diff for: app/frontend/js/components/ResourceOverview.vue

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<template>
2+
<div v-if="!hidden">
3+
<div v-if="noResources">
4+
<pane class="p-6">
5+
<heading class="mb-4">
6+
Welcome to Avo 🥑
7+
</heading>
8+
9+
<p class="mb-2">
10+
You haven't generated any Resources. <strong>Resources</strong> are the backbone of Avo.
11+
</p>
12+
13+
<p class="mb-2">
14+
To generate a resource run this command.
15+
</p>
16+
17+
<div class="mb-2 mt-4">
18+
<code class="block bg-gray-200 px-3 py-2 rounded text-gray-800">bin/rails generate avo:resource Post</code>
19+
</div>
20+
</pane>
21+
</div>
22+
<div v-else>
23+
<div class="mb-4 text-lg font-bold">
24+
Current resources
25+
</div>
26+
<div class="grid grid-cols-3 col-gap-6">
27+
<div v-for="resource in resources" :key="resource.name">
28+
<pane class="p-6">
29+
<div class="font-semibold leading-tight mb-2 text-lg">
30+
{{resource.count}} {{resource.name | pluralize(resource.count) | capitalize()}}
31+
</div>
32+
<div class="flex justify-end">
33+
<router-link :to="{
34+
name: 'index',
35+
params: {
36+
resourceName: resource.url,
37+
},
38+
}"
39+
>view all</router-link>
40+
</div>
41+
</pane>
42+
</div>
43+
</div>
44+
</div>
45+
<pane class="p-6" v-if="!hideDocs">
46+
Read the <a href="https://docs.avohq.io" target="_blank">docs</a> for options on how to customize resources.
47+
</pane>
48+
</div>
49+
</template>
50+
51+
<script>
52+
import Api from '@/js/Api'
53+
import Avo from '@/js/Avo'
54+
import pluralize from 'pluralize'
55+
56+
export default {
57+
data: () => ({
58+
resources: [],
59+
hidden: true,
60+
hideDocs: false,
61+
}),
62+
props: [],
63+
filters: {
64+
pluralize(value, count) {
65+
return pluralize(value, count)
66+
},
67+
capitalize(value) {
68+
return value.charAt(0).toUpperCase() + value.slice(1)
69+
},
70+
},
71+
computed: {
72+
noResources() {
73+
return this.resources.length === 0
74+
},
75+
},
76+
methods: {
77+
async getResources() {
78+
const { data } = await Api.get(`${Avo.rootPath}/avo-tools/resource-overview`)
79+
this.resources = data.resources
80+
this.hidden = data.hidden
81+
this.hideDocs = data.hide_docs
82+
},
83+
},
84+
async mounted() {
85+
await this.getResources()
86+
},
87+
}
88+
</script>

Diff for: app/frontend/js/components/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ Vue.component('item-controls', require('@/js/components/In
9191
Vue.component('view-header', require('@/js/components/ViewHeader.vue').default)
9292
Vue.component('view-footer', require('@/js/components/ViewFooter.vue').default)
9393
Vue.component('panel', require('@/js/components/Panel.vue').default)
94+
Vue.component('pane', require('@/js/components/Pane.vue').default)
95+
Vue.component('resource-overview', require('@/js/components/ResourceOverview.vue').default)
9496
Vue.component('heading', require('@/js/components/Heading.vue').default)
9597
Vue.component('a-button', require('@/js/components/Button.vue').default)
9698
Vue.component('resources-search', require('@/js/components/ResourcesSearch.vue').default)

Diff for: app/frontend/js/views/Dashboard.vue

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<template>
2-
<heading>
3-
Dashboard
4-
</heading>
2+
<div>
3+
<heading class="pt-4 mb-8">
4+
Dashboard
5+
</heading>
6+
<resource-overview />
7+
</div>
58
</template>

Diff for: config/routes.rb

+4
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,9 @@
1414
post '/avo-api/:resource_name/:id/attach/:attachment_name/:attachment_id', to: 'resources#attach'
1515
post '/avo-api/:resource_name/:id/detach/:attachment_name/:attachment_id', to: 'resources#detach'
1616

17+
# Tools
18+
get '/avo-tools/resource-overview', to: 'resource_overview#index'
19+
20+
# Catch them all
1721
get '/:view/(:tool)/(:resource_name)/(:option)', to: 'home#index'
1822
end

Diff for: lib/avo/configuration.rb

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ class Configuration
88
attr_accessor :locale
99
attr_accessor :currency
1010
attr_accessor :default_view_type
11+
attr_accessor :hide_resource_overview_component
12+
attr_accessor :hide_documentation_link
1113

1214
def initialize
1315
@root_path = '/avo'
@@ -18,6 +20,8 @@ def initialize
1820
@locale = 'us-US'
1921
@currency = 'USD'
2022
@default_view_type = :table
23+
@hide_resource_overview_component = false
24+
@hide_documentation_link = false
2125
end
2226
end
2327

Diff for: lib/generators/avo/templates/resource.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def initialize
77
end
88

99
fields do
10-
id :ID
10+
id
1111
end
1212
end
1313
end

Diff for: spec/requests/avo/resource_overview_request_spec.rb

+118
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
require 'rails_helper'
2+
3+
RSpec.describe 'ResourceOverview', type: :request do
4+
context 'configs' do
5+
describe 'with false values' do
6+
it 'returns false values' do
7+
get '/avo/avo-tools/resource-overview'
8+
9+
expect(response).to have_http_status(200)
10+
11+
expect(parsed_response['hidden']).to be false
12+
expect(parsed_response['hide_docs']).to be false
13+
end
14+
end
15+
16+
describe 'with true values' do
17+
around do |spec|
18+
Avo.configuration.hide_resource_overview_component = true
19+
Avo.configuration.hide_documentation_link = true
20+
21+
spec.run
22+
23+
Avo.configuration.hide_resource_overview_component = false
24+
Avo.configuration.hide_documentation_link = false
25+
end
26+
27+
it 'returns true values' do
28+
get '/avo/avo-tools/resource-overview'
29+
30+
expect(response).to have_http_status(200)
31+
32+
expect(parsed_response['hidden']).to be true
33+
expect(parsed_response['hide_docs']).to be true
34+
end
35+
end
36+
end
37+
38+
describe 'without any resources in the DB' do
39+
it 'returns empty response' do
40+
get '/avo/avo-tools/resource-overview'
41+
42+
expect(response).to have_http_status(200)
43+
44+
expect(parsed_response['hidden']).to be false
45+
expect(parsed_response['hide_docs']).to be false
46+
expect(parsed_response['resources']).to match_array([
47+
{
48+
count: 0,
49+
name: 'Team',
50+
url: 'teams',
51+
},
52+
{
53+
count: 0,
54+
name: 'Project',
55+
url: 'projects',
56+
},
57+
{
58+
count: 0,
59+
name: 'Post',
60+
url: 'posts',
61+
},
62+
{
63+
count: 0,
64+
name: 'Team Membership',
65+
url: 'team_memberships',
66+
},
67+
{
68+
count: 0,
69+
name: 'User',
70+
url: 'users',
71+
},
72+
].map(&:deep_stringify_keys))
73+
end
74+
end
75+
76+
describe 'with some resources in the DB' do
77+
before do
78+
create_list :user, 3
79+
create_list :team, 2
80+
end
81+
82+
it 'returns non-empty response' do
83+
get '/avo/avo-tools/resource-overview'
84+
85+
expect(response).to have_http_status(200)
86+
87+
expect(parsed_response['hidden']).to be false
88+
expect(parsed_response['hide_docs']).to be false
89+
expect(parsed_response['resources']).to match_array([
90+
{
91+
count: 2,
92+
name: 'Team',
93+
url: 'teams',
94+
},
95+
{
96+
count: 0,
97+
name: 'Project',
98+
url: 'projects',
99+
},
100+
{
101+
count: 0,
102+
name: 'Post',
103+
url: 'posts',
104+
},
105+
{
106+
count: 0,
107+
name: 'Team Membership',
108+
url: 'team_memberships',
109+
},
110+
{
111+
count: 3,
112+
name: 'User',
113+
url: 'users',
114+
},
115+
].map(&:deep_stringify_keys))
116+
end
117+
end
118+
end

0 commit comments

Comments
 (0)