neighbour-hoods / timetracking-applet

1 stars 0 forks source link

Time `Units` don't load correctly, causing error with time input (WORKAROUND) #13

Open pospi opened 1 year ago

pospi commented 1 year ago

You will hit this upon attempting to run the app locally due to unfinished standardisation work in the VF protocol regarding the querying and retrieval of Units.

Until then, the below can be used to overwrite ui/node_modules/@valueflows/vf-graphql-holochain/queries/unit.js after NPM modules have been installed:

/**
 * Top-level queries relating to Unit
 *
 * @package: HoloREA
 * @since:   2019-09-12
 */
import { mapZomeFn } from '../connection.js';
export default (dnaConfig, conductorUri) => {
    const readOne = mapZomeFn(dnaConfig, conductorUri, 'specification', 'unit', 'get_unit');
  const readOneBySymbol = mapZomeFn(dnaConfig, conductorUri, 'specification', 'unit', 'get_unit_by_symbol')
    const readAll = mapZomeFn(dnaConfig, conductorUri, 'specification', 'unit_index', 'read_all_units');
    return {
        unit: async (root, args) => {
          let res
          try {
            res = await readOne(args)
          } catch (e) {
            try {
              // attempt GUID-based read of Unit based on symbol
              res = await readOneBySymbol({ symbol: args.id })
            } catch (_retried) {
              // throw original (UUID-based) read error if both fail
              throw e
            }
          }
          return res.unit
        },
        units: async (root, args) => {
            return await readAll(args);
        },
    };
};

You will still see conductor errors RE deserialisation of invalid API parameters, but they are now non-fatal as the Units will fallback to being retrieved by symbol.

See also https://github.com/neighbour-hoods/timetracking-applet/blob/39a67feddf520ebd58c8990491c5dbc354fa4092/ui/src/components/valueflows/ProvideTimeUnits/queries.ts#L20 for context.

pospi commented 1 year ago

There is now a workaround for this implemented as a postinstall script in workaround-vf-units.patch.cjs that should be removed when this is resolved upstream.