function populateVisibleContentPreferenceOptions()

in src/components/search/SearchResults.tsx [92:145]


  function populateVisibleContentPreferenceOptions() {
    let tempColumnList: {
      id: any;
      label: any;
      editable: boolean;
    }[] = [];
    const allColumnNameSet = new Set();

    tableItems.forEach((tableItem) => {
      Object.keys(tableItem).forEach((tableItemKey) => {
        allColumnNameSet.add(tableItemKey);
      });
    });

    allColumnNameSet.forEach((columnName: any) => {
      let editable = true;
      if (columnName === "id" || columnName === "resourceType") {
        editable = false;
      }
      tempColumnList.push({
        id: columnName,
        label: columnName,
        editable: editable,
      });
    });

    // Move column id to the be the first column in the table
    const idColumn = tempColumnList.find((column) => {
      return column.id === "id";
    });
    const resourceTypeColumn = tempColumnList.find((column) => {
      return column.id === "resourceType";
    });
    tempColumnList = tempColumnList.filter((column) => {
      return column.id !== "id" && column.id !== "resourceType";
    });
    if (idColumn) {
      tempColumnList.unshift(idColumn);
    }
    if (resourceTypeColumn) {
      tempColumnList.unshift(resourceTypeColumn);
    }

    if (!previewPaneToggle) {
      setPreferences({
        visibleContent: Array.from(allColumnNameSet) as string[],
      });
    } else {
      setPreferences({
        visibleContent: ["id", "resourceType"],
      });
    }
    setVisibleContentPreferenceOptions(tempColumnList);
  }