Skip to content

Commit dcd3364

Browse files
Fix shares
1 parent ed3f076 commit dcd3364

File tree

5 files changed

+111
-41
lines changed

5 files changed

+111
-41
lines changed

resources/compiled/ignition.css

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

resources/compiled/ignition.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

resources/js/components/ShareDropdown.tsx

+24-38
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,35 @@ import { Button, FlareIcon } from '@flareapp/ignition-ui';
33
import Checkbox from 'components/ui/Checkbox';
44
import { IgniteDataContext } from '../contexts/IgniteDataContext';
55
import CopyableUrl from './ui/CopyableUrl';
6+
import shareClient, { SectionName } from '../shareClient';
67

78
type Props = {
89
isOpen: boolean;
910
};
1011

11-
type SectionName = 'stackTrace' | 'context' | 'debug';
12-
1312
export default function ShareDropdown({ isOpen }: Props) {
1413
const igniteData = useContext(IgniteDataContext);
1514
const [ownerUrl, setOwnerUrl] = useState<string | null>(null);
1615
const [publicUrl, setPublicUrl] = useState<string | null>(null);
1716
const [error, setError] = useState<string | null>(null);
1817
const [isLoading, setIsLoading] = useState(false);
1918

20-
const [selectedTabs, setSelectedTabs] = useState<Array<{ name: SectionName; label: string; selected: boolean }>>([
19+
const [selectedSections, setSelectedSections] = useState<
20+
Array<{ name: SectionName; label: string; selected: boolean }>
21+
>([
2122
{ name: 'stackTrace', label: 'Stack', selected: true },
2223
{ name: 'context', label: 'Context', selected: true },
2324
{ name: 'debug', label: 'Debug', selected: true },
2425
]);
2526

26-
function toggleSelected(tabName: SectionName) {
27-
const tab = selectedTabs.find((tab) => tab.name === tabName);
27+
function toggleSelected(sectionName: SectionName) {
28+
const section = selectedSections.find((section) => section.name === sectionName);
2829

29-
if (tab) {
30-
setSelectedTabs(
31-
selectedTabs.map((tab) => (tab.name === tabName ? { ...tab, selected: !tab.selected } : tab)),
30+
if (section) {
31+
setSelectedSections(
32+
selectedSections.map((section) =>
33+
section.name === sectionName ? { ...section, selected: !section.selected } : section,
34+
),
3235
);
3336
}
3437
}
@@ -38,40 +41,23 @@ export default function ShareDropdown({ isOpen }: Props) {
3841
return;
3942
}
4043

41-
const selectedTabNames = selectedTabs
42-
.filter((selectedTab) => selectedTab.selected)
43-
.map((selectedTab) => selectedTab.name);
44-
45-
const data = {
46-
selectedTabNames,
47-
tabs: selectedTabNames,
48-
lineSelection: window.location.hash,
49-
report: igniteData.shareableReport,
50-
};
51-
44+
setError(null);
5245
setIsLoading(true);
5346

47+
const selectedSectionNames = selectedSections
48+
.filter((selectedSection) => selectedSection.selected)
49+
.map((selectedSection) => selectedSection.name);
50+
5451
try {
55-
const response = await (
56-
await fetch(igniteData.config.shareEndpoint, {
57-
method: 'POST',
58-
body: JSON.stringify(data),
59-
headers: {
60-
'Content-Type': 'application/json',
61-
Accept: 'application/json',
62-
},
63-
})
64-
).json();
52+
const response = await shareClient(igniteData, selectedSectionNames);
6553

66-
if (response && response.owner_url && response.public_url) {
67-
setOwnerUrl(response.owner_url);
68-
setPublicUrl(response.public_url);
69-
}
70-
} catch (error) {
54+
setOwnerUrl(response.owner_url);
55+
setPublicUrl(response.public_url);
56+
} catch (e) {
7157
setError('Something went wrong while sharing, please try again.');
72-
} finally {
73-
setIsLoading(false);
7458
}
59+
60+
setIsLoading(false);
7561
}
7662

7763
return (
@@ -97,7 +83,7 @@ export default function ShareDropdown({ isOpen }: Props) {
9783
{!publicUrl && (
9884
<>
9985
<ul className="grid justify-start gap-3">
100-
{selectedTabs.map(({ selected, name, label }) => (
86+
{selectedSections.map(({ selected, name, label }) => (
10187
<li key={name}>
10288
<Checkbox onChange={() => toggleSelected(name)} checked={selected} label={label} />
10389
</li>
@@ -106,7 +92,7 @@ export default function ShareDropdown({ isOpen }: Props) {
10692

10793
<div className="flex items-center gap-4">
10894
<Button
109-
disabled={isLoading}
95+
disabled={isLoading || !selectedSections.some((section) => section.selected)}
11096
className={'bg-violet-500 border-violet-500/25 CopyButton text-white'}
11197
onClick={onShareError}
11298
>

resources/js/shareClient.ts

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import { IgniteData, IgnitionErrorOccurrence } from 'types';
2+
3+
type ShareResponse = {
4+
owner_url: string;
5+
public_url: string;
6+
};
7+
8+
export type SectionName = 'stackTrace' | 'context' | 'debug';
9+
10+
export default function shareError(igniteData: IgniteData, sections: SectionName[]): Promise<ShareResponse> {
11+
const data = {
12+
tabs: sectionsToShareTabs(sections),
13+
lineSelection: window.location.hash,
14+
report: filterReport(igniteData.shareableReport, sections),
15+
};
16+
17+
return new Promise(async (resolve, reject) => {
18+
try {
19+
const response = await (
20+
await fetch(igniteData.config.shareEndpoint, {
21+
method: 'POST',
22+
body: JSON.stringify(data),
23+
headers: {
24+
'Content-Type': 'application/json',
25+
Accept: 'application/json',
26+
},
27+
})
28+
).json();
29+
30+
if (response && response.owner_url && response.public_url) {
31+
resolve(response);
32+
}
33+
} catch (error) {
34+
reject(error);
35+
}
36+
37+
reject();
38+
});
39+
}
40+
41+
function sectionsToShareTabs(sections: SectionName[]): string[] {
42+
let tabs = [];
43+
44+
if (sections.includes('stackTrace')) {
45+
tabs.push('stackTraceTab');
46+
}
47+
48+
if (sections.includes('context')) {
49+
tabs.push('requestTab', 'appTab', 'userTab', 'contextTab');
50+
}
51+
52+
if (sections.includes('debug')) {
53+
tabs.push('debugTab');
54+
}
55+
56+
return tabs;
57+
}
58+
59+
function filterReport(report: IgnitionErrorOccurrence, sections: SectionName[]): IgnitionErrorOccurrence {
60+
if (!sections.includes('stackTrace')) {
61+
report.stacktrace = report.stacktrace.slice(0, 1);
62+
}
63+
64+
if (!sections.includes('debug')) {
65+
report.glows = [];
66+
report.context.dumps = [];
67+
report.context.queries = [];
68+
report.context.logs = [];
69+
}
70+
71+
if (!sections.includes('context')) {
72+
report.context.request_data = { queryString: {}, body: {}, files: [] };
73+
report.context.headers = {};
74+
report.context.cookies = {};
75+
report.context.session = {};
76+
report.context.route = null;
77+
report.context.user = null;
78+
delete report.context.git;
79+
delete report.context.livewire;
80+
report.context.view = null;
81+
}
82+
83+
return report;
84+
}

resources/js/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export type IgnitionErrorOccurrence = {
7979
bindings: Array<any>;
8080
microtime: number;
8181
}>;
82-
git: {
82+
git?: {
8383
hash: string;
8484
message: string;
8585
tag: string;

0 commit comments

Comments
 (0)