diff --git a/client/src/app/components/answer-table/answer-table.tsx b/client/src/app/components/answer-table/answer-table.tsx index c8d56e4c3a..8f015fe588 100644 --- a/client/src/app/components/answer-table/answer-table.tsx +++ b/client/src/app/components/answer-table/answer-table.tsx @@ -31,6 +31,7 @@ const AnswerTable: React.FC = ({ const { t } = useTranslation(); const tableControls = useLocalTableControls({ + tableName: "answer-table", idProperty: "text", items: hideAnswerKey ? answers.filter((answer) => answer.selected) diff --git a/client/src/app/components/questions-table/questions-table.tsx b/client/src/app/components/questions-table/questions-table.tsx index 729a7b036c..4a1a48f14c 100644 --- a/client/src/app/components/questions-table/questions-table.tsx +++ b/client/src/app/components/questions-table/questions-table.tsx @@ -38,6 +38,7 @@ const QuestionsTable: React.FC<{ hideAnswerKey, }) => { const tableControls = useLocalTableControls({ + tableName: "questions-table", idProperty: "text", items: questions || [], columnNames: { diff --git a/client/src/app/hooks/table-controls/DOCS.md b/client/src/app/hooks/table-controls/DOCS.md index ab19bef9fe..987bac09bc 100644 --- a/client/src/app/hooks/table-controls/DOCS.md +++ b/client/src/app/hooks/table-controls/DOCS.md @@ -38,6 +38,7 @@ const things: Thing[] = [ ]; const tableControls = useLocalTableControls({ + tableName: 'page-table-name' // A unique name of the table idProperty: "id", // The name of a unique string or number property on the data items. items: things, // The generic type `TItem` is inferred from the items passed here. columnNames: { diff --git a/client/src/app/hooks/table-controls/column/useColumnState.ts b/client/src/app/hooks/table-controls/column/useColumnState.ts index 73769fae1e..6108b1c102 100644 --- a/client/src/app/hooks/table-controls/column/useColumnState.ts +++ b/client/src/app/hooks/table-controls/column/useColumnState.ts @@ -1,4 +1,4 @@ -import { useState } from "react"; +import { useLocalStorage } from "@migtools/lib-ui"; export interface ColumnState { id: TColumnKey; @@ -13,13 +13,19 @@ export interface IColumnState { interface IColumnStateArgs { initialColumns: ColumnState[]; + columnsKey: string; } export const useColumnState = ( args: IColumnStateArgs ): IColumnState => { - const [columns, setColumns] = useState[]>( - args.initialColumns - ); + // const [columns, setColumns] = useState[]>( + // args.initialColumns + // ); + const [columns, setColumns] = useLocalStorage[]>({ + key: args.columnsKey, + defaultValue: args.initialColumns, + }); + return { columns, setColumns }; }; diff --git a/client/src/app/hooks/table-controls/types.ts b/client/src/app/hooks/table-controls/types.ts index 5ae62caedc..e3a9c8a274 100644 --- a/client/src/app/hooks/table-controls/types.ts +++ b/client/src/app/hooks/table-controls/types.ts @@ -138,6 +138,7 @@ export type IUseTableControlStateArgs< TFilterCategoryKey extends string = string, TPersistenceKeyPrefix extends string = string, > = { + tableName: string; /** * An ordered mapping of unique keys to human-readable column name strings. * - Keys of this object are used as unique identifiers for columns (`columnKey`). diff --git a/client/src/app/hooks/table-controls/useLocalTableControls.ts b/client/src/app/hooks/table-controls/useLocalTableControls.ts index 4ddc694a3b..b67981f13e 100644 --- a/client/src/app/hooks/table-controls/useLocalTableControls.ts +++ b/client/src/app/hooks/table-controls/useLocalTableControls.ts @@ -34,7 +34,6 @@ export const useLocalTableControls = < const state = useTableControlState(args); const derivedState = getLocalTableControlDerivedState({ ...args, ...state }); const { columnState } = state; - console.log("columnState", columnState); return useTableControlProps({ ...args, ...state, diff --git a/client/src/app/hooks/table-controls/useTableControlState.ts b/client/src/app/hooks/table-controls/useTableControlState.ts index a6c0c1b169..61e7c1df33 100644 --- a/client/src/app/hooks/table-controls/useTableControlState.ts +++ b/client/src/app/hooks/table-controls/useTableControlState.ts @@ -70,16 +70,14 @@ export const useTableControlState = < const { columnNames, ...restArgs } = args; - const initialColumns = Object.entries(columnNames).map( - ([id, label], index) => ({ - id: id as TColumnKey, - label: label as string, - isVisible: true, - }) - ); + const initialColumns = Object.entries(columnNames).map(([id, label]) => ({ + id: id as TColumnKey, + label: label as string, + isVisible: true, + })); const columnState = useColumnState({ - ...restArgs, + columnsKey: restArgs.tableName, initialColumns, }); return { diff --git a/client/src/app/pages/applications/applications-table/applications-table.tsx b/client/src/app/pages/applications/applications-table/applications-table.tsx index fc2b9e4b77..6116c3b3f4 100644 --- a/client/src/app/pages/applications/applications-table/applications-table.tsx +++ b/client/src/app/pages/applications/applications-table/applications-table.tsx @@ -311,6 +311,7 @@ export const ApplicationsTable: React.FC = () => { const deserializedFilterValues = deserializeFilterUrlParams({ filters }); const tableControls = useLocalTableControls({ + tableName: "applications", idProperty: "id", items: applications || [], columnNames: { @@ -833,7 +834,6 @@ export const ApplicationsTable: React.FC = () => { - {/* {columnState.columns. isVisible then render this column} */} {getColumnVisibility("name") && ( )} diff --git a/client/src/app/pages/applications/manage-imports/manage-imports.tsx b/client/src/app/pages/applications/manage-imports/manage-imports.tsx index ed07a061cf..351ab51e79 100644 --- a/client/src/app/pages/applications/manage-imports/manage-imports.tsx +++ b/client/src/app/pages/applications/manage-imports/manage-imports.tsx @@ -78,6 +78,7 @@ export const ManageImports: React.FC = () => { ); const tableControls = useLocalTableControls({ + tableName: "manage-imports", idProperty: "id", items: importSummaries, columnNames: { diff --git a/client/src/app/pages/archetypes/archetypes-page.tsx b/client/src/app/pages/archetypes/archetypes-page.tsx index b11e247497..f72ab8c27f 100644 --- a/client/src/app/pages/archetypes/archetypes-page.tsx +++ b/client/src/app/pages/archetypes/archetypes-page.tsx @@ -192,6 +192,7 @@ const Archetypes: React.FC = () => { const deserializedFilterValues = deserializeFilterUrlParams({ filters }); const tableControls = useLocalTableControls({ + tableName: "archetypes-table", persistTo: "urlParams", persistenceKeyPrefix: TablePersistenceKeyPrefix.archetypes, idProperty: "id", diff --git a/client/src/app/pages/assessment-management/assessment-settings/assessment-settings-page.tsx b/client/src/app/pages/assessment-management/assessment-settings/assessment-settings-page.tsx index fbf1384b74..2cd16dff6c 100644 --- a/client/src/app/pages/assessment-management/assessment-settings/assessment-settings-page.tsx +++ b/client/src/app/pages/assessment-management/assessment-settings/assessment-settings-page.tsx @@ -101,6 +101,7 @@ const AssessmentSettings: React.FC = () => { const [questionnaireToDelete, setQuestionnaireToDelete] = React.useState(); const tableControls = useLocalTableControls({ + tableName: "questionnaires-table", idProperty: "id", items: questionnaires || [], columnNames: { diff --git a/client/src/app/pages/assessment/components/assessment-actions/components/questionnaires-table.tsx b/client/src/app/pages/assessment/components/assessment-actions/components/questionnaires-table.tsx index ef3687b839..48384839e4 100644 --- a/client/src/app/pages/assessment/components/assessment-actions/components/questionnaires-table.tsx +++ b/client/src/app/pages/assessment/components/assessment-actions/components/questionnaires-table.tsx @@ -37,6 +37,7 @@ const QuestionnairesTable: React.FC = ({ tableName, }) => { const tableControls = useLocalTableControls({ + tableName: "questionnaires-table", idProperty: "id", items: questionnaires || [], columnNames: { diff --git a/client/src/app/pages/controls/business-services/business-services.tsx b/client/src/app/pages/controls/business-services/business-services.tsx index e45f556af9..c5f9608aba 100644 --- a/client/src/app/pages/controls/business-services/business-services.tsx +++ b/client/src/app/pages/controls/business-services/business-services.tsx @@ -81,6 +81,7 @@ export const BusinessServices: React.FC = () => { const { data: applications } = useFetchApplications(); const tableControls = useLocalTableControls({ + tableName: "business-services-table", idProperty: "name", items: businessServices, columnNames: { diff --git a/client/src/app/pages/controls/stakeholder-groups/stakeholder-groups.tsx b/client/src/app/pages/controls/stakeholder-groups/stakeholder-groups.tsx index ae388d4b7f..eba7a03100 100644 --- a/client/src/app/pages/controls/stakeholder-groups/stakeholder-groups.tsx +++ b/client/src/app/pages/controls/stakeholder-groups/stakeholder-groups.tsx @@ -99,6 +99,7 @@ export const StakeholderGroups: React.FC = () => { }; const tableControls = useLocalTableControls({ + tableName: "stakeholder-groups-table", idProperty: "name", items: stakeholderGroups, columnNames: { diff --git a/client/src/app/pages/controls/stakeholders/stakeholders.tsx b/client/src/app/pages/controls/stakeholders/stakeholders.tsx index cf8a16540e..5fe48a8b3a 100644 --- a/client/src/app/pages/controls/stakeholders/stakeholders.tsx +++ b/client/src/app/pages/controls/stakeholders/stakeholders.tsx @@ -95,6 +95,7 @@ export const Stakeholders: React.FC = () => { }; const tableControls = useLocalTableControls({ + tableName: "stakeholders-table", idProperty: "email", items: stakeholders, columnNames: { diff --git a/client/src/app/pages/dependencies/dependencies.tsx b/client/src/app/pages/dependencies/dependencies.tsx index f05e95c595..53dee126dd 100644 --- a/client/src/app/pages/dependencies/dependencies.tsx +++ b/client/src/app/pages/dependencies/dependencies.tsx @@ -44,6 +44,7 @@ export const Dependencies: React.FC = () => { const deserializedFilterValues = deserializeFilterUrlParams({ filters }); const tableControlState = useTableControlState({ + tableName: "dependencies-table", persistTo: "urlParams", persistenceKeyPrefix: TablePersistenceKeyPrefix.dependencies, columnNames: { diff --git a/client/src/app/pages/dependencies/dependency-apps-table.tsx b/client/src/app/pages/dependencies/dependency-apps-table.tsx index 0efcf836bb..bd8bd9cb18 100644 --- a/client/src/app/pages/dependencies/dependency-apps-table.tsx +++ b/client/src/app/pages/dependencies/dependency-apps-table.tsx @@ -51,6 +51,7 @@ export const DependencyAppsTable: React.FC = ({ const deserializedFilterValues = deserializeFilterUrlParams({ filters }); const tableControlState = useTableControlState({ + tableName: "dependency-apps-table", persistTo: "urlParams", persistenceKeyPrefix: TablePersistenceKeyPrefix.dependencyApplications, columnNames: { diff --git a/client/src/app/pages/external/jira/trackers.tsx b/client/src/app/pages/external/jira/trackers.tsx index 2e09b2aaac..321d3e4acb 100644 --- a/client/src/app/pages/external/jira/trackers.tsx +++ b/client/src/app/pages/external/jira/trackers.tsx @@ -92,6 +92,7 @@ export const JiraTrackers: React.FC = () => { ); const tableControls = useLocalTableControls({ + tableName: "jira-Tracker-table", idProperty: "name", items: trackers, columnNames: { diff --git a/client/src/app/pages/issues/affected-applications/affected-applications.tsx b/client/src/app/pages/issues/affected-applications/affected-applications.tsx index deebaaa4fb..c0db18e0fd 100644 --- a/client/src/app/pages/issues/affected-applications/affected-applications.tsx +++ b/client/src/app/pages/issues/affected-applications/affected-applications.tsx @@ -53,6 +53,7 @@ export const AffectedApplications: React.FC = () => { "Active rule"; const tableControlState = useTableControlState({ + tableName: "affected-applications-table", persistTo: "urlParams", persistenceKeyPrefix: TablePersistenceKeyPrefix.issuesAffectedApps, columnNames: { diff --git a/client/src/app/pages/issues/issue-detail-drawer/file-incidents-detail-modal/file-all-incidents-table.tsx b/client/src/app/pages/issues/issue-detail-drawer/file-incidents-detail-modal/file-all-incidents-table.tsx index 07638c4d30..360856ac0e 100644 --- a/client/src/app/pages/issues/issue-detail-drawer/file-incidents-detail-modal/file-all-incidents-table.tsx +++ b/client/src/app/pages/issues/issue-detail-drawer/file-incidents-detail-modal/file-all-incidents-table.tsx @@ -26,6 +26,7 @@ export const FileAllIncidentsTable: React.FC< IFileRemainingIncidentsTableProps > = ({ fileReport }) => { const tableControlState = useTableControlState({ + tableName: "file-all-incidents-table", persistTo: "urlParams", persistenceKeyPrefix: TablePersistenceKeyPrefix.issuesRemainingIncidents, columnNames: { diff --git a/client/src/app/pages/issues/issue-detail-drawer/issue-affected-files-table.tsx b/client/src/app/pages/issues/issue-detail-drawer/issue-affected-files-table.tsx index 49569a649e..61048d886e 100644 --- a/client/src/app/pages/issues/issue-detail-drawer/issue-affected-files-table.tsx +++ b/client/src/app/pages/issues/issue-detail-drawer/issue-affected-files-table.tsx @@ -37,6 +37,7 @@ export const IssueAffectedFilesTable: React.FC< const { t } = useTranslation(); const tableControlState = useTableControlState({ + tableName: "affected-files-table", persistTo: "urlParams", persistenceKeyPrefix: TablePersistenceKeyPrefix.issuesAffectedFiles, columnNames: { diff --git a/client/src/app/pages/issues/issues-table.tsx b/client/src/app/pages/issues/issues-table.tsx index 401e724eba..17d2dce479 100644 --- a/client/src/app/pages/issues/issues-table.tsx +++ b/client/src/app/pages/issues/issues-table.tsx @@ -96,6 +96,7 @@ export const IssuesTable: React.FC = ({ mode }) => { useSharedAffectedApplicationFilterCategories(); const tableControlState = useTableControlState({ + tableName: "issues-table", persistTo: "urlParams", persistenceKeyPrefix: TablePersistenceKeyPrefix.issues, columnNames: { diff --git a/client/src/app/pages/migration-waves/components/manage-applications-form.tsx b/client/src/app/pages/migration-waves/components/manage-applications-form.tsx index e0fbedb8eb..a1166c51e7 100644 --- a/client/src/app/pages/migration-waves/components/manage-applications-form.tsx +++ b/client/src/app/pages/migration-waves/components/manage-applications-form.tsx @@ -100,6 +100,7 @@ export const ManageApplicationsForm: React.FC = ({ ); const tableControls = useLocalTableControls({ + tableName: "manage-applications-table", idProperty: "name", items: availableApplications, columnNames: { diff --git a/client/src/app/pages/migration-waves/components/stakeholders-table.tsx b/client/src/app/pages/migration-waves/components/stakeholders-table.tsx index e40eac74e3..fb2ab2c879 100644 --- a/client/src/app/pages/migration-waves/components/stakeholders-table.tsx +++ b/client/src/app/pages/migration-waves/components/stakeholders-table.tsx @@ -18,6 +18,7 @@ export const WaveStakeholdersTable: React.FC = ({ migrationWave, }) => { const tableControls = useLocalTableControls({ + tableName: "wave-stakeholders-table", idProperty: "name", items: migrationWave.allStakeholders, columnNames: { diff --git a/client/src/app/pages/migration-waves/components/wave-applications-table.tsx b/client/src/app/pages/migration-waves/components/wave-applications-table.tsx index f56baa1a09..a922a7f448 100644 --- a/client/src/app/pages/migration-waves/components/wave-applications-table.tsx +++ b/client/src/app/pages/migration-waves/components/wave-applications-table.tsx @@ -35,6 +35,7 @@ export const WaveApplicationsTable: React.FC = ({ const { tickets } = useFetchTickets(); const tableControls = useLocalTableControls({ + tableName: "wave-applications-table", idProperty: "name", items: migrationWave.fullApplications, columnNames: { diff --git a/client/src/app/pages/migration-waves/components/wave-status-table.tsx b/client/src/app/pages/migration-waves/components/wave-status-table.tsx index c2e9c2f08b..8e26a22e9e 100644 --- a/client/src/app/pages/migration-waves/components/wave-status-table.tsx +++ b/client/src/app/pages/migration-waves/components/wave-status-table.tsx @@ -61,6 +61,7 @@ export const WaveStatusTable: React.FC = ({ const { mutate: deleteTicket } = useDeleteTicketMutation(); const tableControls = useLocalTableControls({ + tableName: "wave-applications-table", idProperty: "name", items: migrationWave.fullApplications, columnNames: { diff --git a/client/src/app/pages/migration-waves/migration-waves.tsx b/client/src/app/pages/migration-waves/migration-waves.tsx index 5dc78ca762..ae44e79e2f 100644 --- a/client/src/app/pages/migration-waves/migration-waves.tsx +++ b/client/src/app/pages/migration-waves/migration-waves.tsx @@ -180,6 +180,7 @@ export const MigrationWaves: React.FC = () => { }; const tableControls = useLocalTableControls({ + tableName: "migration-waves-table", idProperty: "id", items: migrationWaves, columnNames: { diff --git a/client/src/app/pages/reports/components/adoption-candidate-table/adoption-candidate-table.tsx b/client/src/app/pages/reports/components/adoption-candidate-table/adoption-candidate-table.tsx index 5833a35f3f..bf3b1f1ac0 100644 --- a/client/src/app/pages/reports/components/adoption-candidate-table/adoption-candidate-table.tsx +++ b/client/src/app/pages/reports/components/adoption-candidate-table/adoption-candidate-table.tsx @@ -51,6 +51,7 @@ const AdoptionCandidateTable: React.FC = () => { }, [allApplications, reviews]); const tableControls = useLocalTableControls({ + tableName: "adoption-candidate-table", idProperty: "id", items: applicationsWithReviews || [], columnNames: { diff --git a/client/src/app/pages/reports/components/identified-risks-table/identified-risks-table.tsx b/client/src/app/pages/reports/components/identified-risks-table/identified-risks-table.tsx index cc97ee7cd9..86862521aa 100644 --- a/client/src/app/pages/reports/components/identified-risks-table/identified-risks-table.tsx +++ b/client/src/app/pages/reports/components/identified-risks-table/identified-risks-table.tsx @@ -141,6 +141,7 @@ export const IdentifiedRisksTable: React.FC = ({ }); const tableControls = useLocalTableControls({ + tableName: "identified-risks-table", idProperty: "questionId", items: tableData || [], columnNames: {