Skip to content

Commit

Permalink
Merge pull request #46 from yinstardev/homepage-filter-auto
Browse files Browse the repository at this point in the history
Homepage filter auto
  • Loading branch information
yinstardev authored Mar 30, 2024
2 parents 450bbd8 + 5a00de4 commit 10a3384
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 99 deletions.
12 changes: 11 additions & 1 deletion src/api/db.api.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import axios from 'axios';
import { fetchUserAndToken } from './getUserAndToken';

const getJwtTokenFromLocalStorage = () => {
const token = localStorage.getItem('token');
return token;
};

const be_url = process.env.REACT_APP_BE_URL || '';

export const saveFilterAndTabs = async (filters: Filters, tabs: Tab[]) => {
Expand All @@ -24,9 +29,14 @@ export const saveFilterAndTabs = async (filters: Filters, tabs: Tab[]) => {

export const getFilterAndTabs = async () => {
try {
const { email, token } = await fetchUserAndToken();
const jwtToken = getJwtTokenFromLocalStorage();
if (!jwtToken) throw new Error('JWT token not found');

const emailResponse = await fetchUserAndToken();
const email = emailResponse.email;

const response = await axios.get(`${be_url}/getTabsAndFilters`, {
headers: { Authorization: `Bearer ${jwtToken}` },
params: { email },
});

Expand Down
29 changes: 12 additions & 17 deletions src/pages/DashboardPages/SupportCentralLiveboardPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export const SupportCentralLiveboardPage: React.FC = () => {
const [isLoading, setIsLoading] = useState(false);
const [error, setError] = useState<string | null>(null);
const [preRenderID, setPreRenderID] = useState<string | undefined>(undefined);
const [isInitialized, setIsInitialized] = useState(false);

const handleCustomAction = useCallback((payload: any) => {
if (payload.data.id === 'show-jira-details') {
Expand All @@ -132,16 +133,7 @@ export const SupportCentralLiveboardPage: React.FC = () => {
setEditCaseNumbers(filters.caseNumbers);
};
fetchFiltersAndTabs();

if (embedRef.current) {
const embedInstance = embedRef.current;

embedInstance.on(EmbedEvent.CustomAction, (payload: any) => {
if (payload.id == 'show-jira-details') {
console.log('Custom Action is Activated now');
}
});
}
setIsInitialized(true);
}, []);

const closeModal = useCallback(() => {
Expand All @@ -156,7 +148,6 @@ export const SupportCentralLiveboardPage: React.FC = () => {
) => {
try {
await saveFilterAndTabs({ accountNames: updatedAccountNames, caseNumbers: updatedCaseNumbers }, updatedTabs);
console.log('Tabs and filters updated in database.');
} catch (error) {
console.error('Error updating tabs and filters in database:', error);
}
Expand Down Expand Up @@ -207,8 +198,8 @@ export const SupportCentralLiveboardPage: React.FC = () => {
}, []);

const handleRendered = () => {
setPreRenderID('support-central-lb');
// embedRef.current.preRender(true);
setPreRenderID('support-central-lb' + selectedTabs.join());
embedRef.current.preRender(true);
};

const tabIdsForVisibleTabs = selectedTabs.length > 0 ? selectedTabs.map((tab) => tab.id) : undefined;
Expand Down Expand Up @@ -322,10 +313,14 @@ export const SupportCentralLiveboardPage: React.FC = () => {
Action.RenameModalTitleDescription,
Action.SpotIQAnalyze,
]}
runtimeFilters={[
{ columnName: 'Account Name', operator: RuntimeFilterOp.EQ, values: accountNames },
{ columnName: 'Case Number', operator: RuntimeFilterOp.EQ, values: caseNumbers },
]}
runtimeFilters={
isInitialized
? []
: [
{ columnName: 'Account Name', operator: RuntimeFilterOp.EQ, values: accountNames },
{ columnName: 'Case Number', operator: RuntimeFilterOp.EQ, values: caseNumbers },
]
}
visibleTabs={tabIdsForVisibleTabs}
// onLiveboardRendered={handleRendered}
// usePrerenderedIfAvailable={true}
Expand Down
92 changes: 12 additions & 80 deletions src/pages/DashboardPages/TSEHomeDashboardPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,62 +37,24 @@ const TSEHomeDashboardPage: React.FC = () => {
const [runtimeFilters, setRuntimeFilters] = useState<RuntimeFilter[]>([]);
const [editAccountOwnerName, setEditAccountOwnerName] = useState<string[]>([]);
const [accountOwnerNameList, setAccountOwnerNameList] = useState<string[]>([]);
const [filterByName, setFilterByName] = useState<string>('');

const case_owner_name = 'Case Owner Name';

useEffect(() => {
const fetchAndSetData = async () => {
try {
const { email } = await fetchUserAndToken();
const emailNamePart = email.split('@')[0];
const formattedName = emailNamePart.split('.').join(' ');

const case_owner_name = 'Case Owner Name';
const [data] = await searchData({ query: '', columnName: case_owner_name });

setAccountOwnerNameList(data);

if (embedRef.current) {
if (data.includes(formattedName)) {
embedRef.current.trigger(HostEvent.UpdateRuntimeFilters, [
{
columnName: case_owner_name,
operator: RuntimeFilterOp.EQ,
values: [formattedName],
},
]);
setEditAccountOwnerName([formattedName]);
} else {
embedRef.current.trigger(HostEvent.UpdateRuntimeFilters, [
{
columnName: case_owner_name,
operator: RuntimeFilterOp.EQ,
values: ['azimuddin mohammed'],
},
]);
setEditAccountOwnerName([]);
}
}
setFilterByName('azimuddin mohammed');
} catch (error) {
console.error('Error setting data:', error);
}
};

fetchAndSetData();
}, [embedRef]);

const handleSuperSelectChange = (newValues: string[]) => {
setEditAccountOwnerName(newValues);
console.log(newValues);

if (embedRef.current) {
embedRef.current.trigger(HostEvent.UpdateRuntimeFilters, [
{
columnName: 'Case Owner Name',
operator: RuntimeFilterOp.EQ,
values: newValues,
},
]);
}
};
}, []);

const handleCustomAction = useCallback(
(payload: any) => {
Expand All @@ -104,19 +66,7 @@ const TSEHomeDashboardPage: React.FC = () => {
[navigate, runtimeFilters],
);
const handleVizDoubleClick = (data: any) => {
// console.log(data);
const allowedVizIds = [
'2b259a42-9faf-4446-8aae-d77e790174d9',
'ee46d717-3051-4402-bc62-b5cf8d1921f1',
'adc0ce7b-f383-4eb0-893d-ce265c0e3747',
'af185922-5648-4e26-94c2-826ff8dfab36',
];
// console.log(data.data);
// if(allowedVizIds.includes(data.data.vizId)){

console.log(data.data.vizId);
const viz_id = data.data.vizId;
console.log('Viz Id : ', viz_id);
setCookie('selectedUsers', JSON.stringify(editAccountOwnerName), 7);

let priority = '';
Expand Down Expand Up @@ -149,16 +99,9 @@ const TSEHomeDashboardPage: React.FC = () => {
priority = '';
}
setCookie('PriorityDetailedView', priority, 7);
const priority_console = getCookie('PriorityDetailedView');
console.log(priority_console, 'Priority Console.');
const authUrl = `${process.env.REACT_APP_BE_URL}/salesforce/oauth2/auth`;
window.location.href = authUrl;
navigate('/details-view-sfdc');

// } else {
// console.log("Double click doesn't work here. No Action Assigned to this Viz");
// return;
// }
};

function setCookie(name: any, value: any, days: any) {
Expand All @@ -170,27 +113,10 @@ const TSEHomeDashboardPage: React.FC = () => {
}
document.cookie = name + '=' + (value || '') + expires + '; path=/';
}
function getCookie(name: any) {
const nameEQ = name + '=';
const ca = document.cookie.split(';');
for (let i = 0; i < ca.length; i++) {
let c = ca[i];
while (c.charAt(0) === ' ') c = c.substring(1, c.length);
if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length);
}
return null;
}

const desktopLayout = (
<BaseRow>
<BaseCol xl={24} lg={24}>
<div style={{ maxWidth: '25em', marginLeft: '1em' }}>
<SuperSelect
columnName="Case Owner Name"
defaultValues={editAccountOwnerName}
updateValues={handleSuperSelectChange}
/>
</div>
<TseWrapper>
<LiveboardEmbed
ref={embedRef}
Expand All @@ -207,7 +133,13 @@ const TSEHomeDashboardPage: React.FC = () => {
}}
className="tse-homepage-style"
liveboardId={liveboardId}
runtimeFilters={runtimeFilters}
runtimeFilters={[
{
columnName: case_owner_name,
operator: RuntimeFilterOp.EQ,
values: [filterByName],
},
]}
onCustomAction={handleCustomAction}
preRenderId="tse-homepage"
customizations={{
Expand Down
15 changes: 14 additions & 1 deletion src/pages/DashboardPages/support-central/SuperSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,20 @@ export const SuperSelect: React.FC<SuperSelectProps> = ({ columnName, defaultVal
setIsLoading(false);
return;
}
updateOptions(values);
const sortedValues = values.sort((a, b) => {
const startsWithA = a.toLowerCase().startsWith(query.toLowerCase());
const startsWithB = b.toLowerCase().startsWith(query.toLowerCase());

if (startsWithA && !startsWithB) {
return -1;
} else if (!startsWithA && startsWithB) {
return 1;
} else {
return a.localeCompare(b);
}
});

updateOptions(sortedValues);
} catch (e) {
console.error(e);
}
Expand Down

0 comments on commit 10a3384

Please sign in to comment.