Skip to content

Commit 5d257ee

Browse files
authored
Feature/create reports (#339)
* Add capability to create assets if admin * Implement godmode controls * Improve asset search and select * Fix duplicate asset name bug
1 parent 2a99831 commit 5d257ee

File tree

5 files changed

+539
-65
lines changed

5 files changed

+539
-65
lines changed

web/src/app/api/atlasApi.ts

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ export interface AssetInfo {
1818
export interface CompanyInfo {
1919
slug: string
2020
name: string
21-
role: 'admin' | 'member'
21+
role: 'admin' | 'member' | 'godmode_access'
2222
created_at: string
23+
admins?: string[] // List of admin emails (visible to godmode users)
2324
}
2425

2526
export interface TeamInfo {
@@ -88,6 +89,18 @@ export interface JobExecuteResponse {
8889
new_runs_created: number
8990
}
9091

92+
export interface CreateAssetRequest {
93+
name: string
94+
type: 'scheduled_report' | 'alert'
95+
content: {
96+
url: string
97+
questions: string[]
98+
schedule: string
99+
emails: string[]
100+
template?: string
101+
}
102+
}
103+
91104
export const atlasApi = createApi({
92105
reducerPath: 'atlasApi',
93106
baseQuery: createConcurrencyBaseQuery(configs.ATLAS_BASE_URL, 1),
@@ -147,6 +160,22 @@ export const atlasApi = createApi({
147160
}),
148161
invalidatesTags: (result, error, runId) => [{ type: 'JobRuns' as const }],
149162
}),
163+
createAsset: builder.mutation<AtlasApiResponse<{ asset: AssetInfo }>, {
164+
companySlug: string
165+
teamSlug: string
166+
data: CreateAssetRequest
167+
asUser?: string // For godmode: which admin to act as
168+
}>({
169+
query: ({ companySlug, teamSlug, data, asUser }) => {
170+
const url = `company/${companySlug}/team/${teamSlug}/assets`;
171+
return {
172+
url: asUser ? `${url}?as_user=${encodeURIComponent(asUser)}` : url,
173+
method: 'POST',
174+
body: data
175+
};
176+
},
177+
invalidatesTags: ['User', 'Assets'],
178+
}),
150179
}),
151180
})
152181

@@ -156,5 +185,6 @@ export const {
156185
useExecuteJobMutation,
157186
useGetJobRunHistoryQuery,
158187
useLazyGetJobRunHistoryQuery,
159-
useSendJobEmailMutation
188+
useSendJobEmailMutation,
189+
useCreateAssetMutation
160190
} = atlasApi

web/src/components/common/App.tsx

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ import { getBillingInfo } from '../../app/api/billing'
4646
import { setBillingInfo } from '../../state/billing/reducer'
4747
import { useGetUserStateQuery } from '../../app/api/userStateApi'
4848
import { useGetAtlasMeQuery } from '../../app/api/atlasApi'
49-
import { setAvailableAssets, setAssetsLoading } from '../../state/settings/reducer'
49+
import { setAvailableAssets, setAssetsLoading, setUserCompanies, setUserTeams } from '../../state/settings/reducer'
5050
import { SupportButton } from './Support'
5151
import { Markdown } from './Markdown'
5252
import { getMXToken, setMinusxMode, setStyle, toggleMinusXRoot } from '../../app/rpc'
@@ -205,14 +205,29 @@ const AppLoggedIn = forwardRef((_props, ref) => {
205205
// Handle atlas data loading and updates
206206
useEffect(() => {
207207
dispatch(setAssetsLoading(atlasLoading))
208-
208+
209209
if (atlasData && atlasData.accessible_assets) {
210210
console.log('[minusx] Loaded assets from Atlas API:', atlasData.accessible_assets.length)
211211
dispatch(setAvailableAssets(atlasData.accessible_assets))
212212
} else {
213213
dispatch(setAvailableAssets([]))
214214
}
215-
215+
216+
// Dispatch companies and teams data
217+
if (atlasData && atlasData.companies) {
218+
console.log('[minusx] Loaded companies from Atlas API:', atlasData.companies.length)
219+
dispatch(setUserCompanies(atlasData.companies))
220+
} else {
221+
dispatch(setUserCompanies([]))
222+
}
223+
224+
if (atlasData && atlasData.teams) {
225+
console.log('[minusx] Loaded teams from Atlas API:', atlasData.teams.length)
226+
dispatch(setUserTeams(atlasData.teams))
227+
} else {
228+
dispatch(setUserTeams([]))
229+
}
230+
216231
if (atlasError) {
217232
console.warn('[minusx] Failed to load assets from Atlas API:', atlasError)
218233
}

0 commit comments

Comments
 (0)