fix: fixes saved log sql snippets

This commit is contained in:
TzeYiing authored and Ziinc committed 2022-06-27 12:44:11 +08:00
1 parent 7d6b89a779
commit 41ce995439
2 files changed
+23 -28

No files matched your search

@@ -18,8 +18,7 @@ export const LogsSavedPage: NextPageWithLayout = () => {
if (content.isLoading) {
return <Loading active={true}>{null}</Loading>
}
const saved = content.logSqlSnippets()
const saved = content.savedLogSqlSnippets()
return (
<>
<div className="flex flex-col gap-3">
@@ -30,34 +29,29 @@ export const LogsSavedPage: NextPageWithLayout = () => {
<>
<Table.th>Name</Table.th>
<Table.th>Description</Table.th>
<Table.th className="">Created</Table.th>
<Table.th className="">Last updated</Table.th>
<Table.th className=""></Table.th>
</>
}
body={
<>
{saved.length > 0 &&
saved.map((item: any) => <LogsSavedQueriesItem key={item.id} item={item} />)}
<Table.th>Created</Table.th>
<Table.th>Last updated</Table.th>
<Table.th></Table.th>
</>
}
body={saved.map((item) => (
<LogsSavedQueriesItem key={item.id} item={item} />
))}
/>
)}
</div>
{saved.length === 0 && (
<>
<div className="my-auto flex h-full flex-grow flex-col items-center justify-center gap-1">
<IconSave className="animate-bounce" />
<h3 className="text-scale-1200 text-lg">No Saved Queries Yet</h3>
<p className="text-scale-900 text-sm">
Saved queries will appear here. Queries can be saved from the{' '}
<Link href={`/project/${ref}/logs-explorer`}>
<span className="cursor-pointer font-bold text-white underline">Query</span>
</Link>{' '}
tab.
</p>
</div>
</>
<div className="my-auto flex h-full flex-grow flex-col items-center justify-center gap-1">
<IconSave className="animate-bounce" />
<h3 className="text-scale-1200 text-lg">No Saved Queries Yet</h3>
<p className="text-scale-900 text-sm">
Saved queries will appear here. Queries can be saved from the{' '}
<Link href={`/project/${ref}/logs-explorer`}>
<span className="cursor-pointer font-bold text-white underline">Query</span>
</Link>{' '}
tab.
</p>
</div>
)}
</>
)
+5 -4
View File
@@ -34,7 +34,7 @@ export interface IProjectContentStore {
list: (filter?: any) => any[]
reports: (filter?: any) => any[]
sqlSnippets: (filter?: any) => any[]
logSqlSnippets: (filter?: CustomFilter) => UserContent[]
savedLogSqlSnippets: (filter?: CustomFilter) => UserContent[]
addRecentLogSqlSnippet: (snippet: Partial<LogSqlSnippets.Content>) => void
clearRecentLogSqlSnippets: () => void
setProjectRef: (ref?: string) => void
@@ -111,7 +111,8 @@ export default class ProjectContentStore implements IProjectContentStore {
if (response.error) {
throw response.error
}
this.data = keyBy(response.data ?? response, 'id')
console.log(response)
this.data = keyBy(response.data, 'id')
return response
}
@@ -209,8 +210,8 @@ export default class ProjectContentStore implements IProjectContentStore {
;(window as any).localStorage.setItem(this.recentLogSqlKey, JSON.stringify([]))
}
logSqlSnippets(filter?: CustomFilter) {
let arr = ((Object.values(this.data)[0] as any) || []) as UserContent[]
savedLogSqlSnippets(filter?: CustomFilter) {
let arr = Object.values(this.data) as UserContent[]
let snippets = arr.filter((c) => c.type === 'log_sql')
if (filter) {
snippets = snippets.filter(filter)