Skip to content

Commit

Permalink
Merge branch 'master' into loki-loggerv2
Browse files Browse the repository at this point in the history
  • Loading branch information
lithorus authored Jan 4, 2025
2 parents 58c5d52 + f50d23a commit 8193acb
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 71 deletions.
60 changes: 35 additions & 25 deletions cueweb/app/jobs/data-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,22 +122,24 @@ const initialColumnVisibility = {
maxRss: false,
}

// Initial state
const initialState: State = {
autoloadMine: getItemFromLocalStorage("autoloadMine", "true"),
tableData: getItemFromLocalStorage("tableData", "[]"),
tableDataUnfiltered: getItemFromLocalStorage("tableDataUnfiltered", "[]"),
sorting: getItemFromLocalStorage("sorting", "[]"),
columnFilters: getItemFromLocalStorage("columnFilters", "[]"),
stateSelectValue: getItemFromLocalStorage("stateSelectValue", JSON.stringify("All States")),
jobSearchResults: [],
filteredJobSearchResults: [],
searchQuery: "",
apiQuery: "",
rowSelection: {},
columnVisibility: getItemFromLocalStorage("columnVisibility", JSON.stringify(initialColumnVisibility)),
error: null,
username: UNKNOWN_USER,
// The initial state of the data table on remount using local storage to preserve states
function getInitialState(): State {
return {
autoloadMine: getItemFromLocalStorage("autoloadMine", "true"),
tableData: getItemFromLocalStorage("tableData", "[]"),
tableDataUnfiltered: getItemFromLocalStorage("tableDataUnfiltered", "[]"),
sorting: getItemFromLocalStorage("sorting", "[]"),
columnFilters: getItemFromLocalStorage("columnFilters", "[]"),
stateSelectValue: getItemFromLocalStorage("stateSelectValue", JSON.stringify("All States")),
jobSearchResults: [],
filteredJobSearchResults: [],
searchQuery: "",
apiQuery: "",
rowSelection: {},
columnVisibility: getItemFromLocalStorage("columnVisibility", JSON.stringify(initialColumnVisibility)),
error: null,
username: UNKNOWN_USER,
}
};

// Reducer function
Expand Down Expand Up @@ -174,10 +176,10 @@ function reducer(state: State, action: Action): State {
case "RESET_COLUMN_VISIBILITY":
return {
...state,
columnVisibility: initialState.columnVisibility,
columnVisibility: initialColumnVisibility,
};
case "RESET_STATE":
return initialState;
return getInitialState();
default:
return state;
}
Expand Down Expand Up @@ -215,7 +217,11 @@ export function DataTable({ columns, username }: DataTableProps) {
const { theme, setTheme } = useTheme();

// useReducer hook to manage state
const [state, dispatch] = useReducer(reducer, initialState);
const [state, dispatch] = useReducer(reducer, getInitialState());

useEffect(() => {
dispatch({ type: "RESET_STATE"});
}, []);

useEffect(() => {
addUsersJobs();
Expand Down Expand Up @@ -380,17 +386,16 @@ export function DataTable({ columns, username }: DataTableProps) {
// Filter out any of the old data in the data table which no longer exists (has been finished for over 48 hours)
updatedTableDataUnfiltered = updatedTableDataUnfiltered.filter((oldJob: Job) => newData.some((newJob: Job) => oldJob.id === newJob.id));
updatedTableData = updatedTableData.filter((oldJob: Job) => newData.some((newJob: Job) => oldJob.id === newJob.id));

// Update table data as both a variable and in local storage
dispatch({ type: "SET_TABLE_DATA_UNFILTERED", payload: updatedTableDataUnfiltered });
dispatch({ type: "SET_TABLE_DATA", payload: updatedTableData });
}
};

// Trigger table updates every 5000ms
interval = setInterval(() => {
interval = setInterval(async () => {
updateData();
addUsersJobs();
await addUsersJobs();
}, 5000);
} catch (error) {
handleError(error, "Error updating table");
Expand Down Expand Up @@ -633,9 +638,14 @@ export function DataTable({ columns, username }: DataTableProps) {
const jobsToAdd = userJobs.filter(userJob => {
return !state.tableData.some(existingJob => existingJob.name === userJob.name)
});

dispatch({ type: "SET_TABLE_DATA", payload: [...state.tableDataUnfiltered, ...jobsToAddUnfiltered] });
dispatch({ type: "SET_TABLE_DATA_UNFILTERED", payload: [...state.tableData, ...jobsToAdd] });

if (jobsToAddUnfiltered.length > 0) {
dispatch({ type: "SET_TABLE_DATA", payload: [...state.tableDataUnfiltered, ...jobsToAddUnfiltered] });
}

if (jobsToAdd.length > 0) {
dispatch({ type: "SET_TABLE_DATA_UNFILTERED", payload: [...state.tableData, ...jobsToAdd] });
}
};

const handleStateFiltering = (stateFilter: string) => {
Expand Down
2 changes: 1 addition & 1 deletion cueweb/app/utils/get_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export async function getLayers(body: string): Promise<Layer[]> {

// Fetch jobs for a specific user, including finished jobs
export async function getJobsForUser(user: string): Promise<Job[]> {
const body = { r: { include_finished: true, users: [`${user}`] } };
const body = { r: { include_finished: false, users: [`${user}`] } };
return await getJobs(JSON.stringify(body));
}

Expand Down
88 changes: 44 additions & 44 deletions cueweb/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cueweb/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"lodash": "^4.17.21",
"lodash.debounce": "^4.0.8",
"lucide-react": "^0.304.0",
"next": "^14.2.3",
"next": "^14.2.20",
"next-auth": "^4.24.10",
"next-themes": "^0.2.1",
"prom-client": "^15.1.2",
Expand Down

0 comments on commit 8193acb

Please sign in to comment.