Skip to content

Commit

Permalink
Add unique table name to drive col selection persistence
Browse files Browse the repository at this point in the history
  • Loading branch information
ibolton336 committed Mar 25, 2024
1 parent 1f40765 commit fee201f
Show file tree
Hide file tree
Showing 29 changed files with 42 additions and 14 deletions.
1 change: 1 addition & 0 deletions client/src/app/components/answer-table/answer-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const AnswerTable: React.FC<IAnswerTableProps> = ({
const { t } = useTranslation();

const tableControls = useLocalTableControls({
tableName: "answer-table",
idProperty: "text",
items: hideAnswerKey
? answers.filter((answer) => answer.selected)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const QuestionsTable: React.FC<{
hideAnswerKey,
}) => {
const tableControls = useLocalTableControls({
tableName: "questions-table",
idProperty: "text",
items: questions || [],
columnNames: {
Expand Down
1 change: 1 addition & 0 deletions client/src/app/hooks/table-controls/DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
14 changes: 10 additions & 4 deletions client/src/app/hooks/table-controls/column/useColumnState.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState } from "react";
import { useLocalStorage } from "@migtools/lib-ui";

export interface ColumnState<TColumnKey extends string> {
id: TColumnKey;
Expand All @@ -13,13 +13,19 @@ export interface IColumnState<TColumnKey extends string> {

interface IColumnStateArgs<TColumnKey extends string> {
initialColumns: ColumnState<TColumnKey>[];
columnsKey: string;
}

export const useColumnState = <TColumnKey extends string>(
args: IColumnStateArgs<TColumnKey>
): IColumnState<TColumnKey> => {
const [columns, setColumns] = useState<ColumnState<TColumnKey>[]>(
args.initialColumns
);
// const [columns, setColumns] = useState<ColumnState<TColumnKey>[]>(
// args.initialColumns
// );
const [columns, setColumns] = useLocalStorage<ColumnState<TColumnKey>[]>({
key: args.columnsKey,
defaultValue: args.initialColumns,
});

return { columns, setColumns };
};
1 change: 1 addition & 0 deletions client/src/app/hooks/table-controls/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 6 additions & 8 deletions client/src/app/hooks/table-controls/useTableControlState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<TColumnKey>({
...restArgs,
columnsKey: restArgs.tableName,
initialColumns,
});
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ export const ApplicationsTable: React.FC = () => {
const deserializedFilterValues = deserializeFilterUrlParams({ filters });

const tableControls = useLocalTableControls({
tableName: "applications",
idProperty: "id",
items: applications || [],
columnNames: {
Expand Down Expand Up @@ -833,7 +834,6 @@ export const ApplicationsTable: React.FC = () => {
<Thead>
<Tr>
<TableHeaderContentWithControls {...tableControls}>
{/* {columnState.columns. isVisible then render this column} */}
{getColumnVisibility("name") && (
<Th {...getThProps({ columnKey: "name" })} width={15} />
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export const ManageImports: React.FC = () => {
);

const tableControls = useLocalTableControls({
tableName: "manage-imports",
idProperty: "id",
items: importSummaries,
columnNames: {
Expand Down
1 change: 1 addition & 0 deletions client/src/app/pages/archetypes/archetypes-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ const AssessmentSettings: React.FC = () => {
const [questionnaireToDelete, setQuestionnaireToDelete] =
React.useState<Questionnaire>();
const tableControls = useLocalTableControls({
tableName: "questionnaires-table",
idProperty: "id",
items: questionnaires || [],
columnNames: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const QuestionnairesTable: React.FC<QuestionnairesTableProps> = ({
tableName,
}) => {
const tableControls = useLocalTableControls({
tableName: "questionnaires-table",
idProperty: "id",
items: questionnaires || [],
columnNames: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export const StakeholderGroups: React.FC = () => {
};

const tableControls = useLocalTableControls({
tableName: "stakeholder-groups-table",
idProperty: "name",
items: stakeholderGroups,
columnNames: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export const Stakeholders: React.FC = () => {
};

const tableControls = useLocalTableControls({
tableName: "stakeholders-table",
idProperty: "email",
items: stakeholders,
columnNames: {
Expand Down
1 change: 1 addition & 0 deletions client/src/app/pages/dependencies/dependencies.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export const DependencyAppsTable: React.FC<IDependencyAppsTableProps> = ({
const deserializedFilterValues = deserializeFilterUrlParams({ filters });

const tableControlState = useTableControlState({
tableName: "dependency-apps-table",
persistTo: "urlParams",
persistenceKeyPrefix: TablePersistenceKeyPrefix.dependencyApplications,
columnNames: {
Expand Down
1 change: 1 addition & 0 deletions client/src/app/pages/external/jira/trackers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export const JiraTrackers: React.FC = () => {
);

const tableControls = useLocalTableControls({
tableName: "jira-Tracker-table",
idProperty: "name",
items: trackers,
columnNames: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export const AffectedApplications: React.FC = () => {
"Active rule";

const tableControlState = useTableControlState({
tableName: "affected-applications-table",
persistTo: "urlParams",
persistenceKeyPrefix: TablePersistenceKeyPrefix.issuesAffectedApps,
columnNames: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
1 change: 1 addition & 0 deletions client/src/app/pages/issues/issues-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export const IssuesTable: React.FC<IIssuesTableProps> = ({ mode }) => {
useSharedAffectedApplicationFilterCategories();

const tableControlState = useTableControlState({
tableName: "issues-table",
persistTo: "urlParams",
persistenceKeyPrefix: TablePersistenceKeyPrefix.issues,
columnNames: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export const ManageApplicationsForm: React.FC<ManageApplicationsFormProps> = ({
);

const tableControls = useLocalTableControls({
tableName: "manage-applications-table",
idProperty: "name",
items: availableApplications,
columnNames: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const WaveStakeholdersTable: React.FC<IWaveStakeholdersTableProps> = ({
migrationWave,
}) => {
const tableControls = useLocalTableControls({
tableName: "wave-stakeholders-table",
idProperty: "name",
items: migrationWave.allStakeholders,
columnNames: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const WaveApplicationsTable: React.FC<IWaveApplicationsTableProps> = ({
const { tickets } = useFetchTickets();

const tableControls = useLocalTableControls({
tableName: "wave-applications-table",
idProperty: "name",
items: migrationWave.fullApplications,
columnNames: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export const WaveStatusTable: React.FC<IWaveStatusTableProps> = ({
const { mutate: deleteTicket } = useDeleteTicketMutation();

const tableControls = useLocalTableControls({
tableName: "wave-applications-table",
idProperty: "name",
items: migrationWave.fullApplications,
columnNames: {
Expand Down
1 change: 1 addition & 0 deletions client/src/app/pages/migration-waves/migration-waves.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ export const MigrationWaves: React.FC = () => {
};

const tableControls = useLocalTableControls({
tableName: "migration-waves-table",
idProperty: "id",
items: migrationWaves,
columnNames: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const AdoptionCandidateTable: React.FC<AdoptionCandidateTableProps> = () => {
}, [allApplications, reviews]);

const tableControls = useLocalTableControls({
tableName: "adoption-candidate-table",
idProperty: "id",
items: applicationsWithReviews || [],
columnNames: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ export const IdentifiedRisksTable: React.FC<IIdentifiedRisksTableProps> = ({
});

const tableControls = useLocalTableControls({
tableName: "identified-risks-table",
idProperty: "questionId",
items: tableData || [],
columnNames: {
Expand Down

0 comments on commit fee201f

Please sign in to comment.